summaryrefslogtreecommitdiffstats
path: root/vimrcs/codecmd.vim
diff options
context:
space:
mode:
Diffstat (limited to 'vimrcs/codecmd.vim')
-rw-r--r--vimrcs/codecmd.vim12
1 files changed, 7 insertions, 5 deletions
diff --git a/vimrcs/codecmd.vim b/vimrcs/codecmd.vim
index 179e68e..8ca51f6 100644
--- a/vimrcs/codecmd.vim
+++ b/vimrcs/codecmd.vim
@@ -2,7 +2,7 @@ set expandtab " 设置tab键替换为tabstop规定的空格数
2set tabstop=4 " 编辑时tab键占用的空格数 2set tabstop=4 " 编辑时tab键占用的空格数
3set shiftwidth=4 " 设置tab的间隔(格式化时) 3set shiftwidth=4 " 设置tab的间隔(格式化时)
4set softtabstop=4 " 设置退格键退格的空格数,让vim把连续的空格当作一个tab 4set softtabstop=4 " 设置退格键退格的空格数,让vim把连续的空格当作一个tab
5autocmd FileType asm,nasm,vim,sh,makefile set tabstop=4 softtabstop=4 shiftwidth=4 noexpandtab 5autocmd FileType *asm,vim,*sh,makefile set tabstop=4 softtabstop=4 shiftwidth=4 noexpandtab
6 6
7set showmatch " 在输入括号时光标会短暂地跳到与之相匹配的括号处 7set showmatch " 在输入括号时光标会短暂地跳到与之相匹配的括号处
8set nowrap " 设置自动折行 8set nowrap " 设置自动折行
@@ -31,7 +31,6 @@ function! PreserveCursorAndFormat()
31 call winrestview(l:save_view) 31 call winrestview(l:save_view)
32endfunction 32endfunction
33 33
34
35command! -nargs=0 ClangFormat :call ClangFormat() 34command! -nargs=0 ClangFormat :call ClangFormat()
36autocmd FileType c,h,cpp,hpp,cc nnoremap <buffer> gg=G :ClangFormat<CR> 35autocmd FileType c,h,cpp,hpp,cc nnoremap <buffer> gg=G :ClangFormat<CR>
37" 定义ClangFormat命令: 36" 定义ClangFormat命令:
@@ -39,10 +38,13 @@ autocmd FileType c,h,cpp,hpp,cc nnoremap <buffer> gg=G :ClangFormat<CR>
39" 否则使用默认规则,缩进为4 38" 否则使用默认规则,缩进为4
40function! ClangFormat() 39function! ClangFormat()
41 let clang_format = "clang-format" 40 let clang_format = "clang-format"
42 " find .clang-format file from cur path upward 41 if !executable(clang_format)
43 let clang_format_file = findfile(".clang-format", ".;") 42 normal gg=G
43 return
44 endif
45 let clang_format_file = findfile(".clang-format", expand('%:p:h') . ";")
44 if clang_format_file != "" 46 if clang_format_file != ""
45 let clang_format = clang_format . " -style=file" 47 let clang_format = clang_format . " -style=file:" . clang_format_file
46 else 48 else
47 let clang_format = clang_format . " -style='{IndentWidth: 4}'" 49 let clang_format = clang_format . " -style='{IndentWidth: 4}'"
48 endif 50 endif