init.vim 12.2 KB
Newer Older
1
2
3
" --- https://github.com/junegunn/vim-plug ------------------------------
" Minimalist plugin manager. Update with --> :PlugInstall
"
Nelso Jost's avatar
Nelso Jost committed
4
5
6
7
call plug#begin('~/.local/share/nvim/plugged')

Plug 'flazz/vim-colorschemes'         " molokai, PaperColor, etc
Plug 'scrooloose/nerdcommenter'       " toggle comments and so on
8
9
10
"Plug 'vim-airline/vim-airline'        " nice status bar (but )
Plug 'ap/vim-buftabline'
Plug 'itchyny/lightline.vim'
Nelso Jost's avatar
Nelso Jost committed
11
12
13
14
15
16
17
Plug 'vimlab/split-term.vim'          " better split neovim terminal
Plug 'mhinz/vim-sayonara'             " smart buffer quitting
Plug 'majutsushi/tagbar'              " show file tags (require ctags)
Plug 'kien/ctrlp.vim'                 " fuzzy finder (files, buffer, tags)
Plug 'jiangmiao/auto-pairs'           " Insert quotes/brackets in pairs
Plug 'tpope/vim-obsession'            " create/restore vim sessions
Plug 'scrooloose/nerdtree'            " tree explorer
18
19
20
21
Plug 'plasticboy/vim-markdown'        " markdown syntax
Plug 'benmills/vimux'                 " exec commands on tmux panels
Plug 'xolox/vim-misc'
Plug 'xolox/vim-colorscheme-switcher'
22
Plug 'lvht/tagbar-markdown'
23
24
Plug 't4ku/marktag'
Plug 'octol/vim-cpp-enhanced-highlight'
25
26
Plug 'bkad/CamelCaseMotion'
Plug 'christoomey/vim-tmux-navigator'
27
"Plug 'ervandew/supertab'
28
29

Plug 'Shougo/deoplete.nvim', { 'do': ':UpdateRemotePlugins' }
Nelso Jost's avatar
Nelso Jost committed
30
"Plug 'davidhalter/jedi'
31
"Plug 'zchee/deoplete-jedi'
Nelso Jost's avatar
Nelso Jost committed
32
33
" Plug 'davidhalter/jedi-vim'

34
"Plug 'roxma/nvim-completion-manager'  " async, dynamic, completion
Nelso Jost's avatar
Nelso Jost committed
35
36
37
38
39


call plug#end()
" -----------------------------------------------------------------------

40
colorscheme molokai
Nelso Jost's avatar
Nelso Jost committed
41
42

behave mswin
43
44
set clipboard=unnamed
"set clipboard=unnamedplus
Nelso Jost's avatar
Nelso Jost committed
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
"
set colorcolumn=80
set nowrap

set showcmd             " Show (partial) command in status line.
set showmatch           " Show matching brackets.
set showmode            " Show current mode.
set ruler               " Show the line and column numbers of the cursor.
set number              " Show the line numbers on the left side.
set formatoptions+=o    " Continue comment marker in new lines.
set textwidth=0         " Hard-wrap long lines as you type them.
set expandtab           " Insert spaces when TAB is pressed.
set tabstop=4           " Render TABs using this many spaces.
set shiftwidth=4        " Indentation amount for < and > commands.

set noerrorbells        " No beeps.
set modeline            " Enable modeline.
set esckeys             " Cursor keys in insert mode.
set linespace=0         " Set line-spacing to minimum.
set nojoinspaces        " Prevents inserting two spaces after punctuation on a join (J)

set ignorecase          " ignore case on vim command/completion
set infercase           " smart case insensitivity

" More natural splits
set splitbelow          " Horizontal split below current.
set splitright          " Vertical split to right of current.

if !&scrolloff
  set scrolloff=3       " Show next 3 lines while scrolling.
endif
if !&sidescrolloff
  set sidescrolloff=5   " Show next 5 columns while side-scrolling.
endif
set nostartofline       " Do not jump to first character with page commands.

" with infinite undo and a bit of saving addiction, those aren't needed
set nobackup
set noswapfile
set undofile                 "turn on the feature
set undodir=$HOME/.config/nvim/undo
set undolevels=1000         " How many undos
set undoreload=10000        " number of lines to save for undo

89
90
set noshowmode

Nelso Jost's avatar
Nelso Jost committed
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
" ============================================================================
" FILE ESPECIFICS

