From b76eb4d5d475ca70b066f8a9cc094b05f424c1cf Mon Sep 17 00:00:00 2001 From: Mitja Felicijan Date: Thu, 20 Jun 2024 05:16:06 +0200 Subject: Simplified code formatting --- vimrc | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) (limited to 'vimrc') diff --git a/vimrc b/vimrc index f7cb290..4c6c531 100644 --- a/vimrc +++ b/vimrc @@ -23,7 +23,7 @@ autocmd Filetype nix,html,javascript,css setlocal expandtab tabstop=2 shiftwidth " 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() -- cgit v1.2.3