Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Control + space vim key binding in normal mode does not work

I want to map control+space to :bnext in order to forward switch in normal mode. So I added following to my .vimrc:

nnoremap <silent> <C-Space> :bn<CR>

For backward search following

nnoremap <silent> <C-S-Space> :bp<CR>

However, this solution does not work. Any ideas on what is the problem, and how I may solve it?

Update: My mapping list:

n  [m          *@:call <SNR>45_Python_jump('?^\s*\(class\|def\)')<CR>
n  [[          *@:call <SNR>45_Python_jump('?^\(class\|def\)')<CR>
n  ]m          *@:call <SNR>45_Python_jump('/^\s*\(class\|def\)')<CR>
n  ]]          *@:call <SNR>45_Python_jump('/^\(class\|def\)')<CR>
   <F7>        *@:call Flake8()<CR>
n  <Tab>       * <C-W>w
n  <CR>        * :call gruvbox#hls_hide()<CR><CR>
n  *           * :let @/ = ""<CR>:call gruvbox#hls_show()<CR>*
n  ,tj           :call Tj()<CR>
n  ,st           :call Sts()<CR>           <Space>
n  /           * :let @/ = ""<CR>:call gruvbox#hls_show()<CR>/
n  ?           * :let @/ = ""<CR>:call gruvbox#hls_show()<CR>?
n  \ca           <Plug>NERDCommenterAltDelims
x  \cu           <Plug>NERDCommenterUncomment
n  \cu           <Plug>NERDCommenterUncomment
x  \cb           <Plug>NERDCommenterAlignBoth
n  \cb           <Plug>NERDCommenterAlignBoth
x  \cl           <Plug>NERDCommenterAlignLeft
n  \cl           <Plug>NERDCommenterAlignLeft
n  \cA           <Plug>NERDCommenterAppend
x  \cy           <Plug>NERDCommenterYank
n  \cy           <Plug>NERDCommenterYank
x  \cs           <Plug>NERDCommenterSexy
n  \cs           <Plug>NERDCommenterSexy
x  \ci           <Plug>NERDCommenterInvert
n  \ci           <Plug>NERDCommenterInvert
n  \c$           <Plug>NERDCommenterToEOL
x  \cn           <Plug>NERDCommenterNested
n  \cn           <Plug>NERDCommenterNested
x  \cm           <Plug>NERDCommenterMinimal
n  \cm           <Plug>NERDCommenterMinimal
x  \c<Space>     <Plug>NERDCommenterToggle
n  \c<Space>     <Plug>NERDCommenterToggle
x  \cc           <Plug>NERDCommenterComment
n  \cc           <Plug>NERDCommenterComment
n  \b          * :CommandTBuffer<CR>
n  \t          * :CommandT<CR>
v  \<Space>    * <Esc>:call gruvbox#hls_toggle()<CR>gv
n  \<Space>    * :call gruvbox#hls_toggle()<CR>
n  gx            <Plug>NetrwBrowseX
n  <Plug>NetrwBrowseX * :call netrw#NetrwBrowseX(expand("<cWORD>"),0)<CR>
n  <Plug>NERDCommenterAltDelims * :call <SNR>17_SwitchToAlternativeDelimiters(1)<CR>
x  <Plug>NERDCommenterUncomment * :call NERDComment("x", "Uncomment")<CR>
n  <Plug>NERDCommenterUncomment * :call NERDComment("n", "Uncomment")<CR>
x  <Plug>NERDCommenterAlignBoth * :call NERDComment("x", "AlignBoth")<CR>
n  <Plug>NERDCommenterAlignBoth * :call NERDComment("n", "AlignBoth")<CR>
x  <Plug>NERDCommenterAlignLeft * :call NERDComment("x", "AlignLeft")<CR>
n  <Plug>NERDCommenterAlignLeft * :call NERDComment("n", "AlignLeft")<CR>
n  <Plug>NERDCommenterAppend * :call NERDComment("n", "Append")<CR>
x  <Plug>NERDCommenterYank * :call NERDComment("x", "Yank")<CR>
n  <Plug>NERDCommenterYank * :call NERDComment("n", "Yank")<CR>
x  <Plug>NERDCommenterSexy * :call NERDComment("x", "Sexy")<CR>
n  <Plug>NERDCommenterSexy * :call NERDComment("n", "Sexy")<CR>
x  <Plug>NERDCommenterInvert * :call NERDComment("x", "Invert")<CR>
n  <Plug>NERDCommenterInvert * :call NERDComment("n", "Invert")<CR>
n  <Plug>NERDCommenterToEOL * :call NERDComment("n", "ToEOL")<CR>
x  <Plug>NERDCommenterNested * :call NERDComment("x", "Nested")<CR>
n  <Plug>NERDCommenterNested * :call NERDComment("n", "Nested")<CR>
x  <Plug>NERDCommenterMinimal * :call NERDComment("x", "Minimal")<CR>
n  <Plug>NERDCommenterMinimal * :call NERDComment("n", "Minimal")<CR>
x  <Plug>NERDCommenterToggle * :call NERDComment("x", "Toggle")<CR>
n  <Plug>NERDCommenterToggle * :call NERDComment("n", "Toggle")<CR>
x  <Plug>NERDCommenterComment * :call NERDComment("x", "Comment")<CR>
n  <Plug>NERDCommenterComment * :call NERDComment("n", "Comment")<CR>
   <F4>          :Tlist<CR>
