How do I prepend a value to the beginning of a comma-separated Vim option like path or wildignore?
Answer
:set {option}^=value
Explanation
Vim's :set option^=value operator prepends a value to the front of a list-style option, giving it the highest priority. This is the lesser-known counterpart to += (which appends). For options like path, runtimepath, and wildignore, Vim processes entries in order — so position matters.
How it works
:set option+=value— appendsvalueto the end of the list (lower priority):set option^=value— prependsvalueto the beginning of the list (higher priority):set option-=value— removesvaluefrom the list:set option&— resets the option to its default
These operators work on comma-separated list options: path, runtimepath, backupskip, wildignore, tags, suffixes, complete, and others.
Example
To make Vim search the local ./include directory before any other path entries:
:set path^=./include
To prepend your project's vendor directory at the front of runtimepath so its scripts load first:
:set runtimepath^=~/.vim/vendor/myplugin
Tips
- Check the current value of any list option with
:set option? - Use
:set option&to reset a list option to its default value before rebuilding it. - In a
vimrc, prefer^=for project-local overrides and+=for additive configuration.