Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Persistent vim global marks

Tags:

vim

macvim

I recently found out the usage of global marks in vim. They seem to be quite a powerful feature, however they are deleted when vim is closed. Is there any way of defining vim global marks on vim startup (e.g by defining them in the .vimrc file) ?

like image 266
bergercookie Avatar asked Dec 14 '22 06:12

bergercookie


2 Answers

Normally, global marks are saved in the viminfo file on exit. It is ruled by the viminfo option. You can check its value like this:

:set viminfo?
  • If it's empty, you can set a common value in your .vimrc:

    set viminfo='100,<50,s10,h
    

    Then global marks should be saved on exit.

  • If it's not empty, the f0 parameter has to be removed (because it disables the saving of global marks).

Automatic saving seems the best solution usually, but if you want, you can also set a global mark in your vimrc:

function! SetGMark(mark, filename, line_nr)
    let l:mybuf = bufnr(a:filename, 1)
    call setpos("'".a:mark, [l:mybuf, a:line_nr, 1, 0])
endf

call SetGMark('A', '~/file.txt', 10)
like image 158
yolenoyer Avatar answered Jan 17 '23 00:01

yolenoyer


You need to look into viminfo

:help viminfo will give you general details, and :help 'viminfo' will tell you about the options which need setting. (The quotes are important in this context)

If you exit Vim and later start it again, you would normally lose a lot of
information.  The viminfo file can be used to remember that information,     which
enables you to continue where you left off.

This is introduced in section 21.3 of the user manual.

The viminfo file is used to store:
- The command line history.
- The search string history.
- The input-line history.
- Contents of non-empty registers.
- Marks for several files.
- File marks, pointing to locations in files.
- Last search/substitute pattern (for 'n' and '&').
- The buffer list.
- Global variables.

Essentialy, make sure viminfo does not contain f0 which disables saving file marks across sessions.

My viminfo setting contains

:set viminfo='100,<50,s10,h,%
like image 22
Dave Avatar answered Jan 16 '23 23:01

Dave