diff --git a/vimrc b/vimrc index f7cb290ec8f78ebc01947cc4d17e7ca912bd114e..4c6c53155fec0ebc3923fb9b418c17f62fb8003c 100644 --- a/vimrc +++ b/vimrc @@ -23,7 +23,7 @@ autocmd Filetype nix,html,javascript,css setlocal expandtab tabstop=2 shiftwidth=2 " Commenting blocks of code. " https://stackoverflow.com/a/1676672 -augroup commenting_blocks_of_code +augroup CodeCommenting autocmd! autocmd FileType c,cpp,go,zig let b:comment_leader = '// ' autocmd FileType sh,ruby,python let b:comment_leader = '# ' @@ -34,12 +34,9 @@ augroup END noremap cc :silent s/^/=escape(b:comment_leader,'\/')/:nohlsearch noremap cu :silent s/^\(\s*\)\V=escape(b:comment_leader,'\/')//e:nohlsearch -" Function to auto format source code files. -function! Format() - if &filetype == 'c' | write | call system('clang-format -i '.expand('%')) | edit! | endif - if &filetype == 'go' | write | call system('go fmt '.expand('%')) | edit! | endif -endfunction -command! Format call Format() +" External auto-format programs. +autocmd FileType c,cpp setlocal formatprg=clang-format +autocmd FileType go setlocal formatprg=gofmt " FZF integration. function! FZF()