16 votes
Accepted

Experimenting with vim/gvim in "virgin" mode

From Vim FAQ 2.5: vim -u NONE -U NONE -N -i NONE This starts Vim in nocompatible mode (-N), without reading your viminfo file (-i NONE), without reading any configuration file (-u NONE for ...
mMontu's user avatar
  • 6,640
8 votes

Terminal borked after invoking Vim with xargs

The reason is that xargs sets stdin to /dev/null, whereas vim needs stdin to be /dev/tty. BSD xargs (e.g. Mac) solution: echo -e 'file1\nfile2' | xargs -o vim -o sets the stdin of xarg's child ...
wisbucky's user avatar
  • 950
7 votes

Can I open a file in an existing Vim instance from an external command?

While @craigp's answer is correct, I found it most convenient to simply add --remote-silent without worrying about server names,(this assumes you don't want to address named vim instances). This will ...
ideasman42's user avatar
  • 3,733
7 votes

Vim not sourcing files on startup

You can see what Vim does on startup with vim -V. Does it touch the file? Is there any errors? Safe for errors, my only guess is that filename contains non-ASCII character that looks like "c"; you ...
Alexander Batischev's user avatar
7 votes
Accepted

How can I make sure all buffers end up as tab or force remaining buffers into tabs?

The documentation for this feature can be found at :help -p: Open N tab pages. If [N] is not given, one tab page is opened for every file given as argument. The maximum is set with 'tabpagemax' ...
Rich's user avatar
  • 32k
6 votes
Accepted

Vim not sourcing files on startup

Here is what worked for me: First opening vim normally and doing :scriptnames showed that, in fact, my ~/.vimrc was sourced. Other scripts were just overridding my indent settings. Moving just the ...
Edward Newell's user avatar
6 votes
Accepted

Call vim command from shell, and suppress output while it operates

I successfully used this command in a non-interactive way, but you have to specify the file containing the Plug calls: vim -E -s -u "$HOME/.vimrc" +PlugInstall +qall You might want to read more on ...
LEI's user avatar
  • 1,626
5 votes

How can I read a command-line argument in vimrc?

Vim version 8.1.2233 adds the read-only variable v:argv, which can be used to parse the command line arguments given to Vim.
Christian Brabandt's user avatar
5 votes
Accepted

Using the ex mode command line (-c), how would I insert text?

The documentation for -s in Ex mode :help -s-ex states: To be used when Vim is used to execute Ex commands from a file instead of a terminal. So it seems the correct approach is to save your ...
Rich's user avatar
  • 32k
5 votes
Accepted

How to detect whether Vim has been invoked by another shell command?

Since vipe, git commit (and many other programs which invoke an editor) use the VISUAL and EDITOR variables (unless you specify an editor for git with git config core.editor), you can use that ...
muru's user avatar
  • 24.9k
5 votes

How to detect whether Vim has been invoked by another shell command?

I don't know how reliable it is but I found how to get the PID of the parent of a process here: ps -o ppid= -p <pid of the process> And how to get the name of a process from its PID here: ps -...
user9433424's user avatar
  • 6,138
5 votes
Accepted

How to comment a line directly from bash using vim?

You can use: vim +'normal! 2GI;' +'x' path/to/your/file The + parameter allows to execute a command after opening the buffer. The first command normal! 2GI; goes to line 2 and add a ; at the ...
statox's user avatar
  • 49.9k
5 votes

How do I tell if Vi or Vim is installed on my Linux distribution?

Quick command to tell if it's vi or vim vi -h this will display the help info in my case : $ vi -h VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Aug 7 2016 16:03:11) [... skip other info ...] So ...
Mathieu V's user avatar
5 votes

Is it possible to pipe vim commands to vim?

