-*spell.txt* For Vim version 7.0aa. Last change: 2005 Jun 21
+*spell.txt* For Vim version 7.0aa. Last change: 2005 Jun 22
VIM REFERENCE MANUAL by Bram Moolenaar
*[s*
[s Like "]s" but search backwards, find the misspelled
- word before the cursor.
+ word before the cursor. Doesn't recognize words
+ split over two lines, thus may stop at words that are
+ not highlighted as bad.
*]S*
]S Like "]s" but only stop at bad words, not at rare
Finding suggestions for bad words:
*z?*
-z? For the badly spelled word under the cursor suggest
- the correctly spelled word.
- When there is no badly spelled word under the cursor
- use the one after the cursor, in the same line.
- The results are sorted on similarity to the badly
- spelled word.
+z? For the word under/after the cursor suggest correctly
+ spelled words. This also works to find alternative
+ for words that are not highlighted as bad words.
+ The results are sorted on similarity to the word
+ under/after the cursor.
This may take a long time. Hit CTRL-C when you are
bored.
You can enter the number of your choice or press
If 'verbose' is non-zero a score will be displayed to
indicate the likeliness to the badly spelled word (the
higher the score the more different).
- The score may be slightly wrong for words with
- multi-byte characters.
When a word was replaced the redo command "." will
repeat the word replacement. This works like "ciw",
the good word and <Esc>.
in the form 0xff and 0XFF.
+WORD COMBINATIONS
+
+It is possible to spell-check words that include a space. This is used to
+recognize words that are invalid when used by themselves, e.g. for "et al.".
+It can also be used to recognize "the the" and highlight it.
+
+The number of spaces is irrelevant. In most cases a line break may also
+appear. However, this makes it difficult to find out where to start checking
+for spelling mistakes. When you make a change to one line and only that line
+is redrawn Vim won't look in the previous line, thus when "et" is at the end
+of the previous line "al." will be flagged as an error. And when you type
+"the<CR>the" the highlighting doesn't appear until the first line is redrawn.
+Use |CTRL-L| to redraw right away. "[s" will also stop at a word combination
+with a line break.
+
+When encountering a line break Vim skips characters such as '*', '>' and '"',
+so that comments in C, shell and Vim code can be spell checked.
+
+
SYNTAX HIGHLIGHTING *spell-syntax*
Files that use syntax highlighting can specify where spell checking should be
again. This can be used, for example, to add @Spell to the comments of a
program, and add @NoSpell for items that shouldn't be checked.
+
+VIM SCRIPTS
+
+If you want to write a Vim script that does something with spelling, you may
+find these functions useful:
+
+ spellbadword() find badly spelled word at the cursor
+ spellsuggest() get list of spelling suggestions
+
==============================================================================
2. Generating a spell file *spell-mkspell*
uses. Myspell is used by OpenOffice.org and Mozilla. You should be able to
find them here:
http://lingucomponent.openoffice.org/spell_dic.html
-You can also use a plain word list.
+You can also use a plain word list. The results are the same, the choice
+depends on what you find.
Make sure your current locale is set properly, otherwise Vim doesn't know what
characters are upper/lower case letters. If the locale isn't available (e.g.,
they appear are used. |spell-affix-REP|
|spell-affix-SAL|
+ This command uses a lot of memory, required to find
+ the optimal word tree (Polish requires a few hundred
+ Mbyte). The final result will be much smaller.
+
When the spell file was written all currently used
spell files will be reloaded.
Rare words are highlighted differently from bad words. This is to be used for
words that are correct for the language, but are hardly ever used and could be
-a typing mistake anyway.
+a typing mistake anyway. When the same word is found as good it won't be
+highlighted as rare.
+
+
+BAD WORDS
+ *spell-affix-BAD*
+In the affix file a BAD line can be used to define the affix name used for
+bad words. Example:
+
+ BAD ! ~
+
+This can be used to exclude words that would otherwise be good. For example
+"the the". Once a word has been marked as bad it won't be undone by
+encountering the same word as good.
REPLACEMENTS *spell-affix-REP*
'spell' options.txt /*'spell'*
'spellfile' options.txt /*'spellfile'*
'spelllang' options.txt /*'spelllang'*
+'spellsuggest' options.txt /*'spellsuggest'*
'spf' options.txt /*'spf'*
'spl' options.txt /*'spl'*
'splitbelow' options.txt /*'splitbelow'*
'splitright' options.txt /*'splitright'*
'spr' options.txt /*'spr'*
+'sps' options.txt /*'sps'*
'sr' options.txt /*'sr'*
'srr' options.txt /*'srr'*
'ss' options.txt /*'ss'*
hebrew.txt hebrew.txt /*hebrew.txt*
help various.txt /*help*
help-context help.txt /*help-context*
-help-tags tags 1
help-translated various.txt /*help-translated*
help-xterm-window various.txt /*help-xterm-window*
help.txt help.txt /*help.txt*
-*various.txt* For Vim version 7.0aa. Last change: 2005 May 31
+*various.txt* For Vim version 7.0aa. Last change: 2005 Jun 22
VIM REFERENCE MANUAL by Bram Moolenaar
1. Various commands *various-cmds*
*CTRL-L*
-CTRL-L Clear and redraw the screen (later).
+CTRL-L Clear and redraw the screen. The redraw may happen
+ later, after processing typeahead.
*:redr* *:redraw*
:redr[aw][!] Redraw the screen right now. When ! is included it is
" Vim filetype plugin file
" Language: C
" Maintainer: Bram Moolenaar <Bram@vim.org>
-" Last Change: 2005 Mar 27
+" Last Change: 2005 Jun 22
" Only do this when not done yet for this buffer
if exists("b:did_ftplugin")
let b:did_ftplugin = 1
" Using line continuation here.
+let s:cpo_save = &cpo
set cpo-=C
let b:undo_ftplugin = "setl fo< com< | if has('vms') | setl isk< | endif"
\ "All Files (*.*)\t*.*\n"
endif
endif
+
+let &cpo = s:cpo_save
+unlet s:cpo_save
/* spell.c */
int spell_check __ARGS((win_T *wp, char_u *ptr, int *attrp));
int spell_move_to __ARGS((int dir, int allwords, int curline));
+void spell_cat_line __ARGS((char_u *buf, char_u *line, int maxlen));
char_u *did_set_spelllang __ARGS((buf_T *buf));
void spell_reload __ARGS((void));
void put_bytes __ARGS((FILE *fd, long_u nr, int len));
int has_syntax = FALSE; /* this buffer has syntax highl. */
int save_did_emsg;
int has_spell = FALSE; /* this buffer has spell checking */
+# define SPWORDLEN 150
+ char_u nextline[SPWORDLEN * 2];/* text with start of the next line */
+ int nextlinecol; /* column where nextline[] starts */
+ int nextline_idx; /* index in nextline[] where next line
+ starts */
int spell_attr = 0; /* attributes desired by spelling */
int word_end = 0; /* last byte with same spell_attr */
+ static linenr_T checked_lnum = 0; /* line number for checked_col */
+ static int checked_col = 0; /* column in checked_lnum up to which
+ * there are no spell errors */
+ int cur_checked_col = 0; /* checked column for current line */
#endif
int extra_check; /* has syntax or linebreak */
#ifdef FEAT_MBYTE
/* Prepare for spell checking. */
has_spell = TRUE;
extra_check = TRUE;
+
+ /* Get the start of the next line, so that words that wrap to the next
+ * line are found too: "et<line-break>al.".
+ * Trick: skip a few chars for C/shell/Vim comments */
+ nextline[SPWORDLEN] = NUL;
+ if (lnum < wp->w_buffer->b_ml.ml_line_count)
+ {
+ line = ml_get_buf(wp->w_buffer, lnum + 1, FALSE);
+ spell_cat_line(nextline + SPWORDLEN, line, SPWORDLEN);
+ }
+
+ /* When a word wrapped from the previous line the start of the current
+ * line is valid. */
+ if (lnum == checked_lnum)
+ cur_checked_col = checked_col;
+ checked_lnum = 0;
}
#endif
line = ml_get_buf(wp->w_buffer, lnum, FALSE);
ptr = line;
+#ifdef FEAT_SYN_HL
+ if (has_spell)
+ {
+ /* To be able to spell-check over line boundaries copy the end of the
+ * current line into nextline[]. Above the start of the next line was
+ * copied to nextline[SPWORDLEN]. */
+ if (nextline[SPWORDLEN] == NUL)
+ {
+ /* No next line or it is empty. */
+ nextlinecol = MAXCOL;
+ nextline_idx = 0;
+ }
+ else
+ {
+ v = STRLEN(line);
+ if (v < SPWORDLEN)
+ {
+ /* Short line, use it completely and append the start of the
+ * next line. */
+ nextlinecol = 0;
+ mch_memmove(nextline, line, (size_t)v);
+ mch_memmove(nextline + v, nextline + SPWORDLEN,
+ STRLEN(nextline + SPWORDLEN) + 1);
+ nextline_idx = v + 1;
+ }
+ else
+ {
+ /* Long line, use only the last SPWORDLEN bytes. */
+ nextlinecol = v - SPWORDLEN;
+ mch_memmove(nextline, line + nextlinecol, SPWORDLEN);
+ nextline_idx = SPWORDLEN + 1;
+ }
+ }
+ }
+#endif
+
/* find start of trailing whitespace */
if (wp->w_p_list && lcs_trail)
{
* Only do this when there is no syntax highlighting, the
* @Spell cluster is not used or the current syntax item
* contains the @Spell cluster. */
- if (has_spell && v >= word_end)
+ if (has_spell && v >= word_end && v > cur_checked_col)
{
spell_attr = 0;
if (area_attr == 0 && search_attr == 0)
char_attr = syntax_attr;
if (c != 0 && (!has_syntax || can_spell))
{
- char_u *prev_ptr;
+ char_u *prev_ptr, *p;
+ int len;
# ifdef FEAT_MBYTE
if (has_mbyte)
{
else
# endif
prev_ptr = ptr - 1;
- word_end = v + spell_check(wp, prev_ptr, &spell_attr);
+
+ /* Use nextline[] if possible, it has the start of the
+ * next line concatenated. */
+ if ((prev_ptr - line) - nextlinecol >= 0)
+ p = nextline + (prev_ptr - line) - nextlinecol;
+ else
+ p = prev_ptr;
+ len = spell_check(wp, p, &spell_attr);
+ word_end = v + len;
/* In Insert mode only highlight a word that
* doesn't touch the cursor. */
spell_attr = 0;
spell_redraw_lnum = lnum;
}
+
+ if (spell_attr == 0 && p != prev_ptr
+ && (p - nextline) + len > nextline_idx)
+ {
+ /* Remember that the good word continues at the
+ * start of the next line. */
+ checked_lnum = lnum + 1;
+ checked_col = (p - nextline) + len - nextline_idx;
+ }
}
}
if (spell_attr != 0)
- char_attr = hl_combine_attr(char_attr, spell_attr);
+ {
+ if (area_attr == 0 && search_attr == 0)
+ char_attr = hl_combine_attr(char_attr, spell_attr);
+ else
+ char_attr = hl_combine_attr(spell_attr, char_attr);
+ }
#endif
#ifdef FEAT_LINEBREAK
/*
#if defined(FEAT_SYN_HL) || defined(PROTO)
/*
- * Combine the spelling attributes with other attributes. "spell_attr"
- * overrules "char_attr".
+ * Combine special attributes (e.g., for spelling) with other attributes
+ * (e.g., for syntax highlighting).
+ * "prim_attr" overrules "char_attr".
* This creates a new group when required.
* Since we expect there to be few spelling mistakes we don't cache the
* result.
* Return the resulting attributes.
*/
int
-hl_combine_attr(char_attr, spell_attr)
+hl_combine_attr(char_attr, prim_attr)
int char_attr;
- int spell_attr;
+ int prim_attr;
{
attrentry_T *char_aep = NULL;
attrentry_T *spell_aep;
attrentry_T new_en;
if (char_attr == 0)
- return spell_attr;
- if (char_attr <= HL_ALL && spell_attr <= HL_ALL)
- return char_attr | spell_attr;
+ return prim_attr;
+ if (char_attr <= HL_ALL && prim_attr <= HL_ALL)
+ return char_attr | prim_attr;
#ifdef FEAT_GUI
if (gui.in_use)
{
new_en.ae_attr = char_attr;
}
- if (spell_attr <= HL_ALL)
- new_en.ae_attr |= spell_attr;
+ if (prim_attr <= HL_ALL)
+ new_en.ae_attr |= prim_attr;
else
{
- spell_aep = syn_gui_attr2entry(spell_attr);
+ spell_aep = syn_gui_attr2entry(prim_attr);
if (spell_aep != NULL)
{
new_en.ae_attr |= spell_aep->ae_attr;
new_en.ae_attr = char_attr;
}
- if (spell_attr <= HL_ALL)
- new_en.ae_attr |= spell_attr;
+ if (prim_attr <= HL_ALL)
+ new_en.ae_attr |= prim_attr;
else
{
- spell_aep = syn_cterm_attr2entry(spell_attr);
+ spell_aep = syn_cterm_attr2entry(prim_attr);
if (spell_aep != NULL)
{
new_en.ae_attr |= spell_aep->ae_attr;
new_en.ae_attr = char_attr;
}
- if (spell_attr <= HL_ALL)
- new_en.ae_attr |= spell_attr;
+ if (prim_attr <= HL_ALL)
+ new_en.ae_attr |= prim_attr;
else
{
- spell_aep = syn_cterm_attr2entry(spell_attr);
+ spell_aep = syn_cterm_attr2entry(prim_attr);
if (spell_aep != NULL)
{
new_en.ae_attr |= spell_aep->ae_attr;