I'm trying to map pressing [ctrl] + [semicolon] in insert mode to move to the end of the line and add a semicolon. It's something I find myself doing a lot after installing the surround plugin.
I tried running this command
inoremap <c-;> <esc>A;<esc>
but when I try it, it exits me out of insert mode, and goes into command mode. Trying with another modifier d
yields the same result too.
Can semicolon not be mapped with a modifier? What am I doing wrong?
A;<Esc> is just the command to add a semicolon to the end of a line. A appends to the end of a line, putting you in insert mode at the end of the line. ; just types the character as you're in insert mode, then <Esc> is the escape key that will put you back in normal mode.
To avoid the extra 'shift' keypress when typing the colon to go to cmdline mode, I mapped the semicolon key to do the same thing. This overwrites the original mapping of repeating the last f or t command.
I didn't read your question carefully, just saw your mapping took you out of the insert mode and the last <esc>
... my fault.
You want to map ctrl+;
vim cannot capture the keycode. there are some key combination cannot be mapped in vim. ;
is one of them, another example like ctrl+=
.
so you may want to choose another mapping.
btw, you can try in insert mode press ctrl-v
then the keycombination to see if it could be used.
Depending on your terminal it is possible to set up mappings. For example if you use urxvt, in ~/.Xresources
add:
URxvt.keysym.C-semicolon: \033[;
And in ~/.vimrc
add:
map <Esc>[; <C-Semicolon>
map! <Esc>[; <C-Semicolon>
Then you should be able to map it like this (not tested):
inoremap <c-Semicolon> <Esc>A;<Esc>
I use this to map split window movement like this (this works for me):
noremap <C-Semicolon> <C-w>l
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With