Vim: Examples
The Current File
Get the filename of the current file in normal mode:
<C-g>
Expand the name of the current file in command mode:
:e <C-r>%
Insert Mode Commands
Insert “<Del>”:
<C-k><Del>
Insert the name of the current file in insert mode:
<C-r>%
Insert the name of the alternate file in insert mode:
<C-r>#
Options
Open the options buffer in a new window:
:options
List all options in effect that differ from their default values:
:set
View the value of a boolean option:
:set hidden?
View the value of a numeric option:
:set scroll
or :set scroll?
View the value of a text option:
:set fileformat
or :set fileformat?
Turn on a boolean option.
:set hidden
Turn off a boolean option:
:set nohidden
Note that, unlike numeric and text options,
omitting the ?
after a boolean option does
not return its value but turns it off.
Toggle a boolean option to opposite its current value:
:set hidden!
Get the current shell
:set shell?
Reset an option to its default value
:set iskeyword&
Vim Configuration and Environment
Get current configuration
:version
or vim --version
at the command line.
Get sourced vimrc
:echo $MYVIMRC
Get sourced scripts including vimrc
:scriptnames
Get runtimepath
set runtimepath?