Questions tagged [functions]

Question about the use of functions in Vimscript defined in the .vimrc or a script file.

284 questions
9
votes
2 answers

How to ask vim where function or command was defined?

I'd like to know if there is an analogue to verbose map (which shows the location that the map was assigned) for functions. For example I have a few Git plugins and I'd like to know what plugin defines the :GitFiles function, if Vim knows this…
Steven Lu
  • 2,251
  • 15
  • 26
8
votes
1 answer

Detecting whether vim supports functions

I have a function definition in my .vimrc. This .vimrc is sufficient to demonstrate the problem I'm asking about: function! Greet() echo "hello" endfunction I want to be able use the same .vimrc with a version of vim configured…
Keith Thompson
  • 207
  • 1
  • 6
6
votes
2 answers

How to list / show all built-in functions?

How can I list / show all built-in functions, similar to the :function command which lists all (non-builtin?) functions?
Rob Bednark
  • 371
  • 1
  • 13
5
votes
1 answer

What's the difference between command and function?

As I know, both of them can do quite the same things, but one should call to invoke and other one should use execute to invoke. But whats the difference between command and function? when should I use one and other?
Lai32290
  • 275
  • 1
  • 9
3
votes
1 answer

How to organize autoload functions?

I'd like to put all my custom functions into autoload folder, but I have functions with the same name. How should I organize them?
Cyker
  • 187
  • 7
2
votes
2 answers

Calling function without using call

This is just my own curiosity speaking here, but would it be possible (if it's even possible by default in normal vim, without any additional plugins etc) to call a function inside a vimscript function without having to use call? I'm thinking of…
Nordine Lotfi
  • 683
  • 4
  • 16
2
votes
1 answer

Possible to set `foldexpr` using a function reference?

Got this: let Func = function(folding_function) "folding_function is name of function setlocal foldexpr=call(Func(v:lnum)) This is so user can set a custom function for folding in their config file. I can't get it to work, though. Also…
StevieD
  • 1,492
  • 1
  • 16
  • 24
2
votes
1 answer

How to set opfunc to a lambda function?

I've found it's common to set opfunc in this manner: nnoremap r :set opfunc=my_functiong@ With Vim8 supporting lambda functions, is it possible to now set opfunc to a lambda function? The following cursory try did not work: :set…
Roxy
  • 177
  • 3
1
vote
1 answer

What is the default 'tabline' function?

Or at least, where to find it in the Vim source code? Tried to show it with :set tabline, but only got an empty string back. The custom function example in :h tabline is helpful and one that resembles the default, but without adding a + for a…
toraritte
  • 400
  • 3
  • 13
1
vote
2 answers

Using ! in a function

I have the following command for arranging a few lines in a file using sed and column: :-3,+2!sed 's/- 2021/\&2021/' | sed 's/ 2021/\&2021/' | column -s '&' -t This works fine. For example, the following buffer: a - 2021-01-01 b -…
1
vote
2 answers

How to I insert a return value from a function call into an existing buffer?

This following vim script calls a function that returns an array called lines: call vimwiki#diary#generate_diary_section() There seems to be a bug and nothing is done with the lines array—the content never gets added to the buffer. I have a two part…
StevieD
  • 1,492
  • 1
  • 16
  • 24
1
vote
3 answers

How to recover the color to previous status?

I wrote a function to show some special characters with red color: function! ShowChar() set list set listchars=tab:→\ ,space:·,nbsp:␣,eol:¶ highlight SpecialKey ctermfg=blue ctermbg=red guifg=blue guibg=red endfunction map :call…
showkey
  • 1,130
  • 2
  • 11
  • 30
1
vote
1 answer

write easy accessable function

I want to run an external command by typing :runMyCommand (just run a shellcommand). I thought I'd put the shell command execution into a function, so I can call it with :call runMyCommand, but I want to get rid of the :call. Is this possible and if…
atticus
  • 145
  • 4
1
vote
2 answers

sourcing .vimrc function does not work

I am using nvim v0.4.3. This is the latest version available in repository. I have an Arch build with the most up to date packages and kernel 5.6.4-arch1-1. I have the below function in my ~/.vimrc: " function function! ReSource() let…
Kes
  • 663
  • 1
  • 8
  • 18
1
vote
1 answer

Vim is executing commands that were part of a function definition

On one copy of Vim that I use sometimes, I get errors like this when I start up: Error detected while processing /home/besham/.vimrc: line 524: E749: empty buffer line 555: E749: empty buffer line 578: E749: empty buffer Press ENTER or type…
bdesham
  • 2,983
  • 2
  • 18
  • 20
1
2