59

What is the best way to spellcheck in gVim? Is there an add-on or something? I would like it to offer corrections as well.

Mateusz Piotrowski
  • 8,029
  • 10
  • 53
  • 79

4 Answers4

112

Use :set spell to turn on spell-checking. If it's source code, gvim is smart enough to only spellcheck comments and string literals.

:help spell will give you all the details. Here are some excerpts:

To search for the next misspelled word:

]s           Move to next misspelled word after the cursor.
             A count before the command can be used to repeat.
             'wrapscan' applies.

[s           Like "]s" but search backwards, find the misspelled
             word before the cursor.  
Finding suggestions for bad words:

z=           For the word under/after the cursor, suggest correctly
             spelled words.
To add words to your own word list:

zg           Add word under the cursor as a good word

Also see :help set spelllang for information on changing your dictionary to include other regions, languages, or word sets (for example, medical jargon).

gvim must be compiled with |+syntax|.

I don't put :set spell in my .vimrc because when I'm coding there are just too many variable names in my comments that get flagged. If there is a certain file type you want checked use an autocommand in your .vimrc. Or just turn it on manually when you need it.

Eric Johnson
  • 17,502
  • 10
  • 52
  • 59
  • 2
    You forgot to mention how to turn on spellcheck, but those commands will be useful once it's on. Use ":set spell" to turn it on. note that if it's source code, it's smart enough to only spellcheck comments and string literals :) – rmeador Mar 12 '09 at 20:38
  • 4
    On gvim, put the cursor on a misspelled word and right-click. A list of suggestions will be shown at the context menu. – Denilson Sá Maia Sep 13 '09 at 01:25
  • 1
    Great, I'm amazed that when I set :set spelllang=ru, it offered to download missing spell files and after it worked! I love Vim – Kee Aug 23 '11 at 03:04
  • 1
    I put the following in my `.vimrc` to be able to toggle spell checking; `nnoremap s :set spell!`. (the `` key defaults to `\`) – Roland Smith Aug 11 '13 at 13:44
  • "smart enough to only spellcheck comments and string literals". What about the cases when you use English in a variable name, and you want to make sure you've spelled it right... – Isaac Kleinman Aug 21 '13 at 22:11
  • Is it not possible to automatically move through all errors correcting them like `aspell -c`? – Ciro Santilli OurBigBook.com Jan 18 '14 at 09:16
  • `:set spelloptions=camel` is also useful for spellchecking camelCase and PascalCase words – Micah Lindstrom Jul 06 '23 at 22:50
  • "If it's source code, gvim is smart enough to only spellcheck comments and string literals. ... I don't put `:set spell` in my .vimrc because when I'm coding there are just too many variable names in my comments that get flagged." Isn't that a contradiction? If it's flagging variable names, then it's not checking only comments and string literals. – pyansharp Jul 24 '23 at 20:20
6
:setlocal spell spelllang=en_us
:set spell

For spell checker and to activate right button on mouse:

:set mousemodel=popup

When you place the cursor on the word and click on right button, gvim purpose different correct words.

You can put it on your ~/.vimrc

Taryn
  • 242,637
  • 56
  • 362
  • 405
but2ene
  • 61
  • 1
  • 1
5

Do :set spell to turn on spell-checking. See :h spell for help and info about how spell-checking works and how to use different languages and dictionaries and such.

Brian Carper
  • 71,150
  • 28
  • 166
  • 168
2

I started using

aspell

which comes with Cygwin (http://www.cygwin.com/). (It's a package, but the default install plus manually-added aspell is pretty tiny and quick to download.)

When I want to spell check the current file, I use a function defined in my .vimrc (or _vimrc) that saves the file, runs aspell on it, then reloads the file:

:function! SpellCheck()
:   w!
:   !c:\prog\cygwin\bin\aspell.exe --dont-backup check "%"
:   e! %
:endfunction

to use this function I just do:

:call SpellCheck()

It goes through the file just like Microsoft Word would, I exit, and then the file is reloaded with corrections.

Running aspell externally without having to move my mouse is integrated enough for me. I've never liked on-the-fly spell checking. I find it and things like IntelliSense distracting.