When I open a file in gvim from terminal using gvim abc.cpp, unlike gedit it is opening in new gvim window. Can anyone suggest some way to open new file in a new tab in previously opened gvim window? I couldn't find any information regarding this on searching. I am using Ubuntu 12.04. Vim version is 7.3
gvim --remote-silent abc.cpp
The -silent prevents an error message from showing if there is not already a instance of GVim running
Related
Using vim, I use :term to open the terminal emulator. After cd /path/to/project within the terminal emulator, I have a file called foo.txt. If I did vim foo.txt to open it as I would in a normal terminal, it would open vim within vim which causes a variety of issues. I see two potential solutions:
Find some way to open a file in a split from the terminal emulator
Find some way to change the cwd of vim to the cwd of the terminal emulator.
Does anyone have tips on either solution?
Inside Vim's builtin terminal, do
vim --remote foo.txt
This assume that your Vim was compile with the +clientserver option. You can check with :version or :echo has('clientserver').
vim --remote works on vim, but neovim compiles without clientserver. neovim-remote seems to be an alternative for neovim.
You have a couple of options.
One would be to get your shell to print the full path of the file that you would like to edit (for example, by using bash's realpath ./<file_to_edit_goes_here> command), then exit insert mode, place your cursor over the filepath that was printed, and use gf to open the filepath under the cursor (see :help gf).
Alternatively, if you are using Neovim, I've written a plugin called nvim-unception to open files without nesting Neovim sessions by using Neovim 0.7's built-in RPC functionality.
To open a new Terminal session in vim I can do:
:term
However, this opens the terminal in a new tab. Is it possible, to have the terminal replace the section/frame and not open a new one in vim?
Update: It seems like this is the correct answer, on the vim site: https://vi.stackexchange.com/a/17306/28904
Usually, we open gvim from the command line like this:
gvim someFile.txt
But how are we going to close it from command line too? Instead of closing it from gvim itself?
I wanted to do some automation, hence, will need to close it from command line.
gVIM has the ability to act in client/server manner. That means you can send commands to a running vim.
Do the following
Start GVIM, open a document, do whatever
Run the following command to close GVIM
vim --servername GVIM --remote-send '<C-\><C-N>:wq<CR>'
That will save the file in GVIM and close GVIM.
First, why are you automating using a gui application?
But you can close it by sending it either <ESC>ZZ or :q!
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?
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'.
You can do it using two steps:
:vs (vertical split) or :split (horizontal split)
:open (path to filename)
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.
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.
I would like to open a file in a gvim window, but only if the file is not open in vim already. Preferedly by using commandline options. I tried
file=...
gvim --cmd ':drop $file'
But this opens an additional visible new empty window in my linux environment if the file is already open. Is there a different option/command to achieve the unique behaviour of other editors.
$ gvim --remote filename
Does exactly what you describe. You may need a couple of things in your ~/.vimrc, though:
set switchbuf=useopen,usetab