How can I simplify the following codes in my init.lua? (For "simplify" I mean that by vim.cmd(...) you're actually letting Lua run vimscript under the hood. But there is probably a Lua API to call instead. For example currently I learned that: vim.cmd("set nowrap") can be re-written to vim.opt.wrap = false.)

vim.cmd('runtime plugin/astronauta.vim')
vim.cmd('noremap! <S-Insert> <C-W>')
vim.cmd('cnoreabbrev S LspStart')
vim.g.mapleader = ' '

I think there will be one sentence to solve all these little problems so I combine all of them instead of ask them separately. Thanks!


2 Answers 2


Neovim API is neither complete nor stable, and so, IMO and contrary to what other people may suggest, there's no good point (at least for now) in accepting Lua as primary configuration language. Consider also that you totally break compatibility with Vim while gaining only Lua JIT compiler to speed up execution of your loops... that you probably don't have at all.

Anyway, your best friends are :h vim.api and :h api.txt. They say what you can do now and what you can't (yet?).

So you're able to call vim.api.nvim_set_keymap(...) to set up a mapping without switching to VimScript engine. Also, vim.api.nvim_command(...) can execute that :runtime, though I'm almost sure that vim.command(...) calls it anyway, so they're practically identical. As for abbreviations, I don't see anything relevant (even no :h mapset() ported from Vim), so just leaving it as is.


After some searching.

  • vim.g.mapleader = ' ': Simplest already.

  • vim.cmd('cnoreabbrev S LspStart'): This has not been implemented. (read from a neovim GitHub issue)

  • vim.cmd('noremap! <S-Insert> <C-W>'):

    vim.api.nvim_set_keymap('!', '<S-Insert>', '<C-W>', NOREF_NOERR)

    where NOREF_NOERR_TRUNC is

    local NOREF_NOERR_TRUNC = { noremap = true, silent = true, nowait = true }
  • vim.cmd('runtime plugin/astronauta.vim') can be

    vim.api.nvim_command('runtime plugin/astronauta.vim')

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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