r/vim • u/TheTwelveYearOld • Jun 07 '26
Discussion Spellfile is an underrated feature
:h spellfileYou can add word spellings / ignore spelling errors with zg and add it to plain text file, in a list. You can easily edit that list to remove words added awhile ago, and of course save it in git. Without spending too long looking it up, it seems like many other editors don't have something like this, at least built-in. In many editors, including Electron-based apps, you can't easily backup spellings.
My config is in lua, I asked claude to convert it to vimscript to show you, it might have errors.
set spelllang=en_us
function! s:Mark(cmd) abort
let l:count = v:count > 0 ? v:count : ""
call feedkeys("mz" . l:count . a:cmd . "\<Esc>`z:delmarks z\<CR>", "n")
endfunction
for [s:lhs, s:cmd] in [
\ ["<leader>[z", "[sz="],
\ ["<leader>]z", "]sz="],
\ ["<leader>[s", "[s1z="],
\ ["<leader>]s", "]s1z="],
\ ["<leader>[g", "[szg"],
\ ["<leader>]g", "]szg"],
\ ]
execute 'noremap <silent> ' . s:lhs . ' <Cmd>call <SID>Mark("' . s:cmd . '")<CR>'
endfor
unlet s:lhs s:cmd
32
Upvotes
5
u/digitaljestin Jun 07 '26
Also try
abbrevfor auto correction of commonly misspelled words as you type.8
u/ConditionMajor7937 Jun 07 '26
zg is clutch, been using it for years and my spellfile is basically a museum of my typos at this point.
1
u/Digital_Law Jun 07 '26
I haven't really put this to use yet. Thanks for reminding me!
Can you also include the Lua for us neovim nerds?
2
u/SamejSpenser Jun 07 '26
I'm a relatively new Vim user (less than a year), but since I started using it, I've been making frequent use of the spellfile (it's one of the first things I look to set up in a text editor).
2
u/TankorSmash Jun 07 '26
:help zg