" Key Conventions: " " Super " Open / close windows and tabs " TextMate keybindings " " Meta " Emacs style movement / editing " Special character insertion " Insert commands that stay in insert mode " " " Command line shortcuts " Map Unicode character bindings from ~/.inputrc MapReadlineUnicodeBindings """ Mapleader {{{1 " Transfer decrement-number to (nvoic) to free (nvo) " Bind: M-x => Ctrl-X " Bind: v_M-x => v_Ctrl-X " Bind: o_M-x => o_Ctrl-X noremap noremap " Transfer shift-line-right to (ic)<4-]> to free (ic) " Transfer insert-mode-completions to (ic) to free (ic) " Bind: i_4-] => i_Ctrl-T " Bind: c_4-] => c_Ctrl-T " Bind: i_Ctrl-T => i_Ctrl-X " Bind: c_Ctrl-T => c_Ctrl-X noremap! noremap! <4-]> noremap! noremap! " Mapleader is available in all modes, and always returns to normal-mode " Bind: Ctrl-X => " Bind: v_Ctrl-X => v_ " Bind: o_Ctrl-X => o_ " Bind: i_Ctrl-X => i_Ctrl-\_Ctrl-N_ " Bind: c_Ctrl-X => c_Ctrl-\_Ctrl-N_ let g:mapleader = '' map! " REPLACE move-up-and-start-of-line (nvo)- with " Bind: - => " Bind: v_- => v_ " Bind: o_- => o_ noremap - let g:maplocalleader = '-' """ Escape {{{1 " Allow Ctrl-C, which is easily accessible from the home row, to be a complete " replacement for the Escape key: " " * Complete (don't cancel) visual block insertions " * Alway break out of Select mode " " Bind: i_Ctrl-C => " Bind: v_Ctrl-C => inoremap xnoremap snoremap " Since our mappings never timeout, a single ESC will hang indefinitely, " waiting for a Meta/Mod4 sequence. We will use Ctrl-C as our primary escape, " and double ESC as our secondary. noremap! """ Emacs: Ctrl-A (start-of-line) {{{1 " Transfer increment-number to (nvo) to free (nvo) " Bind: M-a => Ctrl-A " Bind: v_M-a => v_Ctrl-A " Bind: o_M-a => o_Ctrl-A noremap noremap " Transfer insert-prev-text / insert-all-completions to (ic)<4-a> to free " (ic) " Bind: i_4-a => i_Ctrl-A " Bind: c_4-a => c_Ctrl-A noremap! noremap! <4-a> " Bind to start-of-line in all modes " Bind: Ctrl-A => ^ " Bind: v_Ctrl-A => v_^ " Bind: o_Ctrl-A => o_^ " Bind: i_Ctrl-A => i_Ctrl-\_Ctrl-O_^ " Bind: c_Ctrl-A => c_Home noremap ^ inoremap ^ cnoremap """ Emacs: Ctrl-E (end-of-line) {{{1 " Transfer scroll-window-down to (nvo)<4-e> to free (nvo) " Bind: 4-e => Ctrl-E " Bind: v_4-e => v_Ctrl-E " Bind: o_4-e => o_Ctrl-E noremap noremap <4-e> " Transfer insert-character-below / revert-completion to (i)<4-e> to free " (i). c_Ctrl-E is already bound to end-of-command-line. " Bind: i_4-e => i_Ctrl-E / complete_Ctrl-E inoremap inoremap <4-e> " Bind to end-of-line " Bind: Ctrl-E => $ " Bind: v_Ctrl-E => v_$ " Bind: o_Ctrl-E => o_$ " Bind: i_Ctrl-E => i_End noremap $ inoremap """ Emacs: Ctrl-Y (paste-unnamed-register) {{{1 " Transfer scroll-window-up, insert-character-above, accept-completion, and " copy-modeless-selection to (nvoic)<4-y> to free (nvoic), mostly to " mirror <4-e> above. " Bind: 4-y => Ctrl-Y " Bind: v_4-y => v_Ctrl-Y " Bind: o_4-y => o_Ctrl-Y " Bind: i_4-y => i_Ctrl-Y / complete_Ctrl-Y " Bind: c_4-y => c_Ctrl-Y noremap noremap! noremap <4-y> noremap! <4-y> " Set (nvoic) to paste-unnamed-register " Bind: Ctrl-Y => ""p " Bind: v_Ctrl-Y => v_""p " Bind: o_Ctrl-Y => o_""p " Bind: i_Ctrl-Y => i_Ctrl-R_""p " Bind: c_Ctrl-Y => c_Ctrl-R_""p noremap ""p noremap! " """ Emacs: Ctrl-F Ctrl-B (page-{down,up}, char-{right,left}) {{{1 " Rebind scroll-page-{up,down} to also jump to the middle of the page " Bind: Ctrl-F => _M " Bind: v_Ctrl-F => v__M " Bind: o_Ctrl-F => o__M " Bind: Ctrl-B => _M " Bind: v_Ctrl-B => v__M " Bind: o_Ctrl-B => o__M noremap M noremap M " REPLACE deprecated-Ctrl-B and start-of-command-line with char-left " Bind: i_Ctrl-B => i_ " Bind: c_Ctrl-B => c_ noremap! " Transfer c-reindent-line and open-command-line-window to (ic)<4-;> to free " (ic) for char-right. " Bind: i_4-; => i_Ctrl-F " Bind: c_4-; => c_Ctrl-F noremap! noremap! <4-;> " Bind (ic) to char-right " Bind: i_Ctrl-F => i_ " Bind: c_Ctrl-F => c_ noremap! """ Emacs: Ctrl-D (forward-delete) {{{1 " REPLACE scroll-half-page-down (nvo) with forward-delete. " Bind: Ctrl-D => x " Bind: v_Ctrl-D => v_x " Bind: o_Ctrl-D => o_x noremap x " Transfer shift-line-left to (i)<4-[> to free (i) " Bind: i_4-[ => i_Ctrl-D inoremap inoremap <4-[> " Transfer list-pattern-matches to (c)<4-[> to free (c) " Bind: c_4-[ => c_Ctrl-D cnoremap cnoremap <4-[> " Set (ic) as forward-delete " Bind: i_Ctrl-D => i_Del " Bind: c_Ctrl-D => c_Del noremap! """ Emacs: Ctrl-K Ctrl-U (kill-to-{end,start}-of-line) {{{1 " Transfer enter-digraph to (nvoic) to free (nvoic) " Bind: => Ctrl-K " Bind: v_ => v_Ctrl-K " Bind: o_ => o_Ctrl-K " Bind: i_ => i_Ctrl-K " Bind: c_ => c_Ctrl-K noremap noremap noremap! noremap! " Set (nvoic) to kill-to-end-of-line " Bind: Ctrl-K => D " Bind: v_Ctrl-K => v_D " Bind: o_Ctrl-K => o_D " Bind: i_Ctrl-K => i_Ctrl-\_Ctrl-O_D " Bind: c_Ctrl-K => c_Ctrl-F_D_Ctrl-C_ noremap D inoremap D cnoremap D " REPLACE scroll-half-page-up and delete-all-inserted-chars with a simple " kill-to-start-of-line. c_Ctrl-U already does this on the command line. " Bind: Ctrl-U => d^ " Bind: v_Ctrl-U => v_d^ " Bind: o_Ctrl-U => o_d^ " Bind: i_Ctrl-U => i_Ctrl-\_Ctrl-O_d^ noremap d^ inoremap d^ """ Emacs: Meta-f Meta-b Meta-d (word-{right,left} forward-delete-word) {{{1 " Word-right noremap w inoremap w cnoremap " Word-left noremap b inoremap b cnoremap " Forward-delete-word noremap de inoremap de cnoremap de """ Command line and Search {{{1 " Transfer repeat-last-char-search to (nvo), to free (nvo); " Transfer backwards-repeat-last-char-search to (nvo)M-, to free (nvo), " Bind: , => ; " Bind: v_, => v_; " Bind: o_, => o_; noremap ; noremap , noremap , ; " Since C-; opens the command line window, map <4-;> to do the same in (nvo) " Also bind some more ; -> : aliases. noremap <4-;> q: noremap @; @: " Alias (nvo); to (nvo): for quick access to the command line " Bind: ; => : " Bind: v_; => v_: " Bind: o_; => o_: noremap ; : " SWAP c_Ctrl-n and c_, c_Ctrl-p and c_ cnoremap cnoremap cnoremap cnoremap " Transfer go-to-column to (nvo)g| to free (nvo)| " Bind: g| => | " Bind: v_g| => v_| " Bind: o_g| => o_| noremap noremap g " Remap search commands to prepend magic / non-magic modifier noremap / /\v noremap ? ?\v noremap /\V noremap ?\V noremap <4-?> :execute ':vimgrep /' . @/ . '/gj ##' \| set hlsearch " Search for non-printing ASCII characters noremap - /\v[^\x09\x20-\x7e] " Search for lines that exceed textwidth noremap + :execute 'let @/ = "\\v^.{' . &textwidth . '}\\zs.+"' \| setlocal hlsearch \| normal! n " Simple command line aliases noremap ; :help noremap t :tag noremap T :Ctags noremap U :UndoRemove noremap <4-!> :make! noremap <4-p> :SynStack " Clear last match noremap :let @/ = '' " Open file noremap ! :execute 'silent! ! open ' . expand('%') " Rename tmux/screen/term window noremap <4-,> :execute 'Sh xecho title ' . shellescape(fnamemodify(getcwd(), ':p:h:t')) " Change directory to current file's parent noremap <4-.> :cd %:h \| echo getcwd() """ Buffer commands {{{1 " REPLACE linewise-downward with NOTHING to alias toggle-fold nnoremap za " REPLACE ex-mode with NOTHING to alias (n)Q as :quit nnoremap Q :quit " Save / Quit Buffer Mapall <4-s> :update Mapall <4-S> :write !sudo tee % >/dev/null Mapall <4-\> :quit Mapall <4-Bar> :quit! " Settings and Toggles noremap s :setlocal noremap sa :let cbuf = expand('%:p') \| execute 'args `git ls-files`' \| execute 'edit ' . cbuf \| unlet cbuf noremap ?sa :Capture args noremap sc :call Prompt('colorscheme ', '', 'color') noremap ?sc :colorscheme noremap sf :call Prompt('setlocal foldmethod=', 'syntax') noremap ?sf :setlocal foldmethod? noremap sm :call Prompt('setlocal synmaxcol=', '0') \| syntax sync fromstart noremap ?sm :setlocal synmaxcol? noremap st :SetTextwidth noremap ?st :SetTextwidth noremap sw :SetWhitespace noremap ?sw :SetWhitespace noremap :SetAutowrap! \| SetAutowrap noremap :setlocal scrollbind! \| setlocal scrollbind? noremap :SetDiff! \| SetDiff noremap :setlocal expandtab! \| setlocal expandtab? noremap :setlocal hlsearch! \| setlocal hlsearch? noremap :setlocal number! noremap :setlocal cursorline! \| setlocal cursorcolumn! noremap :setlocal spell! \| setlocal spell? noremap :if v:profiling \| execute 'Sh (sleep 1; urxvt-client -e vim /tmp/profile.vim) &' \| quitall! \| else \| call Prompt('Profile ', '', 'function') \| endif noremap :setlocal wrap! \| setlocal wrap? " Edit shortcuts noremap e :call Prompt('tabedit ', '', 'file') noremap ee :edit noremap E :call Prompt('tabedit ', expand('%:p:h') . '/', 'file') " VIMEDITBINDINGS noremap ea :TabOpen $cdhaus/etc/vim/local/autocommands.vim \| lcd $cdhaus noremap eA :TabOpen ~/.mutt/aliases \| lcd ~/.mutt noremap eb :TabOpen $cdhaus/etc/bashrc.d/interactive.bash \| lcd $cdhaus noremap eB :TabOpen $cdhaus/etc/bashrc \| lcd $cdhaus noremap ec :TabOpen $cdhaus/etc/vim/local/commands.vim \| lcd $cdhaus noremap ed :TabOpen $cddnsmasq/dnsmasq.conf \| lcd $cdetc noremap ege :execute 'TabOpen ' . system("printf %s \"$(git rev-parse --show-toplevel)/.git/info/exclude\"") noremap egs :execute 'TabOpen ' . system("printf %s \"$(git rev-parse --show-toplevel)/.git/info/sparse-checkout\"") noremap eh :TabOpen ~/.bash_history noremap eH :TabOpen $cdetc/badhosts \| lcd $cdetc noremap ei :TabOpen $cdetc/iptables/iptables.sh \| lcd $cdetc noremap eI :TabOpen $cdetc/ipset.conf \| lcd $cdetc noremap el :TabOpen $cdhaus/etc/:lein/profiles.clj \| lcd $cdhaus noremap eL :TabOpen $cdsrc/leiningen/sample.project.clj \| lcd $cdsrc noremap em :TabOpen $cdhaus/etc/vim/local/mappings.vim \| lcd $cdhaus noremap eM :TabOpen $cdhaus/etc/:mutt/muttrc \| lcd $cdhaus noremap en :TabOpen $cdnginx/nginx.conf \| lcd $cdnginx noremap eo :Org noremap ep :TabOpen /etc/pacman.conf \| lcd /etc noremap er :TabOpen $cdgunsrepl/src/guns/repl.clj \| lcd $cdgunsrepl noremap eR :TabOpen $cdhaus/Rakefile \| lcd $cdhaus noremap es :vsplit \| Scratch noremap eS :TabOpen /etc/ssh/ssh_config \| lcd /etc noremap et :Org TODO noremap eT :TabOpen $cdhaus/etc/tmux.conf \| lcd $cdhaus noremap eu :TabOpen $cdhaus/share/doc/unicode-table.txt.gz \| lcd $cdhaus noremap ev :TabOpen $MYVIMRC \| lcd $cdhaus noremap eV :TabOpen $cdhaus/etc/vimperatorrc \| lcd $cdhaus noremap ew :TabOpen $cdhaus/etc/:config/bspwm/bspwmrc \| lcd $cdhaus noremap eW :TabOpen $cdhaus/etc/:config/sxhkd/sxhkdrc \| lcd $cdhaus noremap ex :TabOpen $cdhaus/etc/xinitrc \| lcd $cdhaus noremap eX :TabOpen $cdhaus/etc/Xdefaults \| lcd $cdhaus " Set filetype noremap f :call Prompt('setlocal filetype=', '', 'filetype') noremap f? :setlocal filetype? noremap fa :setlocal filetype=asm noremap fc :setlocal filetype=conf noremap fC :setlocal filetype=clojure noremap fd :setlocal filetype=diff noremap fg :setlocal filetype=go noremap fh :setlocal filetype=html noremap fH :setlocal filetype=haskell noremap fj :setlocal filetype=javascript noremap fJ :setlocal filetype=j noremap fm :setlocal filetype=mail noremap fM :setlocal filetype=markdown noremap fo :setlocal filetype=org noremap fp :setlocal filetype=plain noremap fr :setlocal filetype=ruby noremap fs :setlocal filetype=sh noremap fv :setlocal filetype=vim noremap fy :setlocal filetype=yaml """ Windows and Tabs {{{1 " Window focus / position for [g:lhs, g:rhs] in [['Left', 'h'], ['Down', 'j'], ['Up', 'k'], ['Right', 'l']] execute 'Mapall <4-' . g:lhs . '> :wincmd ' . g:rhs . '' execute 'Mapall <4-S-' . g:lhs . '> :wincmd ' . toupper(g:rhs) . '' endfor for g:lhs in ['h', 'j', 'k', 'l'] execute 'Mapall <4-' . g:lhs . '> :wincmd ' . g:lhs . '' execute 'Mapall <4-' . toupper(g:lhs) . '> :wincmd ' . toupper(g:lhs) . '' endfor unlet g:lhs g:rhs " Window capture / breakout Mapall <4-O> :execute winnr('$') == 1 ? 'tabonly' : 'only' noremap ! :wincmd T noremap @ :CapturePane " Tabs Mapall <4-t> :tabnew Mapall <4-T> :tabnew Mapall <4-{> :tabprevious Mapall <4-}> :tabnext Mapall <4-_> :TabmovePrev Mapall <4-+> :TabmoveNext " Quickfix, location, preview windows Mapall <4-x> :ToggleMinorWindows Mapall <4-X> :call setloclist(0, getqflist()) \\\| call setqflist([]) \\\| cclose \\\| topleft lwindow \\\| wincmd p " Open URLs Mapall <4-U> :Open " Save session Mapall <4-w> :Makesession Mapall <4-W> :Makesession \\\| qa """ Text editing {{{1 " Insert other special characters nnoremap i\n vnoremap c\n noremap! \n noremap <4-CR> A; inoremap <4-CR> A; cnoremap <4-CR> ; " Backward-delete-word noremap db noremap! " REPLACE switch-keyboard-language with NOTHING to alias (nvoi) " as undo-and-return-to-normal-mode noremap :undo inoremap :undo " Join lines noremap j J inoremap j J " Select all nnoremap <4-a> VggoG vnoremap <4-a> VggoG " Kill trailing whitespace noremap k :let b:__reg_slash__ = @/m`:%s/\v[ \t\r]+$//e:let @/ = b:__reg_slash__ \| unlet b:__reg_slash__`` " REPLACE insertmode-go-to-normal-mode and command-line-insert-longest-match " with NOTHING for ASCII arrow noremap! -> " Insert paired angle brackets noremap! <> " Indent lines (à la TextMate) nnoremap <4-[> a nnoremap <4-]> a vnoremap <4-[> >gv " http://vim.wikia.com/wiki/Moving_lines_up_or_down nnoremap :move+== nnoremap :move-2== inoremap :move+==gi inoremap :move-2==gi vnoremap :move'>+gv=gv vnoremap :move-2gv=gv " http://vim.wikia.com/wiki/Drag_words_with_Ctrl-left/right vnoremap `<i_mz"_xgvx`zPgvoo vnoremap `>gvxpgvoo " Web queries for [g:lhs, g:rhs] in [['d', 'qdictionary'], \ ['e', 'qetymology'], \ ['g', 'qgoogle'], \ ['s', 'qsymbolhound'], \ ['t', 'qthesaurus'], \ ['w', 'qwikipedia']] let g:fmt = 'noremap q' . g:lhs . \ ' :execute "Sh opensearch search ' . \ '~guns/.local/share/kupfer/searchplugins/' . g:rhs . '.xml "' . \ '. shellescape(CwordOrSel(%d))' execute 'n' . printf(g:fmt, 0) execute 'v' . printf(g:fmt, 1) endfor unlet g:lhs g:rhs g:fmt """ Plugins {{{1 " Plugin: surround.vim - visual surround shortcuts (a la TextMate) " REPLACE (v)( sentence-backward and (v)' jump-to-mark with surrounds. " RECURSIVE map for mappings. vmap ( VSurround( vmap ' VSurround' " Plugin: Shebang noremap fx :call SetExecutable() " Plugin: Fugitive (git) + Gitv - remember to update readline macros noremap g :Git noremap g1 :Git l1 noremap g. :execute 'Git di ' . fnameescape(expand('%')) noremap ga. :silent! Git a % noremap gaa :silent! Git aa noremap gac :silent! Git aa \| Gcommit noremap gap :Git ap noremap gb :Gblame -w noremap gB :Gbrowse noremap gc. :Gcommit % noremap gca :Gcommit -a noremap gcA :Gcommit --amend noremap gcc :Gcommit noremap gcv :Gcommit noremap gd :Git di noremap gD :Gdiff noremap gf :silent! Git f noremap gF :silent! Git ff noremap gg :!clear; git st noremap gl :silent! Git lp noremap gL :silent! Git lfp noremap gp :silent! Git pull noremap gP :silent! Git push noremap gr :silent! Git rs noremap gs :Git stash -u noremap gS :Git stash pop noremap g :Git stash show -p noremap gu :Git up noremap gv :Gitv noremap gV :Gitv! noremap gw :silent! Git wdi noremap gW :silent! Git wlp noremap <4-g> :Gstatus noremap <4-G> q:iGgrep! -Pi nnoremap <4-8> :let @/ = CwordOrSel(0) \| execute 'silent! Ggrep! -F -- ' . shellescape(@/, 1) vnoremap <4-8> :let @/ = CwordOrSel(1) \| execute 'silent! Ggrep! -F -- ' . shellescape(@/, 1) " Plugin: Manpageview noremap m :call Prompt('VEMan ', '', 'shellcmd') noremap M :call Prompt('HMan ', '', 'shellcmd') " Plugin: vim-easy-align " REPLACE (nv)ga print-ascii with NOTHING to alias EasyAlign nmap ga (EasyAlign) vmap ga (EasyAlign) nmap gA (LiveEasyAlign) vmap gA (LiveEasyAlign) " Plugin: Unite.vim noremap u :Unite -no-split Mapall <4-o> :UniteOpen Mapall <4-t> :tabnew \\\| UniteOpen Mapall <4-V> :vsplit \\\| UniteOpen Mapall <4-b> :Unite -no-split file_mru Mapall <4-B> :tabnew \\\| Unite -no-split file_mru Mapall <4-f> :Unite -no-split file Mapall <4-F> :UniteWithBufferDir -no-split file " Plugin: NERDTree Mapall <4-d> :NERDTreeToggle Mapall <4-D> :NERDTreeFind " Plugin: Ack.vim Mapall <4-A> q:iAck! " Plugin: Gundo Mapall <4-u> :GundoToggle " Plugin: Regbuf Mapall <4-r> :RegbufOpen " Plugin: UltiSnips Mapall <4-~> :UltiSnipsEdit " Plugin: Tagbar Mapall <4-i> :TagbarToggle Mapall <4-I> :TagbarOpen " Plugin: CamelCaseMotion map CamelCaseMotion_b imap map CamelCaseMotion_e imap map dCamelCaseMotion_b imap " Plugin: splitjoin.vim noremap J :SplitjoinJoin noremap S :SplitjoinSplit " Plugin: vim-commentary xmap <4-/> Commentary nmap <4-/> m`CommentaryLine`` imap <4-/> <4-/> " Plugin: vim-sexp let g:sexp_mappings = { \ 'sexp_outer_list': 'af', \ 'sexp_inner_list': 'if', \ 'sexp_outer_top_list': 'aF', \ 'sexp_inner_top_list': 'iF', \ 'sexp_outer_string': 'as', \ 'sexp_inner_string': 'is', \ 'sexp_outer_element': 'ae', \ 'sexp_inner_element': 'ie', \ 'sexp_move_to_prev_bracket': '(', \ 'sexp_move_to_next_bracket': ')', \ 'sexp_move_to_prev_element_head': '', \ 'sexp_move_to_next_element_head': '', \ 'sexp_move_to_prev_element_tail': '', \ 'sexp_move_to_next_element_tail': '', \ 'sexp_move_to_prev_top_element': '[[', \ 'sexp_move_to_next_top_element': ']]', \ 'sexp_select_prev_element': '[e', \ 'sexp_select_next_element': ']e', \ 'sexp_indent': '==', \ 'sexp_indent_top': '=-', \ 'sexp_round_head_wrap_list': 'i', \ 'sexp_round_tail_wrap_list': 'I', \ 'sexp_square_head_wrap_list': '[', \ 'sexp_square_tail_wrap_list': ']', \ 'sexp_curly_head_wrap_list': '{', \ 'sexp_curly_tail_wrap_list': '}', \ 'sexp_round_head_wrap_element': 'w', \ 'sexp_round_tail_wrap_element': 'W', \ 'sexp_square_head_wrap_element': 'e[', \ 'sexp_square_tail_wrap_element': 'e]', \ 'sexp_curly_head_wrap_element': 'e{', \ 'sexp_curly_tail_wrap_element': 'e}', \ 'sexp_splice_list': '@', \ 'sexp_raise_list': 'o', \ 'sexp_raise_element': 'O', \ 'sexp_swap_list_backward': '', \ 'sexp_swap_list_forward': '', \ 'sexp_swap_element_backward': '', \ 'sexp_swap_element_forward': '', \ 'sexp_emit_head_element': '', \ 'sexp_emit_tail_element': '', \ 'sexp_capture_prev_element': '', \ 'sexp_capture_next_element': '', \ 'sexp_insert_at_list_head': 'h', \ 'sexp_insert_at_list_tail': 'l', \ }