-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
486 lines (407 loc) · 13.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
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
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
set encoding=utf-8
scriptencoding utf-8
set shell=/bin/sh
set directory=~/src/.swp
set autoread
set mouse=a
au FocusGained,BufEnter * :silent! !
" Bundle
filetype off
" set the runtime path to include Vundle and initialize
set rtp+=~/.config/nvim/bundle/Vundle.vim
call vundle#begin('~/.config/nvim/bundle')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
" All of your Plugins must be added before the following line
call vundle#end()
" Enable file type detection.
filetype plugin indent on
" work around for security issue
set nomodeline
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
" common settings
set nobackup
set history=50
set ruler
set showcmd
set incsearch
set expandtab
set autoindent
set tabstop=4
set softtabstop=4
set shiftwidth=4
set shiftround
set showmatch
set smarttab
set title
set hidden
set number
set relativenumber
set nohlsearch
set visualbell
set scrolljump=8
" set cursorline
set matchpairs+=<:>
set rtp+=/usr/local/bin/fzf
" Plugins
Plugin 'gruvbox-community/gruvbox'
Plugin 'Lokaltog/vim-easymotion'
Plugin 'mileszs/ack.vim'
Plugin 'airblade/vim-gitgutter'
Plugin 'vim-airline/vim-airline'
" Plugin 'vim-syntastic/syntastic'
Plugin 'junegunn/fzf'
Plugin 'junegunn/fzf.vim'
Plugin 'tpope/vim-fugitive'
" Plugin 'davidhalter/jedi-vim'
Plugin 'tomtom/tcomment_vim'
" Plugin 'maxbrunsfeld/vim-yankstack'
Plugin 'editorconfig/editorconfig-vim'
Plugin 'airblade/vim-rooter'
Plugin 'buztard/vim-rel-jump'
Plugin 'junegunn/vim-peekaboo'
Plugin 'chrisbra/improvedft'
" Plugin 'rizzatti/dash.vim'
Plugin 'bufkill.vim'
" Plugin 'Shougo/deoplete.nvim'
" Plugin 'deoplete-plugins/deoplete-jedi'
" Plugin 'jiangmiao/auto-pairs'
Plugin 'jeetsukumaran/vim-pythonsense'
Plugin 'numirias/semshi'
Plugin 'sheerun/vim-polyglot'
Plugin 'neovim/nvim-lspconfig'
Plugin 'RishabhRD/popfix'
Plugin 'RishabhRD/nvim-lsputils'
Plugin 'hrsh7th/nvim-cmp'
Plugin 'hrsh7th/cmp-nvim-lsp'
Plugin 'hrsh7th/cmp-buffer'
Plugin 'saadparwaiz1/cmp_luasnip'
Plugin 'L3MON4D3/LuaSnip'
" Plugin 'justinmk/vim-sneak'
Plugin 'dense-analysis/ale'
Plugin 'nvim-treesitter/nvim-treesitter'
Plugin 'mhinz/vim-startify'
" Switch syntax highlighting on, when the terminal has colors
" Also some MacVim GUI settings
if &t_Co > 2 || has('gui_running')
let g:solarized_contrast='high'
let g:solarized_termcolors=256
let g:gruvbox_contrast_dark='high'
syntax enable
set background=dark
" colorscheme nofrils-dark
" colorscheme molokai
colorscheme gruvbox
" colorscheme Tomorrow-Night
" colorscheme solarized
" colorscheme darkdesert
set guioptions=egmt
" highlight SpellBad term=underline gui=undercurl guisp=Orange
" set guifont=Hack:h14
endif
let g:mapleader = ','
" 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).
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
let g:python3_host_prog = '/usr/local/opt/[email protected]/bin/python3'
" startify
function! s:gitModified()
let files = systemlist('git ls-files -m 2>/dev/null')
return map(files, "{'line': v:val, 'path': v:val}")
endfunction
let g:startify_lists = [
\ { 'type': 'dir', 'header': [' MRU '. getcwd()] },
\ { 'type': 'sessions', 'header': [' Sessions'] },
\ { 'type': function('s:gitModified'), 'header': [' git modified']},
\ { 'type': 'commands', 'header': [' Commands'] },
\ ]
lua << EOF
-- Use an on_attach function to only map the following keys
-- after the language server, attaches to the current buffer
local nvim_lsp = require('lspconfig')
local on_attach = function(client, bufnr)
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end
-- Enable completion triggered by <c-x><c-o>
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc')
-- Mappings.
local opts = { noremap=true, silent=true }
-- See `:help vim.lsp.*` for documentation on any of the below functions
buf_set_keymap('n', '<leader>d', '<cmd>lua vim.lsp.buf.definition()<CR>', opts)
buf_set_keymap('n', '<leader>r', '<cmd>lua vim.lsp.buf.rename()<CR>', opts)
buf_set_keymap('n', '<leader>u', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
buf_set_keymap('n', 'K', '<cmd>lua vim.lsp.buf.hover()<CR>', opts)
buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
buf_set_keymap('i', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts)
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts)
end
-- Set completeopt to have a better completion experience
vim.o.completeopt = 'menuone,noselect'
-- luasnip setup
local luasnip = require 'luasnip'
-- nvim-cmp setup
local cmp = require 'cmp'
cmp.setup {
snippet = {
expand = function(args)
require('luasnip').lsp_expand(args.body)
end,
},
mapping = {
['<C-p>'] = cmp.mapping.select_prev_item(),
['<C-n>'] = cmp.mapping.select_next_item(),
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<CR>'] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true,
},
['<Tab>'] = function(fallback)
if cmp.visible() then
cmp.select_next_item()
else
fallback()
end
end,
['<S-Tab>'] = function(fallback)
if cmp.visible() then
cmp.select_prev_item()
else
fallback()
end
end,
['<Down>'] = function(fallback)
if cmp.visible() then
cmp.select_next_item()
else
fallback()
end
end,
['<Up>'] = function(fallback)
if cmp.visible() then
cmp.select_prev_item()
else
fallback()
end
end,
},
sources = {
{ name = 'nvim_lsp' },
{ name = 'luasnip' },
{ name = 'buffer' },
},
}
-- Use a loop to conveniently call 'setup' on multiple servers and
-- map buffer local keybindings when the language server attaches
local servers = { 'pyright' }
for _, lsp in ipairs(servers) do
nvim_lsp[lsp].setup {
on_attach = on_attach,
flags = {
debounce_text_changes = 150,
}
}
end
EOF
lua vim.lsp.handlers["textDocument/publishDiagnostics"] = function() end
let g:ale_linters = {'python': ['pyright']}
nmap <silent> <C-j> <Plug>(ale_next_wrap)
" nnoremap vp `[v`]
nnoremap <expr> vp '`[' . strpart(getregtype(), 0, 1) . '`]'
vnoremap < <gv
vnoremap > >gv
" Ctrl-S to save
noremap <silent> <C-S> :update<CR>
vnoremap <silent> <C-S> <C-C>:update<CR>
inoremap <silent> <C-S> <C-O>:update<CR>
" Autoinsert ipdb
nmap <leader>i oimport ipdb; ipdb.set_trace()<esc>
" quickly close all
nnoremap Q :qall<CR>
nmap <C-l> :close<CR>
" preview windows
nnoremap <leader>x :ccl<CR>:pc<CR>
" window navigation
nnoremap <silent> <S-left> :wincmd h<CR>
nnoremap <silent> <S-right> :wincmd l<CR>
nnoremap <silent> <S-down> :wincmd j<CR>
nnoremap <silent> <S-up> :wincmd k<CR>
" splits
nnoremap <leader>v :vsplit<CR>
nnoremap <leader>s :split<CR>
" ack
let g:ackprg='/usr/local/bin/ag -Q -i'
nmap <leader>a <Esc>:Ack!<Space>
nmap <leader>A <Esc>:Ack! <cword><CR>
nnoremap <leader>ts :set expandtab shiftwidth=2 softtabstop=2<CR>
nmap <Space> :
" Adds j and k motions to jumplist
nnoremap <expr> k (v:count > 1 ? "m'" . v:count : '') . 'k'
nnoremap <expr> j (v:count > 1 ? "m'" . v:count : '') . 'j'
" Avoid setting caps with u
vmap u <nop>
vmap U <nop>
inoremap jk <esc>
" Yanks and registers
" call yankstack#setup()
nmap - "
vmap - "
vnoremap Y "+y
" map <leader>y :Yanks<CR>
" nmap <leader>p <Plug>yankstack_substitute_older_paste
" nmap <leader>p <Plug>yankstack_substitute_older_paste
" nmap <leader>P <Plug>yankstack_substitute_newer_paste
" Syntatistic
let g:syntastic_python_checkers=['python']
let g:syntastic_always_populate_loc_list=1
let g:syntastic_quiet_messages = { "type": "style" }
" Airline
set laststatus=2
let g:airline#extensions#whitespace#enabled = 0
let g:airline_section_y = airline#section#create(['%m'])
let g:airline#extensions#tagbar#flags = 'f'
let g:airline#extensions#tabline#enabled = 1
let g:airline#extensions#tabline#show_buffers = 1
let g:airline#extensions#tabline#buffer_nr_show = 1
let g:airline_theme='gruvbox'
" EasyMotion config
let g:EasyMotion_do_mapping = 1 " Disable default mappings"
let g:EasyMotion_smartcase = 1
let g:EasyMotion_do_shade = 0
" HJKL motions: Line motions
map <Leader>l <Plug>(easymotion-lineforward)
map <Leader>j <Plug>(easymotion-j)
map <Leader>k <Plug>(easymotion-k)
map <Leader>h <Plug>(easymotion-linebackward)
" search motions
map / <Plug>(easymotion-sn)
omap / <Plug>(easymotion-tn)
map n <Plug>(easymotion-next)
map N <Plug>(easymotion-prev)
map <Leader>w <Plug>(easymotion-bd-w)
" FZF
nnoremap <silent> <leader><space> :Files<CR>
nnoremap <silent> <C-p> :Files<CR>
nnoremap <silent> <C-b> :Buffers<CR>
nnoremap <silent> <leader>oc :Files ~/src/oc/<CR>
nnoremap <silent> <leader>b :Lines<CR>
let g:fzf_layout = { 'down': '30%'}
let g:fzf_colors =
\ { 'fg': ['fg', 'Normal'],
\ 'bg': ['bg', 'Normal'],
\ 'hl': ['fg', 'Comment'],
\ 'fg+': ['fg', 'CursorLine', 'CursorColumn', 'Normal'],
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
\ 'hl+': ['fg', 'Statement'],
\ 'info': ['fg', 'PreProc'],
\ 'border': ['fg', 'Ignore'],
\ 'prompt': ['fg', 'Conditional'],
\ 'pointer': ['fg', 'Exception'],
\ 'marker': ['fg', 'Keyword'],
\ 'spinner': ['fg', 'Label'],
\ 'header': ['fg', 'Comment'] }
" Fugitive
nmap <leader>gw :Gwrite<CR>
nmap <leader>gc :Gcommit<CR>
nmap <leader>gb :Gbrowse<CR>
nmap <leader>gp :Gpush<CR>
nmap <leader>gs :Gstatus<CR>
nmap <leader>gd :Gdiff<CR>
nmap <leader>gr :Gread<CR>
" TComment
nmap <Leader>c :TComment<CR>
vmap <Leader>c :TComment<CR>
" chdir rooter
let g:rooter_silent_chdir = 1
" Peekabo
let g:peekaboo_window = 'vertical botright 50new'
" Motions
map <buffer> ]] <Plug>(PythonsenseStartOfNextPythonFunction)
map <buffer> [[ <Plug>(PythonsenseStartOfPythonFunction)
" Stuff from vimways
function! s:inIndentation()
" select all text in current indentation level excluding any empty lines
" that precede or follow the current indentationt level;
"
" the current implementation is pretty fast, even for many lines since it
" uses "search()" with "\%v" to find the unindented levels
"
" NOTE: if the current level of indentation is 1 (ie in virtual column 1),
" then the entire buffer will be selected
"
" WARNING: python devs have been known to become addicted to this
" magic is needed for this
let l:magic = &magic
set magic
" move to beginning of line and get virtcol (current indentation level)
" BRAM: there is no searchpairvirtpos() ;)
normal! ^
let l:vCol = virtcol(getline('.') =~# '^\s*$' ? '$' : '.')
" pattern matching anything except empty lines and lines with recorded
" indentation level
let l:pat = '^\(\s*\%'.l:vCol.'v\|^$\)\@!'
" find first match (backwards & don't wrap or move cursor)
let l:start = search(l:pat, 'bWn') + 1
" next, find first match (forwards & don't wrap or move cursor)
let l:end = search(l:pat, 'Wn')
if (l:end !=# 0)
" if search succeeded, it went too far, so subtract 1
let l:end -= 1
endif
" go to start (this includes empty lines) and--importantly--column 0
execute 'normal! '.l:start.'G0'
" skip empty lines (unless already on one .. need to be in column 0)
call search('^[^\n\r]', 'Wc')
" go to end (this includes empty lines)
execute 'normal! Vo'.l:end.'G'
" skip backwards to last selected non-empty line
call search('^[^\n\r]', 'bWc')
" go to end-of-line 'cause why not
normal! $o
" restore magic
let &magic = l:magic
endfunction
" "in indentation" (indentation level sans any surrounding empty lines)
xnoremap <silent> ii :<c-u>call <sid>inIndentation()<cr>
onoremap <silent> ii :<c-u>call <sid>inIndentation()<cr>
" regular expressions that match numbers (order matters .. keep '\d' last!)
" note: \+ will be appended to the end of each
let s:regNums = [ '0b[01]', '0x\x', '\d' ]
function! s:inNumber()
" select the next number on the line
" this can handle the following three formats (so long as s:regNums is
" defined as it should be above this function):
" 1. binary (eg: "0b1010", "0b0000", etc)
" 2. hex (eg: "0xffff", "0x0000", "0x10af", etc)
" 3. decimal (eg: "0", "0000", "10", "01", etc)
" NOTE: if there is no number on the rest of the line starting at the
" current cursor position, then visual selection mode is ended (if
" called via an omap) or nothing is selected (if called via xmap)
" need magic for this to work properly
let l:magic = &magic
set magic
let l:lineNr = line('.')
" create regex pattern matching any binary, hex, decimal number
let l:pat = join(s:regNums, '\+\|') . '\+'
" move cursor to end of number
if (!search(l:pat, 'ce', l:lineNr))
" if it fails, there was not match on the line, so return prematurely
return
endif
" start visually selecting from end of number
normal! v
" move cursor to beginning of number
call search(l:pat, 'cb', l:lineNr)
" restore magic
let &magic = l:magic
endfunction
" "in number" (next number after cursor on current line)
xnoremap <silent> in :<c-u>call <sid>inNumber()<cr>
onoremap <silent> in :<c-u>call <sid>inNumber()<cr>