-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc
335 lines (269 loc) · 10.5 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
332
333
334
335
call plug#begin('~/.vim/plugged')
" Main plugins
Plug 'scrooloose/nerdtree' " Handy tree explorer
Plug 'tpope/vim-unimpaired' " Additionnal pair mappings
Plug 'tpope/vim-surround'
Plug 'tpope/vim-repeat'
Plug 'LucHermitte/alternate-lite' " C/C++ header/source file switching (a.vim-like)
Plug 'LucHermitte/lh-vim-lib' " + code dependency
Plug 'Valloric/YouCompleteMe' " Completion support
Plug 'SirVer/ultisnips' " Snippet support
Plug 'ctrlpvim/ctrlp.vim' " Fuzzy file search
Plug 'mileszs/ack.vim'
Plug 'vim-utils/vim-man' " Better manual integration
" FIXME using PR upstream until merged
" see: https://github.com/vhdirk/vim-cmake/pull/33
" Plug 'vhdirk/vim-cmake' " CMake integration
Plug 'otreblan/vim-cmake' " CMake integration
" VCS
Plug 'tpope/vim-fugitive' " Git integration
Plug 'tpope/vim-rhubarb' " + support for GitHub
Plug 'shumphrey/fugitive-gitlab.vim' " + support for GitLab
Plug 'airblade/vim-gitgutter' " Extra column for git +/- signs
" Cosmetic plugins
Plug 'altercation/vim-colors-solarized' " Solarized colors
Plug 'vim-airline/vim-airline' " Main theming plugin
Plug 'vim-airline/vim-airline-themes' " Extra themes
Plug 'Lokaltog/powerline-fonts' " Fancy fonts
Plug 'edkolev/tmuxline.vim' " Apply VIM's theme to tmux
" Extra syntax support
Plug 'octol/vim-cpp-enhanced-highlight' " C++
Plug 'ziglang/zig.vim' " Zig
Plug 'pboettch/vim-cmake-syntax' " CMake
Plug 'beyondmarc/hlsl.vim' " HLSL
Plug 'kbenzie/vim-spirv' " SPIR-V
Plug 'Ryp/vim-gcn-isa' " GCN ISA
Plug 'Ryp/supp.vim' " Valgrind suppression files
Plug 'PProvost/vim-ps1' " Powershell
Plug 'cespare/vim-toml' " TOML
call plug#end()
set nocompatible " be iMproved
set background=dark
colorscheme solarized
set encoding=utf-8 nobomb " Unicode support
set laststatus=2 " Permanent status bar
set t_Co=256 " Colors
set shortmess=atI " No intro message at start
set title
set number " Enable line numbers
set cursorline " Highlight current line
set relativenumber " Show relative line numbers
set list lcs=tab:▸\ ,trail:·,nbsp:_ " Show invisible characters
set showcmd " Show current command
set belloff=all " Disable the bell
set scrolloff=4 " Start scrolling n lines before the horizontal window border
set nowrap " Do not wrap long lines
set modelines=0 " Disable modelines (i don't use them and they are not secure)
set incsearch " Start searching while typing string
set hlsearch " Highlight current search
set foldopen-=search " Do not expand folds when searching
set tabstop=4 " Set tab width
set shiftwidth=4 " Indent size
set smarttab " Auto align on the next indent when using tab
set expandtab " Insert spaces when pressing tab
set backspace=2 " Relaxed rules for backspace in insert mode
set hidden " Allow switching buffers without writing to the current one
set backupdir=~/.vim/backup
set directory=~/.vim/swap
if exists("&undodir")
set undofile " Enable persistent undo history
set undodir=~/.vim/undo " Specify undo history folder
endif
set exrc " Allow vim to source project-specific vimrc's
set secure " Do not allow unsafe commands when sourcing these
set shortmess+=c " Hide default completion messages (interacts with Ycm)
" Key remapping stuff
" In case of conflict, remember this old trick to reveal ambiguous keystrokes:
" :verbose noremap [key_sequence]
" Go from insert to normal mode with jk instead of ESC
inoremap jk <ESC>
" Remap command key (easier to reach)
nnoremap ; :
" Fallback for ; that we just remapped
nnoremap <Bslash> @:
" Nazi mode (maybe check out VIM Hard Mode)
" Level 1: do not allow arrow keys
inoremap <Up> <Nop>
inoremap <Down> <Nop>
inoremap <Left> <Nop>
inoremap <Right> <Nop>
vnoremap <Up> <Nop>
vnoremap <Down> <Nop>
vnoremap <Left> <Nop>
vnoremap <Right> <Nop>
" Level 2: even in insert mode
noremap <Up> <Nop>
noremap <Down> <Nop>
noremap <Left> <Nop>
noremap <Right> <Nop>
" Level 3: do not allow hjkl to move around in normal mode
" noremap h <Nop>
" noremap j <Nop>
" noremap k <Nop>
" noremap l <Nop>
" Build shortcut
" - Avoids 'press OK to continue' pause
" - Jumps to first error
map <F5> :silent make\|redraw!\|cc<CR>
" Automatically open quickfix window if errors are found
autocmd QuickFixCmdPost * :cw
" let g:runprg = ''
function! MakeRun()
silent make
execute 'silent !' . g:runprg
execute 'redraw'
endfunction
function! MakeRunDbg()
silent make
" Works if the confirm prompts is active
execute 'silent !' . 'gdb -quiet -ex="set confirm on" -ex=run -ex=quit --args ' . g:runprg
execute 'redraw'
endfunction
map <F6> :call MakeRunDbg()<CR>
map <F7> :call MakeRun()<CR>
" Simple function to strip trailing whitespaces
function! StripWhitespace()
let save_cursor = getpos(".")
let old_query = getreg('/')
:%s/\s\+$//e
call setpos('.', save_cursor)
call setreg('/', old_query)
endfunction
" Same as StripWhitespace but does a retab too
function! CleanFile()
retab
call StripWhitespace()
endfunction
" Use the space key as leader
let mapleader = "\<Space>"
nnoremap <Space> <Nop>
nmap <leader>C :call CleanFile()<CR>
" Buffer management
nmap <leader>T :enew<CR>
nmap <leader>j :bprevious<CR>
nmap <leader>k :bnext<CR>
" Close the current buffer and move to the previous one
" This replicates the idea of closing a tab
nmap <leader>bc :bp <BAR> bd #<CR>
" Show all open buffers and their status
nmap <leader>bl :ls<CR>
" Manage edits to this file
nnoremap <silent> <leader>ve :e $MYVIMRC<CR>
nnoremap <silent> <leader>vr :so $MYVIMRC<CR>
" My todo/done list
nnoremap <silent> <leader>vt :e $HOME/.mylog<CR>
" Save file as root
noremap <leader>W :w !sudo tee % > /dev/null<CR>
" Open file browser
nmap <silent> <leader>r :!ranger<CR>
" Use clang-format on current source file
map <leader>cf :!clang-format -style=file -i %<CR>
" Plugin configuration
" vim-fugitive
nnoremap <leader>ga :Git add %:p<CR><CR>
nnoremap <leader>gb :Git blame<CR>
nnoremap <leader>gs :Git<CR>
nnoremap <leader>gc :Git commit -v -q<CR>
nnoremap <leader>gt :Git commit -v -q %:p<CR>
nnoremap <leader>gd :Gdiff<CR>
nnoremap <leader>ge :Gedit<CR>
nnoremap <leader>gr :Gread<CR>
nnoremap <leader>gw :Gwrite<CR><CR>
nnoremap <leader>gl :silent! Glog<CR>:bot copen<CR>
nnoremap <leader>gp :Ggrep<Space>
" nnoremap <leader>gm :Gmove<Space> (clash)
" nnoremap <leader>gb :Git branch<Space> (clash)
nnoremap <leader>go :Git checkout<Space>
" nnoremap <leader>gps :Dispatch! git push<CR>
" nnoremap <leader>gpl :Dispatch! git pull<CR>
" Do not open countless buffers
autocmd BufReadPost fugitive://* set bufhidden=delete
" GitHub support (vim-rhubarb)
let g:github_enterprise_urls = []
" GitLab support (fugitive-gitlab)
let g:fugitive_gitlab_domains = []
" Perforce
let g:perforce_use_relative_paths = 1
" Theme configuration
let g:airline_powerline_fonts = 1
if !exists('g:airline_symbols')
let g:airline_symbols = {}
endif
let g:airline_symbols.maxlinenr = ''
let g:airline_theme="base16"
let g:airline#extensions#tabline#enabled = 1 " Show buffer bar
let g:airline#extensions#tabline#fnamemod = ':t' " Only show filename
let g:airline_mode_map = {
\ '__' : '-',
\ 'n' : 'N',
\ 'i' : 'I',
\ 'R' : 'R',
\ 'c' : 'C',
\ 'v' : 'V',
\ 'V' : 'V',
\ '' : 'V',
\ 's' : 'S',
\ 'S' : 'S',
\ '' : 'S',
\ }
" Make CtrlP more accessible
nmap <leader>p :CtrlP<cr>
nmap <leader>m :CtrlPMRUFiles<cr>
" Setup some default ignores
let g:ctrlp_custom_ignore = {
\ 'dir': '\v[\/](\.(git|hg|svn))$',
\ 'file': '\v\.(exe|so|dll|pdb|obj|png)$',
\ }
let g:ctrlp_show_hidden = 1 " Show hidden files by default
let g:ctrlp_working_path_mode = 'r' " Use the nearest .git directory as the cwd
let g:ctrlp_cache_dir = $HOME . '/.cache/ctrlp' " Set cache folder
let g:ctrlp_max_files = 0 " Unset max file limit
let g:ctrlp_clear_cache_on_exit = 0 " Enable permanent cache
if executable('ag')
set grepprg=ag\ --nogroup\ --nocolor " Use ag over grep
" let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
" let g:ackprg = 'ag --nogroup --nocolor --column'
let g:ackprg = 'ag --vimgrep'
endif
let g:ackhighlight = 1
" Search
nmap <leader>a :Ack<Space>
" Search word
nmap <leader>sw :Ack <cword><CR>
" Search entire word
nmap <leader>sew :Ack -w <cword><CR>
" Replace word
nmap <leader>s ye:%s/<c-r>"/<c-r>"
" Open vertically split vim-man for word under cursor
map <leader>gm <Plug>(Vman)
" Configure alternate-lite
nmap <leader>gh :A<CR>
" Configure UltiSnips
let g:UltiSnipsSnippetDirectories = [ "ultisnips" ]
let g:UltiSnipsExpandTrigger = "<c-j>"
let g:UltiSnipsJumpForwardTrigger = "<c-k>"
let g:UltiSnipsJumpBackwardTrigger = "<c-l>"
let g:UltiSnipsListSnippets = "<c-y>"
let g:UltiSnipsEditSplit="vertical"
" let g:UltiSnipsUsePythonVersion = 2
" YouCompleteMe
let g:ycm_confirm_extra_conf = 0
let g:ycm_add_preview_to_completeopt = 1
let g:ycm_autoclose_preview_window_after_insertion = 1
let g:ycm_server_log_level = 'debug'
nnoremap <leader>gt :YcmCompleter GoTo<CR>
" CMake integration
let g:cmake_project_generator = 'Ninja'
let g:cmake_build_shared_libs = 1
" Reuse hlsl highlighting for cg files
autocmd BufNewFile,BufRead *.cg set ft=hlsl
autocmd BufNewFile,BufRead *.hlsli set ft=hlsl
" rTorrent syntax
autocmd BufNewFile,BufRead *rtorrent.rc* set filetype=rtorrent
" Set default makeprg for some filetypes
autocmd FileType python set makeprg=pylint\ --reports=n\ --msg-template=\"{path}:{line}:\ {msg_id}\ {symbol},\ {obj}\ {msg}\"\ %
" Add error format for the glslang shader compiler
let &errorformat = "ERROR\:\ %f\\:%l\\:%m," . &errorformat
" Some other compiler
let &errorformat = "%f(%l\\,%c)\ \:\ warning\ %t%n\:\ %m," . &errorformat
let &errorformat = "%f(%l\\,%c)\ \:\ error\ %t%n\:\ %m," . &errorformat