Question

I have an entry in my .vimrc which makes it page down the viewport when I hit the spacebar. It looks like this:

map <Space> <PageDown>

I want to create another key mapping which pages the viewport up when holding shift and hitting the spacebar. I have tried the following entries:

map <Shift><Space> <PageUp>
map <S-Space> <PageUp>

Neither work. Anybody know how to achieve this functionality?

Was it helpful?

Solution

You cannot. CMS's solution will work for gVim, but not in vim because terminals cannot distinguish between <Space> and <S-Space> because curses sees them the same. It might be possible in the future if vim gains libtermkey support and your terminal supports the proper <CSI> sequences (xterm does if properly configured; nothing else does yet).

OTHER TIPS

If you are using vim inside iTerm2 you can map shift-space to ctrl+U by sending the hex key 15. Here's a screen shot:

enter image description here

To look up a hex code for a ctrl+letter combination, for example ctrl+u, you can do the following:

  • In vim enter the insert mode
  • Hit ctrl+v then ctrl+u then ctrl+c then ga
  • various numerical representations will print at the bottom

You can apply this idea to other terminal emulators that support key mapping.

Use this:

map <Space> ^D   " Pagedown when press Space
map <S-Space> ^U " Page Up when press Shift Space

To get the ^D and ^U symbol correctly just press Control-V Control-D, and Control-V Control-U

For OSX:

nnoremap <Space> <C-d>
nnoremap <S-Space> <C-u>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top