user2679671
user2679671

Reputation:

How do I open a file in another window in VIM through the terminal?

Say I want to open the file "main.cpp". I have my linux terminal open in the correct directory. Normally, I just type "vi main.cpp", but this opens the file in the shell window. How do I open the file in another window?

Upvotes: 4

Views: 10027

Answers (4)

Royston Pinto
Royston Pinto

Reputation: 6721

You can do it using two steps:

  1. :vs (vertical split) or :split (horizontal split)
  2. :open (path to filename)

Upvotes: 2

mhinz
mhinz

Reputation: 3351

I'm not sure I understand your question. I try to answer nevertheless:

:help client-server

Thus, you create a server instance:

vim --servername foo

Afterwards you can open files in that instance from any shell via:

vim --servername foo --remote file1 file2

Or even shorter:

vim --servername vim and vim --remote file1 (the server name 'vim' is assumed here implicitely).

EDIT: Your Vim needs to have support for the client-server architecture:

:echo has('clientserver') should result in '1'.

Upvotes: 1

ptierno
ptierno

Reputation: 10074

vi is a terminal text editor. It will open in the terminal window it is called from. If you wanted an X based editor, like gVIM, then you are using the wrong editor.

Upvotes: 0

Dan Schnau
Dan Schnau

Reputation: 1535

You may want to try gvim main.cpp which will fire up vim in its own GUI which technically will do what you're asking here.

Upvotes: 0

Related Questions