" use hard tab only on Makefiles (to avoid missing separator error)
autocmd Filetype make setlocal noexpandtab shiftwidth=4 softtabstop=0
autocmd Filetype yaml setlocal tabstop=4 softtabstop=4 shiftwidth=4

autocmd BufNewFile,BufReadPost *.ino,*.pde set filetype=cpp

" ============================================================================
" KEY MAPPINGS

" space enter insertion mode (<esc> still goes back to normal mode)
map <space> i

106
" disable ex mode (the 80's should stay in the 80's)
Nelso Jost's avatar
Nelso Jost committed
107
108
109
110
111
112
113
114
115
map Q <Nop>

let mapleader=","

nmap <F2> :TagbarToggle<CR>
imap <F2> :TagbarToggle<CR>

nmap <F3> :NERDTreeToggle<CR>

116
117
nnoremap <Leader>e :update<CR>:VimuxInterruptRunner<CR> :VimuxPromptCommand<CR>
nnoremap <c-e> :update<CR>:VimuxInterruptRunner<CR> :VimuxRunLastCommand<CR>
118
119
120
121

map <F8> :PrevColorScheme<CR>
map <F9> :NextColorScheme<CR>

122
123
map <F10> :mksession<CR>
map  <F12> :ed $MYVIMRC<CR>
Nelso Jost's avatar
Nelso Jost committed
124
125

" open terminal split [term-split.vim]
126
127
"map <C-t> :50VTerm<CR>
"map <C-e> :40VTerm make<CR>
Nelso Jost's avatar
Nelso Jost committed
128
129
130
131
132
133
134
135
136
137
138
139

" delete buffer without closing the window [bclose.vim]
nnoremap q :Sayonara<cr>
nnoremap <C-q> :qa<cr>
inoremap <C-q> <Esc>:Sayonara<cr>
"nnoremap <C-d> :Sayonara<cr>
"inoremap <C-d> :Sayonara<cr>

" toggle comment [NERD commenter]
map <Return> <C-g><leader>c<space>
smap <Return> <C-g><leader>c<space>

140
141
142
nnoremap <PageDown> <C-d>zz
nnoremap <PageUp> <C-u>zz

143
144
145
" delete previous word
" imap <C-BS> <C-W>

146
" fix backspace problems in some terminals
147
148
set backspace=indent,eol,start

Nelso Jost's avatar
Nelso Jost committed
149
150
151
152
" delete word under cursor
noremap <C-Space> ciw
inoremap <C-Space> <ESC>ciw

153
"inoremap <C-d> <ESC>dd
154

155
"noremap s ciw
156

Nelso Jost's avatar
Nelso Jost committed
157
158
159
" easy tab ident
vnoremap <Tab> >
vnoremap <S-Tab> <
160

Nelso Jost's avatar
Nelso Jost committed
161
" easier split navigation
162
163
164
165
"map <C-S-Left> <C-w>h
"map <C-S-Right> <C-w>l
"map <C-S-Down> <C-w>j
"map <C-S-Up> <C-w>k
Nelso Jost's avatar
Nelso Jost committed
166
nmap <Tab> <C-w>w
167
168
"
"nnoremap <silent> <Tab> :TmuxNavigatePrevious<cr>
Nelso Jost's avatar
Nelso Jost committed
169
170
171
172
173
174
175

" move cursor by n lines
nnoremap <C-Up> 5-
nnoremap <C-Down> 5+
inoremap <C-Up> <C-o>5-
inoremap <C-Down> <C-o>5+

176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
map <silent> w <Plug>CamelCaseMotion_w
map <silent> b <Plug>CamelCaseMotion_b
map <silent> e <Plug>CamelCaseMotion_e
map <silent> ge <Plug>CamelCaseMotion_ge
sunmap w
sunmap b
sunmap e
sunmap ge

omap <silent> iw <Plug>CamelCaseMotion_iw
xmap <silent> iw <Plug>CamelCaseMotion_iw
omap <silent> ib <Plug>CamelCaseMotion_ib
xmap <silent> ib <Plug>CamelCaseMotion_ib
omap <silent> ie <Plug>CamelCaseMotion_ie
xmap <silent> ie <Plug>CamelCaseMotion_ie

nnoremap <silent> <C-Right> w
nnoremap <silent> <C-Left> b

