I believe the following script in vimrc, which try to set spellfile, has something to do with the scope of vim variable. Especially the difference of $var and g:var:

I can't figure out what's wrong with this:

let g:spelldir ='~/.vim/myvim/spell'
if !exists( 'g:spelldir' )
  silent exec '!mkdir -p ' . g:spelldir
au FileType tex setlocal spf= g:spelldir/en.utf-8.add

while it works if we change g:spelldir to $spelldir.

1 Answer 1

  1. Use isdirectory not exists to check if a directory exists.

  2. set/setlocal does not expand variables but it does (sometimes) expand environment variables, which explains what you're seeing. Use this instead:

    au FileType tex exe 'setlocal spf='.g:spelldir.'/en.utf-8'

The g:spelldir is copied into the setlocal string when the FileType autocommand is triggered, then the whole string is executed. It has nothing to do with variable scope, g: is global.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.