Module vim
Neovim utilities module
Functions
map (mode, key, action, opts) | Map a keybind for the Neovim instance |
mapExists (mode, key) | Check if a keybind exist for the Neovim instance |
getMap (mode, key) | Get a keybind details for the Neovim instance |
unmap (mode, key, opts) | Unmap a keybind for the Neovim instance |
getOption (option, opts) | Get the value of an option for the Neovim instance |
setOption (option, value, opts) | Set the value of an option for the Neovim instance |
isStringBeforeCursor (str) | Check if a string is preceding the current cursor position |
Functions
- map (mode, key, action, opts)
-
Map a keybind for the Neovim instance
Parameters:
- mode string|table The mode(s) the key bind will created for. Use * for all
- key string The key combination that will trigger the binding
- action string|function The action that will take place when the binding is being triggered
- opts
? table Additional options passed to vim.keymap.set function
opts.buffer: Local buffer mapping. Buffer id. When 0 or true, take current buffer<br/> opts.remap: erase any previous mapping<br/> opts.desc: human-readable description<br/> opts.replace_keycodes: replace keycodes in the resulting string. true if expr is true<br/> opts.nowait: Do not wait if another key bing use the same start of key<br/> opts.silent: Do not produce any message<br/> opts.script: Remap only mappings starting with <SID><br/> opts.expr: Treat the keybind as an expression<br/> opts.unique: Do not erase the previous mapping if any before it
Raises:
error if mode is not a string or a table
error if mode does not have a valid value
error if key is not a string
error if action is not a string
error if opts is given and is not a tableUsage:
map("i", "jk", "<ESC>", { nowait = true })
- mapExists (mode, key)
-
Check if a keybind exist for the Neovim instance
Parameters:
- mode string The mode the key bind should be set for
- key string The key combination the key bind should be triggered by
Returns:
-
boolean # true if a keybind exists for the given mode and key, false otherwise
Raises:
error if mode is not a string
error if mode does not have a valid value
error if key is not a stringUsage:
map("i", "jk", "<ESC>") mapExists("i", "jk") -- true mapExists("i", "notset") -- false
- getMap (mode, key)
-
Get a keybind details for the Neovim instance
Parameters:
- mode string The mode to get the keybind in
- key string The key combination defining the keybind to get
Returns:
-
table|nil # A valid table contains details about the keybind if the keybind exists, nil otherwise
Raises:
error if mode is not a string
error if mode does not have a valid value
error if key is not a stringUsage:
map("i", "jk", "<ESC>", { nowait = true }) print(getMap("i", "jk")) -- { mode = "i", lhs = "jk", rhs = "<Esc>", nowait = true, ... }
- unmap (mode, key, opts)
-
Unmap a keybind for the Neovim instance
Parameters:
- mode string|table The mode(s) the key bind will deleted for. Use * for all
- key string The key combination that will be deleted
- opts
? table Additional options passed to vim.keymap.del function
opts.buffer: Local buffer mapping. Buffer id. When 0 or true, take current buffer
Returns:
-
boolean # true if a keybind have been deleted, false if the keybind does not exist in one of the modes
Raises:
error if mode is not a string or a table
error if mode does not have a valid value
error if key is not a string
error if opts is given and is not a tableUsage:
map("i", "jk", "<ESC>", { nowait = true }) unmap("i", "jk") -- true unmap("i", "notexist") -- false
- getOption (option, opts)
-
Get the value of an option for the Neovim instance
Parameters:
- option string The option name to get the value of
- opts
? table Additional argument about the option
opts.scope "global"|"local": Scope action of the option<br/> opts.win: The id of the window to get the option for<br/> opts.buf: The number of the buffer to get the option for<br/> opts.filetype: Get option for a specific filetype
Returns:
-
string|number|boolean # Option value
Raises:
error if option is not a string
error if option is not a valid optionUsage:
print(m.getOption("mouse")) -- nvi
- setOption (option, value, opts)
-
Set the value of an option for the Neovim instance
Parameters:
- option string The option name to set the value of
- value string|number|boolean The value to set to the option
- opts
? table Additional argument about the option
opts.scope "global"|"local": Scope action of the option<br/> opts.win: The id of the window to set the option for<br/> opts.buf: The number of the buffer to set the option for
Raises:
error if option is not a string
error if option is not a valid option
error if value is not a string, number, or boolean
error if value is not validUsage:
m.setOption("mouse", "i") print(m.getOption("mouse")) -- i
- isStringBeforeCursor (str)
-
Check if a string is preceding the current cursor position
Parameters:
- str string The string to search before the current cursor position
Raises:
error if str is not a stringUsage:
print(m.isStringBeforeCursor("some text preceding the cursor"))