I am using vertical splits to compare two files which cannot be compared with diff.

I don’t know how to save specific settings in the session.

Here is how I proceed:

  1. enable the settings:
     :set nowrap
     :set scrollbind
     :set cursorbind
     :set cursorline
  1. :mks mysession.vim to create the session

  2. :wqa to exit vim

  3. nvim -S mysession.vim to reload the session

The files load correctly, but not the four settings. nvim mysession.vim does not show anything related to scrollbind, cursorbind or cursorline in the code.

How can I save these options in a session?

  • 8
    Have a look at :h 'sessionoptions' Commented Jul 10, 2020 at 7:38
  • 2
    Seconding Christian; this may be one of the few times where saving options in a session makes sense (in general it captures way too much). Have you tried vimdiff?
    – D. Ben Knoble
    Commented Jul 10, 2020 at 12:19

1 Answer 1


Thanks for pointing to sessionoptions, this answered my question like this:

Step by step:

  1. nvim file1.txt

  2. :vsp file2.txt

  3. A perfect environment to compare files. Note: it is necessary to apply each setting individually on every buffer.

:set nowrap
:set cursorbind
:set scrollbind
:set cursorline
  1. :set sessionoptions=options

  2. :mks compare.vim

  3. :wqa!

  4. nvim -S compare.vim

explanations about the options:

further to the comment below, here is the usage of each of the options:

nowrap prevents the text from wrapping, which is important for the three other options:

  • cursorbind moves the cursor in both splits at the same time,
  • scrollbind scroll the two splits in parallel,
  • cursorline highlights the current line where the cursor is.
  • Could you elaborate more on your step 3? What did you mean "a perfect env. to compare files"? Commented Jan 2, 2023 at 15:56
  • 1
    @job_start : I edited my answer according to your question. being able to navigate both splits at the same time in Vim was helpful for me, to compare two documents that could not be compared with vimdiff nor diff. Commented Jan 2, 2023 at 16:55
  • Really thank you! Commented Jan 3, 2023 at 6:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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