50 votes
Accepted

Setting a vim option from the command line?

$ vim -c 'set ai' See :h -c, :h startup and $ vim --help.
user avatar
  • 32.8k
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.
user avatar
  • 4,492
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....
user avatar
  • 16.6k
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 ....
user avatar
  • 15.5k
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: ...
user avatar
  • 16.6k
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 ...
user avatar
  • 2,221
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! ...
user avatar
  • 6,426
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 ...
user avatar
  • 5,874
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 ...
user avatar
  • 6,370
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/...
user avatar
  • 3,236
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 ...
user avatar
  • 16.7k
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 ...
user avatar
  • 5,806
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'"
user avatar
  • 32.8k
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/
user avatar
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....
user avatar
  • 5,874
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 ...
user avatar
  • 101
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'
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 ...
user avatar
  • 1,152
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 ...
user avatar
  • 193
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 ...
user avatar
  • 16.6k
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 }
user avatar
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/...
user avatar
  • 491
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)
user avatar
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 ...
user avatar
  • 6,370
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 ...
user avatar
  • 3,413
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 ...
user avatar
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 ...
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' ...
user avatar
  • 27.5k
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('...
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 ...
user avatar

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