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

VimMappingOmnicomplete

Vim Problem Overview


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.

Vim Solutions


Solution 1 - Vim

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>

Solution 2 - Vim

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.

Solution 3 - Vim

The nitpicker broke pablox solution. The crux of the solution was just about remapping. So when you disable remapping, it cannot work.
If you really want to throw in a noremap, this is what it looks like:

inoremap <expr><C-space> neocomplete#start_manual_complete()
imap <C-@> <C-Space>

What will not work: inoremap <C-@> <C-Space> 'cause the <C-Space> part will not be remapped itself.

Solution 4 - Vim

  • Have you tried :inoremap <c-space> <c-x><c-o> ?
  • Does CtrlX CtrlO do anything when you type in insert mode? Is omnifunc set?

Solution 5 - Vim

Add the following code to ~/.vimrc:

" Ctrl-Space for completions. Heck Yeah!
inoremap <expr> <C-Space> pumvisible() \|\| &omnifunc == '' ?
        \ "\<lt>C-n>" :
        \ "\<lt>C-x>\<lt>C-o><c-r>=pumvisible() ?" .
        \ "\"\\<lt>c-n>\\<lt>c-p>\\<lt>c-n>\" :" .
        \ "\" \\<lt>bs>\\<lt>C-n>\"\<CR>"
imap <C-@> <C-Space>

Source: https://coderwall.com/p/cl6cpq

Solution 6 - Vim

To accommodate both Windows and Linux I applied this to ~/.vimrc

if has("unix")
  inoremap <C-@> <c-x><c-o>
elseif has("win32")
  inoremap <C-Space> <c-x><c-o>
endif

Solution 7 - Vim

I had better results with this set of mappings across all modes on Mac OS. Have not tested Windows or Linux.

I don't understand how the excepted answer is supposed to work in terminal mode.

inoremap <C-space>   <ESC>
vnoremap <C-space>   <ESC>
cnoremap <C-space>   <C-c>
" When in terminal, <C-Space> gets interpreted as <C-@>
imap     <C-@>       <C-space>
vmap     <C-@>       <C-space>
cmap     <C-@>       <C-space>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionplitterView Question on Stackoverflow
Solution 1 - VimPablo Olmos de Aguilera C.View Answer on Stackoverflow
Solution 2 - VimromainlView Answer on Stackoverflow
Solution 3 - VimoliverView Answer on Stackoverflow
Solution 4 - VimBenoitView Answer on Stackoverflow
Solution 5 - VimErwin RooijakkersView Answer on Stackoverflow
Solution 6 - VimKidquickView Answer on Stackoverflow
Solution 7 - VimcmcgintyView Answer on Stackoverflow