" ================================================== " Basic Mappings " ================================================== " Maps for jj to act as Esc in insert and command modes ino jj cno jj " One can map ctrl-c to something else if needed map imap " Smarter j/k navigation " Convert the j and k movement commands from strict linewise movements to " onscreen display line movements via the gj and gk commands. When " preceded with a count we want to go back to strict linewise movements. " will automatically save movements larger than 5 lines to the jumplist. nnoremap j v:count ? (v:count > 5 ? "m'" . v:count : '') . 'j' : 'gj' nnoremap k v:count ? (v:count > 5 ? "m'" . v:count : '') . 'k' : 'gk' " Center next/previous matched string nnoremap n nzz nnoremap N Nzz " quick make map :make " simple pasting from the system clipboard " http://tilvim.com/2014/03/18/a-better-paste.html map p :set pasteo"+]p:set nopaste " un-highlight when esc is pressed "map :noh " Quickly toggle relative line numbers function ToggleRelativeLineNumbers() set invnumber set invrelativenumber endfunction nnoremap l :call ToggleRelativeLineNumbers() " Toggle between absolute -> relative line number "nnoremap :let [&nu, &rnu] = [&nu, &nu+&rnu==1] " Save files as root cnoremap w!! execute ':w suda://%' " ================================================== " vimrc handling " ================================================== " ,v loads .vimrc " ,V reloads .vimrc -- activating changes (needs save) "map v :sp ~/.config/nvim/init.vim_ "map V :source ~/.config/nvim/init.vim:filetype detect:exe ":echo 'vimrc reloaded'" " ================================================== " Window navigation " ================================================== " control + vim direction key to navigate windows noremap j noremap k noremap h noremap l " control + arrow key to navigate windows noremap j noremap k noremap h noremap l " close all windows except the current one nnoremap wco :only nnoremap wcc :cclose " windows creation " create window on the bottom nnoremap wb s " create vertical window nnoremap wv v " " arrow keys resize windows " nnoremap :vertical resize -10 " nnoremap :vertical resize +10 " nnoremap :resize -10 " nnoremap :resize +10 " imap " imap " imap " imap " ================================================== " Splits handling " ================================================== " Make these all work in insert mode "imap " - and + to resize horizontal splits map - - map + + " alt-< or alt-> for vertical splits map > map < " F2 close current split (window) noremap :close " Deleter buffer, keep the split (switch to prev buf, delete now prev buf) nmap d :b#bd# " ================================================== " Tab navigation " ================================================== map to :tabonly map tc :tabclose map tm :tabmove nnoremap tn :tabnew nnoremap th :tabfirst nnoremap tk :tabnext nnoremap tj :tabprev nnoremap tl :tablast " move tab to first position nnoremap tF :tabm 0 nnoremap tL :tabm " Navigate tabs with shift-{h,l} noremap gt noremap gT " Opens a new tab with the current buffer's path " Super useful when editing files in the same directory map te :tabedit =expand("%:p:h")/ " Switch CWD to the directory of the open buffer map cd :cd %:p:h:pwd " Specify the behavior when switching between buffers try set switchbuf=useopen,usetab,newtab set stal=2 catch endtry " ================================================== " Buffer navigation " ================================================== nmap :bnext nmap :bprevious " ================================================== " Clean all end of line whitespace with S " ================================================== fun! TrimWhitespace() let l:save = winsaveview() keeppatterns %s/\s\+$//e call winrestview(l:save) endfun :nnoremap S :call TrimWhitespace() " ================================================== " Spell checking " ================================================== " Pressing ,ss will toggle and untoggle spell checking map ss :setlocal spell! " Shortcuts using map sn ]s map sp [s map sa zg map s? z= " ================================================== " Other Configurations " ================================================== " Quickly open a buffer for scribble map q :e ~/buffer " Quickly open a markdown buffer for scribble map x :e ~/buffer.md " Toggle paste mode on and off map pp :setlocal paste! " indent without kill the selection in vmode vmap < >gv " remap the annoying u in visual mode vmap u y " shortcut to substitute current word under cursor nnoremap [ :%s///g " Change in next bracket nmap cinb cib " delete character after cursor in insert mode inoremap " highlight the line which is longer than the defined margin (120 character) highlight MaxLineChar ctermbg=red autocmd FileType php,js,vue,go call matchadd('MaxLineChar', '\%120v', 100) " open devdocs.io with waterfox and search the word under the cursor command! -nargs=? DevDocs :call system('type -p open >/dev/null 2>&1 && open https://devdocs.io/#q= || waterfox -url https://devdocs.io/#q=') autocmd FileType python,ruby,rspec,javascript,go,html,php,eruby,coffee,haml nmap D :exec "DevDocs " . fnameescape(expand('')) " Markdown autocmd BufNewFile,BufFilePre,BufRead *.md set filetype=markdown " Keep the cursor in place while joining lines nnoremap J mzJ`z " Quit neovim terminal tnoremap " Open images with feh autocmd BufEnter *.png,*.jpg,*gif silent! exec "! feh ".expand("%") | :bw " A |Dict| specifies the matcher for filtering and sorting the completion candidates. let g:cm_matcher={'module': 'cm_matchers.abbrev_matcher', 'case': 'smartcase'} " Disable anoying ex mode nnoremap Q " vim:set et sw=2: