-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.vim
More file actions
402 lines (321 loc) · 13.1 KB
/
init.vim
File metadata and controls
402 lines (321 loc) · 13.1 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
execute pathogen#infect()
call pathogen#helptags()
set nocompatible " be iMproved, required
filetype off " required
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
if has("termguicolors")
set termguicolors
endif
let g:gruvbox_contrast_dark = "hard"
colorscheme gruvbox
set background=dark
" Custom config
syntax on
" Settings
set noerrorbells " No beeps
set number " Show line numbers
set backspace=indent,eol,start " Makes backspace key more powerful.
set showcmd " Show me what I'm typing
set noswapfile " Don't use swapfile
set nobackup " Don't create annoying backup files
set nowritebackup
set splitright " Split vertical windows right to the current windows
set splitbelow " Split horizontal windows below to the current windows
set encoding=utf-8 " Set default encoding to UTF-8
set autowrite " Automatically save before :next, :make etc.
set autoread " Automatically reread changed files without asking me anything
set laststatus=2
set hidden
set signcolumn=no " Disables sign column
set noshowmode " We show the mode with airline or lightline
set incsearch " Shows the match while typing
set hlsearch " Highlight found searches
set ignorecase " Search case insensitive...
set smartcase " ... but not when search pattern contains upper case characters
set ttyfast
" set ttyscroll=3 " noop on linux ?
set lazyredraw " Wait to redraw "
" speed up syntax highlighting
set nocursorcolumn
set nocursorline
" Make Vim to handle long lines nicely.
set nowrap
set textwidth=80
set formatoptions=qrn1
" Do not use relative numbers to where the cursor is.
set norelativenumber
set ts=2 " Tabs are 2 spaces
set bs=2 " Backspace over everything in insert mode
set softtabstop=2
set shiftwidth=2 " Tabs under smart indent
set autoindent
set smarttab
set expandtab
set smartindent
set virtualedit=all
set showmatch " Show matching brackets.
" Time out on key codes but not mappings.
" Basically this makes terminal Vim work sanely.
set notimeout
set ttimeout
set ttimeoutlen=10
" Folding
set foldmethod=indent
set foldlevel=100
" Make the current window big
" set winheight=5
" set winminheight=5
" autocmd WinEnter * wincmd _
au FocusLost * silent! wa " Set vim to save the file on focus out.
" 80 character limit
if exists('+colorcolumn')
hi ColorColumn guibg=#2d2d2d ctermbg=246
set colorcolumn=80
else
au BufWinEnter * let w:m2=matchadd('ErrorMsg', '\%>80v.\+', -1)
endif
" Disables number lines on terminal buffers
if has('nvim')
autocmd TermOpen * :setlocal nonumber norelativenumber signcolumn=no
endif
set mouse=a
if !has('nvim')
set ttymouse=xterm2
endif
" dont save .netrwhist history
let g:netrw_dirhistmax=0
" Functions
" -----------------------------------------
" Replace the current buffer with the given new file. That means a new file
" will be open in a buffer while the old one will be deleted
com! -nargs=1 -complete=file Breplace edit <args>| bdelete #
function! DeleteInactiveBufs()
"From tabpagebuflist() help, get a list of all buffers in all tabs
let tablist = []
for i in range(tabpagenr('$'))
call extend(tablist, tabpagebuflist(i + 1))
endfor
"Below originally inspired by Hara Krishna Dara and Keith Roberts
"http://tech.groups.yahoo.com/group/vim/message/56425
let nWipeouts = 0
for i in range(1, bufnr('$'))
if bufexists(i) && !getbufvar(i,"&mod") && index(tablist, i) == -1
"bufno exists AND isn't modified AND isn't in the list of buffers open in windows and tabs
silent exec 'bwipeout' i
let nWipeouts = nWipeouts + 1
endif
endfor
echomsg nWipeouts . ' buffer(s) wiped out'
endfunction
command! Ball :call DeleteInactiveBufs()
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
" Also don't do it when the mark is in the first line, that is the default
" position when opening a file.
function! JumpToLastKnownCursorPosition()
if line("'\"") > 1 && line("'\"") <= line("$")
exe "normal! g`\""
endif
endfunction
autocmd BufReadPost * silent call JumpToLastKnownCursorPosition()
" Mappings
" -----------------------------------------
" This comes first, because we have mappings that depend on leader
" With a map leader it's possible to do extra key combinations
" i.e: <leader>w saves the current file
let mapleader = "\<Space>"
let g:mapleader = "\<Space>"
" Close quickfix easily
nnoremap <leader>a :cclose<CR>
" Remove search highlight
nnoremap <leader><space> :noh<CR>
" List all buffers
nnoremap <leader>ls :ls<CR>
" Buffer prev/next
nnoremap <silent> <C-z> :bprev <bar> :call JumpToLastKnownCursorPosition()<CR>
nnoremap <silent> <C-x> :bnext <bar> :call JumpToLastKnownCursorPosition()<CR>
" Fast saving
nmap <leader>w :w!<cr>
" Fast closing
nnoremap <silent> <leader>q :Sayonara <bar> :call JumpToLastKnownCursorPosition()<CR>
nnoremap <silent> <leader>da :Ball<CR>
" Copy & Paste
vmap <silent> <C-c> y:call system("pbcopy", getreg("\""))<CR>
nmap <silent> <C-c> :.w !pbcopy<CR><CR> :echo "Copied!"<CR>
vmap <silent> <C-x> d:call system("pbcopy", getreg("\""))<CR>
nmap <silent> <C-v> :set paste<CR> :r !pbpaste<CR>:set nopaste<CR>
imap <C-v> <Esc> :call setreg("\"",system("pbpaste"))<CR>pO
" Copy current file path
nmap <silent> <leader>cf :let @+ = expand("%")<CR> :echo "Copied!"<CR>
" Copy current directory path
nmap <silent> <leader>cd :let @+ = expand("%:h")<CR> :echo "Copied!"<CR>
"
" Copy current git branch
nmap <silent> <leader>cb :let @+ = system("git rev-parse --abbrev-ref HEAD")<CR> :echo "Copied!"<CR>
" Move up and down on splitted lines (on small width screens)
map <Up> gk
map <Down> gj
map k gk
map j gj
" Search mappings: These will make it so that going to the next one in a
" search will center on the line it's found in.
nnoremap n nzzzv
nnoremap N Nzzzv
" Do not show stupid q: window
map q: :q
" trim all whitespaces away
nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<CR>
" Show help for current word
nnoremap <leader>hw :h <C-R>=expand("<cword>")<CR><CR>
" Terminal
if has('nvim')
nnoremap <silent> <leader>t :wa<CR>:Term<CR>
tnoremap <silent> <leader><Esc> <C-\><C-n>:Sayonara<CR>
endif
if !has('nvim')
" Allow hitting <Esc> to switch to normal mode
tnoremap <Esc> <C-\><C-n>
nnoremap <silent> <leader>t :wa<CR>:terminal<CR>
tnoremap <silent> <leader><Esc> <C-\><C-n>:bdelete!<CR>
endif
" File Type settings
" -----------------------------------------
au BufRead,BufNewFile *.rb,*.rhtml,*.erb,*.haml,*.js set shiftwidth=2
au BufRead,BufNewFile *.rb,*.rhtml,*.erb,*.haml,*.js set softtabstop=2
au BufRead,BufNewFile *.haml setf haml
au BufRead,BufNewFile *.scss setf sass
au BufNewFile,BufRead *.yml,*.yaml setlocal expandtab ts=2 sw=2
au BufNewFile,BufRead *.json setlocal expandtab ts=2 sw=2
" Wildmenu completion {{{
set wildmenu
" set wildmode=list:longest
set wildmode=list:full
set wildignore+=.hg,.git,.svn " Version control
set wildignore+=*.aux,*.out,*.toc " LaTeX intermediate files
set wildignore+=*.jpg,*.bmp,*.gif,*.png,*.jpeg " binary images
set wildignore+=*.o,*.obj,*.exe,*.dll,*.manifest " compiled object files
set wildignore+=*.spl " compiled spelling word lists
set wildignore+=*.sw? " Vim swap files
set wildignore+=*.DS_Store " OSX bullshit
set wildignore+=*.luac " Lua byte code
set wildignore+=migrations " Django migrations
set wildignore+=go/pkg " Go static files
set wildignore+=go/bin " Go bin files
set wildignore+=go/bin-vagrant " Go bin-vagrant files
set wildignore+=*.pyc " Python byte code
set wildignore+=*.orig " Merge resolution files
" Ruby
noremap <silent> <leader>rx :!ruby %<CR>
noremap <silent> <leader>rjp :%!ruby -rjson -e 'puts JSON.pretty_generate(JSON.load_file("%"))'<CR>
" Plugin configs
" -----------------------------------------
" ==================== CtrlP ====================
let g:ctrlp_cmd = 'CtrlP'
let g:ctrlp_working_path_mode = 'ra'
let g:ctrlp_max_height = 10 " maxiumum height of match window
let g:ctrlp_switch_buffer = 'et' " jump to a file if it's open already
let g:ctrlp_mruf_max=450 " number of recently opened files
let g:ctrlp_max_files=0 " do not limit the number of searchable files
let g:ctrlp_use_caching = 1
let g:ctrlp_clear_cache_on_exit = 1
let g:ctrlp_cache_dir = $HOME.'/.cache/ctrlp'
" ignore files in .gitignore
let g:ctrlp_user_command = ['.git', 'cd %s && git ls-files -co --exclude-standard']
let g:ctrlp_custom_ignore = '\v[\/](node_modules|target|dist)|(\.(swp|ico|git|svn))$'
" ==================== Fugitive ====================
nnoremap <leader>ga :Git add %:p<CR><CR>
nnoremap <leader>gs :Gstatus<CR>
nnoremap <leader>gp :Gpush<CR>
vnoremap <leader>gb :Gblame<CR>
nnoremap <leader>gj :diffget //3<CR>
nnoremap <leader>gf :diffget //2<CR>
" ========= vim-better-whitespace ==================
" auto strip whitespace except for file with extention blacklisted
let blacklist = ['diff', 'gitcommit', 'unite', 'qf', 'help', 'markdown']
autocmd BufWritePre * if index(blacklist, &ft) < 0 | StripWhitespace
" =================== coc.nvim ========================
" Give more space for displaying messages.
set cmdheight=2
" Having longer updatetime (default is 4000 ms = 4 s) leads to noticeable
" delays and poor user experience.
set updatetime=300
" Don't pass messages to |ins-completion-menu|.
set shortmess+=c
" Use tab for trigger completion with characters ahead and navigate.
" NOTE: Use command ':verbose imap <tab>' to make sure tab is not mapped by
" other plugin before putting this into your config.
inoremap <silent><expr> <TAB>
\ coc#pum#visible() ? coc#pum#next(1):
\ CheckBackspace() ? "\<Tab>" :
\ coc#refresh()
inoremap <expr><S-TAB> coc#pum#visible() ? coc#pum#prev(1) : "\<C-h>"
" Make <CR> to accept selected completion item or notify coc.nvim to format
" <C-g>u breaks current undo, please make your own choice.
inoremap <silent><expr> <CR> coc#pum#visible() ? coc#pum#confirm()
\: "\<C-g>u\<CR>\<c-r>=coc#on_enter()\<CR>"
function! CheckBackspace() abort
let col = col('.') - 1
return !col || getline('.')[col - 1] =~# '\s'
endfunction
" Use <c-space> to trigger completion.
if has('nvim')
inoremap <silent><expr> <c-space> coc#refresh()
else
inoremap <silent><expr> <c-@> coc#refresh()
endif
" GoTo code navigation.
nmap <silent> gd <Plug>(coc-definition)
nmap <silent> gy <Plug>(coc-type-definition)
nmap <silent> gi <Plug>(coc-implementation)
nmap <silent> gr <Plug>(coc-references)
" Use K to show documentation in preview window.
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
else
call CocAction('doHover')
endif
endfunction
" Highlight the symbol and its references when holding the cursor.
autocmd CursorHold * silent call CocActionAsync('highlight')
" Symbol renaming.
nmap <leader>rn <Plug>(coc-rename)
" Formatting selected code.
xmap <leader>f <Plug>(coc-format-selected)
nmap <leader>f <Plug>(coc-format-selected)
" CocSearch
" nnoremap <leader>prw :CocSearch <C-R>=expand("<cword>")<CR><CR>
let g:coc_global_extensions = ['coc-explorer', 'coc-eslint', 'coc-json', 'coc-solargraph', 'coc-tsserver']
" =================== tmuxline.nvim ========================
" git clone https://github.com/edkolev/tmuxline.vim.git bundle/tmuxline.vim
" let g:tmuxline_preset = {
" \'a' : '#S',
" \'win' : ['#I', '#W'],
" \'cwin' : ['#I', '#W'],
" \'y' : ['%Y-%m-%d', '%H:%M'],
" \'z' : '#(pmset -g batt | tail -n1 | cut -f2 | cut -d";" -f1)'}
" =================== vim-tmux-navigator ========================
" Write all buffers before navigating from Vim to tmux pane
let g:tmux_navigator_save_on_switch = 2
" =================== fzf ========================
set rtp+=/opt/homebrew/opt/fzf
let g:fzf_layout = { 'window': { 'width': 0.8, 'height': 0.8 } }
let $FZF_DEFAULT_OPTS='--reverse'
nnoremap <silent> <C-p> :Files<CR>
inoremap <silent> <C-p> <Esc>:GFiles<CR>
nnoremap <Leader>pg :GFiles<CR>
" Rg (Search)
nnoremap <leader>pw :Rg <C-R>=expand("<cword>")<CR><CR>
nnoremap <c-f> :Rg<SPACE>
" =================== vim-airline ========================
let g:airline_powerline_fonts = 1
let g:airline#extensions#branch#displayed_head_limit = 10
" =================== coc-explorer ========================
nmap <silent> <c-n> :CocCommand explorer<CR>
autocmd BufEnter * if (winnr("$") == 1 && &filetype == 'coc-explorer') | q | endif