In my vimrc I have a shortcut for opening a vertical split:
let mapleader = ','
map <leader>v :vsplit<CR> " ,v for vsplit
map <leader>s :split<CR> " ,s for split
This has been working fine for months, but recently it's started misbehaving: almost every time I try to split the window, it does split but then changes a load of text at the cursor and leaves itself in insert mode.
Here's an example:
before split: const queryValidation
after split: plit", n
All that I did was hit ,v
which has been working fine until recently. I can't work out why this is happening now. My vim version is 7.4.2109.
(This doesn't happen if I just use :vsplit
)
map <leader>s :split<CR>| " ,s for split
. Note the|
.:vsplit
and:split
already have normal mode commands:<C-w>v
and<C-w>s
. No need to waste keys on redundant shortcuts."
in a mapping, it will typically imply the normal mode key"
, which indicates a register. For example, the following map will ensure thatdd
does not add to the most recent register, but instead save to the "black hole"-register:nnoremap dd "_dd
. The point is, since"
is a reasonable part of the right-hand side of a map, it can NOT be used to start a comment. This explains why the comments screw up your mapping, and why it works when you remove them.