Igor Bukanov
Igor Bukanov

Reputation: 5152

Convenient single-key remapping for PageUp and PageDown in Vim

As many laptop and even desktop keyboards lack dedicated PageUp and PageDown keys, or those are placed in awkward positions, I am thinking to remap in Vim the Space and V keys as PageUp and PageDown so I can conveniently scroll with a single keystroke.

I wonder if there is perhaps other useful combinations? For example, like remapping B as PageUp to be compatible with less and other viewers, and remapping B to some other key. Or even remap Backspace and Enter as PageUp and PageDown. Any other useful combinations?

Upvotes: 1

Views: 884

Answers (2)

dsimic
dsimic

Reputation: 390

Let's remember that the <S-Up> and <S-Down> keypresses are recognized in vim and mapped by default to <PageUp> and <PageDown>, respectively. In other words, the Shift + and Shift + keypresses can be used in vim instead of the PageUp and PageDown keys, respectively.

However, depending on the terminal emulator you're using, you may actually need to properly handle the escape sequences generated for the Shift + and Shift + keypresses to make the scrolling work. See this question and this answer for rather detailed instructions and a bit of background information, but please be prepared to spend some time on it.

Obviously, the OP's question was about scrolling one page up or down in vim using single keys on a laptop keyboard, but let's keep in mind that the arrow keys are virtually always in very close proximity to the right Shift key on laptop keyboards. Thus, pressing Shift + or Shift + on a laptop keyboard with just one hand isn't bad at all, with the important additional benefit of introducing no non-standard vim mappings.

Sticking to some kind of an already established standard should be good in this case, at least because you'll feel at home when you find yourself using bone-stock vim on someone else's laptop.

Upvotes: 2

Sander Vanhove
Sander Vanhove

Reputation: 1115

There are a lot of shortcuts for navigating around. Here are some useful ones:

  • Ctrl-u: Go up half a screen.
  • Ctrl-d: Go down half a screen.
  • Ctrl-b: Go up one full screen.
  • Ctrl-f: Go down one full screen.

Upvotes: 3

Related Questions