VIM Super Fast Navigation

VimNavigation

Vim Problem Overview


The only thing that I miss about using other editors is finding my place with the mouse. I can look with my eyes to a specific area on the file and with a motion of the mouse and a click I am there. With VIM i have to jjjjjkkkkkkjjjjhhhh... almost there hhhhh oh crap I missed by 3 characters, lll.

I am learning to do marks and i found a bookmarks plugin that is great, I can create markers and destroy them with <f3> and navigate to them with unfortunately the marks are forgotten when the file is closed.

How do you all super navigate files? I know I could also do 5j7k4j5h and so forth, but there must be a plugin that can read my eyes and put the cursor where I really need it..

I also have learned to use /% to search for a specific term. It does help but all the matching characters are highlighted through out the document.

Vim Solutions


Solution 1 - Vim

Try $ vimtutor, it will teach you everything you need to know to get started.

hjkl are the tip of the top of the iceberg and very rarely used, at least in my case.

wWEe and BbgegE all allow to move word by word:

  • w and e go forward, W and E take whitespace and punctuation into account

      " here the * marks the default location of the cursor
      " and each letter shows where you jump when you hit the key.
    
      Latin: Lorem ipsum dolor sit amet.
                         *   e   e    e
                         *   E   E     E
      *    w w     w     w     w   w   w
      *      W     W     W     W   W   W
    
  • b and ge go backward, B and gE take whitespace and punctuation into account

      Latin: Lorem ipsum dolor sit amet.
      b    b b     b     *
      B      B     B     *
           ge    ge    ge*
          ge
           gE    gE    gE*
    

fFtT are used to reach for a particular character on the current line and ;, are used to repeat that motion, in the same direction for ;and in the opposite direction for ,:

  • fm jumps ON the next m forward, F goes backward

      Latin: Lorem ipsum dolor sit amet.
      *          fm    ;            ;
                 ;     Fm          *
    
  • tm jumps BEFORE the next m forward, T goes backward

      Latin: Lorem ipsum dolor sit amet.
      *         tm    ;            ;
                ;     Tm           *
    

/? are used to jump to the first occurrence of a pattern from the current cursor position:

  • /pattern goes forward

      Latin: Lorem ipsum dolor sit amet.
      *            /ips
    
  • ?pattern goes backward

      Latin: Lorem ipsum dolor sit amet.
      ?Lat             *
    

0$ are used to jump to the first and last character of the line.

    (whitespace)Latin: Lorem ipsum dolor sit amet.(whitespace)
    0                  *                                     $

^g_ are used to jump to the first and last printable character of the line.

    (whitespace)Latin: Lorem ipsum dolor sit amet.(whitespace)
                ^      *                         g_

Single and combined ()[]{} are used to move phrase by phrase or paragraph by paragraph or code block by code block.

<C-b> and <C-f> are used to scroll by screen backward and forward.

<C-u> and <C-d> are used to scroll by half-screen backward and forward.

H, M and L move the cursor to the top, middle, bottom of the viewport, respectively.

zt, zz and zb move the line under the cursor to the top, middle, bottom of the viewport, respectively.

And so on.

:help motion.txt will blow your mind.

Solution 2 - Vim

besides vim's motion command, I find a vim plugin named EasyMotion is pretty useful to navigate, if you are familiar with vimperator or pentadactyl, EasyMotion just bring hint mode back to vim. here is a animated demo and here is the video tutorial. Hope it's helpful for you.

Solution 3 - Vim

There are a zillion ways to move around in vim, this is one of its really strong areas. I use { and } a lot, which move up and down to the next blank line in that direction. % is useful for moving back and forth to a matching bracket (of any kind). W and B move forward and back by a "word".

It might be worthwhile reviewing the Moving around section of the Vim manual.

Solution 4 - Vim

vim has mouse support! give this a try (in your .vimrc):

set mouse=a

sidenote: as a screen user, I've found that I also need

set ttymouse=xterm2

for this to work.

Solution 5 - Vim

personally I prefer to use:

"/<chars><enter>" to quickly move to somewhere   ( extremely fast! trust me! )
":<number>" to go to some line, 
"ctrl + f/b" to forward/back
"g;" to move to the last editing place.
"w/b" to move by word
"jklh" to move your cursor to the exact position

