Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VIM Super Fast Navigation

Tags:

vim

navigation

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.

like image 611
Helmut Granda Avatar asked Jan 05 '12 21:01

Helmut Granda


People also ask

What are the 4 navigation keys in vi?

We can prefix the repeat factor with navigation keys (h, j, k and l). Explanation: The repeat factor can be used as a command prefix with all these four commands.

Which command is used for navigating 5 pages forward in vi editor?

To scroll forward (move down) one screenful, press Ctrl-F. (Hold down the Control key and press the F key.) The cursor moves to the upper left corner of the new screen.


2 Answers

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.

like image 88
romainl Avatar answered Oct 04 '22 16:10

romainl


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.

like image 29
Vincent Avatar answered Oct 04 '22 18:10

Vincent