Vim: Reorganize mapping into a single place

This commit is contained in:
Robert Kmiec
2020-07-07 14:55:54 +02:00
parent f39aff0edf
commit 421d33b90e

View File

@@ -132,10 +132,19 @@ set ttyfast
set lazyredraw
set ruler
set backspace=eol,indent,start
" statusline {{{
set statusline=%<%f%h%m%r%=%b\ 0x%B\ \ %l,%c%V\ %P
set laststatus=2
" Vista configuration
function! NearestMethodOrFunction() abort
return get(b:, 'vista_nearest_method_or_function', '')
endfunction
set statusline+=\
set statusline+=%{NearestMethodOrFunction()}
" }}}
set number
set norelativenumber
set relativenumber
" Make Vim to handle long lines nicely.
set wrap
set textwidth=79
@@ -158,6 +167,7 @@ nnoremap <leader><space> :nohlsearch<cr>
set shell=/bin/bash
set path+=**
packadd termdebug
" Undofile {{{
@@ -179,19 +189,16 @@ let g:gutentags_cache_dir='~/.vim/tags'
"let g:gutentags_ctags_extra_args=['--fields=+l']
" }}}
"
" Mappings {{{
" Editing {{{
"Changing Leader Key
let mapleader = "\\"
" Make pasting done without any indentation break
set pastetoggle=<F3>
set clipboard=unnamed
nnoremap <leader>j J
nnoremap <leader>k K
nnoremap J 5j
nnoremap K 5k
"nnoremap j gj
"nnoremap k gk
@@ -199,31 +206,91 @@ nnoremap K 5k
inoremap <F1> <ESC>
nnoremap <F1> <ESC>
vnoremap <F1> <ESC>
" jj For Quicker Escaping between normal and editing mode
inoremap jj <ESC>
inoremap jk <ESC>
inoremap :w<CR> <Esc>:w<CR>i
" Map : to ; also in command mode.
" space one line, home,end globally increase/decrease
nnoremap <space><space> za
nnoremap <Home> zm
nnoremap <End> zr
" Map : to ; also in command mode
"nnoremap ; :
" Reselect visual block after incrementing/decrementing
vnoremap <c-a> <c-a>gv
vnoremap <c-x> <c-x>gv
" Set vim to save the file on focus out
"au FocusLost * :wa
nnoremap <leader>2 <esc>:set tabstop=2 softtabstop=2 shiftwidth=2<cr>
nnoremap <leader>4 <esc>:set tabstop=4 softtabstop=4 shiftwidth=4<cr>
nnoremap <leader>8 <esc>:set tabstop=8 softtabstop=8 shiftwidth=8<cr>
map <F12> :colorscheme random<CR>
" Make pasting done without any indentation break
set pastetoggle=<F3>
" leader Command to remove white space from a file
""nnoremap <leader>W :%s/\s\+$//<cr>:let @/=''<CR>
" Re-hardwrap Paragraph
nnoremap <leader>q gqip
tnoremap <Esc> <C-W><C-W>
" }}}
" Plugins {{{
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
" jj For Quicker Escaping between normal and editing mode
inoremap jj <ESC>
inoremap jk <ESC>
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)
" Resize Split When the window is resized
au VimResized * :wincmd =
nnoremap <silent> <space>k :call <SID>show_documentation()<CR>
" Wildmenu completion
xmap <leader>f <Plug>(coc-format-selected)
nmap <leader>f <Plug>(coc-format-selected)
" Show all diagnostics
nnoremap <silent> <space>a :<C-u>CocList diagnostics<cr>
" Manage extensions
nnoremap <silent> <space>e :<C-u>CocList extensions<cr>
" Show commands
nnoremap <silent> <space>c :<C-u>CocList commands<cr>
" Find symbol of current document
nnoremap <silent> <space>o :<C-u>CocList outline<cr>
" Search workspace symbols
nnoremap <silent> <space>s :<C-u>CocList -I symbols<cr>
" Do default action for next item.
nnoremap <silent> <space>j :<C-u>CocNext<CR>
" Do default action for previous item.
nnoremap <silent> <space>k :<C-u>CocPrev<CR>
" Resume latest coc list
nnoremap <silent> <space>p :<C-u>CocListResume<CR>
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<CR>"
let g:UltiSnipsJumpBackwardTrigger="<leader>p"
" yoink configuration
nmap <leader>p <plug>(YoinkPostPasteSwapBack)
nmap <leader>n <plug>(YoinkPostPasteSwapForward)
nmap p <plug>(YoinkPaste_p)
nmap P <plug>(YoinkPaste_P)
nnoremap <leader>l :Lines<CR>
nnoremap <leader>b :Buffers<CR>
nnoremap <leader>s :Snippets<CR>
nnoremap <leader>a :Ag <C-R><C-W><CR>
" Tagbar key bindings."
"nmap <leader>t :TlistToggle<cr>
" }}}
" }}}
set clipboard=unnamed
" Wildmenu completion {{{
set wildmenu
set wildmode=list:longest
set wildignore+=.hg,.git,.svn " Version Controls"
@@ -237,6 +304,7 @@ set wildignore+=*.luac "Lua byte code"
set wildignore+=migrations "Django migrations"
set wildignore+=*.pyc "Python Object codes"
set wildignore+=*.orig "Merge resolution files"
" }}}
match Error /\s\+$\|DU\cPA/
@@ -265,13 +333,6 @@ let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplModSelTarget = 1
let g:miniBufExplStatusLineText = ''
" Tagbar key bindings."
"nmap <leader>t :TlistToggle<cr>
nnoremap <leader>2 <esc>:set tabstop=2 softtabstop=2 shiftwidth=2<cr>
nnoremap <leader>4 <esc>:set tabstop=4 softtabstop=4 shiftwidth=4<cr>
nnoremap <leader>8 <esc>:set tabstop=8 softtabstop=8 shiftwidth=8<cr>
"Full line:
"set colorcolumn=120
"call matchadd('ColorColumn', '\%80v', 100)
@@ -284,68 +345,35 @@ if has("autocmd")
autocmd WinLeave * set nocursorline
autocmd WinEnter * set cursorline
"autocmd FileType tex set textwidth=79
"autocmd FileType c,cpp,hpp,h :RainbowLevelsOn
" Set vim to save the file on focus out
"au FocusLost * :wa
" Resize Split When the window is resized
au VimResized * :wincmd =
" If you want to show the nearest function in your statusline automatically
autocmd VimEnter * call vista#RunForNearestMethodOrFunction()
endif
"hi! link RainbowLevel0 Constant
"hi! link RainbowLevel1 Type
"hi! link RainbowLevel2 Function
"hi! link RainbowLevel3 String
"hi! link RainbowLevel4 PreProc
"hi! link RainbowLevel5 Statement
"hi! link RainbowLevel6 Identifier
"hi! link RainbowLevel7 Normal
"hi! link RainbowLevel8 Comment
"nnoremap yg :YcmCompleter GoTo<CR>
"nnoremap yf :YcmCompleter FixIt<CR>
"nnoremap yd :YcmCompleter GetDoc<CR>
"nnoremap yt :YcmCompleter GetType<CR>
"nnoremap yp :YcmCompleter GetParent<CR>
"let g:ycm_confirm_extra_conf = 0
"let g:ycm_warning_symbol = '>'
"let g:ycm_complete_in_strings = 0
"let g:ycm_collect_identifiers_from_tags_files = 1
"let g:ycm_enable_diagnostic_highlighting = 0
"let g:ycm_autoclose_preview_window_after_completion = 0
"let g:ycm_autoclose_preview_window_after_insertion = 1
"let g:ycm_min_num_of_chars_for_completion = 99
map <F12> :colorscheme random<CR>
" Folding {{{
function! FoldFormat()
let foldsize = (v:foldend - v:foldstart)
return getline(v:foldstart)."\t\t\t(".foldsize."\tmore lines)"
endfunction
" space one line, home,end globally increase/decrease
set foldenable
set foldlevelstart=999
set foldnestmax=5
set foldtext=FoldFormat()
set fillchars=fold:\ " comment just to remove trailing
set foldmethod=syntax
nnoremap <space> za
nnoremap <Home> zm
nnoremap <End> zr
if has('folding')
setglobal foldopen+=jump
endif
" }}}
set updatetime=100
" From C.vim:
" ADDITIONAL MAPPING : complete a classical C comment: '/*' => '/* | */'
"vnoremap <buffer> /* s/*<Space><Space>*/<Left><Left><Left><Esc>p
" additional mapping : complete a classical C multi-line comment:
"inoremap <buffer> /*<CR> /*<CR><CR>/<Esc>kA<Space>
" additional mapping : {<CR> always opens a block
"inoremap <buffer> {<CR> {<CR>}<Esc>O
"vnoremap <buffer> {<CR> S{<CR>}<Esc>Pk=iB
inoremap :w<CR> <Esc>:w<CR>i
"nnoremap <F2> :silent ! plantuml %:p && eog -g %:p:r.png &<CR>:redraw!<CR>
" ctrlp configuration
"let g:ctrlp_map = '<c-p>'
"let g:ctrlp_cmd = 'CtrlPLastMode'
@@ -353,49 +381,22 @@ inoremap :w<CR> <Esc>:w<CR>i
"let g:ctrlp_working_path_mode = 'rw'
nnoremap <c-p> :FZF<CR>
tnoremap <Esc> <C-W><C-W>
set nospell
set runtimepath+=/usr/share/vim/vimfiles
set spelllang=en
" Dictionary path, from which the words are being looked up.
set dictionary+=/usr/share/dict/words
" from vimconfig.com
"let g:rtagsRcCmd='rtags-rc'
"let g:matchparen_timeout = 2
"let g:matchparen_insert_timeout = 2
" Mapping to NERDTree
"nnoremap <C-n> :e .<CR>
nnoremap <C-n> :NERDTreeToggle<CR>
let NERDTreeIgnore=['\.vim$', '\~$', '\.pyc$']
"nnoremap <C-n> :e .<CR>
"let g:netrw_banner=0
"let g:netrw_wisize=20
"let g:netrw_liststyle=3
"let g:netrw_lolcalrmdir='rm -r'
"nnoremap <leader>n :Lexplore<CR>
" taken from Damian Conway
"nnoremap <silent> n n:call HLNext(0.2)<cr>
"nnoremap <silent> N N:call HLNext(0.2)<cr>
"
"function! HLNext(blinktime)
" let [bufnum, lnum, col, off] = getpos('.')
" let matchlen = strlen(matchstr(strpart(getline('.'), col - 1), @/))
" let target_pat = '\c\%#'.@/
" let blinks = 1
" for n in range(1, blinks)
" let red = matchadd('WarningMsg', target_pat, 101)
" redraw
" exec 'sleep ' . float2nr(a:blinktime / (2*blinks) * 1000) . 'm'
" call matchdelete(red)
" redraw
" exec 'sleep ' . float2nr(a:blinktime / (2*blinks) * 1000) . 'm'
" endfor
"endfunction
nnoremap S :%s//g<LEFT><LEFT>
xnoremap S :s//g<LEFT><LEFT>
xmap <BS> x
@@ -408,7 +409,7 @@ function! FindAlternate()
elseif (l:curr_ext == 'cpp')
let l:ext = 'h'
elseif (l:curr_ext == 'h')
let l:ext = 'cpp'
let l:ext = 'c'
elseif (l:curr_ext == 'hpp')
let l:ext = 'cpp'
endif
@@ -420,27 +421,20 @@ nnoremap <F6> :call FindAlternate()<CR>
"let g:alternateSearchPath="sfr:../source,sfr:../src,sfr:../include,sfr:../inc,sfr:./Source,sfr:.."
"map <F6> :call CurtineIncSw()<CR>
" taken from tpope
let g:startify_custom_header = ''
setglobal complete-=i
setglobal virtualedit=block
setglobal shiftround
if has('folding')
setglobal foldopen+=jump
endif
packadd termdebug
let g:startify_custom_header = ''
set shortmess+=c
inoremap <silent><expr> <c-space> coc#refresh()
"inoremap <silent><expr> <leader><space> coc#refresh()
set signcolumn=yes
set cmdheight=2
inoremap <silent><expr> <TAB>
\ pumvisible() ? "\<C-n>" :
\ <SID>check_back_space() ? "\<TAB>" :
\ coc#refresh()
"inoremap <silent><expr> <TAB>
" \ pumvisible() ? "\<C-n>" :
" \ <SID>check_back_space() ? "\<TAB>" :
" \ coc#refresh()
inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<C-h>"
function! s:check_back_space() abort
@@ -448,15 +442,6 @@ function! s:check_back_space() abort
return !col || getline('.')[col - 1] =~# '\s'
endfunction
inoremap <expr> <cr> pumvisible() ? "\<C-y>" : "\<C-g>u\<CR>"
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)
nnoremap <silent> K :call <SID>show_documentation()<CR>
function! s:show_documentation()
if (index(['vim','help'], &filetype) >= 0)
execute 'h '.expand('<cword>')
@@ -466,55 +451,8 @@ function! s:show_documentation()
endfunction
autocmd CursorHold * silent call CocActionAsync('highlight')
xmap <leader>f <Plug>(coc-format-selected)
nmap <leader>f <Plug>(coc-format-selected)
" Show all diagnostics
nnoremap <silent> <space>a :<C-u>CocList diagnostics<cr>
" Manage extensions
nnoremap <silent> <space>e :<C-u>CocList extensions<cr>
" Show commands
nnoremap <silent> <space>c :<C-u>CocList commands<cr>
" Find symbol of current document
nnoremap <silent> <space>o :<C-u>CocList outline<cr>
" Search workspace symbols
nnoremap <silent> <space>s :<C-u>CocList -I symbols<cr>
" Do default action for next item.
nnoremap <silent> <space>j :<C-u>CocNext<CR>
" Do default action for previous item.
nnoremap <silent> <space>k :<C-u>CocPrev<CR>
" Resume latest coc list
nnoremap <silent> <space>p :<C-u>CocListResume<CR>
" Vista configuration
function! NearestMethodOrFunction() abort
return get(b:, 'vista_nearest_method_or_function', '')
endfunction
set statusline+=\
set statusline+=%{NearestMethodOrFunction()}
" By default vista.vim never run if you don't call it explicitly.
"
" If you want to show the nearest function in your statusline automatically
autocmd VimEnter * call vista#RunForNearestMethodOrFunction()
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<CR>"
let g:UltiSnipsJumpBackwardTrigger="<leader>p"
" yoink configuration
nmap <leader>p <plug>(YoinkPostPasteSwapBack)
nmap <leader>n <plug>(YoinkPostPasteSwapForward)
nmap p <plug>(YoinkPaste_p)
nmap P <plug>(YoinkPaste_P)
hi None ctermbg=None ctermfg=None
nnoremap <leader>l :Lines<CR>
nnoremap <leader>b :Buffers<CR>
nnoremap <leader>s :Snippets<CR>
nnoremap <leader>a :Ag <C-R><C-W><CR>
let g:vim_search_pulse_mode = 'pattern'
let g:vim_search_pulse_duration = 400