n  <C-Space>   * :bnext<CR>
n  <S-Tab>     * <C-W>W
   <F3>          :NERDTreeToggle<CR><CR>

My buffers when I am trying:

:ls
  1 #    "views.py"                     line 73
  2 %a   "./forms.py"                   line 19

What cause the problem? Can you help?

like image 753
Khamidulla Avatar asked Apr 21 '14 01:04

Khamidulla


3 Answers

In most terminals (which I'm assuming you're using, since you didn't specify gVim/MacVim), <C-Space> and <C-S-Space> don't map to actual ASCII characters. You can confirm this by entering insert mode, typing <C-V> to initiate literal character insertion, and then typing either of those keys. If you see ^@ that means you entered the Null character, which can't be mapped to. So unfortunately you'll either need to switch to a GUI flavor of Vim (which does understand non-ASCII maps) or choose a different mapping.

Edit: my mistake, the null character can be mapped to, via <NUL>, as another answer points out. There's still no distinguishing <C-S-Space> and <C-Space> (or <C-j>, and <C-@>), but you can map them at least.

like image 194
joshtch Avatar answered Oct 21 '22 01:10

joshtch


You can use <NUL> for this:

nnoremap <NUL> :w<CR>

saves the current file when you type <c-space> in normal mode. This works for me in the terminal (I use cygwin terminal in windows, should work in other terminals).

like image 40
skeept Avatar answered Oct 21 '22 03:10

skeept


Some key combinations, like Ctrl + non-alphabetic cannot be mapped, and Ctrl + letter vs. Ctrl + Shift + letter cannot be distinguished. (Unless your terminal sends a distinct termcap code for it, which most don't.) In insert or command-line mode, try typing the key combination. If nothing happens / is inserted, you cannot use that key combination. This also applies to <Tab> / <C-I>, <CR> / <C-M> / <Esc> / <C-[> etc. (Only exception is <BS> / <C-H>.) This is a known pain point, and the subject of various discussions on vim_dev and the #vim IRC channel.

Some people (foremost Paul LeoNerd Evans) want to fix that (even for console Vim in terminals that support this), and have floated various proposals, cp. http://groups.google.com/group/vim_dev/browse_thread/thread/626e83fa4588b32a/bfbcb22f37a8a1f8

But as of today, no patches or volunteers have yet come forward, though many have expressed a desire to have this in a future Vim 8 major release.

like image 6
Ingo Karkat Avatar answered Oct 21 '22 01:10

Ingo Karkat