Created
May 20, 2016 11:54
-
-
Save reddec/2d35054d31a3bc067d752989f880c89e to your computer and use it in GitHub Desktop.
vimrc for C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Restore cursor position, window position, and last search after running a | |
" command. | |
function! Preserve(command) | |
" Save the last search. | |
let search = @/ | |
" Save the current cursor position. | |
let cursor_position = getpos('.') | |
" Save the current window position. | |
normal! H | |
let window_position = getpos('.') | |
call setpos('.', cursor_position) | |
" Execute the command. | |
execute a:command | |
" Restore the last search. | |
let @/ = search | |
" Restore the previous window position. | |
call setpos('.', window_position) | |
normal! zt | |
" Restore the previous cursor position. | |
call setpos('.', cursor_position) | |
endfunction | |
" Re-indent the whole buffer. | |
function! Indent() | |
call Preserve('normal gg=G') | |
endfunction | |
function! Reformat() | |
call Preserve('normal gggqG') | |
endfunction | |
set tabstop=4 | |
set softtabstop=4 | |
set shiftwidth=4 | |
set noexpandtab | |
set colorcolumn=110 | |
set autoread | |
set formatprg=clang-format-3.6\ -style=Google | |
set makeprg=make\ -j2 | |
highlight ColorColumn ctermbg=darkgray | |
augroup project | |
autocmd! | |
autocmd BufWritePre *.h,*.c call Reformat() | |
autocmd BufRead,BufNewFile *.h,*.c set filetype=c.doxygen | |
augroup END |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment