1

I find myself adding a single letter during edits. Is there any way to add a character and exit insert mode just like replacing r but not deleting the character in Vs code vim extension? pressing i <character> <Esc> each and every time defeats the purpose of being productive. I have also looked for mapping and tried but not sure how they work. Any help is appreciated.

romainl
  • 186,200
  • 21
  • 280
  • 313
Sanket Wagh
  • 156
  • 1
  • 14

1 Answers1

2

From normal mode, you can put yourself in insert mode, type a space, exit back to normal mode, then put yourself in replace mode. That way you find your cursor on a blank space in replace mode, where you can simply type the character you want to add.
Here's how to do it (replace "your-desired-mapping-here" by the mapping that you like, for example: M)
vscode vim plugin way: (add this to your settings.json)

"vim.normalModeKeyBindingsNonRecursive": [
    {
        "before": ["<your-desired-mapping-here>"],
        "after": ["i", " ", "<ESC>", "r"]
    }
]

vim way: (add this to your .vimrc)

nnoremap <your-desired-mapping-here> i <esc>r

note: please notice the space after i in the vim way.

Maaddy
  • 618
  • 5
  • 13
  • 1
    Thanks a lot. I almost got close .mapped escape in the end .I think this should be definitely added as it has many use cases. – Sanket Wagh Oct 27 '21 at 13:53