I can run this snippit of code within a vimscript block:0read /home/user/.vim/bundle/vim-lorum/lorums/lorum.jsAs expected, it puts the contents of lorum.js into the current bufferBut, I need to make this a little more dynamic. If I try something like:let g:filePath=/home/user/.vim/bundle/vim-lorum/lorums/lorum.js0read g:filePathI get this error message:E484: Can't open file g:filePathI tried wrapping g:filePath in expand and glob but I get similar errors. Any ideas?
Read file from vimscript variable
vimscript;filesystem
This is because vim does not evaluate variable names or functions with most commands.  In your case, vim thinks you literally want to read the contents of a file called g:filePath into the buffer.  What you want can be accomplished with the :execute command.  This command takes a string as an argument, and will then run that string as a command.  In your case, this is how it would look::let g:filePath=/home/user/.vim/bundle/vim-lorum/lorums/lorum.js:execute 0read  . fnameescape(g:filePath)The fnameescape part is just to ensure that all special characters are escaped properly (see :help fnameescape()).  For more on how to use :execute, read :help :execute.  Also note that . is vim's string concatenation operator.