Within a single file when you want to go to a particular position or line, then you can use local marking. If the bookmark name is a lower case letter, then that is local mark.
Type m{macro-name}. macro-name is an alphabet to refer to the name of the bookmark.
If you type “ma” , it will create bookmark on the current line at the current location with name “a”. In the following example, typing ma has created a bookmark at the exact location where the cursor is highlighted.
ma
Fig 1: Bookmark current location inside Vim using ma
backtick followed by the macro name. Move to the exact bookmark location. This will jump to the exact character location within the line from where it was bookmarked earlier.
For example, if you type `a , it will take you to the bookmark with name “a”. i.e It will take you to the place where the cursor is high-lighted in the above Fig 1.
`a
single-quote followed by the macro name. Move to the beginning of the bookmarked line.
For example, if you type ‘a , it will take you to beginning of the line that has the bookmark with name “a”. It will take you to the the beginning of the “CustomLog logs/access_log combined” line in the above Fig 1.
'a
When you have multiple files open, if you want to go to a particular position in any one of the open files, then you can use Global mark feature of Vim. If the bookmark name is an upper case letter, then that is a Global Bookmark.
Following sequence of steps will explain how to use global bookmark while editing multiple files.
If you’ve created several bookmarks and don’t remember them, you can easily get a list of all the bookmarks by typing :marks as shown below.
:marks mark line col file/text a 15 9 ypserver 192.168.1.119 b 11 18 domain THEGEEKSTUFF G 56 0 group P 45 0 passwd
This indicates that I have created the following bookmarks:
Apart from the above bookmarks, anytime you type :marks inside Vim, you may get the following lines. These marks ‘ (single-quote), ” (double quote), [ , ], ^ and . (period) are created by vim by default and you don’t have any control over it.
:marks mark line col file/text ' 8 12 #^IUse broadcast on the local net for domain NISDOMAIN " 1 0 # /etc/yp.conf - ypbind configuration file [ 11 0 domain THEGEEKSTUFF ] 11 19 domain THEGEEKSTUFF ^ 11 19 domain THEGEEKSTUFF . 11 18 domain THEGEEKSTUFF
For example, the mark . (period) indicates the last position where a change was made. So, you can always do `. (back-tick followed by period), which will take you to the position where the last change was done.