3

I have a Vim function (written by somebody else) that runs the highlighted visual block as a script in another program. I have a keybinding (F9) for it so I can call it with a visual block of lines.

I would like to further automatize things by creating specific shortcuts to two tasks:

  • Visually select here from to the beginning of the document and call the function.
  • Visually select the current line and call the function.

I don't necessarily need to use a macro, but I tried to use macros to do this. So added something like

:let @r='0vgg<F9>'

to my .vimrc for the first task. And when try to run it, it seems to highlight the right area, but the function call never happens.

How would you suggest I create these shortcuts successfully?

thanks

1 Answer 1

6

you should take a look the function, if it supports range. If true, you don't have to do visual selection. you could:

nnoremap <F7> :1,.call YourFunction()<cr>
nnoremap <F8> :.call YourFunction()<cr>

so, the <F7> would call the function with range from line1 till current line. <F8> will call the function on current line.

If you want to define a macro, you have to escape the <f9>:

:let @r="0vgg\<F9>"

otherwise, vim thinks you pressed < f 9 and >

1
  • I don't think this function can handle ranges. But your correction of my macro works great. thanks!
    – utku
    May 9, 2013 at 16:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.