4

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?

2
  • 1
    What do you mean by another window? Do you want to open in gvim or another terminal window? Commented Aug 13, 2013 at 18:20
  • 2
    gnome-terminal -e "vi /etc/passwd" opens vi in a new gnome-terminal window (read more). Commented Aug 13, 2013 at 18:30

4 Answers 4

2

You can do it using two steps:

  1. :vs (vertical split) or :split (horizontal split)
  2. :open (path to filename)
Sign up to request clarification or add additional context in comments.

3 Comments

and then use ^w [hjkl] to navigate between the various vim windows.
That's not a new window
shortcut: :[N]sp[lit] [++opt] [+cmd] [file] for horizontal and :[N]vs[plit] [++opt] [+cmd] [file] for vertical.
1

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'.

Comments

0

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.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.