2

I am trying to give vim a global spellfile and a project-specific spellfile. The project-specific file is ./en.utf-8.add relative to the cwd. This works fine if the project directory has no spaces, but gives error E474: Invalid argument when calling set spellfile+= for a path with spaces. I tried escaping the path with fnameescape(), but I still get the error. Surrounding the path in quotes does not give any error, but it doesn't seem to have any effect.

I know I can just put the basename of the spell file relative to cwd, but I want entries in spellfile to be absolute. Mostly because I want to be able to programmatically find the index of the local spellfile for [count]zg and [count]zug.

Edit: Add examples

set spellfile=/foo bar/en.utf-8.add -> E474: Invalid argument: spellfile=/foo
set spellfile=/foo\ bar/en.utf-8.add -> E474: Invalid argument: spellfile=/foo\ bar/en.utf-8.add
set spellfile=/foo\\ bar/en.utf-8.add -> E474: Invalid argument: spellfile=/foo\\
set spellfile=/foobar/en.utf-8.add -> Sets the spellfile to /foobar/en.utf-8.add as expected

Interestingly, it seems that with a single space, the whole path is accepted, but somehow still invalid. With 0 or 2 spaces, the input is chopped when the space is reached, which makes sense. So, I can correctly encode the space, but it's still invalid for a spellfile?

7
  • :help :set-args and :help option-backslash
    – D. Ben Knoble
    Oct 29, 2020 at 19:47
  • Also :help-& if this is happening programmatically.
    – D. Ben Knoble
    Oct 29, 2020 at 22:08
  • 1
    According to option-backslash, a single backslash before each space should suffice. "To include white space in a string option value it has to be preceded with a backslash. To include a backslash you have to use two." If I want a space, I put a backslash before. I don't want a backslash in the result, so I don't put 2.
    – Marcel
    Oct 29, 2020 at 22:31
  • Anyway, I tried it with 1, 2, 4, and 8 backslashes before each space and still no luck. Removing the space from the path removes the error. Tried in vim and nvim.
    – Marcel
    Oct 29, 2020 at 22:32
  • it might help if you edit with specific examples.
    – D. Ben Knoble
    Oct 29, 2020 at 22:33

1 Answer 1

1

UPDATE: This has been fixed in version 8.2.1926.

Looking at the source code for Vim, it seems Vim will try to validate the spell file name and it will only consider characters in 'isfname' as valid.

As a workaround, you can add a space to 'isfname' (perhaps temporarily) in order to set 'spellfile' to a name containing a space:

set isfname+=32
set spellfile=/foo\ bar/en.utf-8.add
set isfname-=32

Note that 32 is the ASCII code for a space character. See :help 'isfname' for more details on how that option works.

4
  • Filed a bug about it: github.com/vim/vim/issues/7230
    – filbranden
    Oct 29, 2020 at 23:33
  • Thank you so much! This is exactly what I was looking for. One note: maybe it would be more explicit to use char2nr(' ')?
    – Marcel
    Oct 30, 2020 at 1:31
  • @Marcel The problem with using a function such as char2nr() is that :set doesn't evaluate functions, so you need to use :let &isfname but it's hard to do so when appending a value (as in :set spellfile+=...) or use :execute. In any case, I'm hoping the bug will be taken care upstream, it clearly looks like a bug to me, I don't know anywhere else where path names are checked for validity using the 'isfname' setting, that's mostly to identify paths inside a buffer's contents.
    – filbranden
    Oct 30, 2020 at 17:02
  • 1
    It is a bit more challenging, yes. Here is what I decided on: let l:prev_isfname = &isfname execute 'set isfname+=' . char2nr(' ') execute 'set spellfile+=' . fnameescape(g:local_spellfile_path) let &isfname = l:prev_isfname
    – Marcel
    Oct 31, 2020 at 18:02

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.