" ================================================== " 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 " Save session exec 'nnoremap ss :mksession! ~/.nvim_runtime/sessions/*.vim' " Reload session exec 'nnoremap sl :so ~/.nvim_runtime/sessions/*.vim' " 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 " Quickly save, quit, or save-and-quit map w :w map x :x map q :q " 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 vertival 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 " Let 'tl' toggle between this and the last accessed tab let g:lasttab = 1 nmap 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 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 " ================================================== ":nnoremap S :let _s=@/:%s/\s\+$//e:let @/=_s:nohl fun! TrimWhitespace() let l:save = winsaveview() keeppatterns %s/\s\+$//e call winrestview(l:save) endfun :nnoremap S :call TrimWhitespace() " ================================================== " Visual mode related " ================================================== " Visual mode pressing * or # searches for the current selection " Super useful! From an idea by Michael Naumann vnoremap * :call VisualSelection('', '')/=@/ vnoremap # :call VisualSelection('', '')?=@/ function! VisualSelection(direction, extra_filter) range let l:saved_reg = @" execute "normal! vgvy" let l:pattern = escape(@", "\\/.*'$^~[]") let l:pattern = substitute(l:pattern, "\n$", "", "") if a:direction == 'gv' call CmdLine("Ack '" . l:pattern . "' " ) elseif a:direction == 'replace' call CmdLine("%s" . '/'. l:pattern . '/') endif let @/ = l:pattern let @" = l:saved_reg endfunction " ================================================== " Editing mappings " ================================================== " Remap VIM 0 to first non-blank character map 0 ^ " Move a line of text using ALT+[jk] or Command+[jk] on mac nmap mz:m+`z nmap mz:m-2`z vmap :m'>+`mzgv`yo`z vmap :m'<-2`>my` nmap vmap vmap endif " ================================================== " 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 " ================================================== " Remove the Windows ^M - when the encodings gets messed up noremap m mmHmt:%s///ge'tzt'm " 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! noremap :Denite buffer file_rec tag xmap a gaip* nmap t sj:terminal nmap vt vl:terminal nmap g :Goyo nmap j :set filetype=journal nmap l :Limelight!! autocmd FileType python nmap x :0,$!~/.config/nvim/env/bin/python -m yapf vmap !boxes -d stone " surround by quotes - frequently use cases of vim-surround map " ysiw" map ' ysiw' " Act like D and C nnoremap Y y$ " 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 " Visual mode pressing * or # searches for the current selection " Super useful! From an idea by Michael Naumann vnoremap * :call general#VisualSelection('', '')/=@/ vnoremap # :call general#VisualSelection('', '')?=@/ " 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 " Neovim :Terminal tmap tmap autocmd BufWinEnter,WinEnter term://* startinsert autocmd BufLeave term://* stopinsert " vim:set et sw=2: