I'm trying to do something very simple, enter normal mode and ALWAYS be able to somehow put the normal mode cursor where it was in insert mode, whether through a mark, or otherwise.

I'm doing this because my neovim GUI doesn't handle copy/paste and I need to map it myself. This is proving extremely painful and challenging to get it working properly, like how MacVim does it is perfect.

def hello
  puts "hi"

If I hit <esc>

It enters normal mode but at the beginning of the line. this makes it hard to paste "+P exactly where the cursor was.

-- indentation
vim.opt.autoindent  = true -- continue indentation to new line
vim.opt.smartindent = true -- add extra indent when it makes sense
vim.opt.smarttab    = true -- <tab> at the start of a line behaves as expected
vim.opt.expandtab   = true -- <tab> inserts spaces
vim.opt.shiftwidth  = 2    -- >>, << shift line by 4 spaces
vim.opt.tabstop     = 2    -- <tab> appears as 4 spaces
vim.opt.softtabstop = 2    -- <tab> behaves as 4 spaces when editing

-- cursor
vim.opt.virtualedit = 'all'
  • :help autoindent
    – D. Ben Knoble
    Commented Aug 1, 2023 at 16:10
  • Are you already aware of the ]p command? Depending on your exact usecase, might be easier than altering the behaviour of autoindent.
    – Rich
    Commented Jul 10 at 11:51


Your Answer

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