1

I use sessions to separate projects in my workflow.

- info.txt file that I always mark "I"
- log.txt file that I always mark "L"

But when I switch sessions, my markers are kept from the last project, causing lots of confusion!

Is there a way to isolate markers per session?

Or let's say... save my markers to a local viminfo that runs on each session load?

Or is there a better way to do this? what's the vim way?

  • As the answer below says file marks are treated globally and stored in viminfo when exiting vim. Vim does have commands allowing direct manipulation of viminfo (e.g. manually trigger viminfo save, read/write specified viminfo sections, use files other than .viminfo, etc). You could use these (plus autocommands probably) to create a custom solution. Not sure if you're that committed. See my answer here for a glimpse of some of this stuff: vi.stackexchange.com/a/17570/11054 – B Layer Aug 23 at 4:11
2

Marks are stored in viminfo not in a session and the viminfo file is only written when exiting vim. So if you are closing vim to switch projects then vim will only have marks for the previous project that you were working on. One would potentially have to come up with a plugin that separately reads and stores marks from viminfo when calling :mksession and then overwrites them in viminfo when sourcing the session file.

From :h session

1. Restores global mappings and options, if 'sessionoptions' contains
       "options".  Script-local mappings will not be written.
    2. Restores global variables that start with an uppercase letter and contain
       at least one lowercase letter, if 'sessionoptions' contains "globals".
    3. Unloads all currently loaded buffers.
    4. Restores the current directory if 'sessionoptions' contains "curdir", or
       sets the current directory to where the Session file is if 'sessionoptions'
       contains "sesdir".
    5. Restores GUI Vim window position, if 'sessionoptions' contains "winpos".
    6. Restores screen size, if 'sessionoptions' contains "resize".
    7. Reloads the buffer list, with the last cursor positions.  If
       'sessionoptions' contains "buffers" then all buffers are restored,
       including hidden and unloaded buffers.  Otherwise only buffers in windows
       are restored.
    8. Restores all windows with the same layout.  If 'sessionoptions' contains
       "help", help windows are restored.  If 'sessionoptions' contains "blank",
       windows editing a buffer without a name will be restored.
       If 'sessionoptions' contains "winsize" and no (help/blank) windows were
       left out, the window sizes are restored (relative to the screen size).
       Otherwise, the windows are just given sensible sizes.
    9. Restores the Views for all the windows, as with :mkview.  But
       'sessionoptions' is used instead of 'viewoptions'.
    10. If a file exists with the same name as the Session file, but ending in
       "x.vim" (for eXtra), executes that as well.  You can use *x.vim files to
       specify additional settings and actions associated with a given Session,
       such as creating menu items in the GUI version.

From :h viminfo

 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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.