Alexey
Alexey

Reputation: 9447

How to bookmark the whole file in Vim, not a specific line?

Use Case

Upvotes: 1

Views: 221

Answers (3)

Rory O'Kane
Rory O'Kane

Reputation: 30418

Add this to your ~/.vimrc:

nnoremap <c-m> :execute 'buffer' getpos("'" . nr2char(getchar()))[0]<cr>

Then just bookmark the file using mX, and jump to the last position in it using <c-m>X.

Upvotes: 0

Ingo Karkat
Ingo Karkat

Reputation: 172708

You can do that with (uppercase) file marks by just considering the buffer number; i.e. instead of recalling the (exact marked) position via A, do

:execute 'buffer' getpos("'A")[0]

As Vim remembers the last position in the buffer, it'll take you there, not to the marked position.

Upvotes: 3

Peter Rincker
Peter Rincker

Reputation: 45157

Marks are used to go to a specific line, column, and file in which they are set. That is there purpose.

Options that might work for you:

  • Set a upper case mark, e.g. mA
  • Use a buffer navigation command, e.g. :b foo (:b can take partial filenames)
  • Use a fuzzy finder to jump to your buffer
  • Remember the buffer number and use it directly :b 12 (avoid this)
  • Use <c-o> to go back to the buffer
  • Use <c-6> to jump to the previous buffer
  • Use a split so you can see both buffers at the same time
  • Open the buffer in a new tab (I tend to avoid tabs)

Personally I would just set another uppercase mark or use :b.

Upvotes: 2

Related Questions