-
Notifications
You must be signed in to change notification settings - Fork 1
/
vimrc
executable file
·173 lines (138 loc) · 7.37 KB
/
vimrc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
" -------------------------------------------------------------------------------------------------
" GENERAL SETTINGS
" -------------------------------------------------------------------------------------------------
filetype plugin indent on " enable filetype detection
set autoindent " auto indent when inserting a new line
set autoread " reload a file when it is changed outside vim
set autowriteall " auto save files on certain events
set backspace=indent,eol,start " allow backspacing over auto indent, line breaks, insert action
set cinoptions+=(0 " align function arguments on newlines with the first argument
set clipboard=exclude:.* " don't try to connect to X server
set complete-=i " don't scan include files during insert mode auto completion
set completeopt=longest,menuone " better insert mode auto completion
set cscopequickfix=s-,c-,a- " enable cscope results in the quickfix window
set cscopetag " use cscope by default for tag jumps
set expandtab " tabs are spaces
set formatoptions+=j " delete comment character when joining lines
set hlsearch " highlight matches
set ignorecase " ignore case when searching lowercase
set incsearch " search as characters are entered
set list " show trailing whitespace
set listchars=tab:>\ ,trail:- " show tabs and trailing white space when list is enabled
set mouse=a " enable mouse support
set noswapfile " disable swap files
set notimeout " never timeout on mappings
set nowrap " don't wrap
set ruler " show line and column number in command line
set shiftround " round to multiple of shift width when adjusting indentation
set shiftwidth=4 " number of spaces for each step of auto indent
set smartcase " don't ignore case when inserting uppercase characters in search
set softtabstop=4 " number of spaces per tab when editing
set spellfile=~/.vim/en.utf-8.add " add spelling dictionary
set tabstop=4 " number of visual spaces per tab
set ttimeout " timeout on key codes
set ttimeoutlen=200 " timeout length on key codes
set ttymouse=xterm2 " enable mouse dragging
set undodir=~/.vim/undo// " undo history directory
set undofile " persistent undo history
set updatetime=100 " milliseconds VIM will wait to trigger the CursorHold event
set visualbell " use visual bell instead of beeping
set wildmenu " visual auto complete for command menu
set wildmode=longest,full " first complete to the longest match, then to the first full one
syntax on " enable syntax highlighting
" open man pages in vim with :Man
runtime ftplugin/man.vim
" auto load cscope database
if filereadable("cscope.out")
silent! cscope add cscope.out
endif
" -------------------------------------------------------------------------------------------------
" AUTO COMMANDS
" -------------------------------------------------------------------------------------------------
augroup custom_autocommands
" clear all auto commands in this group
autocmd!
" check if the file has changed outside of Vim when the cursor has moved
autocmd CursorHold * silent! checktime
" enable spell checking by default for git commit files
autocmd Filetype gitcommit setlocal spell
" enable spell checking and show hidden chars for markdown files by default
autocmd Filetype markdown setlocal spell list textwidth=100
" don't show hidden characters in man pages
autocmd Filetype man setlocal nolist
" open quickfix and git commit window always at the bottom and with the full width of the screen
autocmd FileType qf,gitcommit wincmd J
" use tabs, the go tool and format files on save for go
autocmd Filetype go setlocal nolist noexpandtab
autocmd BufWritePost *.go silent! execute "!gofmt -s -w <afile>" | redraw!
autocmd BufWritePost *.go silent! execute "!goimports -w <afile>" | redraw!
" yaml files
autocmd FileType yaml setlocal tabstop=2 softtabstop=2 shiftwidth=2 expandtab
" open quickfix/location list when it is populated
autocmd QuickFixCmdPost [^l]* cwindow
autocmd QuickFixCmdPost l* lwindow
autocmd VimEnter * cwindow
augroup END
" -------------------------------------------------------------------------------------------------
" ABBREVIATIONS
" -------------------------------------------------------------------------------------------------
" insert a C style to do comment
iabbrev TODO /* TODO dboucken: */<left><left><left>
" insert a C style DO_NOT_COMMIT comment
iabbrev DO /* DO_NOT_COMMIT: */<left><left><left>
" -------------------------------------------------------------------------------------------------
" CUSTOM KEY MAPPINGS
" -------------------------------------------------------------------------------------------------
" remap escape in insert mode
inoremap jj <Esc>
" remap : in normal mode
nnoremap ; :
" auto expand curly brackets in insert mode
inoremap {<cr> {<cr>}<Esc>O
" keep the found words in the middle of screen when jumping to the next/previous
nnoremap n nzzzv
nnoremap N Nzzzv
" -------------------------------------------------------------------------------------------------
" LEADER KEY MAPPINGS
" -------------------------------------------------------------------------------------------------
" use space as leader
let mapleader=" "
" remap <c-w> to something easier
nnoremap <leader>w <c-w>
" quickly open vimrc
nnoremap <leader>ev :vertical split $MYVIMRC<cr>
" delete trailing white space on a line
nnoremap <leader>dd :s/\s\+$//e<cr>
" open/close the quickfix list window
nnoremap <silent> <leader>qo :copen<cr>
nnoremap <silent> <leader>qc :cclose<cr>
" find cscope symbol under the cursor
nnoremap <leader>gs :cscope find s <c-r><c-w><cr><cr>
" find callers of the function under the cursor
nnoremap <leader>gc :cscope find c <c-r><c-w><cr><cr>
" grep the word under the cursor recursively, don't return to be able to pass options and dirs
nnoremap <leader>gw :grep! -rw <c-r><c-w>
" grep the word under the cursor recursively in the directory of the current file
nnoremap <leader>gd :grep! -rw <c-r><c-w> %:p:h<cr>
" run the macro in register q
nnoremap <leader><leader> @q
" allow saving of files as sudo when I forgot to start vim using sudo.
cnoremap w!! w !sudo tee > /dev/null %
" open files recursively in the working directory
nnoremap <leader>ee :e **/*
" clear search highlight
nnoremap <leader>hl :nohlsearch<cr>
" replace the word under the cursor with the last yanked (not deleted) text
nnoremap <leader>pp ciw<C-r>0<ESC>
" preview a tag and close the preview window
nnoremap <leader>pt :ptag <c-r><c-w><cr>
nnoremap <leader>pc :pclose<cr>
" -------------------------------------------------------------------------------------------------
" PLUGINS
" -------------------------------------------------------------------------------------------------
call plug#begin()
Plug 'airblade/vim-gitgutter'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-unimpaired'
call plug#end()