18 votes
Accepted

Is it possible to pipe vim commands to vim?

To insert the string "hello" on the first line of the file j, you could type in your shell the following command: vim +"1 | put! ='hello'" j :1 moves the cursor to the first line of the buffer :put! ...
saginaw's user avatar
  • 6,706
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,600
11 votes

Is it possible to pipe vim commands to vim?

Here is a way you can use normal-mode commands, rather than just ex commands, to edit a stream presented to Vim from stdin. This isn't a very useful example, but it illustrates the techniques involved....
garyjohn's user avatar
  • 6,284
10 votes
Accepted

How do I introduce a "light mode", in which not all plugins are loaded?

There are (at least) two possibilities: use env: EDITOR='/usr/bin/env VIM_LIGHT_MODE=1 vim' use vim with another initialization file, say .vimrc-light: EDITOR='/usr/bin/vim -u ~/.vimrc-light'
gniourf_gniourf's user avatar
10 votes
Accepted

Why won't vim source my .vimrc file

Expanding on @mMontu's answer; Vim hunts for initialization in order of that list till it finds one. Since the $VIMINIT variable take precedent to the .vimrc file, it satisfies the search and any ...
Sukima's user avatar
  • 1,192
9 votes

Terminal borked after invoking Vim with xargs

Besides reset, you can try: stty sane which should also make your terminal usable again. See here for explanations. And somehow this can be considered a vim misbehavior, at least Neovim doesn't ...
ryenus's user avatar
  • 193
8 votes

Why won't vim source my .vimrc file

You probably misunderstood the documentation: c. Four places are searched for initializations. The first that exists is used, the others are ignored. Thus if you are using the VIMINIT, the ...
mMontu's user avatar
  • 6,600
8 votes

Is there a vim command line option to edit last edited file?

For this purpose, I have definde the following alias in my shell: alias lvim="vim -c \"normal '0\"" (l meaning last)
Christian Brabandt's user avatar
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
  • 910
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,683
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
  • 31.3k
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

How do I open multiple files from find each in a separate tab in vim?

vim -p `find . -name '*.txt'` Putting the find command between backticks executes find before running the full command and the results replace what's between the backticks. So before running the ...
Neaţu Ovidiu Gabriel'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,606
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
Accepted

Is there a vim command line option to edit last edited file?

An heavy solution: the sessions Another possible option is to use the sessions mechanism: First your vim version has to be compiled with the +mksession option. (Use :echo has('mksession') to check ...
statox's user avatar
  • 49.3k
5 votes

How do I open multiple files from find each in a separate tab in vim?

find "$PWD" -name '*.txt' -exec vim -p {} +
andorov's user avatar
  • 205
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
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.3k
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,118
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.7k
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
  • 31.3k
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
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 can I suppress feedback when calling vim with certain commands?

Use :silent to suppress the output of the command. vim +'silent 0,/^$/g/^\(Cc\|Bcc\|Reply-To\): $/d' /tmp/test
jamessan's user avatar
  • 10.9k
4 votes

Is there a vim command line option to edit last edited file?

The last file should be at the top of the jumplist, which you can visit with CTRL-O. Another way around your bash issue, related to muru's comment, is with the reverse-search-history CTRL-R.
Steve's user avatar
  • 446
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
  • 13.9k
3 votes

Is there a vim command line option to edit last edited file?

Another possible alias: alias lvim="vim -c':e#<1'"
romainl's user avatar
  • 39.1k

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