First of all, there are fancy quotes; you need to use plain ("
) ones. Other than that, the :let
is okay.
let dir = "/home/user/Downloads/"
You could use :execute
to evaluate the defined variable with :set
, but it's easier to use :let
, because it can change Vim options, too, with the special notation &{optionname}
:
let &path = dir
For the mapping, if dir
doesn't change during runtime, it's easiest to use :execute
. Note how the quoted backslashes must be escaped (i.e. doubled):
execute "nnoremap gr :grep '\\b<cword>\\b' " . dir . "/*<CR>"
All that information is part of :help eval
. Learn how the excellent and comprehensive help is structured; all the information is in there (you just need to know how to find it)!