How To Add Bookmarks Inside Vim Editor

1. Vim Local Bookmark

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.

How to Create Bookmark Inside Vi?

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

How To Add Bookmarks Inside Vim Editor_第1张图片

Fig 1: Bookmark current location inside Vim using ma

Two Methods To Access Bookmarked Line Inside Vi

Method 1: `{macro-name}

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

Method 2: ‘{macro-name}

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

2. Vim Global Bookmark

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.

  1. Open multiple files: # vim /etc/passwd /etc/group
  2. While editing /etc/passwd file go to a specific line and type mP to create a global bookmark called P
  3. Type :n from /etc/passwd file to jump to /etc/group file in vim.
  4. While editing /etc/group file go to a specific line and type mG to create a global bookmark called G
  5. Type `P (back-tick followed by upper-case P), which will take you to the bookmark in /etc/passwd
  6. From /etc/passwd, type `G (back-tick followed by upper-case G), which will take you to the bookmark in /etc/group.

3. How to Display All Bookmarks

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:

  • a – local bookmark with name “a” at line 15 and col 9. This also give the text of line#15 . This is from the current open file, which is yp.conf
  • b – local bookmark with name “b” at line 11 and col 18. This also gives the text of line#18. This is from the current open file, which is yp.conf
  • G – global bookmark with name “G” at line 56 and col 0 of “group” file
  • P – global bookmark with name “P” at line 45 and col 0 of “passwd” file.


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.

4. Quick Summary of Vim Bookmark Commands

  • ma – Creates a bookmark called a
  • `a – Jump to the exact location (line and column) of the bookmark a
  • ‘a – Jump to the beginning of the line of the bookmark a
  • :marks – Display all the bookmarks
  • :marks a – Display the details of the bookmark with name a
    `. – Jump to the exact location (line and column) where the last change was performed
  • ‘. – Jump to the beginning of the line where the last change was performed

你可能感兴趣的:(File,vim,domain,character,methods,bookmarks)