Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I map Ctrl + semicolon to add a semicolon to the end of the line?

Tags:

vim

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?

like image 627
fent Avatar asked May 08 '14 15:05

fent


People also ask

How to add semicolon at the end of each line vi editor?

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.

What does semi colon do in Vim?

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.


2 Answers

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.

like image 169
Kent Avatar answered Oct 24 '22 16:10

Kent


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
like image 28
PhilT Avatar answered Oct 24 '22 18:10

PhilT