I have multiple lines like the once below in .vimrc file.
nnoremap \html :-1read $HOME/.vim/snippets/html_basic.snippet<CR> nnoremap \bs :-1read $HOME/.vim/snippets/bootstrap.snippet<CR> ... more snippets like these
Problem is if I want to change my snippet directory
$HOME/.vim/snippets to something else like
$HOME/.vim/templates/ I would have to edit all the map commands above.
How can I refactor and execute the same map commands using variables containing snippet directory path? For instance, something like this ...
# variable holding snippet directory path let snippet_home = "$HOME/.vim/templates/" # map commands using $snippet_home variable value to read file contents nnoremap \html :-1read $snippet_home/html_basic.snippet<CR> nnoremap \bs :-1read $snippet_home/bootstrap.snippet<CR> ... more snippets like these
This way if I move or rename my
snippet directory I would have to simple update
snippet_home variable and all map commands remain the same.
Kindly suggest how do I achieve this in vimscript?