59

I would like to open a file that already exists while already in Vim.

What is the command to do this?

1

2 Answers 2

82

vim [your file]

If this isn't working for you, make sure you have it installed with:

sudo apt-get install vim

If you're already IN vim do

:edit [your file]

Additionally, to move back to the previous file after you finish editing the new file you can use

:e#

This will return you to the previous file

9
  • 1
    It says "Invalid search pattern or delimiter". And I have installed vim with this command.
    – Adam
    Oct 16, 2014 at 19:37
  • When does it say that? When you try to open it from the command line? Or when you're already in vim?
    – Mitch
    Oct 16, 2014 at 19:39
  • When I am in vim.
    – Adam
    Oct 16, 2014 at 19:39
  • What is the exact command you're typing?
    – Mitch
    Oct 16, 2014 at 19:41
  • 3
    If you're in vim you have to do :edit [full path]
    – Mitch
    Oct 16, 2014 at 19:45
30

You can also use tabs and split views:

:tabe /path/to/file

Effect: enter image description here

:vs /path/to/file

(or :sp for a horizontal split)
Effect: enter image description here

Use :tabn, :tabp to navigate between tabs, and CtrlW with the arrow keys to navigate between splits.

2
  • Isn't it :sp to split horizontally?
    – kuzyn
    Jun 17, 2016 at 15:06
  • @kuzyn indeed. My bad.
    – muru
    Jun 17, 2016 at 19:15

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .