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

StackOverflow https://stackoverflow.com/questions/23546025

  •  18-07-2023
  •  | 
  •  

質問

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?

役に立ちましたか?

解決

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
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top