3

I've been using Vim regularly for a decade, but still feel rather inexperienced because there is so much of Vim that I am not aware of and do not use.

I sometimes want to see two different parts of a single file and edit both simultaneously, without having to either

  1. Make an edit at the top, scroll down, make an edit at the bottom, scroll up (etc.) or
  2. have two views open, make an edit in one session, save the file in that session, switch to the second session, reload the file in the second session, make an edit, save, switch to first session (etc.).

Is there a good way to do this in Vim?

1 Answer 1

9

I think you need to read :h windows-intro which explains the concepts of buffer, window and tab, summarized like this:

Summary:
   A buffer is the in-memory text of a file.
   A window is a viewport on a buffer.
   A tab page is a collection of windows.

Then you should read the end of the help file windows.txt because it is really useful.

So what you want is to create new windows which can be done in different ways:

  • Via the command line :h :split and :h :vsplit should be helpful
  • In normal mode ctrl+w+ctrl+s and ctrl+w+ctrl+v are helpful
  • In a script :h :wincmd can be useful.

Then to move between the splits and to move the splits themselves you probably want to read :h window-move-cursor and :h window-moving.


In your precise use case I would:

  • Open my buffer with :e, :find, netrw or however you usually do
  • Switch create a new split with :vs
  • Move to the new split with ctrl+wl
  • Go to the bottom of the buffer in the new split with G
  • And then move between my splits with ctrl+wl and ctrl+wh

Your Answer

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

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