Skip to content
This repository has been archived by the owner on Dec 19, 2022. It is now read-only.

Commit

Permalink
fix(syntax): only mention vim.fn
Browse files Browse the repository at this point in the history
recommendation TJ DeVries 20210214_0102
  • Loading branch information
matu3ba authored and nanotee committed Feb 14, 2021
1 parent 6bd5fde commit 16423fe
Showing 1 changed file with 4 additions and 26 deletions.
30 changes: 4 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -755,33 +755,10 @@ This is a known issue:

## Calling Vimscript functions

### vim.call()

`vim.call()` calls a Vimscript function. This can either be a built-in Vim function or a user function. Again, data types are converted back and forth from Lua to Vimscript.

It takes in the name of the function followed by the arguments you want to pass to that function:

```lua
print(vim.call('printf', 'Hello from %s', 'Lua'))

local reversed_list = vim.call('reverse', { 'a', 'b', 'c' })
print(vim.inspect(reversed_list)) -- { "c", "b", "a" }

local function print_stdout(chan_id, data, name)
print(data[1])
end

vim.call('jobstart', 'ls', { on_stdout = print_stdout })

vim.call('my#autoload#function')
```

See also:
- `:help vim.call()`

### vim.fn.{function}()

`vim.fn` does the exact same thing as `vim.call()`, but looks more like a native Lua function call:
`vim.fn` is for calling a Vimscript function.
The Vimscript function can either be a built-in Vim function or a user function. Data types are converted back and forth from Lua to Vimscript.

```lua
print(vim.fn.printf('Hello from %s', 'Lua'))
Expand All @@ -796,7 +773,8 @@ end
vim.fn.jobstart('ls', { on_stdout = print_stdout })
```

Hashes `#` aren't valid characters for indentifiers in Lua, so autoload functions have to be called with this syntax:
Strings with invalid Lua names can be used with `vim.fn[variable]`.
For example, hashes (`#`) are no valid characters for indentifiers in Lua, so autoload functions have to be called with this syntax:

```lua
vim.fn['my#autoload#function']()
Expand Down

0 comments on commit 16423fe

Please sign in to comment.