I have hard times figuring out what is wrong with these lines I am writing in my init.lua file in Neovim:

vim.cmd "cd C:/Users/samue/Desktop/"      
vim.api.nvim_command "<Space>e"
vim.api.nvim_command "<C-w>w"
vim.api.nvim_command ":vsplit"
vim.api.nvim_command ":terminal"
vim.api.nvim_command "<C-w>W"

Anything I write after '<' is said to be erroneous trailing stuff upon NV startup.

1 Answer 1


The nvim_command is to run Ex command (i.e. command that starts with :).

If you want to simulate character you can use the execute and normal command:

vim.api.nvim_command 'execute "normal" "\\<Space>e"'

But my advise is to stick with Ex commands:

vim.cmd "cd ~/Desktop" 
vim.cmd "NvimTreeOpen"
vim.cmd "wincmd w"
vim.cmd "vsplit"
vim.cmd "terminal"
vim.cmd "wincmd w"

You can also use a multi-line Lua string like in:

cd ~/Desktop 
wincmd w
wincmd w
  • 1
    What is the diff between Ed and Ex then? Feb 20, 2023 at 15:15
  • 1
    also the diff between vim.cmd and vim.api.nvim_command? Feb 20, 2023 at 15:15
  • My mistake I meant Ex. Feb 20, 2023 at 15:22
  • 1
    OK. So your solution does not work :( I get invalid escape sequence near 'execute "normal" Feb 20, 2023 at 15:25
  • 1
    My mistake I forgot one `` :-| Feb 20, 2023 at 15:28

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.