Nelso Jost's avatar
Nelso Jost committed
195
" CTRL-Z is Undo; not in cmdline though
196
197
noremap <C-Z> u :set nopaste<cr>
inoremap <C-Z> <Esc> u :set nopaste<cr> i
Nelso Jost's avatar
Nelso Jost committed
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

noremap <C-Y> <C-R>
inoremap <C-Y> <C-O><C-R>

vnoremap <C-X> "+x
vnoremap <C-C> "+y
"map <C-V>		"+gP

" CTRL-S for saving (require "stty -ixon" line on ~/.bashrc)
noremap <silent> <C-S>          :update<CR>
vnoremap <silent> <C-S>         <C-C>:update<CR>
inoremap <silent> <C-S>         <C-O>:update<CR><Esc>

" Switching buffers
map <C-PageDown> :bnext!<cr>
map <C-PageUp> :bprevious!<cr>
imap <C-PageDown> <ESC>:bnext!<cr>
imap <C-PageUp> <ESC>:bprevious!<cr>

" enter CtrlP tag fuzzy search [ctrp.vim]
noremap <C-o> :CtrlPBufTag<CR>
noremap <C-l> :CtrlPLine<CR>

"tnoremap <Esc> <C-\><C-n>

" keep terminal buffer hidden on background on bn
autocmd TermOpen * set bufhidden=hide

let python_highlight_all = 1

" --- Airline -----------------------------------------------------------------

" show buffer bar
let g:airline#extensions#tabline#enabled = 1

" Show just the filename
let g:airline#extensions#tabline#fnamemod = ':t'


" --- CtrlP -------------------------------------------------------------------
"
let g:ctrlp_map = '<c-p>'
let g:ctrlp_cmd = 'CtrlP'
" let g:ctrlp_cmd = 'CtrlPLastMode'

   let g:ctrlp_extensions = ['buffertag', 'tag', 'line', 'dir']

let g:ctrlp_custom_ignore = {
  \ 'dir':  '\v[\/]\.(git|hg|svn|venv)$',
  \ 'file': '\v\.(exe|so|dll)$',
  \ 'link': 'some_bad_symbolic_links',
  \ }


let g:tagbar_map_togglesort = "r"
let g:tagbar_map_preview = "<CR>"
let g:tagbar_map_jump = "<C-CR>"
255
let g:tagbar_autofocus = 1
Nelso Jost's avatar
Nelso Jost committed
256
257
258
259
260
261
262
let g:tagbar_expand = 1
let g:tagbar_indent = 1
let g:tagbar_compact = 1
let g:tagbar_sort = 0
let g:tagbar_width = 25


263
264
" don't give |ins-completion-menu| messages.  For example,
" '-- XXX completion (YYY)', 'match 1 of 2', 'The only match',
265
set shortmess+=c
266
267


268
269
270
271
let g:deoplete#enable_at_startup=1
let g:deoplete#enable_refresh_always=0
let g:deoplete#file#enable_buffer_path=1
let g:deoplete#auto_completion_start_length = 0
272
273
274
275
276
277
278
279

inoremap <expr><tab> pumvisible() ? "\<c-n>" : "\<tab>"

" <CR>: close popup and save indent.
"inoremap <silent> <CR> <C-r>=<SID>my_cr_function()<CR>
"function! s:my_cr_function() abort
  "return deoplete#close_popup() . "\<CR>"
"endfunction
Nelso Jost's avatar
Nelso Jost committed
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

"function! Completefunc(findstart, base)
    "return "\<c-x>\<c-p>"
"endfunction

" Don't let autocomplete affect usual typing habits
"set completeopt=menuone,preview,noinsert

""""""" Jedi-VIM """""""
" Don't mess up undo history<Paste>
"let g:jedi#show_call_signatures = "0"


"let g:deoplete#sources#jedi#show_docstring = 1


" for python completions
"let g:python_support_python3_requirements = add(get(g:,'python_support_python3_requirements',[]),'jedi')
" language specific completions on markdown file
"let g:python_support_python3_requirements = add(get(g:,'python_support_python3_requirements',[]),'mistune')

" utils, optional
"let g:python_support_python3_requirements = add(get(g:,'python_support_python3_requirements',[]),'psutil')
"let g:python_support_python3_requirements = add(get(g:,'python_support_python3_requirements',[]),'setproctitle')

"inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>"
"inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>"
"inoremap <expr> <CR> (pumvisible() ? "\<c-y>\<cr>" : "\<CR>")

309
"set shortmess+=c
Nelso Jost's avatar
Nelso Jost committed
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

