""""""""""""""""""""""""""""" " Keymaps """"""""""""""""""""""""""""" let g:mapleader = "\" let g:maplocalleader = ',' nnoremap :WhichKey '' nnoremap :WhichKey ',' " Treat long paragraph as a line map j gj map k gk """""""""""""""""""" " Window movement """""""""""""""""""" " Go to the bottom window noremap j " Go to the top window noremap k " Go to the right window noremap l " Go to the left window noremap h """""""""""""""""""""""" " Remove highlighting """""""""""""""""""""""" nnoremap hl :nohlsearch " Save file nnoremap :w! """""""""""""""""""""""""" " Buffer """"""""""""""""""""""""" " Close the current buffer noremap bd :Bclose:tabclosegT " Close all the buffers noremap ba :bufdo bd " Go to the next buffer noremap bn :bnext " Go to the previous buffer noremap bp :bprevious """""""""""""""""""""""""""" " Tabs """"""""""""""""""""""""""" " Open a new tab noremap tn :tabnew " Close all others tab noremap to :tabonly " Close current tab page noremap tc :tabclose " Move tabs after another noremap tm :tabmove " Go to the next tab noremap t :tabnext " Let 'tl' toggle between this and the last accessed tab let g:lasttab = 1 nnoremap tl :exe "tabn ".g:lasttab au TabLeave * let g:lasttab = tabpagenr() " Opens a new tab with the current buffer's path " Super useful when editing files in the same directory noremap te :tabedit =escape(expand("%:p:h"), " ")/ " Switch CWD to the directory of the open buffer noremap cd :cd %:p:h:pwd " Specify the behavior when switching between buffers try set switchbuf=useopen,usetab,newtab set stal=2 catch endtry " Return to last edit position when opening files (You want this!) au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif """""""""""""""""""""""" " Netrw """"""""""""""""""""""" " Toggle tree view nnoremap :Lexplore """""""""""""""""""" " GitGutter """""""""""""""""""" let g:gitgutter_enabled=1 " Enable by default gitgutter " Go to the previous hunk nnoremap hp (GitGutterPrevHunk) " Go to the next hunk nnoremap hn (GitGutterNextHunk) " Enable / Disable GitGutter nnoremap ht (GitGutterToggle) " Stage Hunk in Git nnoremap hs (GitGutterStageHunk) " Undo Hunk nnoremap hu (GitGutterUndoHunk) " Preview Hunk nnoremap hP :GitGutterPreviewHunk " Always show the status line set laststatus=2 """"""""""""""""""""" " Spell """"""""""""""""""""" " Toggle and untoggle spell checking noremap ss :setlocal spell! " Next word to spellcheck noremap sn ]s " Previous word to spellcheck noremap sp [s " Add word into the spellcheck dictionary noremap sa zg " show the list of alternatives for the word noremap s? z= """""""""""""""""""" " LSP """""""""""""""""""" nmap [g (coc-diagnostic-prev) nmap ]g (coc-diagnostic-next) " GoTo code navigation nmap gd (coc-definition) nmap gy (coc-type-definition) nmap gi (coc-implementation) nmap gr (coc-references) " Use K to show documentation in preview window nnoremap K :call ShowDocumentation() function! ShowDocumentation() if CocAction('hasProvider', 'hover') call CocActionAsync('doHover') else call feedkeys('K', 'in') endif endfunction " Highlight the symbol and its references when holding the cursor autocmd CursorHold * silent call CocActionAsync('highlight') " Symbol renaming nmap gR (coc-rename) " Formatting selected code xmap gf (coc-format-selected) nmap gf (coc-format-selected) " Applying code actions to the selected code block xmap ga (coc-codeaction-selected) nmap ga (coc-codeaction-selected) " Remap keys for applying code actions at the cursor position nmap gc (coc-codeaction-cursor) " Remap keys for apply code actions affect whole buffer nmap gs (coc-codeaction-source) " Apply the most preferred quickfix action to fix diagnostic on the current line nmap gqf (coc-fix-current) " Remap keys for applying refactor code actions nmap gr (coc-codeaction-refactor) xmap r (coc-codeaction-refactor-selected) nmap r (coc-codeaction-refactor-selected) " Run the Code Lens action on the current line nmap gcl (coc-codelens-action)