Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Various ways to execute a function in vim

Tags:

vim

I've been doing some trial-and-error on how functions can be called, and it seems like the following is my understanding:

  1. From the command line, typing in :call MyFunction()
  2. From the command line, typing in :call execute('call MyFunction'), where execute essentially performs a string escape (if that's the correct term?) to pass back to the first call param.
  3. From within a function or vim file, typing in call MyFunction(). In other words, each line in a vim function/file acts like the command-line.
  4. From within a function or vim file, typing in call execute('call MyFunction')

Is that a correct understanding of the various ways to call a function? Are there any other possible ways to do it?

like image 529
David542 Avatar asked Jan 17 '26 06:01

David542


1 Answers

I don't really understand what you are doing, but if you ask if there are other ways to call a function, yes, there are.

For example,

  • the eval(...) can call another function
  • echo getline('.') or something like this
  • :s/../\=getline(...)
  • in expr mappings
  • ...

Simply put, in almost any place when a vimscript can be evaluated, a function can be called.

like image 107
Kent Avatar answered Jan 19 '26 20:01

Kent