50
votes
Accepted
Setting a vim option from the command line?
$ vim -c 'set ai'
See :h -c, :h startup and $ vim --help.
36
votes
Accepted
How to edit content from the standard input?
You have to use - in place of the file name on the command line:
echo This is example. | vim -
The above command will open an unnamed buffer filled with the text read from the standard input.
36
votes
Accepted
How to edit files non-interactively (e.g. in pipeline)?
To edit file non-interactively using ex (vi is the visual mode for ex), you can use +{command} or -c {command} parameters which allows you to execute the vi commands after the first file has been read....
36
votes
Accepted
Automatically load Vi into insert mode
You can use the +startinsert option (or +star for short) to start Vim with insert mode.
vim +star myfile.txt
If you want this to happen by default when starting Vim, you can make an alias (in your ....
30
votes
Terminal borked after invoking Vim with xargs
This happens when vim is invoked and it's connected to the previous pipeline's output, instead of the terminal and it's receiving different unexpected input (like NULs).
The same happens when you run: ...
28
votes
Accepted
Can I open a file in an existing Vim instance from an external command?
You need vim compiled with +clientserver, and then you can use the command:
vim --servername SERVER to start a vim instance, and
vim --servername SERVER --remote FILE to open the file in the named ...
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! ...
16
votes
Accepted
How do I tell if Vi or Vim is installed on my Linux distribution?
Vim started as a clone of vi and has almost all of the commands and features of the original vi, plus a lot of enhancements. (See :help design-compatible.) It can be compiled into one of basically ...
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 ...
15
votes
Automatically load Vi into insert mode
$ vim -y <file>
-y Easy mode. Implied for |evim| and |eview|. Starts with 'insertmode' set and behaves like a click-and-type editor. This
sources the script $VIMRUNTIME/...
14
votes
Accepted
Can :Explore be started from the terminal?
Alternatively (the passing of directory argument(s) as in @EvergreenTree's answer relies on the autocmds of the netrw plugin, and aren't a general solution), you can pass any Ex command to Vim on ...
13
votes
Terminal borked after invoking Vim with xargs
Workaround suggestion: use a buffer as a filesystem navigator
Use the vim - command to read a list of paths from stdin. Vim's :help -- explains this:1
Start editing a new buffer, which is filled ...
12
votes
Accepted
How to specify the content of a new buffer from command line?
Did you try something like this?
$ echo "foo, bar, baz, and qux" | vim -
Or like that?
$ vim -c "put='foo, bar, baz, and qux'"
11
votes
Can :Explore be started from the terminal?
The "Explore Mode" you are talking about is netrw, a vim plugin which is provided by default. It should open in that "mode" if you just try to open a directory with vim, eg. vim foo/bar/baz/
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....
10
votes
How do I tell if Vi or Vim is installed on my Linux distribution?
Since you're on Ubuntu, verify if Vim is installed by running
dpkg -l | grep vim
Check the available alternatives to Vi by running
update-alternatives --list vi
Set your favorite alternative to Vi ...
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'
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 ...
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 ...
9
votes
Accepted
How to write whole buffer to standard output from the command line?
To print buffer to shell standard output, vim needs to start in Ex mode, otherwise it'll open "normal" way with its own window and clear any output buffers on quit.
Here is the simplest working ...
8
votes
Accepted
How to search the help docs from a command prompt
Use the -c argument to execute a command after Vim starts up:
vim -c ':help TOPIC' -c :only
You may want to define a shell function:
vimhelp () {
vim -c ":help $1" -c :only
}
8
votes
How to edit content from the standard input?
This is just mostly a fun note about bash and readline, but if you set your EDITOR environment variable to vim, hitting Ctrl+x+e will open up the current line in vim. Further, if you type Meta(Alt/Opt/...
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)
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 ...
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 ...
7
votes
How can I start vim and then execute a particular command that includes a \, from the command line?
-c doesn't execute keybinds in normal mode; it executes commands (what you normally do with :). So you need to use the execute command, which seems to work:
$ vim -c 'execute "normal \\t"'
We need ...
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 ...
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' ...
6
votes
Accepted
How can I start vim and then execute a particular command that includes a \, from the command line?
You could make a function that creates the new entry, and then use the function as part of your mapping:
nnoremap <leader>t :call NewEntry()<cr>
function! NewEntry()
let title = expand('...
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 ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
invocation × 53command-line × 7
vimrc × 5
ex-mode × 5
terminal × 4
plugin-system × 4
startup × 4
unix × 4
gvim × 3
microsoft-windows × 3
linux × 3
tabbed-user-interface × 3
bash × 3
autocmd × 2
normal-mode × 2
netrw × 2
options × 2
multiple-files × 2
sessions × 2
quit × 2
clientserver × 2
vimscript × 1
key-bindings × 1
syntax-highlighting × 1
substitute × 1