The name vi comes from the "visual interface" for the ex line editor.
That is the reason vi's configuration file is called ~/.exrc. When vi
is launched via an ex symlinked or hard-linked name, it runs in ex mode.
The ex editor is the Berkeley Unix replacement for the AT&T System V ed editor. It is a line editor geared to teletype and DECwriter paper terminals.
Vi/Vim command mode was based on ex mode commands.
- Your console, terminal, ssh, or tmux session is all messed up,
- and you are trying to fix this,
- or you want to do a quick edit on some server & be done with it.
- You want to script multiple bulk edits on multiple files and either
- your Sed and AWK skills are a bit rusty, or
- you need something more "stateful" between edits and/or files.
- You accidentally enter ex mode and you want to get out of it.
Just giving a useful, but incomplete, subset of the possibilities.
- From vi normal mode
Q- switch back to visual mode via
vicommand
- switch back to visual mode via
- From terminal
ex fileToEdit1 fileToEdit2 fileToEdit3- switch to visual mode via
vicommand
- switch to visual mode via
- From terminal
vi -e fileToEdit1 fileToEdit2 fileToEdit3- switch to visual mode via
vicommand
- switch to visual mode via
- From terminal enter
vi -es filenameorex -s filename- command mode commands taken from stdin
- interactively edit
- pipe in command mode commands from stdin
- heredocs
$EXINITand.exrcfiles are not processed- does not start a UI
- cannot switch to visual mode
- command mode commands taken from stdin
- From nvim normal mode
gQ- switch back to visual mode via
vicommand
- switch back to visual mode via
- From terminal
nvim -e fileToEdit1 fileToEdit2 fileToEdit3- command mode commands taken from stdin
- interactively edit
- pipe in command mode commands from stdin
- heredocs
- does not play nice with some plugins
- Launch
nvim --clean -e fileToEdit1 fileToEdit2 fileToEdit3
- Launch
- switch to visual mode via
vicommand
- command mode commands taken from stdin
- From terminal non-interactively
- from terminal
cat myScript | nvim -es fileToEdit - does not start a UI
- cannot switch to visual mode
- session ends at end of script,
qnot necessary
- from terminal
Piping commands in thru stdin
$ echo '10,20p
n
10,15p
q' | nvim -es .bashrc .bash_profileUsing a heredoc, note: real tabs
$ nvim -es .bashrc <<-EOF
> 10,20p
> 1,5p
> q
> EOFCreate a non-interactive script interactively, then run the script non-interactively.
$ nvim --clean -w myscript -e .bashrc
$ cat myscript | nvim -es .bashrc| prev: Adv Trad Vi Commands | Home | next: Vim Specific Features |