diff options
Diffstat (limited to 'vim/vimrcs/codecmd.vim')
-rw-r--r-- | vim/vimrcs/codecmd.vim | 162 |
1 files changed, 78 insertions, 84 deletions
diff --git a/vim/vimrcs/codecmd.vim b/vim/vimrcs/codecmd.vim index 82b0bfe..cbe08bf 100644 --- a/vim/vimrcs/codecmd.vim +++ b/vim/vimrcs/codecmd.vim | |||
@@ -1,23 +1,17 @@ | |||
1 | set expandtab "设置tab键替换为tabstop规定的空格数 | 1 | set expandtab " 设置tab键替换为tabstop规定的空格数 |
2 | set tabstop=4 | 2 | set tabstop=4 |
3 | set shiftwidth=4 "设置tab的间隔 | 3 | set shiftwidth=4 " 设置tab的间隔 |
4 | set softtabstop=4 | 4 | set softtabstop=4 |
5 | autocmd FileType asm,nasm,vim set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab | 5 | autocmd FileType asm,nasm,vim,sh,makefile set tabstop=4 softtabstop=4 shiftwidth=4 noexpandtab |
6 | 6 | ||
7 | set showmatch "在输入括号时光标会短暂地跳到与之相匹配的括号处 | 7 | set showmatch " 在输入括号时光标会短暂地跳到与之相匹配的括号处 |
8 | set wrap "设置自动折行 | 8 | set wrap " 设置自动折行 |
9 | set textwidth=500 "设置自动换行的长度 | 9 | set textwidth=500 " 设置自动换行的长度 |
10 | set lbr | 10 | set lbr |
11 | "set autoindent "设置自动缩进 | 11 | set foldmethod=syntax " 设置按语法折叠代码 |
12 | "set smartindent "设置智能缩进 | 12 | set nofoldenable " 在打开文件时不要折叠 |
13 | "set foldmethod=indent "设置按缩进折叠代码 | ||
14 | set foldmethod=syntax "设置按语法折叠代码 | ||
15 | "set foldlevel=99 "折叠层级 | ||
16 | "在打开文件时不要折叠 | ||
17 | set nofoldenable | ||
18 | 13 | ||
19 | 14 | " 自动补全配置 | |
20 | "自动补全配置 | ||
21 | autocmd FileType python set omnifunc=pythoncomplete#Complete | 15 | autocmd FileType python set omnifunc=pythoncomplete#Complete |
22 | autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS | 16 | autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS |
23 | autocmd FileType html set omnifunc=htmlcomplete#CompleteTags | 17 | autocmd FileType html set omnifunc=htmlcomplete#CompleteTags |
@@ -25,92 +19,92 @@ autocmd FileType css set omnifunc=csscomplete#CompleteCSS | |||
25 | autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags | 19 | autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags |
26 | autocmd FileType php set omnifunc=phpcomplete#CompletePHP | 20 | autocmd FileType php set omnifunc=phpcomplete#CompletePHP |
27 | autocmd FileType c set omnifunc=ccomplete#Complete | 21 | autocmd FileType c set omnifunc=ccomplete#Complete |
22 | |||
28 | " 要求格式化之后的代码不要移动光标,并且不要删除换行符和空行,保留原来的视图 | 23 | " 要求格式化之后的代码不要移动光标,并且不要删除换行符和空行,保留原来的视图 |
29 | autocmd BufReadPost,BufWritePre *.html,*.vim normal! g1G=G`"z<CR> | 24 | autocmd BufReadPost,BufWritePre *.html,*.vim normal! g1G=G`"z<CR> |
30 | " 在保存时自动使用clang-format格式化代码 | 25 | " 在保存时自动使用clang-format格式化代码 |
31 | augroup FormatAutocmd | 26 | augroup FormatAutocmd |
32 | autocmd! | 27 | autocmd! |
33 | autocmd BufWritePre *.c,*.cpp :normal! ggVG | 28 | autocmd BufWritePre *.c,*.cpp,*.h :normal! ggVG |
34 | autocmd BufWritePre *.c,*.cpp :let save_cursor = getpos(".") | 29 | autocmd BufWritePre *.c,*.cpp,*.h :let save_cursor = getpos(".") |
35 | autocmd BufWritePre *.c,*.cpp :ClangFormat | 30 | autocmd BufWritePre *.c,*.cpp,*.h :ClangFormat |
36 | autocmd BufWritePost *.c,*.cpp :call setpos('.', save_cursor) | 31 | autocmd BufWritePost *.c,*.cpp,*.h :call setpos('.', save_cursor) |
37 | augroup END | 32 | augroup END |
38 | " 定义ClangFormat命令 | 33 | " 定义ClangFormat命令 |
39 | command! -nargs=0 ClangFormat :silent %!clang-format -style="{IndentWidth: 4}" | 34 | command! -nargs=0 ClangFormat :silent %!clang-format -style="{IndentWidth: 4}" |
40 | " 映射gg=G到ClangFormat | 35 | " 映射gg=G到ClangFormat |
41 | autocmd FileType c,cpp nnoremap <buffer> gg=G :ClangFormat<CR> | 36 | autocmd FileType c,h,cpp,hpp,cc nnoremap <buffer> gg=G :ClangFormat<CR> |
37 | " cmake使用cmake-format格式化 | ||
38 | autocmd FileType cmake nnoremap <buffer> gg=G :silent !cmake-format % -i<CR><CR>L | ||
42 | 39 | ||
43 | "新建.c,.h,.sh,.java文件,自动插入文件头 | 40 | " 新建.c/.cpp/.sh/.py文件,自动插入文件头 |
44 | autocmd BufNewFile *.cpp,*.[ch],*.sh exec ":call SetTitle()" | 41 | autocmd BufNewFile *.cpp,*.[ch],*.sh exec ":call SetTitle()" |
45 | func SetTitle() | 42 | func SetTitle() |
46 | if &filetype == 'sh' | 43 | if &filetype == 'sh' |
47 | call setline(1,"#!/bin/bash") | 44 | call setline(1,"#!/bin/bash") |
48 | call append(line("."), "" ) | 45 | call append(line("."), "" ) |
49 | call append(line(".")+1, "\##########################################################################" ) | 46 | call append(line(".")+1, "\##########################################################################" ) |
50 | call append(line(".")+2, "\# File Name : ".expand("%")) | 47 | call append(line(".")+2, "\# File Name : ".expand("%")) |
51 | call append(line(".")+3, "\# Encoding : utf-8") | 48 | call append(line(".")+3, "\# Encoding : utf-8") |
52 | call append(line(".")+4, "\# Author : We-unite") | 49 | call append(line(".")+4, "\# Author : We-unite") |
53 | call append(line(".")+5, "\# Email : weunite1848@gmail.com") | 50 | call append(line(".")+5, "\# Email : weunite1848@gmail.com") |
54 | call append(line(".")+6, "\# Created Time : ".strftime("%Y-%m-%d",localtime())) | 51 | call append(line(".")+6, "\# Created Time : ".strftime("%Y-%m-%d %H:%M:%S",localtime())) |
55 | call append(line(".")+7, "\##########################################################################" ) | 52 | call append(line(".")+7, "\##########################################################################" ) |
56 | call append(line(".")+8, "") | 53 | call append(line(".")+8, "") |
57 | elseif &filetype =='py' | 54 | elseif &filetype =='py' |
58 | call setline(1,"#!/usr/bin/env python") | 55 | call setline(1,"#!/usr/bin/env python") |
59 | call append(line("."), "" ) | 56 | call append(line("."), "" ) |
60 | call append(line(".")+1, "\##########################################################################" ) | 57 | call append(line(".")+1, "\##########################################################################" ) |
61 | call append(line(".")+2, "\# File Name : ".expand("%")) | 58 | call append(line(".")+2, "\# File Name : ".expand("%")) |
62 | call append(line(".")+3, "\# Encoding : utf-8") | 59 | call append(line(".")+3, "\# Encoding : utf-8") |
63 | call append(line(".")+4, "\# Author : We-unite") | 60 | call append(line(".")+4, "\# Author : We-unite") |
64 | call append(line(".")+5, "\# Email : weunite1848@gmail.com") | 61 | call append(line(".")+5, "\# Email : weunite1848@gmail.com") |
65 | call append(line(".")+6, "\# Created Time : ".strftime("%Y-%m-%d",localtime())) | 62 | call append(line(".")+6, "\# Created Time : ".strftime("%Y-%m-%d %H:%M:%S",localtime())) |
66 | call append(line(".")+7, "\##########################################################################" ) | 63 | call append(line(".")+7, "\##########################################################################" ) |
67 | call append(line(".")+8, "") | 64 | call append(line(".")+8, "") |
68 | else | 65 | else |
69 | call setline(1, "/*************************************************************************") | 66 | call setline(1, "/*************************************************************************") |
70 | call append(line("."), " > File Name : ".expand("%")) | 67 | call append(line("."), " > File Name : ".expand("%")) |
71 | call append(line(".")+1, " > Encoding : utf-8") | 68 | call append(line(".")+1, " > Encoding : utf-8") |
72 | call append(line(".")+2, " > Author : We-unite") | 69 | call append(line(".")+2, " > Author : We-unite") |
73 | call append(line(".")+3, " > Email : weunite1848@gmail.com ") | 70 | call append(line(".")+3, " > Email : weunite1848@gmail.com ") |
74 | call append(line(".")+4, " > Created Time : ".strftime("%Y-%m-%d %H:%M:%S",localtime())) | 71 | call append(line(".")+4, " > Created Time : ".strftime("%Y-%m-%d %H:%M:%S",localtime())) |
75 | call append(line(".")+5, " ************************************************************************/") | 72 | call append(line(".")+5, " ************************************************************************/") |
76 | call append(line(".")+6, "") | 73 | call append(line(".")+6, "") |
77 | if &filetype == 'cpp' | 74 | if &filetype == 'cpp' |
78 | call append(line(".")+7, "#include <iostream>") | 75 | call append(line(".")+7, "#include <iostream>") |
79 | call append(line(".")+8, "using namespace std;") | 76 | call append(line(".")+8, "using namespace std;") |
80 | call append(line(".")+9, "") | 77 | call append(line(".")+9, "") |
81 | elseif &filetype == 'c' | 78 | elseif &filetype == 'c' |
82 | call append(line(".")+7, "#include <stdio.h>") | 79 | call append(line(".")+7, "#include <stdio.h>") |
83 | call append(line(".")+8, "#include <stdlib.h>") | 80 | call append(line(".")+8, "#include <stdlib.h>") |
84 | call append(line(".")+9, "") | 81 | call append(line(".")+9, "") |
85 | endif | 82 | endif |
86 | endif | 83 | endif |
87 | " 光标移动到文件末尾 | 84 | " 光标移动到文件末尾 |
88 | normal G | 85 | normal G |
89 | endfunc | 86 | endfunc |
90 | 87 | ||
91 | "C,C++编译运行 | 88 | " C,C++编译运行 |
92 | map <leader>r :call CompileRunGcc()<CR> | 89 | map <leader>r :call CompileRunGcc()<CR> |
93 | func CompileRunGcc() | 90 | func CompileRunGcc() |
94 | exec "w" | 91 | exec "w" |
95 | if &filetype == 'c' | 92 | if &filetype == 'c' |
96 | exec "!gcc -g -o %< %" | 93 | exec "!gcc -g -o %< %" |
97 | exec "! ./%<" | 94 | exec "! ./%<" |
98 | elseif &filetype == 'cpp' | 95 | elseif &filetype == 'cpp' |
99 | exec "!g++ -g -o %< %" | 96 | exec "!g++ -g -o %< %" |
100 | exec "! ./%<" | 97 | exec "! ./%<" |
101 | "elseif &filetype == 'java' | 98 | elseif &filetype == 'sh' |
102 | " exec "!javac %" | 99 | :!./% |
103 | " exec "!java %<" | 100 | elseif &filetype == 'python' |
104 | elseif &filetype == 'sh' | 101 | exec "!python %" |
105 | :!./% | 102 | endif |
106 | elseif &filetype == 'python' | ||
107 | exec "!python %" | ||
108 | endif | ||
109 | endfunc | 103 | endfunc |
110 | 104 | ||
111 | "C,C++调试 | 105 | " C,C++调试 |
112 | map <leader>d :call RunGdb()<CR> | 106 | map <leader>d :call RunGdb()<CR> |
113 | func RunGdb() | 107 | func RunGdb() |
114 | exec "w" | 108 | exec "w" |
115 | exec "!gdb ./%<" | 109 | exec "!gdb ./%<" |
116 | endfunc | 110 | endfunc |