-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path.vimrc
More file actions
445 lines (358 loc) · 11.7 KB
/
.vimrc
File metadata and controls
445 lines (358 loc) · 11.7 KB
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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
" Load plugins {{{
call plug#begin('~/.vim/plugged')
Plug 'tmhedberg/matchit'
Plug 'yuttie/comfortable-motion.vim'
Plug 'mg979/vim-visual-multi', {'branch': 'master'}
Plug 'tpope/vim-eunuch'
Plug 'easymotion/vim-easymotion'
Plug 'jamessan/vim-gnupg', {'branch': 'main'}
Plug 'jpalardy/vim-slime', {'branch': 'main'}
Plug 'dhruvasagar/vim-table-mode'
Plug 'godlygeek/tabular' " Dependency of `vim-markdown` below
Plug 'plasticboy/vim-markdown'
Plug 'djoshea/vim-autoread'
Plug 'tpope/vim-surround'
Plug 'kchmck/vim-coffee-script' " No treesitter configuration yet for coffee script
Plug 'altercation/vim-colors-solarized'
Plug 'ddrscott/vim-side-search'
Plug 'joshdick/onedark.vim', {'branch': 'main'}
Plug 'ruanyl/vim-gh-line' " Open file in Github, so that link can be shared
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } }
Plug 'junegunn/fzf.vim'
Plug 'tpope/vim-haml'
if has('nvim')
Plug 'numToStr/Comment.nvim' " Commenting pluggin
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}
Plug 'nvim-lua/plenary.nvim'
Plug 'MunifTanjim/nui.nvim'
Plug 'rcarriga/nvim-notify'
Plug 'folke/noice.nvim'
Plug 'kyazdani42/nvim-tree.lua' " File manager, sidebar
Plug 'lewis6991/gitsigns.nvim'
" Folding based on language
set foldexpr=nvim_treesitter#foldexpr()
" Live preview of replacements with (eg. s/old/new)
set inccommand=split
endif
call plug#end()
" }}}
" Theme {{{
syntax on
" Show line numbers
set number
" Display not printable characters set list
set list listchars=tab:»»,trail:¶
" Disable poor HTML rendering - not really compatible with HTML5 or
" any frontend JavaScript frameworks
let html_no_rendering = 1
" Theme
let g:onedark_termcolors=256
let g:onedark_color_overrides = {
\ "background": { "gui": "#21252b", "cterm": "0", "cterm16": "0" },
\}
set background=dark
set termguicolors
colorscheme onedark
" Hide status bar
set noruler
set noshowcmd
set noshowmode
set laststatus=0
" }}}
" Edit behaviour {{{
" Mapleader from \ to ,
let mapleader=" "
" Prefered file format
set fileformat=unix
" Encoding
scriptencoding utf-8
" Set tab to 2 spaces
set tabstop=2
set softtabstop=2
set shiftwidth=2
set expandtab
set smarttab
" Don't wrap text (it's like punishment for bad code)
set nowrap
set textwidth=0
" Enable mouse features for normal mode only, to prevent paste from explosion
set mouse=n
" For new lines automatically indent by current line indent
set autoindent
set copyindent
" Allow cursor to go in to 'invalid' places
set virtualedit=all
" Share keyboard with OS
set clipboard+=unnamed
" Include dash to split words (useful for CSS classes autocompletion for names
" having dash symbol "-")
set iskeyword=@,48-57,_,192-255,-
" When in git commit message - set cursor to the first line
au FileType gitcommit au! BufEnter COMMIT_EDITMSG call setpos('.', [0, 1, strlen(getline(1))+1, 0])
" Allow backspace on everything in insert mode
set backspace=indent,eol,start
" No welcome screen
set shortmess=Fmnrwx
set cmdheight=1
" When using :term - start in insert mode
if has('nvim')
autocmd TermOpen * startinsert
endif
" LSP autocompletion (filled by LSP config LUA file below)
set completeopt=menu,menuone,noselect
" }}}
" Search {{{
" Ignore case in search and replace
set ignorecase
" Found text will be highlighted and search will be repeated over file
set incsearch
" Smart search: if lowercase ignore case of matches, if not case-sensitive search
set smartcase
" Clean highlight when requested
nnoremap <leader>. :nohl<CR>
" }}}
" Backups and swap file {{{
" Create folders which will be auto removed after OS restart
silent execute '!mkdir -p ~/.vim/backup'
silent execute '!mkdir -p ~/.vim/undo'
" Setup backups and files prefixing with date
set backup
set backupdir=~/.vim/backup
autocmd BufWritePre * let &bex = '-' . strftime("%Y-%m-%d_%H:%M")
" Swap files are trashing every folder/project
set noswapfile
" Store undo history so it can be restored after VIM is closed
set undofile
set undodir=~/.vim/undo
" }}}
" Folding rules {{{
set foldenable
set foldcolumn=0
set foldlevel=9999
set foldmethod=expr
" }}}
" Keyboard mappings {{{
" VIM moving based on screen works better for long text files
nnoremap k gk
nnoremap gk k
nnoremap j gj
nnoremap gj j
" Use the damn hjkl keys instead of arrow keys
map <up> <nop>
map <down> <nop>
map <left> <nop>
map <right> <nop>
" Fixed copying. The number one annoying feature of VIM!
xnoremap p pgvy "
" Quick search from visual text
vnorem // y/<c-r>"<cr>
" Fixing "broken" VIM regexp - all characters now should be escaped
nnoremap / /\v
" Don't press the SHIFT in normal mode
nnoremap ; :
" Copy filename to clipboard
nnor <leader>cf :let @*=expand("%")<CR>
" Expand %% to full file directory (without filename!)
cnoremap <expr> %% getcmdtype() == ':' ? expand('%:h').'/' : '%%'
" move to beginning/end of line
nnoremap B ^
nnoremap E $
" Fix copying of lines
nmap Y yy
" By default, ' jumps to the marked line, ` jumps to the marked line and
" column, so swap them
nnoremap ' `
nnoremap ` '
" Save without :w quickly
inoremap jj <ESC>
nmap ww <ESC>:nohl<CR><ESC>:write!<CR>
" Autosave
set updatetime=1000
autocmd CursorHold,CursorHoldI * silent! update
" Close buffer
nnoremap <c-x> :bd<CR>
" Enter current folder files list
map <leader>e :Ex<CR>
" Copy filename to the clipboard
nmap ,cs :let @*=expand("%")<CR>
" }}}
" Spell Checker {{{
function! ToggleSpellCheck()
set spell!
if &spell
echo "Spellcheck ON"
else
echo "Spellcheck OFF"
endif
endfunction
nnoremap <silent> <Leader>sp :call ToggleSpellCheck()<CR>
" }}}
" Ignore rules for file editing {{{
set wildmenu
set wildchar=<tab>
set wildmode=list:full
set wildignore+=*.swp,*.bak,*.pyc,*.pyo,*.so,*~,*.zip,*.gz,*.tar,*.png,*.webp,node_modules/,tmp/,_site/,cache/
" }}}
" Repeat very last command in the next tmux window for quick command lines testing {{{
nnoremap <Leader>r :call <SID>TmuxRepeat()<CR>
function! s:TmuxRepeat()
silent! exec "!clear && tmux select-pane -l && tmux send up enter && tmux select-pane -l"
redraw!
endfunction
" }}}
" Poor man surrounding system {{{
vnoremap <silent> S( xi()<esc>P
vnoremap <silent> S[ xi[]<esc>P
vnoremap <silent> S{ xi{}<esc>P
vnoremap <silent> S' xi''<esc>P
vnoremap <silent> S" xi""<esc>P
" }}}
" Smarter files opening {{{
" Resolve file extensions when required when on filename pressing `gf`
augroup suffixes
autocmd!
let associations = [
\ ["javascript", ".js"],
\ ["python", ".py"],
\ ["ruby", ".rb"]
\ ]
for ft in associations
execute "autocmd FileType " . ft[0] . " setlocal suffixesadd=" . ft[1]
endfor
" For Javascript replace `@` to src which is most common
set includeexpr=substitute(v:fname,'^.','src/','g')
augroup END
" }}}
" Common file types {{{
autocmd BufRead,BufNewFile .czrc setfiletype json
autocmd BufRead,BufNewFile .huskyrc setfiletype json
autocmd BufRead,BufNewFile *.rabl setfiletype ruby
autocmd BufRead,BufNewFile *.njk setfiletype html
" }}}
" VIM Outliner plugin settings {{{
autocmd BufEnter *.otl setlocal foldlevel=0
autocmd BufEnter *.otl setlocal textwidth=80
autocmd BufEnter *.otl setlocal wrap
autocmd BufEnter *.otl setlocal foldenable
autocmd! BufRead,BufNewFile *.otl setfiletype vo_base
autocmd BufRead,BufNewFile *.otl filetype plugin indent on
autocmd BufRead,BufNewFile *.otl setlocal nolist
" }}}
" VIM Smooth Scroll plugin settings {{{
set scrolloff=8
" }}}
" VIM Nerd commenter plugin settings {{{
let g:NERDSpaceDelims=1
let g:NERDDefaultAlign = 'left'
" }}}
" VIM Surround plugin settings {{{
let g:surround_{char2nr('„')} = "„\r“"
" }}}
" VIM Vue plugin settings {{{
let g:vue_pre_processors = ['scss']
autocmd FileType vue syntax sync fromstart
autocmd BufRead,BufNewFile *.vue setlocal filetype=vue.html.javascript
" }}}
" VIM Visual Multi plugin settings {{{
nmap <M-Down> :<C-u>call vm#commands#add_cursor_down(0, v:count1)<cr>
nmap <M-Up> :<C-u>call vm#commands#add_cursor_up(0, v:count1)<cr>
" }}}
" VIM Easy Motion plugin settings {{{
let g:EasyMotion_do_mapping = 0 " Disable default mappings
map <Space><Space> <Plug>(easymotion-bd-w)
" }}}
" VIM Slime plugin settings {{{
let g:slime_target = "tmux"
let g:slime_default_config = {"socket_name": "default", "target_pane": "{last}"}
let g:slime_dont_ask_default = 1
nnoremap <c-c><c-c> :SlimeSendCurrentLine<CR>
" }}}
" VIM Markdown plugin settings {{{
let g:vim_markdown_frontmatter = 1
autocmd BufEnter *.markdown setlocal foldlevel=1
autocmd BufEnter *.markdown setlocal textwidth=80
autocmd BufEnter *.markdown setlocal wrap
" }}}
" VIM Side Search plugin settings {{{
command! -complete=file -nargs=+ S execute 'SideSearch <args>'
" Disable "smart" mode of this plugin and search only from dir VIM has been started
function! FindRootDirectory()
return getcwd()
endfunction
" Default command uses --word-regexp which misses a lot results!, so
" overriding to fix that and adding smart case handling
let g:side_search_prg = 'rg --heading --stats -C 2 --smart-case --line-number'
" }}}
" Load LSP and other Lua configs {{{
if has('nvim')
luafile ~/.vim/lsp.lua
" Open definition in the new tab with `gJ`, while `gj` configured to open in the same window
nnoremap gJ <cmd>tab split \| lua vim.lsp.buf.definition()<cr>
endif
" }}}
" Display folder and filename in tabs {{{
set tabline=%!TabLine()
function! TabLine()
let line = ''
for i in range(tabpagenr('$'))
let line .= (i+1 == tabpagenr()) ? '%#TabLineSel#' : '%#TabLine#'
let line .= '%' . (i + 1) . 'T'
let line .= TabLabel(i + 1)
endfor
let line .= '%#TabLineFill#%T'
return line
endfunction
function! TabLabel(n)
" Return list of buffer numbers for each window pane open in tab.
let panelist = tabpagebuflist(a:n)
" See :help setting-tabline then search MyTabLabel if you want to
" use use the active window. I use the topmost pane, which let's
" me rename the tab just by putting a window from a different
" directory in the first position.
let filepath = bufname(panelist[0])
let filename = fnamemodify(filepath, ':t')
let dirname = fnamemodify(filepath, ':p:h:t')
return ' ' . dirname. '/' . filename . ' '
endfunction
" }}}
" Native VIM grep should use rg command {{{
set grepprg=rg\ --vimgrep\ --smart-case\ --follow
" }}}
" Load project-local .nvimrc files {{{
set exrc
set secure
" }}}
" VIM Nvim Tree Plugin Settings {{{
map <leader>t :NvimTreeFindFile<CR>
" }}}
" VIM FZF plugin settings {{{
let g:fzf_layout = { "window": "silent botright enew" }
let g:fzf_preview_window = ['up:60%']
let $FZF_DEFAULT_COMMAND="rg --files --hidden --no-ignore --glob '!.git' --glob '!*.gpg' --glob '!*.png' --glob '!*.svg' --glob '!*.pyc' --glob '!*.jpg' --glob '!*.jpeg' --glob '!*.zip' --glob '!node_modules' --glob '!_site' --glob '!.jekyll-cache'"
map <leader>/ :Rg <CR>
map // :BLines <CR>
map <leader>f :Files<CR>
map <leader>b :Buffers<CR>
map <leader>m :Marks<CR>
map <leader>g :GFiles?<CR>
" Search for word under cursor
command! -bang -nargs=* RgExact
\ call fzf#vim#grep(
\ 'rg -F --column --line-number --no-heading --color=always --smart-case -- '.shellescape(<q-args>), 1,
\ fzf#vim#with_preview(), <bang>0)
nmap <Leader>w :execute 'RgExact ' . expand('<cword>') <Cr>
" }}}
" Automatically search file name from selection with fuzzy search {{{
function! s:getVisualSelection()
let [line_start, column_start] = getpos("'<")[1:2]
let [line_end, column_end] = getpos("'>")[1:2]
let lines = getline(line_start, line_end)
if len(lines) == 0
return ""
endif
let lines[-1] = lines[-1][:column_end - (&selection == "inclusive" ? 1 : 2)]
let lines[0] = lines[0][column_start - 1:]
return join(lines, "\n")
endfunction
vnoremap <silent><leader>f <Esc>:FZF -q <C-R>=<SID>getVisualSelection()<CR><CR>
" }}}