Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I map ctrl x ctrl o to ctrl space in terminal vim?

After searching a bit on the net it seems that I can't map CtrlSpace to anything/alot. Is there a way to do it today, what I found was usually 2 years old.

like image 957
plitter Avatar asked Oct 11 '11 06:10

plitter


People also ask

What does Ctrl space do in Vim?

When you press <C-Space> , the terminal sends an ambiguous signal to Vim which interprets it as <Nul> . Because <Nul> is usually represented as <C-@> , Vim acts as if you actually pressed <C-@> and tries to insert the previously inserted text.

How do you Ctrl Shift in Vim?

For example, add the following to . Xresources for xterm to send <Esc>[65;5u for Ctrl Shift A . You can then map that in Vim to <C-S-a> . (65 is the decimal Unicode value for shift-a and 5 is the bit for the ctrl modifier.


2 Answers

I've run into the same issue, the short answer is yes you can, and not only in the gui version. Adding this on you .vimrc is enough:

inoremap <C-Space> <C-x><C-o>
inoremap <C-@> <C-Space>
like image 93
Pablo Olmos de Aguilera C. Avatar answered Sep 22 '22 08:09

Pablo Olmos de Aguilera C.


The problem seems to be that Terminal.app doesn't interpret <C-Space> correctly and Vim understands it as <C-@> which is a built-in mapping (:help CTRL-@).

Maybe you could go with something like the following in your .vimrc:

if !has("gui_running")
    inoremap <C-@> <C-x><C-o>
endif

which seems to work, here, but I don't like the idea of overriding built-ins like that.

Instead you should try with <Leader> (:help leader), it gives you huge possibilities for defining your own custom mappings and (depending on the mapleader you choose) won't interfere with OS/app specific shortcuts/limitations and hence be more portable.

With this in my .vimrc:

let mapleader=","
inoremap <leader>, <C-x><C-o>

I just hit ,, to complete method names.

like image 26
romainl Avatar answered Sep 23 '22 08:09

romainl