1

When using Ctrl+w s the window is split horizontally and the current buffer is loaded. Why should I open two windows to edit the same buffer?

Glorfindel
  • 211
  • 1
  • 3
  • 11
dgruending
  • 113
  • 3

2 Answers2

7

I tend to use nano much more frequently than vim.

An editor-agnostic answer: There have been more than a few times that I needed to edit a bash script that is hundreds of lines long, and one section of the script refers to or otherwise impacts another section. It is often helpful to have both sections visible at the same time and to be able to independently scroll between the reference window and the window being actively edited.

3

Having multiple views of the same buffer allows you to quickly compare or copy-and-paste without moving back and forth, as @RudyB's answer explains.

Another use case is the opening of another file; of course, with plain Vim commands, you can achieve this by using :split instead of :edit.

However, many people have plugins (that provide most recently used files, a speeddial, quick addressing within the current project, access to remote files, and so on), and not all of them have the functionality to open that file in a split (or it might be there, but using an obscure mapping, or inconsistent mappings, as Vim doesn't have a good precedence for this functionality to base custom mappings on). Opening files in the current window is the default functionality. So, you'll just first create the target window, and then invoke the plugin to jump to another file. Splitting the current window and duplicating the displayed buffer contents is the easiest way (and avoids the creation of a new empty buffer, as CTRL-W n would do).

And this approach can also be used for splitting to a new tab page (which even fewer plugins support directly): You just need to remember the Vim command to split to a new tab page (:tab split, but many have a custom mapping for that).

Ingo Karkat
  • 17,819
  • 1
  • 45
  • 61