In :set
: you must write \
for spaces. See :help option-backslash
(also from :help :set
and scrolling).
*option-backslash*
To include white space in a string option value it has to be preceded with a
backslash. To include a backslash you have to use two. Effectively this
means that the number of backslashes in an option value is halved (rounded
down).
In options 'path', 'cdpath', and 'tags', spaces have to be preceded with three
backslashes instead for compatibility with version 3.0 where the options can
be separated by either commas or spaces.
Comma-separated options like 'backupdir' and 'tags' will also require commas
to be escaped with two backslashes, whereas this is not needed for
non-comma-separated ones like 'makeprg'.
When setting options using |:let| and |literal-string|, you need to use one
fewer layer of backslash.
A few examples: >
:set makeprg=make\ file results in "make file"
:let &makeprg='make file' (same as above)
:set makeprg=make\\\ file results in "make\ file"
:set tags=tags\ /usr/tags results in "tags" and "/usr/tags"
:set tags=tags\\\ file results in "tags file"
:let &tags='tags\ file' (same as above)
:set makeprg=make,file results in "make,file"
:set makeprg=make\\,file results in "make\,file"
:set tags=tags,file results in "tags" and "file"
:set tags=tags\\,file results in "tags,file"
:let &tags='tags\,file' (same as above)
For 'path'
specifically, there's an extra caveat :
< - Spaces can also be used to separate directory names (for backwards
compatibility with version 3.0). To have a space in a directory
name, precede it with an extra backslash, and escape the space: >
:set path=.,/dir/with\\\ space
You can also use &
-notation (documented at :help let-&
):
:let &{option-name} = {expr1} *:let-option* *:let-&*
Set option {option-name} to the result of the
expression {expr1}. A String or Number value is
always converted to the type of the option.
For an option local to a window or buffer the effect
is just like using the |:set| command: both the local
value and the global value are changed.
Example: >
:let &path = &path .. ',/usr/local/include'
< This also works for terminal codes in the form t_xx.
But only for alphanumerical names. Example: >
:let &t_k1 = "\<Esc>[234;"
< When the code does not exist yet it will be created as
a terminal key code, there is no error.
So the example would be written in one of these two ways:
set path=/c/Program\\\ Files/exampledir
let &path = '/c/Program\ Files/exampledir'
With neovim's Lua, you could write
vim.opt.path = '/c/Program Files/exampledir'
Finally, the question "How do I navigate to topics in Vim's documentation?" provides a number of tips for finding out how to do something in Vim.