Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vim --remote-silent always opens [No Name] buffer for first file

Tags:

vim

I want to be able to open files using the same instance so I added --remote-silent when opening files. But the first time it loads, Vim will open an empty buffer, then my file. So now I have 2 buffers.

Upon further investigation, I noticed that setting nohidden will solve this problem. BUT, not only is it against my liking, it will cause the first buffer to have no syntax highlighting.

This doesn't happen without the --remote-silent option.

Any help appreciated. Thanks!

like image 261
Dalton Tan Avatar asked Sep 08 '12 05:09

Dalton Tan


People also ask

What does buffer mean in Vim?

A buffer is an area of Vim's memory used to hold text read from a file. In addition, an empty buffer with no associated file can be created to allow the entry of text. The :e filename command can edit an existing file or a new file.

How do I use buffers in Vim?

Use the ":sbuffer" command passing the name of the buffer or the buffer number. Vim will split open a new window and open the specified buffer in that window. You can enter the buffer number you want to jump/edit and press the Ctrl-W ^ or Ctrl-W Ctrl-^ keys. This will open the specified buffer in a new window.

How do we save and quit for all active tabs Vim?

:wa - save all tabs / unsaved buffers. :xa / :wqa - save all tabs / unsaved buffers and exit Vim.


1 Answers

Doing $ vim --servername FOO --remote[-silent] filename without an instance already running launches a new instance first then opens the file: it is not like $vim filename. You have to find a way to completely remove the first empty buffer.

From my limited testing, adding set bufhidden=wipe to your ~/.vimrc may solve the problem.

set bufhidden=wipe, being local to a buffer, is applied only to the first empty buffer and reset afterwards.

See :h bufhidden.

This will certainly cause some problems when you run Vim normally, though.

edit

Yes, set bufhidden=wipe causes obvious problems. When launched "normally" (with $vim file1) the first buffer is wiped when you edit a second file which is not what you want.

A simple check on the name of the buffer resolves that problem:

if bufname('%') == ''
  set bufhidden=wipe
endif

Syntax highlighting works in every situation, here. Could you post the content of your ~/.vim/ and ~/.vimrc somewhere?

like image 115
romainl Avatar answered Nov 15 '22 09:11

romainl