let g:VM.select_motions = ['h', 'j', 'k', 'l', 'w', 'W', 'b', 'B', 'e', 'E', 'ge', 'gE', 'BBW'] let g:VM.motions = ['h', 'j', 'k', 'l', 'w', 'W', 'b', 'B', 'e', 'E', ',', ';', '$', '0', '^', '%', 'ge', 'gE'] let g:VM.find_motions = ['f', 'F', 't', 'T'] """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" "Plugs """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" fun! vm#plugs#init() nnoremap (VM-Select-Operator) :call vm#operators#select(0, 0)y nnoremap (VM-Select-All-Operator) :call vm#operators#select(1, v:count) nmap (VM-Find-Operator) vm#operators#find(1, 0) xmap (VM-Visual-Find) vm#operators#find(1, 1) nnoremap (VM-Add-Cursor-At-Pos) :call vm#commands#add_cursor_at_pos(0) nnoremap (VM-Add-Cursor-At-Word) :call vm#commands#add_cursor_at_word(1, 1) nnoremap (VM-Add-Cursor-Down) :call vm#commands#add_cursor_down(0, v:count1) nnoremap (VM-Add-Cursor-Up) :call vm#commands#add_cursor_up(0, v:count1) nnoremap (VM-Select-Cursor-Down) :call vm#commands#add_cursor_down(1, v:count1) nnoremap (VM-Select-Cursor-Up) :call vm#commands#add_cursor_up(1, v:count1) nnoremap (VM-Select-Line-Down) :call vm#commands#expand_line(1) nnoremap (VM-Select-Line-Up) :call vm#commands#expand_line(0) nnoremap (VM-Select-All) :call vm#commands#find_all(0, 1, 0) xnoremap (VM-Visual-All) Visual('all') xnoremap (VM-Visual-Cursors) :call vm#commands#from_visual('cursors') xnoremap (VM-Visual-Add) :call vm#commands#from_visual('add') xnoremap (VM-Visual-Subtract) :call vm#commands#from_visual('subtract') nnoremap (VM-Split-Regions) :call vm#visual#split() nnoremap (VM-Remove-Empty-Lines) :call vm#commands#remove_empty_lines() nnoremap (VM-Find-Under) :call vm#commands#ctrld(v:count1) xnoremap (VM-Find-Subword-Under) Visual('under') nnoremap (VM-Find-I-Word) :call vm#commands#find_under(0, 0, 0) nnoremap (VM-Find-A-Word) :call vm#commands#find_under(0, 0, 1) nnoremap (VM-Find-I-Whole-Word) :call vm#commands#find_under(0, 1, 0) nnoremap (VM-Find-A-Whole-Word) :call vm#commands#find_under(0, 1, 1) xnoremap (VM-Find-A-Subword) Visual('subw') xnoremap (VM-Find-A-Whole-Subword) Visual('wsubw') nnoremap (VM-Star) :call Star(1) nnoremap (VM-Hash) :call Star(2) xnoremap (VM-Visual-Star) Visual('star') xnoremap (VM-Visual-Hash) Visual('hash') nnoremap (VM-Toggle-Mappings) :call b:VM_Selection.Maps.mappings_toggle() nnoremap (VM-Toggle-Multiline) :call b:VM_Selection.Funcs.toggle_option('multiline', 1) nnoremap (VM-Toggle-Block) :call b:VM_Selection.Funcs.toggle_option('block_mode', 1) nnoremap (VM-Toggle-Debug) :let g:VM_debug = !g:VM_debug nnoremap (VM-Toggle-Whole-Word) :call b:VM_Selection.Funcs.toggle_option('whole_word', 1) nnoremap (VM-Toggle-Only-This-Region) :call b:VM_Selection.Funcs.toggle_option('only_this_always', 1) nnoremap (VM-Show-Help) :call vm#special#help#show() nnoremap (VM-Case-Setting) :call b:VM_Selection.Search.case() nnoremap (VM-Rewrite-Last-Search) :call b:VM_Selection.Search.rewrite(1) nnoremap (VM-Rewrite-All-Search) :call b:VM_Selection.Search.rewrite(0) nnoremap (VM-Read-From-Search) :call b:VM_Selection.Search.get_slash_reg() nnoremap (VM-Add-Search) :call b:VM_Selection.Search.get() nnoremap (VM-Remove-Search) :call b:VM_Selection.Search.remove(0) nnoremap (VM-Remove-Search-Regions) :call b:VM_Selection.Search.remove(1) nnoremap (VM-Search-Menu) :call b:VM_Selection.Search.menu() nnoremap (VM-Case-Conversion-Menu) :call b:VM_Selection.Case.menu() nnoremap (VM-Start-Regex-Search) :call vm#commands#find_by_regex(1):call Mode()/ xnoremap (VM-Visual-Regex) :call vm#commands#find_by_regex(2):call Mode()/ nnoremap (VM-Show-Regions-Info) :call b:VM_Selection.Funcs.regions_contents() nnoremap (VM-Show-Registers) :call b:VM_Selection.Funcs.show_registers() nnoremap (VM-Tools-Menu) :call vm#special#commands#menu() nnoremap (VM-Erase-Regions) :call vm#commands#erase_regions(1) nnoremap (VM-Filter-Regions) :call vm#special#commands#filter_regions() nnoremap (VM-Regions-To-Buffer) :call vm#special#commands#regions_to_buffer() nnoremap (VM-Filter-Lines) :call vm#special#commands#filter_lines(0) nnoremap (VM-Filter-Lines-Strip) :call vm#special#commands#filter_lines(1) nnoremap (VM-Merge-Regions) :call b:VM_Selection.Global.merge_regions() nnoremap (VM-Switch-Mode) :call b:VM_Selection.Global.change_mode(1) nnoremap (VM-Reset) :call vm#reset() nnoremap (VM-Undo) u:call b:VM_Selection.Global.update_regions() nnoremap (VM-Invert-Direction) :call vm#commands#invert_direction(1) nnoremap (VM-Goto-Next) :call vm#commands#find_next(0, 1) nnoremap (VM-Goto-Prev) :call vm#commands#find_prev(0, 1) nnoremap (VM-F3-Next) :call vm#commands#find_next(0, 1) nnoremap (VM-F2-Prev) :call vm#commands#find_prev(0, 1) nnoremap (VM-Find-Next) :call vm#commands#find_next(0, 0) nnoremap (VM-Find-Prev) :call vm#commands#find_prev(0, 0) nnoremap (VM-Seek-Up) :call vm#commands#seek_up() nnoremap (VM-Seek-Down) :call vm#commands#seek_down() nnoremap (VM-Skip-Region) :call vm#commands#skip(0) nnoremap (VM-q-Skip) :call vm#commands#skip(0) nnoremap (VM-Remove-Region) :call vm#commands#skip(1) nnoremap (VM-Remove-Last-Region) :call b:VM_Selection.Global.remove_last_region() nnoremap (VM-Remove-Every-n-Regions) :call vm#commands#remove_every_n_regions(v:count) nnoremap (VM-Undo-Visual) :call vm#commands#undo() nnoremap (VM-Show-Infoline) :call b:VM_Selection.Funcs.count_msg(2) for m in g:VM.motions exe "nnoremap (VM-Motion-".m.") :\call vm#commands#motion('".m."', v:count1, 0, 0)\" exe "nnoremap (VM-This-Motion-".m.") :\call vm#commands#motion('".m."',v:count1, 0, 1)\" endfor for m in g:VM.find_motions exe "nnoremap (VM-Motion-".m.") :call vm#commands#find_motion('".m."', '', 0)\" endfor for m in g:VM.select_motions exe "nnoremap (VM-Select-".m.") :\call vm#commands#motion('".m."', v:count1, 1, 0)\" exe "nnoremap (VM-This-Select-".m.") :\call vm#commands#motion('".m."', v:count1, 1, 1)\" endfor let remaps = g:VM_custom_remaps for m in keys(remaps) exe "nnoremap (VM-Remap-Motion-".remaps[m].") :call vm#commands#remap_motion('".remaps[m]."', 0)\" endfor let noremaps = g:VM_custom_noremaps for m in keys(noremaps) exe "nnoremap (VM-Motion-".noremaps[m].") :\call vm#commands#motion('".noremaps[m]."', 1, 0, 0)\" endfor let cm = g:VM_custom_commands for m in keys(cm) exe "nnoremap (VM-".m.") ".cm[m][1] endfor nnoremap (VM-Shrink) :call vm#commands#shrink_or_enlarge(1, 0) nnoremap (VM-Enlarge) :call vm#commands#shrink_or_enlarge(0, 0) nnoremap (VM-Merge-To-Eol) :call vm#commands#merge_to_beol(1, 0) nnoremap (VM-Merge-To-Bol) :call vm#commands#merge_to_beol(0, 0) "Edit commands nnoremap (VM-D) :call vm#operators#cursors('d', 0, v:register, 'd$') nnoremap (VM-Y) :call vm#operators#cursors('y', 0, v:register, 'y$') nnoremap (VM-x) :call b:VM_Selection.Edit.run_normal('x', 0, v:count1, 0):silent! undojoin nnoremap (VM-X) :call b:VM_Selection.Edit.run_normal('X', 0, v:count1, 0):silent! undojoin nnoremap (VM-J) :call b:VM_Selection.Edit.run_normal('J', 0, v:count1, 0):silent! undojoin nnoremap (VM-~) :call b:VM_Selection.Edit.run_normal('~', 0, 1, 0):silent! undojoin nnoremap (VM-Del) :call b:VM_Selection.Edit.special('del') nnoremap (VM-Dot) :call b:VM_Selection.Edit.dot() nnoremap (VM-Increase) :call b:VM_Selection.Edit.run_normal('', 0, v:count1, 0) nnoremap (VM-Decrease) :call b:VM_Selection.Edit.run_normal('', 0, v:count1, 0) nnoremap (VM-a) :call b:VM_Selection.Insert.key('a') nnoremap (VM-A) :call b:VM_Selection.Insert.key('A') nnoremap (VM-i) :call b:VM_Selection.Insert.key('i') nnoremap (VM-I) :call b:VM_Selection.Insert.key('I') nnoremap (VM-o) :call b:VM_Selection.Insert.key('o') nnoremap (VM-O) :call b:VM_Selection.Insert.key('O') nnoremap (VM-c) :call b:VM_Selection.Edit.change(g:VM.extend_mode, v:count1, v:register) nnoremap (VM-C) :call vm#operators#cursors('c', 0, v:register, 'c$') nnoremap (VM-Delete) :call b:VM_Selection.Edit.delete(g:VM.extend_mode, v:register, v:count1, 1) nnoremap (VM-Delete-Exit) :call b:VM_Selection.Edit.delete(g:VM.extend_mode, v:register, v:count1, 1):call vm#reset() nnoremap (VM-Replace) :call b:VM_Selection.Edit.replace() nnoremap (VM-Replace-Pattern) :call b:VM_Selection.Edit.replace_pattern() nnoremap (VM-Transform-Regions) :call b:VM_Selection.Edit.replace_expression() nnoremap (VM-p-Paste-Regions) :call b:VM_Selection.Edit.paste((g:VM.extend_mode? 1 : 0), 0, g:VM.extend_mode, v:register) nnoremap (VM-P-Paste-Regions) :call b:VM_Selection.Edit.paste((g:VM.extend_mode? 1 : 1), 0, g:VM.extend_mode, v:register) nnoremap (VM-p-Paste-Normal) :call b:VM_Selection.Edit.paste((g:VM.extend_mode? 1 : 0), 1, g:VM.extend_mode, v:register) nnoremap (VM-P-Paste-Normal) :call b:VM_Selection.Edit.paste((g:VM.extend_mode? 1 : 1), 1, g:VM.extend_mode, v:register) nnoremap (VM-Yank) Yank(0) nnoremap (VM-Yank-Hard) Yank(1) nnoremap (VM-Move-Right) :call b:VM_Selection.Edit.shift(1) nnoremap (VM-Move-Left) :call b:VM_Selection.Edit.shift(0) nnoremap (VM-Transpose) :call b:VM_Selection.Edit.transpose() nnoremap (VM-Duplicate) :call b:VM_Selection.Edit.duplicate() nnoremap (VM-Align) :call vm#commands#align() nnoremap (VM-Align-Char) :call vm#commands#align_char(v:count1) nnoremap (VM-Align-Regex) :call vm#commands#align_regex() nnoremap (VM-Numbers) :call b:VM_Selection.Edit.numbers(v:count1, 0) nnoremap (VM-Numbers-Append) :call b:VM_Selection.Edit.numbers(v:count1, 1) nnoremap (VM-Zero-Numbers) :call b:VM_Selection.Edit.numbers(v:count, 0) nnoremap (VM-Zero-Numbers-Append) :call b:VM_Selection.Edit.numbers(v:count, 1) nnoremap (VM-Run-Dot) :call b:VM_Selection.Edit.run_normal('.', 0, v:count1, 0) nnoremap (VM-Surround) :call b:VM_Selection.Edit.surround() nnoremap (VM-Run-Macro) :call b:VM_Selection.Edit.run_macro(0) nnoremap (VM-Run-Ex) :call b:VM_Selection.Edit.run_ex(v:count1) nnoremap (VM-Run-Last-Ex) :call b:VM_Selection.Edit.run_ex(v:count1, g:VM.last_ex) nnoremap (VM-Run-Normal) :call b:VM_Selection.Edit.run_normal(-1, 1, v:count1,1) nnoremap (VM-Run-Last-Normal) :call b:VM_Selection.Edit.run_normal(g:VM.last_normal[0] ,g:VM.last_normal[1], v:count1, 1) nnoremap (VM-Run-Visual) :call b:VM_Selection.Edit.run_visual(-1, 0) nnoremap (VM-Run-Last-Visual) :call b:VM_Selection.Edit.run_visual(g:VM.last_visual[0], g:VM.last_visual[1]) inoremap (VM-I-Arrow-w) Insert('w') inoremap (VM-I-Arrow-b) Insert('b') inoremap (VM-I-Arrow-W) Insert('W') inoremap (VM-I-Arrow-B) Insert('B') inoremap (VM-I-Arrow-e) Insert('e') inoremap (VM-I-Arrow-ge) Insert('ge') inoremap (VM-I-Arrow-E) Insert('E') inoremap (VM-I-Arrow-gE) Insert('gE') inoremap (VM-I-Left-Arrow) Insert('h') inoremap (VM-I-Right-Arrow) Insert('l') inoremap (VM-I-Up-Arrow) Insert('h') inoremap (VM-I-Down-Arrow) Insert('l') inoremap (VM-I-Return) Insert('cr') inoremap (VM-I-BS) Insert('X') inoremap (VM-I-Paste) Insert('p') inoremap (VM-I-CtrlW) Insert('cw') inoremap (VM-I-CtrlD) Insert('x') inoremap (VM-I-Del) Insert('x') inoremap (VM-I-CtrlA) Insert('^') inoremap (VM-I-CtrlE) Insert('$') inoremap (VM-I-CtrlB) Insert('h') inoremap (VM-I-CtrlF) Insert('l') "Cmdline nnoremap (VM-:) vm#commands#regex_reset(':') nnoremap (VM-/) vm#commands#regex_reset('/') nnoremap (VM-?) vm#commands#regex_reset('?') "mouse nmap (VM-Mouse-Cursor) g nmap (VM-Mouse-Word) (VM-Find-Under) nmap (VM-Mouse-Column) :call vm#commands#mouse_column() endfun """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Helper functions """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" fun! s:Star(type) set nosmartcase set noignorecase if a:type == 1 call vm#commands#find_under(0, 1, 0) elseif a:type == 2 call vm#commands#find_under(0, 1, 1) elseif a:type == 3 call vm#commands#find_under(1, 0, 0) elseif a:type == 4 call vm#commands#find_under(1, 1, 0) endif endfun fun! s:Insert(key) let b:VM_Selection.Vars.restart_insert = 1 let i = ":call b:VM_Selection.Insert.key('i')\" let a = ":call b:VM_Selection.Insert.key('a')\" let u = b:VM_Selection.Insert.change? ":silent! undojoin\" : "" if a:key == 'cr' "return return "\:call vm#icmds#return()\".i elseif a:key ==? 'x' "x/X "only join undo if there's been a change return "\".u.":call vm#icmds#x('".a:key."')\".i elseif index(split('hlwbWBeE', '\zs'), a:key) >= 0 return "\:call vm#commands#motion('".a:key."', 1, 0, 0)\".i elseif a:key ==? 'ge' return "\:call vm#commands#motion('".a:key."', 1, 0, 0)\".i elseif a:key == '$' return "\".u.":call b:VM_Selection.Insert.key('A')\" elseif a:key == '^' return "\".u.":call b:VM_Selection.Insert.key('I')\" elseif a:key == 'p' "c-v return "\".u.":call vm#icmds#paste()\".a elseif a:key == 'cw' "c-w return "\".u.":call vm#icmds#cw()\".i endif endfun fun! s:Yank(hard) if empty(b:VM_Selection.Global.is_region_at_pos('.')) let b:VM_Selection.Vars.yanked = 1 | return 'y' endif let hard = a:hard && !g:VM_overwrite_vim_registers || \ !a:hard && g:VM_overwrite_vim_registers return ":\call b:VM_Selection.Edit.yank(".hard.", 0, 0, 1)\" endfun fun! s:Mode() let mode = g:VM.extend_mode? ' (extend mode)' : ' (cursor mode)' call b:VM_Selection.Funcs.msg([["Enter regex".mode.":", 'WarningMsg'], ["\n/", 'None']], 1) endfun fun! s:Visual(cmd) """Restore register after a visual yank.""" if !g:VM.is_active let g:VM.visual_reg = ['"', getreg('"'), getregtype('"')] let r = "g:VM.visual_reg[0], g:VM.visual_reg[1], g:VM.visual_reg[2]" let r = ":let b:VM_Selection.Vars.oldreg = g:VM.visual_reg\:call setreg(".r.")\" else let r = '' endif return a:cmd == 'all' ? "y:call vm#commands#find_all(1, 0, 0)\".r."`]" : \ a:cmd == 'under'? "y:call vm#commands#find_under(1, 0, 0, 1)\".r."`]" : \ a:cmd == 'subw' ? "y:call vm#commands#find_under(1, 0, 0)\".r."`]" : \ a:cmd == 'wsubw'? "y:call vm#commands#find_under(1, 1, 0)\".r."`]" : \ a:cmd == 'star' ? "y:call Star(3)\".r."`]" : "y:call Star(4)\".r."`]" endfun