-
Notifications
You must be signed in to change notification settings - Fork 4
/
.vimrc
372 lines (294 loc) · 11.3 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
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
"Shows an exhaustive list during tab completion
set wildmode=longest,list,full
set wildmenu
" Ignore files
set wildignore+=*.pyc
set wildignore+=*_build/*
set wildignore+=**/coverage/*
set wildignore+=**/node_modules/*
set wildignore+=**/android/*
set wildignore+=**/ios/*
set wildignore+=**/.git/*
" removes annoying error sound
set noerrorbells
set scrolloff=10 "Smooth scrolling at the bottom
" While over the incorrect work in normal mode :z=1 to see suggestions
"[s and ]s to go navigate through misspelled word
set spell spelllang=en_us
" Set internal encoding of vim
set encoding=utf-8
" TextEdit might fail if hidden is not set.
set hidden
" Some servers have issues with backup files
set nobackup
set nowritebackup
" Give more space for displaying messages.
" Remove the messages that pop up at the bottom
" set shortmess=a
" set cmdheight=2
vnoremap <C-c><C-c> :<c-u>silent '<,'>write !xsel -b<cr>
set relativenumber
set textwidth=120
" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
" delays and poor user experience.
set updatetime=50
" Don't pass messages to |ins-completion-menu|.
" set shortmess+=c
set formatoptions-=c formatoptions-=r formatoptions-=o " To stop comments from continuing
set tabstop=4 softtabstop=4
set shiftwidth=4
set expandtab
set smartindent
set nu
set smartcase
set incsearch
set hlsearch
set ic " case insensitive search
set foldmethod=indent
set foldlevel=99
" Install VimPlug from - https://github.com/junegunn/vim-plug
" curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
call plug#begin('~/.vim/plugged')
Plug 'tpope/vim-surround'
Plug 'honza/vim-snippets'
Plug 'junegunn/vim-easy-align'
" Plug 'lervag/vimtex' " Latex plugins
Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } "shows files, git-file in the current directory, Install bat for syntax highlighting
Plug 'junegunn/fzf.vim'
Plug 'yuttie/comfortable-motion.vim' " smooth scrolling 'C-d' or 'C-u'
"Themes for vim editor
Plug 'sonph/onehalf', { 'rtp': 'vim' } "preferred on linux server
Plug 'rakr/vim-one' " For mac
Plug 'tpope/vim-commentary' "commenting - `gcc` for commenting and un-commenting
Plug 'tpope/vim-fugitive' "Git workflows
Plug 'tpope/vim-rhubarb' "Git - to go to github link in the browser
Plug 'vim-airline/vim-airline' "Shows status line - Fugitive status line depends on airline
Plug 'sheerun/vim-polyglot' " Syntax highlighting
Plug 'preservim/nerdtree' "nerd tree - shows files in folder in a vertical split
Plug 'Xuyuanp/nerdtree-git-plugin' " New nerd tree ?
Plug 'airblade/vim-gitgutter' "Git gutter
" Replace words with copied word
" Copy the words using - "yiw" (yank inner word)
" Go to the word which you want replaced and type "griw" (go replace inner word)
" Action as usual is repeatable using "."
Plug 'inkarkat/vim-ReplaceWithRegister'
Plug 'neoclide/coc.nvim', {'branch': 'release'} " Auto complete and very quick navigation between functions
Plug 'iamcco/markdown-preview.nvim', { 'do': { -> mkdp#util#install() }, 'for': ['markdown', 'vim-plug']} " Markdown preview
Plug 'jiangmiao/auto-pairs' " Insert or delete brackets, parens, quotes in pair.
call plug#end()
" Start interactive EasyAlign in visual mode (e.g. vipga)
xmap ga <Plug>(EasyAlign)
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga <Plug>(EasyAlign)
"Comfortable motion scrolling params
let g:comfortable_motion_friction = 80.0
let g:comfortable_motion_air_drag = 12.0
" MarkdownPreview settings
let g:mkdp_auto_start = 0
let g:mkdp_auto_close = 1
let g:mkdp_refresh_slow = 0
let g:mkdp_command_for_global = 0
let g:mkdp_open_to_the_world = 0
let g:mkdp_open_ip = ''
let g:mkdp_browser = ''
let g:mkdp_echo_preview_url = 0
let g:mkdp_browserfunc = ''
let g:mkdp_preview_options = {
\ 'mkit': {},
\ 'katex': {},
\ 'uml': {},
\ 'maid': {},
\ 'disable_sync_scroll': 0,
\ 'sync_scroll_type': 'middle',
\ 'hide_yaml_meta': 1
\ }
let g:mkdp_markdown_css = ''
let g:mkdp_highlight_css = ''
let g:mkdp_port = ''
let g:mkdp_page_title = '「${name}」'
set statusline=%<%f\ %h%m%r%{FugitiveStatusline()}%=%-14.(%l,%c%V%)\ %P
let g:gitgutter_async=0
let ostype = substitute(system('uname'), "\n", "", "")
set cursorline
set t_Co=256
if ostype == "Darwin"
colorscheme one
set termguicolors
else
set t_ut=
colorscheme onehalfdark
highlight Comment gui=none cterm=none
let g:airline_theme='onehalfdark'
endif
" Press Space to turn off highlighting and clear any message already displayed.
noremap <silent> <Esc> :nohlsearch<Bar>:echo<CR>
" https://stackoverflow.com/questions/6488683/how-do-i-change-the-cursor-between-normal-and-insert-modes-in-vim
" Regular mode - block, Insert mode - vertical line, Replace mode - _
if exists('$TMUX')
let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\"
let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"
let &t_SR = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=2\x7\<Esc>\\"
else
"this works for Centos
if $TERM == 'xterm-256color'
"echo "For Centos"
let &t_SI = "\<Esc>[6 q"
let &t_SR = "\<Esc>[4 q"
let &t_EI = "\<Esc>[2 q"
else
"echo "For other Linux distros"
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
let &t_SR = "\<Esc>]50;CursorShape=2\x7"
endif
endif
" make the switch between insert and normal mode faster
set ttimeout
set ttimeoutlen=1
set listchars=tab:>-,trail:~,extends:>,precedes:<,space:.
set ttyfast
" map the leader key to space bar
let mapleader = " "
" move through buffers - Leader key is currently mapped to space bar
nmap <leader>[ :bp!<CR>
nmap <leader>] :bn!<CR>
nmap <leader>x :bd<CR>
"shows all files in the current directory
noremap <leader>f :Files<CR>
"shows all git files in the current directory
noremap <leader>gf :GFiles<CR>
"shows all files store in buffer
noremap <leader>b :Buffers<CR>
" Recurrsive grep, must need to install rg
" Mac - brew install ripgrep
" Linux - sudo apt-get install ripgrep
noremap <leader>grep :Rg!
let g:netrw_banner = 0
noremap <leader>nt :NERDTree<CR>
"reduce and increase the side of vertical split
noremap <leader><Left> :vertical resize +5<CR>
noremap <leader><Right> :vertical resize -5<CR>
noremap <leader><Down> : resize +5<CR>
noremap <leader><Up> : resize -5<CR>
"Change split windows from vertical to horizontally
map <leader>tv <C-w>t<C-w>H
map <leader>th <C-w>t<C-w>K
"Search and replace -> %s/<targetWord><replaceWith>/gI
"To replace visual block do [Shift][:]s/<targetWord>/<replaceWith><CR>
noremap <leader>sr :%s//gI<Left><Left><Left>
" Disable arrow keys - hard mode
noremap <Up> <Nop>
noremap <Down> <Nop>
noremap <Left> <Nop>
noremap <Right> <Nop>
" Scrolling with keyboard
" Move up/down lines with [CTRL + u][CTRL + d]
" map <C-d> 5j
" map <C-u> 5k
" Git fugitive mappings
noremap <leader>gl :G log<CR>
noremap <leader>gc :G commit<CR>
noremap <leader>gp :G push<CR>
" Equivalent to git status
noremap <leader>gs :G <CR>
"open github url on web browser
noremap <leader>gb :GBrowse <CR>
if ostype == "Linux"
let python_highlight_all = 1
let python_highlight_space_errors = 0
endif
" Show documentation when you press K
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
elseif (coc#rpc#ready())
call CocActionAsync('doHover')
else
execute '!' . &keywordprg . " " . expand('<cword>')
endif
endfunction
" Use K to show documentation in preview window.
noremap <silent> K :call <SID>show_documentation()<CR>
" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')
" Formatting selected code.
xmap <leader>F <Plug>(coc-format-selected)
nmap <leader>F <Plug>(coc-format-selected)
" format sql code
noremap <leader>sql :CocCommand sql.Format <CR>
" Symbol renaming.
nmap <leader>rn <Plug>(coc-rename)
" GoTo code navigation using coc
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent><leader>gr <Plug>(coc-references)
nmap <silent> sgd :call CocAction('jumpDefinition', 'split')<CR>
" Disable autocomplete for specific file types
autocmd FileType python let b:coc_suggest_disable = 1
autocmd FileType Markdown let b:coc_suggest_disable = 1
autocmd FileType vim let b:coc_suggest_disable = 1
" For easy vertical navigation in markdown files
autocmd FileType markdown map j gj
autocmd FileType markdown map k gk
" Add path to your node binary here - requirement for coc plugin
" Coc plugin also requires nmp for installing extension please refere to README on how to configure that
" let g:coc_node_path = '$HOME/node-from-source/bin/node'
" Copy vim clipboard to system clipboard - https://stackoverflow.com/questions/3961859/how-to-copy-to-clipboard-in-vim
if ostype== "Darwin"
noremap <silent>Y "*y
else
noremap <silent>Y "+y
endif
set clipboard=unnamed " Does the something, might remove the one above
"CTRL-A CTRL-Q to select all and build quickfix list - https://github.com/junegunn/fzf.vim/issues/185
":cexpr [] to delete all items from the quick fix list
function! s:build_quickfix_list(lines)
call setqflist(map(copy(a:lines), '{ "filename": v:val }'))
copen
cc
endfunction
let g:fzf_action = {
\ 'ctrl-q': function('s:build_quickfix_list'),
\ 'ctrl-t': 'tab split',
\ 'ctrl-x': 'split',
\ 'ctrl-v': 'vsplit' }
let $FZF_DEFAULT_OPTS = '--bind ctrl-a:select-all'
" Show hidden files in fzf
if ostype == "Darwin"
" Different options for searching folder
" You can optionally exclude folders from being searched in case they contain way too many files
"
" let $FZF_DEFAULT_COMMAND = 'fd --type f --hidden --follow --exclude .git --exclude exclude_me '
" let $FZF_DEFAULT_COMMAND = 'ag --hidden --ignore .git --ignore-dir={exclude_me,} -l -g ""'
let $FZF_DEFAULT_COMMAND = 'rg --files --follow --hidden -g "!.git" -g "!exclude_me"'
endif
" Grep the current file with fzf with preview
" To get preview with BLines - https://github.com/junegunn/fzf.vim/issues/374
command! -bang -nargs=* BLines
\ call fzf#vim#grep(
\ 'rg --with-filename --column --line-number --no-heading --smart-case . '.fnameescape(expand('%:p')), 1,
\ fzf#vim#with_preview({'options': '--layout reverse --query '.shellescape(<q-args>).' --with-nth=4.. --delimiter=":"'}, 'right:50%'))
nnoremap <silent> <Leader>/ :BLines<CR>
" Move 1 more lines up or down in normal and visual selection modes.
nnoremap <C-k> :m .-2<CR>==
nnoremap <C-j> :m .+1<CR>==
vnoremap <C-k> :m '<-2<CR>gv=gv
vnoremap <C-j> :m '>+1<CR>gv=gv
" use <tab> for trigger completion and navigate to the next complete item
function! s:check_back_space() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~ '\s'
endfunction
inoremap <silent><expr> <Tab>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<Tab>" :
\ coc#refresh()
"Tab to navigate completion list
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
" Trigger coc-autocomplete on pressing Enter
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
"Correct colors for Coc Pmenus
hi Pmenu ctermbg=234 ctermfg=145
hi PmenuSel ctermbg=237 ctermfg=145