Vim: Increase document traversal speed

vim
12,028

Solution 1

While possible (use :noremap j 3j Enter and :noremap j j Enter to restore), it may not be useful for very long to change the behaviour of these keys.

There are many ways to navigate in Vim. Of course you can advance by full screens using CtrlF and CtrlB.

You can, as you alluded to, enter a number of moves before executing the navigation.

You can also go directly to a specific line using :9Enter, for example.

If you see the text to which you want to navigate, use / or ? followed by the text.

For h and l, you can navigate word boundaries more quickly with b, w, and e, and contiguous non-whitespace with B, W, and E.

Solution 2

Try Ctrl+D/Ctrl+U and Ctrl+F/B (Up/Down, Forward/Back respectively).

These will traverse the document much faster than h,j,k,l.

Solution 3

What @Bryan Ross have suggested is absolutely right. I want to add just a thing. Use relativenumber, it will help you to use j and k more efficiently.

Solution 4

Another thing that helps is to have line numbers turned on (:set number). If you see on the screen where you need to go and see the line number, it's just G.

If you deal with code in blocks, % will move you to a matching brace, parenthesis, etc.

If you deal with files with lots of wacky characters, t, T, f, and F are very helpful.

Solution 5

Answered by Jay is sufficient, I would like to add the following !

There are many different kinds of navigation possible in vim, ( where as the h, j, k, l are just line navigation ). Some more are:

  • screen navigation
  • spl navigation
  • search navigation
  • word navigation

Refer this write up to find out the short cut keys to do it: Essential Vim editor navigation

Share:
12,028
josh-fuggle
Author by

josh-fuggle

Hello, My name is Josh. I am a mobile growth / iOS developer currently working on iAuditor at SafetyCulture. I was originally attracted to the iOS platform as I work well visually and I love being able to pull something out of my pocket and saying "this is what I have made"​. Building mobile applications strikes a fantastic balance between logic and creativity. You can satisfy the creative side of your mind by building delightful user experiences at the same time as satisfying the logic side of your mind by building complicated engineering systems.

Updated on July 31, 2022

Comments

  • josh-fuggle
    josh-fuggle over 1 year

    I sometimes find document traversal to be too slow in Vim when using h, j, k, l. Is there a way to temporally increase the number of lines / characters that these keys move the cursor? (I.e. instead of moving 1j, pressing j will move 3j)

    Edit: Solution:

    :map <F8> :noremap j 3j <CR>
    :map <S-F8> :noremap j j <CR>
    

    I wanted something like this so that I can easily browse longer bodies of code that am not necessarily familiar it. This approach allows me to easily toggle between "browsing" mode and "coding" mode.