Solution 6 - Vim

Apart from {, }, (, ), <number>cb, <number>cB, <number>cW and %, I use such navigating techniques:

  • ciw, diw (ciW, diW). etc. to quickly edit/delete word under the cursor (including non-space characters)
  • ci(, ci" (ca(, ca"), etc. to quickly edit inside parentheses, quotes (including parentheses, quotes). The same applies for d.
  • Marks with CAPITAL letters to set them globally (across files) and persistently (when buffer is closed). For instance, mA will create global mark A that will be available with 'A command (or ````A``` to respect column).
  • gf to go quickly to file under cursor
  • f, t (F, T) to move to the char, before the char right (left) (use ; to repeat). These are particularly useful for d and c commands (use . to repeat).
  • ^] to move to the tag and ^T to move back.

And lots of others ways to move :)

Check this out for more information: http://www.thegeekstuff.com/2009/03/8-essential-vim-editor-navigation-fundamentals/

P.S. For rails users there is a very useful rails-vim plugin, you may want to check it out too.

Solution 7 - Vim

With option relativenumber (:help relativenumber - included with Vim 7.3) you can get to the line under your eyes with the a [count]k or [count]j movement, which you let you move in current line with movements like ftweb as explained by @romainl.

Solution 8 - Vim

I only have this diagrams!

▼/▶ Cursor   ▽/▷ Target
┌───────────── 0      
│  ┌────────── ^      $ ──────────────┐
│  │  ┌─────── Fo     fe ────────┐    │
│  │  │┌────── To     te ───────┐│    │
│  │  ││ ┌──── ge     w ───┐    ││    │
│  │  ││ │ ┌── b      e ─┐ │    ││    │ 
│  │  ││ │ │  ┌h      l┐ │ │    ││    │
▽  ▽  ▽▽ ▽ ▽  ▽▼      ▼▽ ▽ ▽    ▽▽    ▽
   echo "A cheatsheet from quickref.me"
                 - SCREEN 1 START
   ┌─┬─────────▷ #!/usr/bin/python
   │ │     ┌───▷     
   │ │     │     print("Hello")
   │ │     { } ▶ print("Vim")
   │ │       │   print("!")
   │ │       └─▷    
   │ │ ┌───┬───▷ print("Welcome")
G gg H M L k j ▶ print("to")
│        │   └─▷ print("quickref.me")
│        │       print("/vim")
│        │     
│        └─────▷ 
│                - SCREEN 1 END
└──────────────▷ print("SCREEN 2")

Solution 9 - Vim

this is a good place to learn the main navigation commands, some of the power/speed of vim comes from the combination of movement with action i.e. cw -> change word, d10j -> delete 10 lines down etc. Also this and this are interesting reads.

Solution 10 - Vim

You can :set nohlsearch to turn off the highlight of your search characters.

I navigate using ctags a lot too.

Solution 11 - Vim

I have wrote a plugin with super fast navigation in mind, it's called move-less:

https://github.com/anschnapp/move-less

It let's you search the hole file comfortable by scrolling with (h j k l-keys). You don't change your cursor position while scrolling the hole site (based on folding trick). If you abort your search you just where you started.

For super fast navigation the intension is to use my plugin to get the target position on the screen and then jump to the right position via easymotion (which already was recommended from another answer):

https://github.com/easymotion/vim-easymotion

If you combine both you could even take advance of the jump-history and you can jump between your origin and target destination simply via <c-o> and <c-i>.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionHelmut GrandaView Question on Stackoverflow
Solution 1 - VimromainlView Answer on Stackoverflow
Solution 2 - VimVincentView Answer on Stackoverflow
Solution 3 - VimGreg HewgillView Answer on Stackoverflow
Solution 4 - VimrgcbView Answer on Stackoverflow
Solution 5 - VimSiweiView Answer on Stackoverflow
Solution 6 - VimpenkovskyView Answer on Stackoverflow
Solution 7 - VimmMontuView Answer on Stackoverflow
Solution 8 - VimRaosView Answer on Stackoverflow
Solution 9 - VimT IView Answer on Stackoverflow
Solution 10 - VimrichoView Answer on Stackoverflow
Solution 11 - VimsnapView Answer on Stackoverflow