2

Currently I'm using this to open a file in an existing vim instance.

gvim --remote-silent some_file.txt

While it opens the file as expected, it sometimes splits the window.

I'm not sure what logic it uses, but I'd like to be able to tell it never to create a new split-window for the new buffer since it means I need to manually delete the new window - which gets annoying.

4
  • Do you have :set hidden in your vimrc?
    – romainl
    Nov 5, 2016 at 9:04
  • No, but I have: set nohidden.
    – ideasman42
    Nov 5, 2016 at 9:26
  • Well, your "problem" is a direct consequence of :set nohidden.
    – romainl
    Nov 5, 2016 at 16:07
  • I've removed set nohidden and still had this problem occur. Perhaps nerdtree or some other plugin is messing with my config. (though I don't use so many plugins)
    – ideasman42
    Nov 7, 2016 at 12:41

5 Answers 5

2

When you use Vim's --remote options, it constructs a :drop command.

If the specified file is not already open in an existing window, it will be opened in the current window, unless the file currently in that window cannot be abandoned. (i.e. if the current file is modified and you have both hidden and autowrite options switched off.) In that case, the window is split instead.

Note however, that at some point in the past there was a bug with this behaviour, which was fixed in version 6.1.173:

When using remote control to edit a position in a file and this file is the current buffer and it's modified, the window is split and the ":drop" command fails.

1

I use :enew when using (n)vim from the terminal.

1
  • :enew starts a new buffer in the current window. :edit[!] can be used to open any file as a buffer in the current window (also :buffer for loading an existing buffer). But the question is about --remote-silent.
    – D. Ben Knoble
    Nov 8, 2022 at 18:44
0

I may be off from your actual purpose and you may already know what I suggest here, but how about opening the file in a new tab from within vim?

:tabnew some_file.txt

If some_file.txt exists it will open it in a new tab, if not it will create a new empty file. You navigate from tab to tab with gt (move one tab on the right) and gT (move the other way).

0

Sometime I use :open file to open file in current window. If you want a awesome search and open a file use telescope link: https://github.com/nvim-telescope/telescope.nvim

2
0

:edit some_file.txt works in nvim, like

:open some_file.txt works in vim(/vi?)

which opens some_file.txt file in the window where cursor is [without splitting/...]

1

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.