" My vimrc - http://www.johnleach.co.uk/downloads/misc/vimrc " Based on everyone elses vimrc's I've seen :) " $Id: vimrc 17 2003-11-14 10:24:02Z john $ set nocompatible set ai set history=50 set ruler set showmode set showcmd set showmatch "set nowrap set nosol set autoindent "set textwidth=79 if has("autocmd") " When editing a file, always jump to the last cursor position autocmd BufReadPost * if line("'\"") | exe "'\"" | endif endif syntax on set hlsearch set comments+=b:\" set comments+=n:: filetype on autocmd FileType python set smartindent autocmd FileType css set smartindent autocmd FileType html set formatoptions+=tl set ignorecase set smartcase " * Spelling " define `Ispell' language and personal dictionary, used in several places " below: let IspellLang = 'british' let PersonalDict = '~/.ispell_' . IspellLang " try to avoid misspelling words in the first place -- have the insert mode " +N/+P keys perform completion on partially-typed words by " checking the Linux word list and the personal `Ispell' dictionary; sort out " case sensibly (so that words at starts of sentences can still be completed " with words that are in the dictionary all in lower case): execute 'set dictionary+=' . PersonalDict set dictionary+=/usr/dict/words set complete=.,w,b,d,u,t,i,k set infercase " correct my common typos without me even noticing them: abbreviate teh the " Spell checking operations are defined next. They are all set to normal mode " keystrokes beginning \s but function keys are also mapped to the most common " ones. The functions referred to are defined at the end of this .vimrc. " \si ("spelling interactive") saves the current file then spell checks it " interactively through `Ispell' and reloads the corrected version: execute 'nnoremap \si :w:!ispell -x -d ' . IspellLang . ' %:e' " \sl ("spelling list") lists all spelling mistakes in the current buffer, " but excludes any in news/mail headers or in ("> ") quoted text: execute 'nnoremap \sl :w ! grep -v "^>" grep -E -v "^[[:alpha:]-]+: " ' . \ ' ispell -l -d ' . IspellLang . ' sort uniq' " \sh ("spelling highlight") highlights (in red) all misspelt words in the " current buffer, and also excluding the possessive forms of any valid words " (EG "Lizzy's" won't be highlighted if "Lizzy" is in the dictionary); with " mail and news messages it ignores headers and quoted text; for HTML it " ignores tags and only checks words that will appear, and turns off other " syntax highlighting to make the errors more apparent [function at end of " file]: nnoremap \sh :call HighlightSpellingErrors() " nmap \sh " \sc ("spelling clear") clears all highlighted misspellings; for HTML it " restores regular syntax highlighting: nnoremap \sc :if &ft == 'html' sy on \ else :sy clear SpellError endif " nmap \sc " \sa ("spelling add") adds the word at the cursor position to the personal " dictionary (but for possessives adds the base word, so that when the cursor " is on "Ceri's" only "Ceri" gets added to the dictionary), and stops " highlighting that word as an error (if appropriate) [function at end of " file]: nnoremap \sa :call AddWordToDictionary() " * Functions Referred to Above function! HighlightSpellingErrors() " highlights spelling errors in the current window; used for the \sh operation " defined above; " requires the ispell, sort, and uniq commands to be in the path; " requires the global variable IspellLang to be defined above, and to contain " the preferred `Ispell' language; " for mail/news messages, requires the grep command to be in the path; " for HTML documents, saves the file to disk and requires the lynx command to " be in the path " " by Smylers http://www.stripey.com/vim/ " (inspired by Krishna Gadepalli and Neil Schemenauer's vimspell.sh) " " 2000 Jun 1: for `Vim' 5.6 " for HTML files, remove all current syntax highlighting (so that " misspellings show up clearly), and note it's HTML for future reference: if &filetype == 'html' let HTML = 1 syntax clear " for everything else, simply remove any previously-identified spelling " errors (and corrections): else let HTML = 0 if hlexists('SpellError') syntax clear SpellError endif if hlexists('Normal') syntax clear Normal endif endif " form a command that has the text to be checked piping through standard " output; for HTML files this involves saving the current file and processing " it with `Lynx'; for everything else, use all the buffer except quoted text " and mail/news headers: if HTML write let PipeCmd = '! lynx --dump --nolist % |' else let PipeCmd = 'write !' if &filetype == 'mail' let PipeCmd = PipeCmd . ' grep -v "^> " | grep -E -v "^[[:alpha:]-]+:" |' endif endif " execute that command, then generate a unique list of misspelt words and " store it in a temporary file: let ErrorsFile = tempname() execute PipeCmd . ' ispell -l -d '. g:IspellLang . \ ' | sort | uniq > ' . ErrorsFile " open that list of words in another window: execute 'split ' . ErrorsFile " for every word in that list ending with "'s", check if the root form " without the "'s" is in the dictionary, and if so remove the word from the " list: global /'s$/ execute 'read ! echo ' . expand('') . \ ' | ispell -l -d ' . g:IspellLang | delete " (If the root form is in the dictionary, ispell -l will have no output so " nothing will be read in, the cursor will remain in the same place and the " :delete will delete the word from the list. If the root form is not in the " dictionary, then ispell -l will output it and it will be read on to a new " line; the delete command will then remove that misspelt root form, leaving " the original possessive form in the list!) " only do anything if there are some misspellings: if strlen(getline('.')) > 0 " if (previously noted as) HTML, replace each non-alphanum char with a " regexp that matches either that char or a &...; entity: if HTML % substitute /\W/\\(&\\|\&\\(#\\d\\{2,4}\\|\w\\{2,8}\\);\\)/e endif " turn each mistake into a `Vim' command to place it in the SpellError " syntax highlighting group: % substitute /^/syntax match SpellError !\\!/ endif " save and close that file (so switch back to the one being checked): exit " make syntax highlighting case-sensitive, then execute all the match " commands that have just been set up in that temporary file, delete it, and " highlight all those words in red: syntax case match execute 'source ' . ErrorsFile call delete(ErrorsFile) highlight SpellError term=reverse ctermfg=DarkRed guifg=Red " with HTML, don't mark any errors in e-mail addresses or URLs, and ignore " anything marked in a fix-width font (as being computer code): if HTML syntax case ignore syntax match Normal !\<[[:alnum:]._-]\+@[[:alnum:]._-]\+\.\a\+\>! syntax match Normal \ !\<\(ht\|f\)tp://[-[:alnum:].]\+\a\(/[-_.[:alnum:]/#&=,]*\)\=\>! syntax region Normal start=!
! end=!
! syntax region Normal start=!! end=!! syntax region Normal start=!! end=!! endif endfunction " HighlightSpellingErrors() function! AddWordToDictionary() " adds the word under the cursor to the personal dictonary; used for the \sa " operation defined above; " requires the global variable PersonalDict to be defined above, and to contain " the `Ispell' personal dictionary; " " by Smylers http://www.stripey.com/vim/ " " 2000 Apr 30: for `Vim' 5.6 " get the word under the cursor, including the apostrophe as a word character " to allow for words like "won't", but then ignoring any apostrophes at the " start or end of the word: set iskeyword+=' let Word = substitute(expand(''), "^'\\+", '', '') let Word = substitute(Word, "'\\+$", '', '') set iskeyword-=' " override any SpellError highlighting that might exist for this word, " `highlighting' it as normal text: execute 'syntax match Normal #\<' . Word . '\>#' " remove any final "'s" so that possessive forms don't end up in the " dictionary, then add the word to the dictionary: let Word = substitute(Word, "'s$", '', '') execute '!echo "' . Word . '" >> ' . g:PersonalDict endfunction " AddWordToDictionary()