54

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

What is the command to do this?

77

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

  • 1
    It says "Invalid search pattern or delimiter". And I have installed vim with this command. – Adam Oct 16 '14 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 '14 at 19:39
  • When I am in vim. – Adam Oct 16 '14 at 19:39
  • What is the exact command you're typing? – Mitch Oct 16 '14 at 19:41
  • 3
    If you're in vim you have to do :edit [full path] – Mitch Oct 16 '14 at 19:45
29

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.

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

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.