utku
utku

Reputation: 73

vim shortcut for keyboard combo and a function call

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:

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

Upvotes: 3

Views: 1363

Answers (1)

Kent
Kent

Reputation: 195029

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 >

Upvotes: 6

Related Questions