Intro

Going to cover marks in nvim, which could also be thought of as bookmarks. Marks is a core vim feature, so it doesn't require any special plugins. The marks feature allows us to easily move / jump around important points in a file (or in different files).

How I use it?

As a developer; I would be working on a feature, the code for which would span across multiple files. I would create marks for certain positions in a single file or across multiple files. This would help me jump around these positions, saving me countless minutes in switching between the files if I had to do it manually.

Marks are used on the normal mode. So if I use m followed by a character, let's say a, it would mark the exact location. I can view the existing marks by using the :marks command. The uppercase marks 'A to 'Z include the file name. So kind of a global mark. I use it to jump across files.

Since I use telescope I could also see all my marks in the telescope window. I also see a small preview of where my marks are. I could also move on the list to choose the mark I want.

Deleting marks

I rarely delete marks. Lowercase marks 'a to 'z are remembered as long as the file remains in the buffer list. If the file is removed from the buffer list, all its marks are lost. If the line containing the mark is deleted, the mark is erased. They are also restored when using undo and redo.

Using operators along with marks

The lowercase marks can be used in combination with operators as well. For example: d't would delete the lines from the cursor position to the mark t. Generally I would use mark t for top and b for bottom etc.

List of commands useful for marks

Command       | Operation
--------------|----------------------------------------------------------
m{a-zA-Z}     | Sets the mark, for example `ma`
'a            | Go to the mark set at `a`, the cursor would be positioned on the first non-blank character in the line
`a            | Go to the mark set at `a`, the cursor would be positioned on the exact location
]'            | Go to the next lowercase mark set, cursor positioned on the first non-blank character in the line
]`            | Go to the next lowercase mark set, cursor positioned on the exact location
['            | Go to the previous lowercase mark set, cursor positioned on the first non-blank character in the line
[`            | Go to the previous lowercase mark set, cursor positioned on the exact location
:marks        | Shows the list of marks
:marks a      | Shows the list of mark at a
:marks ab     | Shows the list of marks at a and b
:marks a-c    | Shows the list of marks at a, b and c
:delmarks a   | Deletes the mark at a
:delmarks ab  | Deletes the mark at a and b
:delmarks a-c | Deletes the mark at a, b and c
:delmarks!    | Deletes all marks for current buffer (with lowercase {a-z})

References and further reading

  1. Marks in Vim Are A Game Changer
  2. Marks & Folds - Vim Tips (5)
  3. :help marks
  4. Plugin to view marks on the sign column

Further reading, related topics

  1. Jumps
  2. Changes