"let g:cm_auto_popup = 0
"
"



"let g:deoplete#disable_auto_complete = 1

"inoremap <silent><expr> <TAB>
"\ pumvisible() ? "\<C-n>" :
"\ <SID>check_back_space() ? "\<TAB>" :
"\ deoplete#mappings#manual_complete()
"function! s:check_back_space() abort "{{{
"let col = col('.') - 1
"return !col || getline('.')[col - 1]  =~ '\s'
"endfunction"}}}

"inoremap <silent> <C-CR> <C-r>=<SID>my_cr_function()<CR>
    "function! s:my_cr_function() abort
      "return deoplete#close_popup() . ""
      "endfunction
      "
"if &term =~ '^screen'
    " tmux will send xterm-style keys when its xterm-keys option is on
    "execute "set <xUp>=\e[1;*A"
    "execute "set <xDown>=\e[1;*B"
    "execute "set <xRight>=\e[1;*C"
    "execute "set <xLeft>=\e[1;*D"
"endif


342
" https://github.com/scrooloose/nerdtree
Nelso Jost's avatar
Nelso Jost committed
343
344
345
346
" How can I open a NERDTree automatically when vim starts up if no files were specified?
autocmd StdinReadPre * let s:std_in=1
autocmd VimEnter * if argc() == 0 && !exists("s:std_in") | NERDTree | endif

347
348
349
350
351
352
353
354
355

let g:vim_markdown_folding_disabled = 1

"au BufNewFile,BufFilePre,BufRead *.md set filetype=markdown tw=80 fo+=t colorcolumn=80

"=======================================================================
" http://vim.wikia.com/wiki/Move_cursor_by_display_lines_when_wrapping

noremap <silent> <Leader>w :call ToggleWrap()<CR>
356
357

function! ToggleWrap()
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
  if &wrap
    echo "Wrap OFF"
    setlocal nowrap
    set virtualedit=all
    silent! nunmap <buffer> <Up>
    silent! nunmap <buffer> <Down>
    silent! nunmap <buffer> <Home>
    silent! nunmap <buffer> <End>
    silent! iunmap <buffer> <Up>
    silent! iunmap <buffer> <Down>
    silent! iunmap <buffer> <Home>
    silent! iunmap <buffer> <End>
  else
    echo "Wrap ON"
    setlocal wrap linebreak nolist
    set virtualedit=
    setlocal display+=lastline
    noremap  <buffer> <silent> <Up>   gk
    noremap  <buffer> <silent> <Down> gj
    noremap  <buffer> <silent> <Home> g<Home>
    noremap  <buffer> <silent> <End>  g<End>
    inoremap <buffer> <silent> <Up>   <C-o>gk
    inoremap <buffer> <silent> <Down> <C-o>gj
    inoremap <buffer> <silent> <Home> <C-o>g<Home>
    inoremap <buffer> <silent> <End>  <C-o>g<End>
  endif
endfunction

" http://vim.wikia.com/wiki/Remove_unwanted_spaces
autocmd BufWritePre * %s/\s\+$//e

389
" auto detect vim settings when config file is saved
390
391
392
393
394
395
"autocmd! bufwritepost $MYVIMRC source $MYVIMRC
" https://github.com/itchyny/lightline.vim/issues/102
augroup reload_vimrc " {
    autocmd!
    autocmd BufWritePost $MYVIMRC nested source $MYVIMRC
augroup END " }
396

397
398
399
400
401
402
403
404
405

let g:tagbar_type_markdown = {
  \ 'ctagstype' : 'markdown',
  \ 'kinds' : [
    \ 'h:Heading_L1',
    \ 'i:Heading_L2',
    \ 'k:Heading_L3'
  \ ]
\ }
406
407


408
hi MatchParen cterm=none ctermbg=black ctermfg=green
409
410
"highlight MatchParen term=underline cterm=underline gui=underline

411
" auxiliate cursor navigation between _ on words
412
413
set iskeyword-=_

414
415
416
417
418
419
420
421
422
423
424
425
426
427
428

" https://stackoverflow.com/questions/2514445/turning-off-auto-indent-when-pasting-text-into-vim
let &t_SI .= "\<Esc>[?2004h"
let &t_EI .= "\<Esc>[?2004l"

inoremap <special> <expr> <Esc>[200~ XTermPasteBegin()

function! XTermPasteBegin()
  set pastetoggle=<Esc>[201~
  set paste
  return ""
endfunction