Is it possible to edit a file under different settings at the same time? More precisely, I'd like to have multiple buffers in the same instance of Vim which have the same content (changing one buffer affects the other buffer's content immediately), but different cursor positions, different marks, different syntax highlighting, etc.

Common use cases include editing different parts of the same file independently (without e.g. entering visual mode in one instance break the current visual mode selection in the other instance), and editing mixed-format files (e.g. HTML and Javascript) without having to switch settings. (An alternate approach for the second use case would be to change settings automatically based on the cursor position but that's out of scope for this question.)

An editor whose mention admittedly could shock calls this “indirect buffers”.

1 Answer 1


Using multiple windows to view the same buffer allows you to view, edit, select, ... on different parts of a buffer.

Syntax highlighting is a more complicated matter, depending on what exactly you want. Vim already supports highlighting different parts of a buffer with different syntax. For example, if you have an html filetype buffer, then <style> tags will be highlighted as CSS, <script> tags will be highlighted as javascript, etc. This is done by using the :syn include command and then defining the relevant syntax regions that the syntax should be applied to.

An alternative is to use the :ownsyntax command to specify the syntax highlighting that is used for a specific window.

Marks are the sticky point. The lowercase marks are specific to a buffer and the uppercase marks are global, but there aren't any window-specific marks.

  • 1
    If I use multiple windows, does that mean they have to be on-screen all the time? What happens if I close a window while another window shows the same buffer, is the cursor position in that window lost? Is there anything like :ownsyntax for other settings, such as indentation, compiler command, etc.? Feb 4, 2015 at 21:12
  • @Gilles You can have two windows that aren't ever on-screen together by placing them in seperate tabs, thus maintaining window-specific settings, cursor position, etc. This might help, depending on your specific use-case.
    – Rich
    Jan 24, 2017 at 12:28

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.