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

Khamidulla picture Khamidulla · Apr 21, 2014 · Viewed 9.4k times · Source

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?

Answer

joshtch picture joshtch · Apr 21, 2014

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.