Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fast switching between two lines in file in vim

Tags:

vim

sometimes I have to switch between 2 lines. To do this, I have to pass line number. Are there shortcuts to moving between 2 last 'visited' list. Something similar to '. (it moves to last edited line)

like image 989
Sławosz Avatar asked Sep 16 '10 09:09

Sławosz


People also ask

How do you jump between lines in vim?

If we are in the vim editor, then simply do this, “Press the ENTER key, write the Line number, and press Shift+ g”: Again the output is the same.

How do I toggle between files in vim?

Ctrl-W w to switch between open windows, and Ctrl-W h (or j or k or l ) to navigate through open windows. Ctrl-W c to close the current window, and Ctrl-W o to close all windows except the current one. Starting vim with a -o or -O flag opens each file in its own split.

How do we jump to the start of a word in vim?

Press 0 to go to the beginning of a line, or ^ to go to the first non-blank character in a line. Save this answer.


2 Answers

You can use bookmarks, something like ma to mark a bookmark named a, and then 'a to go to it. Naming boomarks a and b for example, you can switch between them with 'a and 'b.

like image 146
Greg Hewgill Avatar answered Oct 11 '22 03:10

Greg Hewgill


Double-backtick or double single-quote will do exactly that

There is a command that will bounce to the last location you jumped away from. If repeated, it will then return to the jump destination you were just on. If repeated further it will bounce you back and forth between the two locations.

The command has two forms:

``

or

''
like image 20
DigitalRoss Avatar answered Oct 11 '22 01:10

DigitalRoss