Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim: how to specify arrow keys

Tags:

vim

People also ask

Can I use arrow keys in vim?

Note: For scrolling in vim editor, you can utilize the arrow keys too, but hjkl keys usage will make you scroll faster in the vim editor.

How do I use arrow keys in HJKL?

You can create a couple of windows using Control-w + s and Control-w + v , then use your trusty hjkl to move around between your windows, Control-w + h moves a window left, Control-w + j moves a window down, etcetera. So it's not just that they are an improvement over the arrow keys.

How do I use arrow keys in terminal?

The way to scroll using the arrow keys in a terminal emulator is to hold down the shift key. This is because a terminal emulator send all keypresses to the application running in the terminal; holding shift down bypasses that. This can also be used with other keys like copy and paste.

How do I map a key in vim?

To map a sequence of keys to execute another sequence of keys, use the ':map' command. For example, the following command maps the <F2> key to display the current date and time. The ':map' command creates a key map that works in normal, visual, select and operator pending modes.


If you don't know the internal code for a certain key, type CtrlK and then the function key. For example, this sequence followed by the up arrow key will output:

<Up>

You can learn more about this command in the documentation for both insert and command mode. The specific ways to map a special key are given in the documentation with the tag :map-special-keys. Additionally, you can find a handy table with :h key-notation.


Quite literal:

<Left>
<Right>
<Up>
<Down>

As noted in the comments, find this and more in this tutorial.


And

<C-Right>

for Control key and Right.

For example, I used the following mappings (in my .vimrc) to cycle through my open buffers:

nnoremap <silent> <C-Right> :bn<CR>
nnoremap <silent> <C-Left> :bp<CR>