Vim (Vi improved) is a text editor based on the vi text editor. It can be used from the command-line or as a standalone application with a graphical user interface.
Vim should not be confused with Neovim, a similar program which may be used in its place.
The Vi article provides general information on vi-like editors. See the Vim guide for an introductory tutorial on vi-like editor usage. See the text editor article for general information on installing and configuring text editors in Gentoo.
USE flags for app-editors/vim Vim, an improved vi-style text editor
||Link console vim against X11 libraries to enable title and clipboard features in xterm|
||Add support for Access Control Lists|
||Use dev-libs/libsodium for crypto support|
||Enable cscope interface|
||Enable extra debug codepaths, like asserts and extra output. If you want to get meaningful backtraces see https://wiki.gentoo.org/wiki/Project:Quality_Assurance/Backtraces|
||Add support for sys-libs/gpm (Console-based mouse driver)|
||Enable Lua scripting support|
||Install a very minimal build (disables, for example, plugins, fonts, most drivers, non-critical features)|
||Add Native Language Support (using gettext - GNU locale utilities)|
||Add optional support/bindings for the Perl language|
||Add optional support/bindings for the Python language|
||Enable support for Scheme using dev-scheme/racket|
||Add support/bindings for the Ruby language|
||!!internal use only!! Security Enhanced Linux support, this must be set by the selinux profile or breakage will occur|
||Enable sound support|
||Add support the Tcl language|
||Enable terminal emulation support|
||Install vimpager and vimmanpager links|
If X Window System support is not needed, install app-editors/vim:
emerge --ask app-editors/vim
To install Vim with both the ncurses-based interface (/usr/bin/vim) as well as the graphical interface (for the X Window System - /usr/bin/gvim), install the app-editors/gvim package:
emerge --ask app-editors/gvim
Vim has support for packages, which provide a native mechanism to extend functionality. Read the built-in packages documentation for more information: :help packages
The category app-vim provides a lot of additional syntax definitions, plugins and other Vim related stuff.
Use emerge or eix to get an overview of available packages in the app-vim category:
emerge --search "%@^app-vim"
eix -cC app-vim
Not all Vim plugins will be available in the Gentoo repository. Vim now includes native packages, as a way to install plugins, and there are also several plugin managers for Vim.
Vim can be configured on a per-user basis or through a system-wide configuration file:
- /etc/vim/vimrc - The system wide (global) settings file.
- ~/.vimrc - The user-specific (local) configuration file. The tilde (~) means it is in the user's home directory.
- ~/.vim/pack/foo - Location where plugins are installed (vim 8 and higher). Substitute foo for the name of each plugin.
About a dozen color schemes are shipped with the base Vim package. They can be listed in last line mode by typing colorscheme, then pressing either Ctrl+d or pressing the Tab key twice:
blue darkblue default delek desert elflord evening industry koehler morning murphy pablo peachpuff ron shine slate torte zellner
They can be changed in Vim by using the colorscheme (alternatively use colo) command while in last line mode:
Color schemes can be permanently applied in the .vimrc file:
colorscheme peachpuff syntax on
The first line sets the default color scheme while the last line activates the color scheme.
Selecting vi editor and system default editor
If Vim - and only Vim - is installed, the vi command should launch Vim. If other vi-like editors are installed, eselect may be used to choose which editor the vi command launches.
The text editor article may also be of interest for setting a system default editor, if Vim is to be set as the default.
To enable support for the Gentoo syntax plugin (app-vim/gentoo-syntax) within vim, add the following lines to the user's ~/.vimrc file:
filetype plugin on filetype indent on
From the command line:
vim --help VIM - Vi IMproved 8.2 (2019 Dec 12, compiled Nov 26 2021 11:56:27) Usage: vim [arguments] [file ..] edit specified file(s) or: vim [arguments] - read text from stdin or: vim [arguments] -t tag edit file where tag is defined or: vim [arguments] -q [errorfile] edit file with first error Arguments: -- Only file names after this -v Vi mode (like "vi") -e Ex mode (like "ex") -E Improved Ex mode -s Silent (batch) mode (only for "ex") -d Diff mode (like "vimdiff") -y Easy mode (like "evim", modeless) -R Readonly mode (like "view") -Z Restricted mode (like "rvim") -m Modifications (writing files) not allowed -M Modifications in text not allowed -b Binary mode -l Lisp mode -C Compatible with Vi: 'compatible' -N Not fully Vi compatible: 'nocompatible' -V[N][fname] Be verbose [level N] [log messages to fname] -D Debugging mode -n No swap file, use memory only -r List swap files and exit -r (with file name) Recover crashed session -L Same as -r -A Start in Arabic mode -H Start in Hebrew mode -T <terminal> Set terminal type to <terminal> --not-a-term Skip warning for input/output not being a terminal --ttyfail Exit if input or output is not a terminal -u <vimrc> Use <vimrc> instead of any .vimrc --noplugin Don't load plugin scripts -p[N] Open N tab pages (default: one for each file) -o[N] Open N windows (default: one for each file) -O[N] Like -o but split vertically + Start at end of file +<lnum> Start at line <lnum> --cmd <command> Execute <command> before loading any vimrc file -c <command> Execute <command> after loading the first file -S <session> Source file <session> after loading the first file -s <scriptin> Read Normal mode commands from file <scriptin> -w <scriptout> Append all typed commands to file <scriptout> -W <scriptout> Write all typed commands to file <scriptout> -x Edit encrypted files --startuptime <file> Write startup timing messages to <file> -i <viminfo> Use <viminfo> instead of .viminfo --clean 'nocompatible', Vim defaults, no plugins, no viminfo -h or --help Print Help (this message) and exit --version Print version information and exit
The vi command may also be used to launch Vim, if so configured.
Specify a name, to open an existing file, or to create a new one:
Vim has a built-in tutorial which should require around 30 minutes to go through. Start it using the vimtutor command:
Tips and tricks
Using Vim like ex or ed from the command line
It is possible to use Vim for one-liners — commands that can be used in scripts or on the command-line to make changes in an unattended manner.
For instance, the following command adds
# to the beginning of each line in the file.txt file:
vim -c ":%s/^/#/g" -c ":x" file.txt
What happens is that Vim interprets the passed on commands (through the
-c option). The first command is Vim's substitution command (which is very similar to sed's), the second one is Vim's instruction to save and exit the editor.
Change file encoding
To change the file encoding of a file to UTF-8, use the following command (in last line mode):
As shown in the previous trick, it is possible to do this from the command line as well:
vim -c ":wq! ++enc=utf8" file.txt
I'm trapped in vim!
For someone entering vim without first having learned how to use it, it may not be obvious how to quit.
Press esc several times, then :, q, enter. To quit without saving, press esc several times, then :, q, !, enter.
If several files are open, try pressing esc several times, then :, q, a, enter. To quit without saving, press esc several times, then :, q, a, !, enter.
If this doesn't help, and desperate measures are needed, something like killall vim may be a last ditch solution (from another terminal). Beware that this will terminate all the vim sessions for a user, without saving. If run as root, such a command will terminate all vim sessions for all users on the system.
Pastes are being tabbed
Say the following text is trying to be pasted into a Vim buffer:
some: yaml: - data - structured in: - this - shape that: - VIM - may not: like
Vim may interpret this with autotabbing, breaking the paste:
some: yaml: - data - structured in: - this - shape that: - VIM - may not: like
To correct this, run the following command: :set paste to enable Vim's paste mode, once the paste is completed, :set nopaste can be used to go back to the previous settings.
E1187: Failed to source defaults.vim Press ENTER or type command to continue
Seems solved by destabilize 8.2.4328.
- Knowledge Base:Edit a configuration file
- Neovim — a hyperextensible Vim-based text editor.
- Text editor — a program to create and edit text files.
- Useful plugin: app-vim/gentoo-syntax
- Vi — a powerful "modal" text-based editor with a long history in the Unix(like) operating system.
- Vim/Guide — explain basic usage for users new to vi-like text editors in general, and vim in particular.
- Vim Documentation Includes Manuals (aka ":help" and Free VIM OPL Book), FAQS, HOWTO's, Tutorials, in HTML PDF, and PS formats.
- A vim Tutorial and Primer - An excellent vim tutorial/primer. Read this first.
- VIM Scripts/Plugins
- Vim for Humans (free ebook) - Clone and cd into the sources directory, mkdir dist, change
sphinx-buildfor SPHINXBUILD in rst/en/Makefile. Run ./makedist.sh. Read PDF in ./dist/vimpourleshumains/.
- Learning the vi and Vim Editors, 7th Edition O'Reilly Print ISBN: 978-0-596-52983-3, Ebook ISBN: 978-0-596-15935-1
- Vim anti-patterns - A blog entry on maintaining flow with Vim.
- Vim Tips Wiki - Previously known as Wikia, Vim Tips Wiki is now on Fandom.com.
- Vim: Seven habits of effective text editing - A guide written in the year 2000 that still is relevant today!