aboutsummaryrefslogtreecommitdiffstats
path: root/vim/vimrcs/codecmd.vim
diff options
context:
space:
mode:
Diffstat (limited to 'vim/vimrcs/codecmd.vim')
-rw-r--r--vim/vimrcs/codecmd.vim162
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 @@
1set expandtab "设置tab键替换为tabstop规定的空格数 1set expandtab " 设置tab键替换为tabstop规定的空格数
2set tabstop=4 2set tabstop=4
3set shiftwidth=4 "设置tab的间隔 3set shiftwidth=4 " 设置tab的间隔
4set softtabstop=4 4set softtabstop=4
5autocmd FileType asm,nasm,vim set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab 5autocmd FileType asm,nasm,vim,sh,makefile set tabstop=4 softtabstop=4 shiftwidth=4 noexpandtab
6 6
7set showmatch "在输入括号时光标会短暂地跳到与之相匹配的括号处 7set showmatch " 在输入括号时光标会短暂地跳到与之相匹配的括号处
8set wrap "设置自动折行 8set wrap " 设置自动折行
9set textwidth=500 "设置自动换行的长度 9set textwidth=500 " 设置自动换行的长度
10set lbr 10set lbr
11"set autoindent "设置自动缩进 11set foldmethod=syntax " 设置按语法折叠代码
12"set smartindent "设置智能缩进 12set nofoldenable " 在打开文件时不要折叠
13"set foldmethod=indent "设置按缩进折叠代码
14set foldmethod=syntax "设置按语法折叠代码
15"set foldlevel=99 "折叠层级
16"在打开文件时不要折叠
17set nofoldenable
18 13
19 14" 自动补全配置
20"自动补全配置
21autocmd FileType python set omnifunc=pythoncomplete#Complete 15autocmd FileType python set omnifunc=pythoncomplete#Complete
22autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS 16autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
23autocmd FileType html set omnifunc=htmlcomplete#CompleteTags 17autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
@@ -25,92 +19,92 @@ autocmd FileType css set omnifunc=csscomplete#CompleteCSS
25autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags 19autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
26autocmd FileType php set omnifunc=phpcomplete#CompletePHP 20autocmd FileType php set omnifunc=phpcomplete#CompletePHP
27autocmd FileType c set omnifunc=ccomplete#Complete 21autocmd FileType c set omnifunc=ccomplete#Complete
22
28" 要求格式化之后的代码不要移动光标,并且不要删除换行符和空行,保留原来的视图 23" 要求格式化之后的代码不要移动光标,并且不要删除换行符和空行,保留原来的视图
29autocmd BufReadPost,BufWritePre *.html,*.vim normal! g1G=G`"z<CR> 24autocmd BufReadPost,BufWritePre *.html,*.vim normal! g1G=G`"z<CR>
30" 在保存时自动使用clang-format格式化代码 25" 在保存时自动使用clang-format格式化代码
31augroup FormatAutocmd 26augroup 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)
37augroup END 32augroup END
38" 定义ClangFormat命令 33" 定义ClangFormat命令
39command! -nargs=0 ClangFormat :silent %!clang-format -style="{IndentWidth: 4}" 34command! -nargs=0 ClangFormat :silent %!clang-format -style="{IndentWidth: 4}"
40" 映射gg=G到ClangFormat 35" 映射gg=G到ClangFormat
41autocmd FileType c,cpp nnoremap <buffer> gg=G :ClangFormat<CR> 36autocmd FileType c,h,cpp,hpp,cc nnoremap <buffer> gg=G :ClangFormat<CR>
37" cmake使用cmake-format格式化
38autocmd 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文件,自动插入文件头
44autocmd BufNewFile *.cpp,*.[ch],*.sh exec ":call SetTitle()" 41autocmd BufNewFile *.cpp,*.[ch],*.sh exec ":call SetTitle()"
45func SetTitle() 42func 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
89endfunc 86endfunc
90 87
91"C,C++编译运行 88" C,C++编译运行
92map <leader>r :call CompileRunGcc()<CR> 89map <leader>r :call CompileRunGcc()<CR>
93func CompileRunGcc() 90func 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
109endfunc 103endfunc
110 104
111"C,C++调试 105" C,C++调试
112map <leader>d :call RunGdb()<CR> 106map <leader>d :call RunGdb()<CR>
113func RunGdb() 107func RunGdb()
114 exec "w" 108 exec "w"
115 exec "!gdb ./%<" 109 exec "!gdb ./%<"
116endfunc 110endfunc