Tallboy
Tallboy

Reputation: 13417

how to automatically make new file with mvim

When I run mvim . it opens NERDTree but doesnt open a new file/buffer.

  1. How might I accomplish this? Ideally when you type mvim . from terminal it would open MacVim, close NERDtree, and open a new buffer

  2. I'm not sure if this is possible but is there a way that if I run mvim . from the command line multiple times it wouldn't open vim in a new window each time?

Upvotes: 0

Views: 214

Answers (2)

sidyll
sidyll

Reputation: 59287

1.You are asking it to open your directory viewer, right? If not, why do you start vim passing the current directory (.) as argument? Leave it off and it will start with an empty buffer.

$ mvim

2.Take a look in the vim manual (man vim). You probably want the --remote-silent option.

$ mvim --remote-silent file

I personally use this so often that I've created an alias for it in my .profile:

alias v='mvim --remote-silent'

Upvotes: 1

pb2q
pb2q

Reputation: 59617

As for your second question, vim allows you to send a file to an already running instance with --remote arguments, if vim is compiled with +clientserver. MacVim should be - if :echo has("clientserver") prints 1 in the command-line, then this should work. This will work for any vim compiled with +clientserver, including vim running within a terminal window.

When vim is using clientserver you can run mvim so that it sends the new file(s) to an already-running instance of vim, e.g.:

$ mvim --remote-silent file2.txt

Make an alias for mvim that always passes --remote-silent.

See :help remote for more details.

Upvotes: 2

Related Questions