2

I'm new to vi/vim.

I learned that I can close a file I'm editing and open the another file at once by typing :vi filename

But I sometimes want to open other files without closing the file I'm editing and interchange these buffers with commands like :next or :prev

Can I do that?

(I haven't understand the difference among buffer, window and file exactly yet. So some words could be wrong I used avobe.)

my vim's version is 7.2, Small version without GUI and be used on CentOS6.7

7

First, I want to recommend that you go through the vimtutor (:h tutor). That will explain a lot of the different concepts in Vim. To learn about the difference between the buffers, windows and a file, you can read for instance: :h windows.txt and :h editing.txt.

The command :vi or :visual is used to get out of ex mode and back to normal mode. If you don't know what ex mode is, then I suggest you instead use the command :e ... to edit new files.

If you want to close a file, but leave the buffer open, I suggest that you use the option :set hidden. See :h 'hidden' for a detailed explanation. In short, this will set closed buffers to hidden instead of wiping them. Thus you can reopen closed files with :bnext and :bprev and similar.

  • 1
    Great answer. Hidden buffers is closest to what the question described: I like to use tabs for any unsaved buffers without :set hidden, but that's a matter of personal preference. – Steve Dec 18 '15 at 10:17
0

I use :ls to list the buffers open and :b <filename_from_list_of_open_buffers> to edit it.

n.b. :b auto completes so I just start typing and bash the tab key until the file displayed is correct.

If I want to open a new buffer, I use e: <filename>. I am by no means a vim expert so the terminology might be wrong.

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.