Gangmax Blog

How to Open Multiple Files in vi

I want to do so because I want to copy content from one file to another in vi.

From here.

You can open two files in one bash window using VIM’s “:split” command:

  1. Open a file with “$ vim file1”, open a second file within VIM using “:split file2” command.

  2. Or, use $ vim -o file1 file2 from bash.

  3. Switch between files(toggle active file) in VIM with “ctrl-w”.

An example operation is copy (or yank) in file1 “y”, switch(“ctrl-w”), then paste (or put) “p” content into file2.

Everything else is normal when either window is active, thus “:q” quits and “:q!” force quits.