This website have moved to hunden.linuxkompis.se
How I use temporary keybindings for spellcheck in Neovim
I use my text editor Neovim for everything, and I really mean everything. I even use it for inputing text on the web via my web browser qutebrowser and it’s of course the editor I use for all my emails. This also means that I commonly use the spellchecking feature all the time.
And because I use the spellcheck feature all the time, I also want the shortcuts for it to be close to the home row. Unfortunately, I couldn’t find any available keys that felt natural to me to bind the spellcheck commands to, but after some thinking, I got the idea that I could use temporary keybindings.
This means that the keybindings for the spellcheck is only available when I have the spellcheck feature enabled, and I can bind them to keys that I normally use for other things.
After some experimenting, I came up with this solution:
map <silent> <F1> \ :set nospell<BAR> :silent! unmap ff<BAR> :silent! unmap fF<BAR> \ :silent! unmap fa<BAR> :silent! unmap fn<BAR> :silent! unmap fd<BAR> \ :redraw<BAR> echom "Spellcheck disabled"<CR>
map <F2> \ :setlocal spell spelllang=sv<BAR> :noremap ff ]s<BAR> :noremap fF [s<BAR> \ :noremap fa zg<BAR> :noremap fn z=<BAR> :noremap fd zuw<BAR> \ :highlight SpellBad ctermfg=003 ctermbg=none cterm=none<BAR> :redraw<BAR> \ echom "Swedish spellcheck enabled"<CR>
map <F3> \ :setlocal spell spelllang=en<BAR> :noremap ff ]s<BAR> :noremap fF [s <BAR> \ :noremap fa zg<BAR> :noremap fn z=<BAR> :noremap fd zuw<BAR> \ :highlight SpellBad ctermfg=003 ctermbg=none cterm=none<BAR> :redraw<BAR> \ echom "English spellcheck enabled"<CR>
This means that when I enable spellcheck I also enable these keybindings:
||Go to the next misspelled word.|
||Go the previously misspelled word.|
||Correct the current misspelled word.|
||Add the current word to the dictionary.|
||Remove the current word from the dictionary.|
And when I disable the spellcheck, it then removes the keybindings and restore the default behaviour for the