I've read some other answers here about how to add a command that creates a blank line above or below the current line while staying in normal mode. The closest I've come to what I want to achieve is the following (using the VSCode Vim extension hence the JSON format):
{
"before": ["C-j"],
"after": ["o", "<Esc>", "\"", "_", "c", "c", "<Esc>"]
},
{
"before": ["C-k"],
"after": ["O", "<Esc>", "\"", "_", "c", "c", "<Esc>"]
},
This almost does what I want. It successfully creates new line and doesn't overwrite my clipboard register.
There's one problem with it, which is that if I run this command and then immediately undo it, it deletes more content on the next line after the inserted blank line.
For example: If I have my cursor at the '*' location.
1 guessField.focus();*
2 }
If I hit C-j to run my remapping as shown above I get the following:
1 guessField.focus();
2 *
3 }
Which is what I want, a blank line inserted and my cursor is at the same position while still in Normal mode. The problem occurs if I then hit 'u' to undo this command. The following happens:
1 guessField.focus();
2
The '}' from line 2 is now deleted which is not what I want.
This is strange because if I run through my remapping manually and type all those inputs, this behaviour doesn't occur. I've read up on it and I believe it's something to do with the way vim keeps track of the undo register when moving between insert and normal mode.
Is there any suggestion to avoid this or for a different remapping that would achieve the same thing but not have this issue?