-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.vimrc
331 lines (271 loc) · 10.9 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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
" Begin .vimrc
set nocompatible
" Required Vundle setup
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
Plugin 'vim-scripts/OmniCppComplete.git'
Plugin 'vim-scripts/argtextobj.vim'
Plugin 'ctrlpvim/ctrlp.vim'
Plugin 'ervandew/supertab.git'
Plugin 'majutsushi/tagbar.git'
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
Plugin 'altercation/vim-colors-solarized.git'
Plugin 'airblade/vim-gitgutter.git'
Plugin 'terryma/vim-expand-region'
Plugin 'tpope/vim-commentary'
Plugin 'tpope/vim-fugitive.git'
Plugin 'tpope/vim-repeat.git'
Plugin 'tpope/vim-sensible.git'
Plugin 'tpope/vim-sleuth.git'
Plugin 'tpope/vim-surround.git'
Plugin 'tpope/vim-unimpaired.git'
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
set bs=2
set background=dark
set wrapmargin=8
set ruler
set hidden
" Look down the parent folders for tag files
set tags=tags,../tags,../../tags,../../../tags
" Inspired by: http://nvie.com/posts/how-i-boosted-my-vim/
set nowrap " don't wrap lines
set backspace=indent,eol,start
" allow backspacing over everything in insert mode
set autoindent " always set autoindenting on
set copyindent " copy the previous indentation on autoindenting
set number " always show line numbers
set shiftwidth=4 " number of spaces to use for autoindenting
set shiftround " use multiple of shiftwidth when indenting with '<' and '>'
set showmatch " set show matching parenthesis
set matchtime=3 " (for showmatch)
set ignorecase " ignore case when searching
set smartcase " ignore case if search pattern is all lowercase,
" case-sensitive otherwise
set hlsearch " highlight search terms
set incsearch " show search matches as you type
set wildmenu " nicer tab completions
set history=1000 " remember more commands and search history
set undolevels=1000 " use many muchos levels of undo
set wildignore=*.swp,*.bak,*.pyc,*.class
set title " change the terminal's title
set visualbell " don't beep
set noerrorbells " don't beep
set tildeop " wait for the motion command after '~' case conversion operator
set nobackup
set noswapfile
" Note: vim-sleuth plugin may override these (https://github.com/tpope/vim-sleuth)
set tabstop=4 " a tab is four spaces
set smarttab " insert tabs on the start of a line according to shiftwidth, not tabstop
set expandtab " Don't insert tabs, use spaces
set gdefault " Ussume 'g' flag by default for :s
" Setting leader key, obviously
" The idea to use space is from: https://sheerun.net/2014/03/21/how-to-boost-your-vim-productivity/
let mapleader="\<Space>"
"set clipboard=unnamed " Yank into system clipboard (this allows using 'Shift-Ins' to paste in insert mode ;)
" Togling smart indent when pasting code. Start in 'set paste' as a default.
"set paste
set pastetoggle=<F10>
" Omni completion provides smart autocompletion for programs. To use omni completion, type <C-X><C-O> while open in Insert mode
" http://vim.wikia.com/wiki/Omni_completion
set omnifunc=syntaxcomplete#Complete
" Save buffer before doing other stuff (e.g., running external commands)
set autowrite
" Detect external buffer modification and autoupdate the file
set autoread
" Clear current search highlight -- a bit annoying, may be I should adjust keys timeout.
"nnoremap <esc> :noh<return><esc>
" Filetype plugin indent on
autocmd filetype python set expandtab
"set t_Co=256
"if &t_Co >= 256 || has("gui_running")
" colorscheme desert256
" let g:solarized_termcolors=256
" colorscheme solarized
"endif
if &t_Co > 2 || has("gui_running")
" switch syntax highlighting on, when the terminal has colors
syntax on
endif
" Vim can highlight whitespaces for you in a convenient way:
" For more info, see :h listchars.
set list
set listchars=tab:>.,trail:.,extends:#,nbsp:.
" In some files, like HTML and XML files, tabs are fine and showing them is really annoying..
" autocmd filetype html,xml set listchars-=tab:>.
" Use ; to switch to command mode instead of :.
" nnoremap ; :
" Use Q for formatting the current paragraph (or selection)
vmap Q gq
nmap Q gqap
" Make up&down work more naturally when moving in wrapped lines
nnoremap j gj
nnoremap k gk
" Easy window navigation
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
" Typing w!! saves the file with 'sudo'
cmap w!! w !sudo tee % >/dev/null
" map control-backspace to delete the previous word
imap <C-BS> <C-W>
" map C-right/left to jump text in various modes on my terminal (could I use termcap?)
imap <Esc>[1;5C <C-O>w
nmap <Esc>[1;5C w
imap <Esc>[1;5D <C-O>b
nmap <Esc>[1;5D b
" Jumping to beginning/end of the outer block, useful in e.g., HTML
nnoremap ]t vatatv
nnoremap [t vatatov
" Hitting enter in command mode disables the last search highlighting
nnoremap <CR> :noh<CR><CR>
" Pressing Tab on the command line will show a menu to complete buffer and
" file names. From: http://vim.wikia.com/wiki/Easier_buffer_switching
set wildchar=<Tab> wildmenu wildmode=full
" If you are still getting used to Vim and want to force yourself to stop using the arrow keys, add this:
"map <up> <nop>
"map <down> <nop>
"map <left> <nop>
"map <right> <nop>
" Restore cursor to file position in previous editing session
" http://vim.wikia.com/wiki/Restore_cursor_to_file_position_in_previous_editing_session
"
" Tell vim to remember certain things when we exit
" '10 : marks will be remembered for up to 10 previously edited files
" "100 : will save up to 100 lines for each register
" :20 : up to 20 lines of command-line history will be remembered
" % : saves and restores the buffer list
" n... : where to save the viminfo files
set viminfo='10,\"100,:20,%,n~/.viminfo
" This will jump to the last position in the visited files
function! ResCur()
if line("'\"") <= line("$")
normal! g`"
return 1
endif
endfunction
augroup resCur
autocmd!
autocmd BufWinEnter * call ResCur()
augroup END
" git grep mapping for vi
" http://vim.wikia.com/wiki/Git_grep
" Find the pattern :G <pattern> -- '*.c'
func GitGrep(...)
let save = &grepprg
set grepprg=git\ grep\ -n\ $*
let s = 'grep'
for i in a:000
let s = s . ' ' . i
endfor
exe s
let &grepprg = save
endfun
command -nargs=? G call GitGrep(<f-args>)
" Find the word under the cursor when hitting Ctrl+X G
func GitGrepWord()
normal! "zyiw
call GitGrep('-w -e ', getreg('z'))
endf
nmap <C-x>g :call GitGrepWord()<CR>
nmap <leader>gg :Ggrep! -w <cword><cr>
" 'Global' integration
map <C-\>^] :GtagsCursor<CR>
nmap <leader>l :TagbarToggle<CR>
nmap <leader>w :w<CR>
"nmap <leader>q :wqa<CR>
nmap <leader>d :bd<CR>
" Map '' to jump to the last line+column
nmap '' `'
" Quit all windows (overriding 'enter ex mode')
map Q :qa<CR>
" 'Stop that stupid window from popping up'
" (https://sheerun.net/2014/03/21/how-to-boost-your-vim-productivity/)
map q: :q
" Swap full/partial word search semantics of '*'. Don't like '/' register to
" be cluttered with word boundary symbols: '</'.
nnoremap * g*
nnoremap g* *
" Change the 'completeopt' option so that Vim's popup menu doesn't select the
" first completion item, but rather just inserts the longest common text of
" all matches; and the menu will come up even if there's only one match.
" Also, scratch preview window is not shown.
" http://vim.wikia.com/wiki/Make_Vim_completion_popup_menu_work_just_like_in_an_IDE
set completeopt=longest,menuone
" Keep menu item always highlighted by simulating <Up> on pu visible
inoremap <expr> <C-p> pumvisible() ? '<C-p>' :
\ '<C-p><C-r>=pumvisible() ? "\<lt>Up>" : ""<CR>'
" Map 'Enter' to select current menu item, as Ctrl-Y does
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
" Customize behaviour in vimdiff mode
if &diff
"colorscheme evening
"map Q :cquit<CR> "quit with an error code
" Fix the difficult-to-read default setting for diff text highlighting. The
" bang (!) is required since we are overwriting the DiffText setting. The highlighting
" for "Todo" also looks nice (yellow) if you don't like the "MatchParen" colors.
" highlight! link DiffText MatchParen " simple one-liner
" highlight! link DiffText TODO
" Override diff colors to specific values. Color-scheme specific, works fine with the default one.
" http://vim.wikia.com/wiki/Xterm256_color_names_for_console_Vim?file=Xterm-color-table.png
" http://stackoverflow.com/questions/2019281/load-different-colorscheme-when-using-vimdiff
highlight DiffAdd cterm=bold ctermfg=13 ctermbg=17 gui=none guifg=bg guibg=Red
highlight DiffDelete cterm=bold ctermfg=13 ctermbg=17 gui=none guifg=bg guibg=Red
highlight DiffChange cterm=bold ctermfg=13 ctermbg=17 gui=none guifg=bg guibg=Red
highlight DiffText cterm=bold ctermfg=13 ctermbg=23 gui=none guifg=bg guibg=Red
endif
" Make :find searching recursively
" http://stackoverflow.com/questions/3554719/find-a-file-via-recursive-directory-search-in-vim
":set path+=**
" Mapping keys for 'vim-expand-region'
vmap v <Plug>(expand_region_expand)
vmap <C-v> <Plug>(expand_region_shrink)
" Gitgutter
nmap ]h <Plug>GitGutterNextHunk
nmap [h <Plug>GitGutterPrevHunk
" Teach 'ctrlp' to use git ls-files when available
let g:ctrlp_use_caching = 1 " F5 to refresh quickly
let g:ctrlp_lazy_update = 200 " Delay updates up to 200ms
let g:ctrlp_by_filename = 0
let g:ctrlp_default_input = 1
let g:ctrlp_regexp = 0
let g:ctrlp_working_path_mode = 'rw'
let g:ctrlp_root_markers = ['../leia']
" if executable('ag')
" set grepprg=ag\ --nogroup\ --nocolor
" let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
" else
"let g:ctrlp_working_path_mode = 'ra'
let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files . -co --exclude-standard', 'find %s -type f']
" let g:ctrlp_prompt_mappings = {
" \ 'AcceptSelection("e")': ['<space>', '<cr>', '<2-LeftMouse>'],
" \ }
" endif
" Use C++ style comments in C files
autocmd FileType c setlocal commentstring=//\ %s
" Recognize XIV templates as .c header
autocmd BufRead,BufNewFile *.xh set filetype=c
" AUtomatically open quickfix window following grep invocations
autocmd QuickFixCmdPost *grep* cwindow
" Airline bar customization
let g:airline#extensions#tabline#enabled = 1 " Automatically displays all buffers when there's only one tab open.
let g:airline#extensions#whitespace#enabled = 0 " Disable builtin whitespace extension
let g:airline#extensions#tabline#buffer_idx_mode = 1
nmap <leader>1 <Plug>AirlineSelectTab1
nmap <leader>2 <Plug>AirlineSelectTab2
nmap <leader>3 <Plug>AirlineSelectTab3
nmap <leader>4 <Plug>AirlineSelectTab4
nmap <leader>5 <Plug>AirlineSelectTab5
nmap <leader>6 <Plug>AirlineSelectTab6
nmap <leader>7 <Plug>AirlineSelectTab7
nmap <leader>8 <Plug>AirlineSelectTab8
nmap <leader>9 <Plug>AirlineSelectTab9
" Highlight trailing whitespaces using 'error' color (http://www.bestofvim.com/tip/trailing-whitespace/)
match ErrorMsg '\s\+$'
" End .vimrc