I have been a vim user for over 15 years, but until recently I had never tried writing any Vimscript. I had occasionally tried (usually in vain) to understand the Vimscript in some of the plugins I use. But actually writing my own seemed inaccessible, or at least, not important enough to try.
That changed recently when I decided that I had too many lines like this in my .vimrc:
I decided that determining if we should use ESLint for Syntastic should be automated. We could simply look for the presence of eslint under the node_modules directory. If it exists, assume that we are using ESLint.
So, here is my Vimscript code to do that:
but basically the usage here takes the file name provided by autocmd, expands it to its full path, and removes the file name, resulting in the parent directory.
SetLinter in turn calls FindEslint on this directory.
means "the variable rootdir that is a function argument". In Vimscript, you have to be explicit about the scope of the variables you are referencing.
to travel up the directory tree, looking for a node_modules directory. If it finds one, it again uses finddir to look for an eslint directory or a gulp-eslint directory. I use gulp-eslint that this makes sense for me.
If FindEslint finds a directory like this, SetLinter uses that directory to set the appropriate syntastic options.
In the end, I found Vimscript to be somewhat odd compared to other languages I know. On the other hand, the built in documentation made learning the necessary commands relatively easy.
If you use and love vim like I do, I definitely recommend getting your feet wet with Vimscript!