vim - Replacing a motion in operator mode -


i'm trying alter ge motion's functionality when it's used operator. instead of operating on last character of target word, i'd work exclusively until target word's last character w.

example:

foo bar      ^ 

should lead fooar instead of foar when use dge cursor @ ^

i don't know vimscript , i'm pretty relying on exe now. quick attempt wrote seems full of errors. variables don't seem working right @ all.

my leading idea escape when ge typed in operator mode , call function right arguments. set mark on starting position, move left 1 column (to ensure work repeated movements, though operator mode only), move set amount of ges , move 1 column right (my main goal here) , delete till set mark.

if point out errors i've made, appreciated!

function! fixge(count, operator)     exe 'normal m['     exe 'normal h'     exe count.'normal ge'     exe 'normal l'     exe operator.'normal `[' endfunction onoremap ge <esc>:call fixge(v:prevcount, v:operator)<cr> 

this little closer (untested):

function! fixge(count, operator)     exe 'normal m['     exe 'normal h'     exe 'normal ' . a:count . 'ge'     exe 'normal l'     exe 'normal ' . a:operator . '`[' endfunction onoremap ge <esc>:call fixge(v:prevcount, v:operator)<cr> 

function arguments have use :a prefix (or sigil, think). know count reserved variable: :let count = 7 gives error. think ok use function argument, though.

i have put :normal @ beginning of 2 lines, instead of in middle.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -