33

$ vim -c 'set ai' See :h -c, :h startup and $ vim --help.


32

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. The ex is a standard command-line editor (similar to ed). There is also vipe (a Vim command pipe editor) should be used which is part of moreutils package ...


31

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 .bashrc or .zshrc for example) as follows: alias vim="vim +startinsert" However, that works only when starting Vim. If you want Vim to be in Insert mode even ...


23

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.


22

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 vim instance. macOS only MacVim runs a server by default - you can use mvim --remote-tab-silent to open a file in a new tab in your existing MacVim instance, or ...


21

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: vim < /dev/null, so reset command in this case helps. This is explained well by grawity at superuser. If you're using find to pass file names to edit, you ...


16

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 not reading .vimrc file and -U NONE for not reading a .gvimrc file) or even plugin. After opening Vim/gVim you can use :source <path> to load a test ...


15

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 five configurations: tiny, small, normal, big and huge. (See :help :version.) It can also be configured at run time to disable the extended features and use only ...


15

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! ='hello' pastes the string "hello" above the current line To insert the string "hello" and then save and quit the file: vim +"1 | put! ='hello' | x" j Same ...


14

$ 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/evim.vim. Mappings are set up to work like most click-and-type editors, see |evim-keys|. The GUI is started when available. {not in ...


12

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 with text that is read from stdin. The commands that would normally be read from stdin will now be read from stderr. Example: find . -name "*.c" -print | ...


12

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 startup via the -c argument: $ vim -c Explore You can also use +, which is exactly the same as -c, except slightly shorter: $ vim +Explore


11

Did you try something like this? $ echo "foo, bar, baz, and qux" | vim - Or like that? $ vim -c "put='foo, bar, baz, and qux'"


10

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/


10

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

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 other option after that is ignored. The reason it still didn't work after: $ VIMINIT= $ echo $VIMINIT Is (1) you're setting a local variable not an environment ...


9

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 example: $ echo foo | vim -e '+%print' '+q!' /dev/stdin foo or even shorter: $ echo foo | ex +%p -cq! /dev/stdin $ echo foo | ex +"%p|q!" /dev/stdin Note: The ...


9

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. It assumes that your shell is bash. echo "The brown fox jumped." | vim -s <(printf 'wcwred\e:wq! foo\n') - The - at the end tells Vim to read text (not ...


8

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 have this issue at the moment.


8

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 by running update-alternatives --config vi


8

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 vimrc won't be loaded. - The environment variable VIMINIT (see also |compatible-default|) (*) The value of $VIMINIT is used as an Ex command line. You are ...


7

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 }


7

-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 the double \\ because we're issuing a shell command (and don't want the shell to interpret this as an escape sequence). Tested with the keybind: nnoremap <...


7

For this purpose, I have definde the following alias in my shell: alias lvim="vim -c \"normal '0\"" (l meaning last)


6

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/Esc)+Ctrl+e, bash will perform an in place expansion on the current command line, i.e.: $ echo $EDITOR # Assuming EDITOR was set with Meta(Alt/Opt/Esc)+Ctrl+...


6

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 lines pertaining to indentation from my ~/.vimrc into a new file at ~/.vim/after/ftplugin/python.vim solved the problem. The filename is crucial, and it is ...


6

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' pages (default 10). (emphasis mine) So to increase the number of tab pages, add a line to your .vimrc, e.g.: set tabpagemax=20 If you don't want to change ...


5

Another option would be to run multiple commands in one line vim README.md +"56;norm zz"


5

Although I think starting in insert mode is not the vim way, you can do this very easily. You should start vim with vim -c startinsert 'file' The -c flag passes in a command into vim. The :startinsert command changes to insert mode. As you can imagine, you could start vim with any number of commands if you so desired.


5

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('~/Notes/') . strftime('%F') . '-' . input("Title: ") execute 'edit ' . title endfunction The mapping may be called as described by @Carpetsmoker: vim -c '...


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