aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/api/vim.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/api/vim.c')
-rw-r--r--src/nvim/api/vim.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c
index 37f2d3c367..53aad1fe39 100644
--- a/src/nvim/api/vim.c
+++ b/src/nvim/api/vim.c
@@ -1262,6 +1262,53 @@ ArrayOf(Dictionary) nvim_get_keymap(String mode)
return keymap_array(mode, NULL);
}
+/// Sets a global |mapping| for the given mode.
+///
+/// To set a buffer-local mapping, use |nvim_buf_set_keymap|.
+///
+/// Unlike ordinary Ex mode |:map| commands, special characters like literal
+/// spaces and newlines are treated as an actual part of the {lhs} or {rhs}.
+/// An empty {rhs} is treated like a |<Nop>|. |keycodes| are still replaced as
+/// usual.
+///
+/// `call nvim_set_keymap('n', ' <NL>', '', {'nowait': v:true})`
+///
+/// Is equivalent to,
+///
+/// `nmap <nowait> <Space><NL> <Nop>`
+///
+/// @param mode Mode short-name (the first character of an map command,
+/// e.g. "n", "i", "v", "x", etc.) OR the string "!" (for
+/// |:map!|). |:map| can be represented with a single space " ",
+/// an empty string, or "m".
+/// @param lhs Left-hand-side |{lhs}| of the mapping.
+/// @param rhs Right-hand-side |{rhs}| of the mapping.
+/// @param opts |dict| of optional parameters. Accepts all |:map-arguments|
+/// as keys excluding |<buffer>| but also including |noremap|.
+/// Values should all be Booleans. Unrecognized keys will result
+/// in an error.
+/// @param[out] err Error details, if any.
+void nvim_set_keymap(String mode, String lhs, String rhs,
+ Dictionary opts, Error *err)
+ FUNC_API_SINCE(6)
+{
+ modify_keymap(-1, false, mode, lhs, rhs, opts, err);
+}
+
+/// Unmap a global |mapping| for the given mode.
+///
+/// To unmap a buffer-local mapping, use |nvim_buf_del_keymap|.
+///
+/// Arguments are handled like |nvim_set_keymap|. Like with ordinary |:unmap|
+/// commands (and `nvim_set_keymap`), the given {lhs} is interpreted literally:
+/// for instance, trailing whitespace is treated as part of the {lhs}.
+/// |keycodes| are still replaced as usual.
+void nvim_del_keymap(String mode, String lhs, Error *err)
+ FUNC_API_SINCE(6)
+{
+ nvim_buf_del_keymap(-1, mode, lhs, err);
+}
+
/// Gets a map of global (non-buffer-local) Ex commands.
///
/// Currently only |user-commands| are supported, not builtin Ex commands.