On 01/04/2011 12:28 AM, Douglas A. Augusto wrote:
On 30/12/2010 at 18:45,
AK<[email protected]>  wrote:

Not sure about jumping to exact spot but I made a plugin
that jumps to 25%, 50% and 75% of text of current line (i.e.
it discards leading&  trailing whitespace). I can share if
anyone's interested. I find it's usually close enough
that I can use w/b or W/B keys or f/F to get where I need.
     -ak

Hi AK,

I came up with a solution. I wrote a function that takes a Vim command and: (1)
put the current position into the jump list; and (2) execute the command,
passing a count (if given) and its argument if it takes one:

    function! MarkAndExecute(cmd, has_char_arg)
       let c = (a:has_char_arg != 0) ? nr2char(getchar()) : ''
       let n = (v:count != 0) ? v:count : ''
       " Put the current position into the jump list
       normal m'
       " Execute the wrapped command
       silent exec 'normal! '.n.a:cmd.c
    endfunction

Then, I remap the usual character-wise commands (such as $, 0, w, gm, f, ;,
etc.) to appropriately call the above mentioned function. For instance:

    nnoremap<silent>  $ :<C-U>call MarkAndExecute("$", 0)<CR>
    nnoremap<silent>  w :<C-U>call MarkAndExecute("w", 0)<CR>
    nnoremap<silent>  f :<C-U>call MarkAndExecute("f", 1)<CR>
    ...

Thus, pressing CTRL-O after a jump on the line puts the cursor back to the
original position. It also works with aggregated commands, such as '3w', 'y$',
or even 'y2fc'. :)

Current issue: I couldn't figure out how to properly map commands/keys like
<Home>  or g<End>. For example, I've tried to pass<Home>  to MarkAndExecute as
"<Home>", '<Home>', '\<Home>','<lt>Home>', and '\<lt>Home>' without success.

I will work to test/improve the current plugin and then publish it; I think it
can also be useful for somebody else. Last but not least, I'm new to Vim
scripting, so I really appreciate suggestions.



This looks interesting.. I might use it, too. Since it will overwrite ' mark, maybe it's best to go back using '' command instead of ctrl-O? (i.e. easier to type?) But I thought ' mark only keeps line, not column
position? I'll try it tomorrow.. -ak

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to