-
Notifications
You must be signed in to change notification settings - Fork 2
/
vimrc
330 lines (251 loc) · 10.4 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
set nocompatible
" VIM Plugins (vim-plug)
" -----------------------------------------------------------------------------
call plug#begin('~/.vim/plugged') " Plugins will be installed in this folder
" Visual
Plug 'Yggdroot/indentLine'
" Plug 'vim-airline/vim-airline'
" Plug 'vim-airline/vim-airline-themes'
Plug 'romainl/Apprentice'
Plug 'Glench/Vim-Jinja2-Syntax'
" General Purpose Plugins
Plug 'preservim/nerdtree'
Plug 'ciaranm/detectindent'
Plug 'SirVer/ultisnips'
Plug 'ycm-core/YouCompleteMe'
Plug 'srstevenson/vim-picker'
Plug 'AndrewRadev/linediff.vim'
Plug 'zivyangll/git-blame.vim'
Plug 'christianrondeau/vim-base64'
Plug 'mgedmin/python-imports.vim'
Plug 'tpope/vim-surround'
" Python Plugins
Plug 'dense-analysis/ale'
Plug 'vim-scripts/indentpython.vim'
Plug 'hynek/vim-python-pep8-indent'
Plug 'morhetz/gruvbox'
" Docker Plugins
Plug 'ekalinin/Dockerfile.vim'
" Vagrant Plugin
Plug 'hashivim/vim-vagrant'
" Vue Plugins
Plug 'posva/vim-vue'
" Rust Plugins
Plug 'rust-lang/rust.vim'
" Openhab Plugins
Plug 'cyberkov/openhab-vim'
" PHP
Plug 'StanAngeloff/php.vim'
" Logstash highlight
Plug 'robbles/logstash.vim'
" Logrotate syntax highlight
Plug 'moon-musick/vim-logrotate'
" Yaml
Plug 'stephpy/vim-yaml'
" RST
Plug 'dhruvasagar/vim-table-mode'
" Yang
Plug 'nathanalderson/yang.vim'
" TOML
Plug 'cespare/vim-toml'
" Nginx
Plug 'chr4/nginx.vim'
call plug#end()
" Display
" -----------------------------------------------------------------------------
set number relativenumber " display relative numbers
" set foldcolumn=2 " display up to 4 folds
" set nowrap " Prevent wrapping
set title " display title in X.
set visualbell t_vb= " disable visualbells completely
set cursorline " highlight the current line
set termguicolors " Enable Truecolor support
"set cursorcolumn " hightlight the current column
colorscheme apprentice
" Nerdtree
" -----------------------------------------------------------------------------
" autocmd vimenter * NERDTree " Autostarts nerdtree
let mapleader = "," " , is easier to reach than the default
nmap <leader>ne :NERDTree<cr> " Shortcut to open Nerdtree
let NERDTreeMapOpenInTab='\r' " Default open files in Tabs
let NERDTreeMapOpenInTab='<ENTER>' " Default open files in Tabs
" Vim Settings
" -----------------------------------------------------------------------------
filetype plugin indent on " required
set nocompatible " be iMproved
set encoding=utf-8 " use UTF-8
set t_Co=256 " 256 colours
set background=dark " the darker the better
set ignorecase " ignore case
set smartcase " makes it easier to search for vim commands
set wildmode=longest,list,full " more intuative vim command tab completion
syntax on " syntax highlighting
" Airline specific
" -----------------------------------------------------------------------------
set laststatus=2 " always show status bar
set cmdheight=2 " set cmd height to 2
let g:airline_powerline_fonts = 1 " Use patched fonts
let g:airline_theme='wombat' " Airline theme https://github.com/vim-airline/vim-airline/wiki/Screenshots
" Picker Settings
" -----------------------------------------------------------------------------
let g:picker_selector_executable = 'pick'
let g:picker_selector_flags = ''
nmap <unique> <leader>pe <Plug>(PickerEdit)
nmap <unique> <leader>ps <Plug>(PickerSplit)
nmap <unique> <leader>pt <Plug>(PickerTabedit)
nmap <unique> <leader>pd <Plug>(PickerTabdrop)
nmap <unique> <leader>pv <Plug>(PickerVsplit)
nmap <unique> <leader>pb <Plug>(PickerBuffer)
nmap <unique> <leader>ph <Plug>(PickerHelp)
" Indentation settings
" -----------------------------------------------------------------------------
"set autoindent " always set autoindenting on
set shiftwidth=4 " Force indentation to be 4 spaces
set tabstop=4 " -- idem --
set ffs=unix
set list " EOL, trailing spaces, tabs: show them.
set lcs=tab:├─ " Tabs are shown as ├──
set lcs+=trail:␣ " Show trailing spaces as ␣
set expandtab " always expand tabs to spaces
set backspace=2 " make backspace behave like in most other apps
" Visual Mode settings
" -----------------------------------------------------------------------------
set hlsearch " Hightlight searches
set ignorecase " Ignore case when searching
set smartcase " Override the ignorecase when search
" contains upper letters
vnoremap < <gv " indent '>' multiple times in visual mode
vnoremap > >gv " indent '<' multiple times in visual mode
" Vim Table settings
" -----------------------------------------------------------------------------
let g:table_mode_corner_corner='+' " RST Table style
" Ultisnippets settings
" -----------------------------------------------------------------------------
let g:UltiSnipsExpandTrigger="<C-j>"
let g:UltiSnipsJumpForwardTrigger="<C-j>"
let g:UltiSnipsJumpBackwardTrigger="<C-k>"
" Code Style settings
" -----------------------------------------------------------------------------
"
" Folding
"
set foldmethod=indent " Folding method
set foldlevel=99 " Folding level
nnoremap <space> za " Open up folding
vnoremap <space> zf " Close folding
"
" Text Bubbling (http://vimcasts.org/episodes/bubbling-text/)
"
nmap <C-Up> ddkP " Single line up
nmap <C-Down> ddp " Single line down
vmap <C-Up> xkP`[V`] " Visual mode multiple lines up
vmap <C-Down> xp`[V`] " Visual mode multiple lines down
" ctrl-p settings
" -----------------------------------------------------------------------------
let g:ctrlp_working_path_mode = 0
"
" Ansible Settings
" -----------------------------------------------------------------------------
let g:anisble_vault_password_file = '~/workspace/ansible/vault_password'
"
" Ale config
" -----------------------------------------------------------------------------
let g:ale_fixers = {
\ 'python': ['isort', 'autopep8', 'black'],
\}
let g:ale_linters = {
\ 'python': ['mypy', 'pylint'],
\ 'shell': ['shellcheck'],
\}
" Don't lint test files
let g:ale_pattern_options = {
\ 'tests\/': {
\ 'ale_linters': ['pylint'],
\ 'ale_fixers': ['isort', 'autopep8']
\ },
\}
" General Ale Settings
let g:ale_cache_executable_check_failures = 1
let b:ale_python_mypy_use_global = 0
let b:ale_python_pylint_use_global = 0
" Test Type Anotations with strict option
let g:ale_python_mypy_options = '--ignore-missing-imports --strict'
" Set this. Airline will handle the rest.
let g:airline#extensions#ale#enabled = 1
" Format Ale Error Messages
let g:ale_echo_msg_error_str = 'E'
let g:ale_echo_msg_warning_str = 'W'
let g:ale_echo_msg_format = '[%severity%] [%linter%: %code%] %s'
" Integrate with vim-airline
" let g:airline#extensions#ale#enabled = 1
" 2023-01-24 try to disable to avoid refresh issue
" Run ALEFix
nnoremap <C-i> :ALEFix<CR>
"
" Git blame setting
" -----------------------------------------------------------------------------
nnoremap <Leader>s :<C-u>call gitblame#echo()<CR>
" IndentLine Settings
" -----------------------------------------------------------------------------
let g:indentLine_char = '|'
" YouCompleteMe Settings
" -----------------------------------------------------------------------------
let g:ycm_extra_conf_globlist = ['.ycm_extra_conf.py']
let g:ycm_min_num_of_chars_for_completion = 2
let g:ycm_autoclose_preview_window_after_completion = 1
let g:ycm_auto_trigger = 1
let g:ycm_min_num_of_chars_for_completion = 3
" Keyboard maps
" -----------------------------------------------------------------------------
set pastetoggle=<F2> " F2 for paste mode
nnoremap <F3> :set hlsearch!<CR> " Activate or disactive Search Highlighting
let mapleader = "," " , is easier to reach than the default
map <Leader> a ggVG " select all
vmap Q gq " wrap 80col paragraph vertically
imap <silent> <C-l> <Plug>(YCMToggleSignatureHelp)
" Compile RestructeredText with rst2html
" -----------------------------------------------------------------------------
function! Compilerst()
execute 'silent !rst2html % > /tmp/rsttemp.html'
execute 'silent !firefox /tmp/rsttemp.html &'
execute 'redraw!'
endfunction
nnoremap <F7> :call Compilerst()<CR>
" Spell check per filetype
" -----------------------------------------------------------------------------
autocmd BufRead,BufNewFile *.md setlocal spell spelllang=en_us
autocmd BufRead,BufNewFile *.rst setlocal spell spelllang=en_us
autocmd BufRead,BufNewFile *.txt setlocal spell spelllang=en_us
autocmd BufRead,BufNewFile *.in setlocal spell spelllang=en_us
autocmd FileType gitcommit setlocal spell spelllang=en_us
" Specific settings for filetypes
" -----------------------------------------------------------------------------
autocmd BufRead,BufNewFile *.rst setlocal tw=80
autocmd BufRead,BufNewFile *.json setlocal tabstop=2 sw=2
autocmd FileType javascript set tabstop=2 sw=2
autocmd FileType html set tabstop=2 sw=2
autocmd FileType sh set tabstop=2 sw=2
autocmd FileType xml set tabstop=2 sw=2
autocmd FileType vue set tabstop=2 sw=2
" autocmd BufNewFile,BufRead *.yaml,*.yml so ~/.vim/bundle/vim-yaml/after/syntax/yaml.vim
augroup python
autocmd!
autocmd FileType python
\ syn keyword pythonSelf self
\ | highlight def link pythonSelf Special
augroup end
"
" Scripts
" -----------------------------------------------------------------------------
function Header(width, word)
let a:inserted_word = ' ' . a:word . ' '
let a:word_width = strlen(a:inserted_word)
let a:length_before = (a:width - a:word_width) / 2
let a:hashes_before = repeat('#', a:length_before)
let a:hashes_after = repeat('#', a:width - (a:word_width + a:length_before))
let a:hash_line = repeat('#', a:width)
let a:word_line = a:hashes_before . a:inserted_word . a:hashes_after
:put =a:hash_line
:put =a:word_line
:put =a:hash_line
endfunction