I have found the method of taking the output of a program as redirected from sub-shell to be very easy: vim <( program ) Example: vim <( grep -nH hello myFile.cpp ) vim <( find . -name ...
J Jorgenson's user avatar
4 votes

Is it possible to pipe vim commands to vim?

I had the exact same desire as you: I wanted to write normal vim commands and have those edit a pipeline stream. I was disappointed by the difficulty of using normal vim in this way (so many flags!), ...
Miles's user avatar
  • 141
4 votes
Accepted

How to use a specific vimrc file and still load the usual files?

A simple/hacky workaround for this is to use -u to point to a vimrc that uses so (abbreviated version of source) to read the vimrcs you want to load in the order in which you want to load them. For ...
rjmill's user avatar
  • 156
4 votes
Accepted

Read from standard input and close if empty

Here is a "vim only" solution: echo '' | vim - +'exe !search(".")?"quit!":""' It is not perfect because a) doesn't distinguish between empty (0 bytes) and newline only b) the screen flash and c) the ...
Mass's user avatar
  • 14.1k
3 votes

Launching Vim with a file as argument does not work, if my .vimrc contains a `:cd` command

If you want Vim to always start in a certain directory, then you should likely do that after it has finished handling normal startup. You can do that with the VimEnter autocommand. Replace cd C:\...
jamessan's user avatar
  • 11.1k
3 votes
Accepted

How can I select a syntax highlighting at the (shell-) command line?

You can use +command to execute command after the "file" is loaded: cat File.hs | some | processing | pipeline | vim -R +'setf haskell' -
romainl's user avatar
  • 40.7k
3 votes

Is it possible to pipe vim commands to vim?

This is a fairly old question, but I felt that it was worth contributing that if your given distro/OS has access to moreutils, then you can install it and simply use vipe as a standard addition to vim:...
Erich Gubler's user avatar
3 votes

How to specify the content of a new buffer from command line?

I've recently looked for a way, how to put the clipboard content into a new buffer in vim. I think, it is worth to share it here: vim -c "put! *" UPDATE: This will put the text from register * ...
Mattia72's user avatar
  • 191
3 votes
Accepted

Open file, make changes, save it as a new one. In one step, using the Windows command prompt

You can use Ex commands (linux version using pipes): printf '%s\n' 'normal! xp' 'saveas bar.txt' 'q!' | ex foo.txt vim -e and vim -E can usually be used as a substitute for ex. Or use a custom script:...
D. Ben Knoble's user avatar
  • 26.2k
3 votes
Accepted

Start vim with ex-command and append it to vim's command history

When I start vim with an ex-command as command line parameter, it won't show up in vim's command history. Why? Presumably because only commands that are typed interactively while Vim is running are ...
user938271's user avatar
  • 5,957
3 votes

how to load multiple files into separate buffers from zsh command line?

That should be enough: ls -v *.py | xargs gvim
Matt's user avatar
  • 20.7k
3 votes

How do I open vim from the command-line at a particular tag?

Good news! This is easy to do. Just use the -t command-line option: vim -t TAGNAME
Flimm's user avatar
  • 2,232
2 votes

Can I open a file in an existing Vim instance from an external command?

In addition to @craigp's answer, you can also open a file in a remote tab. vim --servername SERVER --remote-tab FILE
Tyhou's user avatar
  • 121
2 votes
Accepted

Command line argument for lengthy command

yypVr-o-_ are not ex-commands, but normal. Use :normal to execute normal commands. vim +'normal Go' +'r!date' +'yypVr-o-_' ~/notes/sys.md For more help see: :norm :h -c :h :r!
Peter Rincker's user avatar
2 votes

Open or create a specific Vimwiki page from a command prompt

Add a function like this to you ~/.bashrc: function vimwikipage() { vim -c "VimwikiIndex" -c "VimwikiGoto $1" } Now, you can open/create a specific Vimwiki page like this: $ ...
Alexander Pozdneev's user avatar
2 votes

Open some files in split and some other in tab at the vim invocation

Vim’s -S option can take any file of vim commands and run them at startup. It’s usually used for sessions (:mksession; pairs well with tpope’s obsession plugin). In this case, though, you could make ...
D. Ben Knoble's user avatar
  • 26.2k
2 votes
Accepted

How to escape a single quote when passing an ex-mode command from the command line, back to the command line?

You can use '\'' to insert a literal single quote into a single-quoted string into the shell. What this does is: close the currently-running single-quoted string with the first ', then insert an ...
filbranden's user avatar
  • 28.8k

Only top scored, non community-wiki answers of a minimum length are eligible