3

How can I port map commands in my vimrc file to Neovim lua configuration? For example:

nmap <silent> <F2> <Plug>(lcn-rename)

1 Answer 1

7

You use vim.api.nvim_set_keymap

vim.api.nvim_set_keymap(mode, keys, mapping, options)

So to port

nmap <silent> <F2> <Plug>(lcn-rename)

It would look like

vim.api.nvim_set_keymap('n', '<F2>', "<Plug>(lcn-rename')", { noremap = true, silent = true });

Alternatively you can create convenience functions,

function map(mode, shortcut, command)
  vim.api.nvim_set_keymap(mode, shortcut, command, { noremap = true, silent = true })
end

function nmap(shortcut, command)
  map('n', shortcut, command)
end

function imap(shortcut, command)
  map('i', shortcut, command)
end

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.