Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VimL: how to execute a function on a visual selection only once

Tags:

vim

I need your help. Suppose I have a function:

fun! Foo()
    " Do awesome staff
endfunction

And the following key binding in my plugin:

vnoremap <LocalLeader>cv :call Foo()<RETURN>

My problem is that Foo() gets call for each line of my visual selection. Instead, I just want Foo() to be executed one and only once.

Any ideas?

Thanks in advance.

like image 498
Alfredo Di Napoli Avatar asked Feb 20 '23 07:02

Alfredo Di Napoli


1 Answers

See :help function-range-example

fun! Foo() range
  " Do awesome stuff
endfun
vnoremap <LocalLeader>cv :call Foo()<cr>
like image 136
Conner Avatar answered May 29 '23 15:05

Conner