" vimrc - Max Baker max -at- warped.org " $Id: vimrc,v 1.7 2004/10/23 15:10:10 max Exp $ " " Change Summary : " Added Commands : " cz - add c comments (normal mode) " :cz - with range (command mode) " cx - remove c comments " :cx " :dq - delete in between quotes, including \" " - Help " - Prev Error (make) " - Next Error (make) " - Make " - DeadKeys On " - DeadKeys Off " - Spell Check " - Clear spelling errors " - Add word under cursor to dictionary (~/.ispell_english) " Ctrl-N / Ctrl-P (Insert Mode) - autocomplete from dictionary! " Color Syntax highlighting using default ANSI color escapes, " assuming black background. " Dead Keys! " " " General Settings " set magic set nobackup set nowritebackup set makeprg=gmake set et set nu set sw=4 set ts=4 set laststatus=2 set ruler set nowrap set showmatch " have command-line completion (for filenames, help topics, option names) " first list the available options and complete the longest common part, then " have further s cycle through the possibilities: set wildmode=list:longest,full " use "[RO]" for "[readonly]" to save space in the message line: set shortmess+=r " display the current mode and partially-typed commands in the status line: set showmode set showcmd " have the mouse enabled all the time: "set mouse=a " normally don't automatically format `text' as it is typed, IE only do this " with comments, at 79 characters: set formatoptions-=t "set textwidth=79 " enable filetype detection: filetype on " make searches case-insensitive, unless they contain upper-case letters: set ignorecase set smartcase " show the `best match so far' as search strings are typed: set incsearch " assume the /g flag on :s substitutions to replace all matches in a line: set gdefault "" Syntax Highlighting : " windows / gvim highlight Normal guibg=Black guifg=White set background=dark "if has("terminfo") " set t_Co=8 " set t_Sf=[3%p1%dm " set t_Sb=[4%p1%dm "else " set t_Co=8 " set t_Sf=[3%dm " set t_Sb=[4%dm "endif " Fix backspace if &term == "xterm-color" set t_kb= fixdel endif if &term == "dtterm" set t_kb= fixdel endif "Fast window resizing with +/- keys (horizontal); / and * keys (vertical) "if bufwinnr(1) " map + " map - " map < " map > "endif syn on syntax sync minlines=500 hi Comment term=bold ctermfg=lightgrey ctermbg=blue " --- Language Specific Hacks -- " -- Perl -- let perl_fold=1 " -- Java -- "let java_mark_braces_in_parens_as_errors=1 :let java_highlight_java_io=1 let java_highlight_functions=1 let java_highlight_debug=1 let java_sapce_errors=1 let java_highlight_java_lang_ids=1 let java_highlight_all=1 " let java_allow_cpp_keywords=1 " let html_my_rendering=1 " let java_javascript=1 " let java_css=1 " let java_ignore_javadoc=1 let perl_fold=1 "My commands nm :cp nm :cn nm :make nm :call DeadKeys() nm :call DeadKeysOff() " :dq - delete between quotes. Smartenough to see \" as part of the string " note \| escaped due to vimrc weirdness cm dq .s/"\(\\"\\|[^"]\)*"/""/ " :cz - c comment the line, ranges comment EACH line individually cm cz s/^\(.*\)$/\/*\1*\// " :cx - uncomment line cm cx s/^\(\s*\)\/\*\(.*\)\*\/\s*$/\1\2/ " omappings -- for cz and cx in normal mode editing (like cw command) omap z :cz omap x :cx " * Keystrokes -- Moving Around noremap noremap - " have prompt for a help topic, rather than displaying the introduction " page, and have it do this from any mode: nnoremap :help vmap omap map! " * Spelling " define `Ispell' language and personal dictionary, used in several places " below: let IspellLang = 'english' 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/share/dict/words set complete=.,w,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() nmap \sa " * 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() function! InsertCloseTag() " inserts the appropriate closing HTML tag; used for the \hc operation defined " above; " requires ignorecase to be set, or to type HTML tags in exactly the same case " that I do; " doesn't treat

as something that needs closing; " clobbers register z and mark z " " by Smylers http://www.stripey.com/vim/ " 2000 May 4 if &filetype == 'html' " list of tags which shouldn't be closed: let UnaryTags = ' Area Base Br DD DT HR Img Input LI Link Meta P Param ' " remember current position: normal mz " loop backwards looking for tags: let Found = 0 while Found == 0 " find the previous <, then go forwards one character and grab the first " character plus the entire word: execute "normal ?\\l" normal "zyl let Tag = expand('') " if this is a closing tag, skip back to its matching opening tag: if @z == '/' execute "normal ?\" . Tag . "\" " if this is a unary tag, then position the cursor for the next " iteration: elseif match(UnaryTags, ' ' . Tag . ' ') > 0 normal h " otherwise this is the tag that needs closing: else let Found = 1 endif endwhile " not yet found match " create the closing tag and insert it: let @z = '' normal `z if col('.') == 1 normal "zP else normal "zp endif else " filetype is not HTML echohl ErrorMsg echo 'The InsertCloseTag() function is only intended to be used in HTML ' . \ 'files.' sleep echohl None endif " check on filetype endfunction " InsertCloseTag() function! RepeatTag(Forward) " repeats a (non-closing) HTML tag from elsewhere in the document; call " repeatedly until the correct tag is inserted (like with insert mode +P " and +N completion), with Forward determining whether to copy forwards " or backwards through the file; used for the \hp and \hn operations defined " above; " requires preservation of marks i and j; " clobbers register z " " by Smylers http://www.stripey.com/vim/ " " 2000 May 4: for `Vim' 5.6 if &filetype == 'html' " if the cursor is where this function left it, then continue from there: if line('.') == line("'i") && col('.') == col("'i") " delete the tag inserted last time: if col('.') == strlen(getline('.')) normal dF].\\{-}>\mj\"zyf>`i" if col('.') == 1 normal "zP else normal "zp endif normal mi else " filetype is not HTML echohl ErrorMsg echo 'The RepeatTag() function is only intended to be used in HTML files.' sleep echohl None endif endfunction " RepeatTag() function! DeadKeys() :echo "Dead Keys: On" let g:DeadKeysOn=1 " map dead keys :imap "a ä :imap "A Ä :imap "e ë :imap "E Ë :imap "i ï :imap "I Ï :imap "o ö :imap "O Ö :imap "u ü :imap "U Ü :imap "y ÿ :imap " "" :imap "" "" :imap 'a á :imap 'A Á :imap 'e é :imap 'E É :imap 'i í :imap 'I Í :imap 'o ó :imap 'O Ó :imap 'u ú :imap 'U Ú :imap 'y ý :imap '' '' :imap ' '' :imap 'c ç :imap 'C Ç :imap `a à :imap `A À :imap `e è :imap `E È :imap `i ì :imap `I Ì :imap `o ò :imap `O Ò :imap `u ù :imap `U Ù :imap `` `` :imap ` `` :imap ^a â :imap ^A Â :imap ^e ê :imap ^E Ê :imap ^i î :imap ^I Î :imap ^o ô :imap ^O Ô :imap ^u û :imap ^U Û :imap ^y xxxx :iunmap ^y :imap ^^ ^^ :imap ^ ^^ :imap ~n ñ :imap ~N Ñ :imap ~~ ~~ :imap ~ ~~ endfunction " deadkeys() function! DeadKeysOff() " Make sure turning them off without having turned them on " does nothing bad. if !exists("g:DeadKeysOn") || !g:DeadKeysOn :echo "Dead Keys not on." return endif :echo "Dead Keys: Off" let g:DeadKeysOn=0 :iunmap "a :iunmap "A :iunmap "e :iunmap "E :iunmap "i :iunmap "I :iunmap "o :iunmap "O :iunmap "u :iunmap "U :iunmap "y :iunmap "" :iunmap " :iunmap 'a :iunmap 'A :iunmap 'e :iunmap 'E :iunmap 'i :iunmap 'I :iunmap 'o :iunmap 'O :iunmap 'u :iunmap 'U :iunmap 'y :iunmap ' :iunmap '' :iunmap 'c :iunmap 'C :iunmap `a :iunmap `A :iunmap `e :iunmap `E :iunmap `i :iunmap `I :iunmap `o :iunmap `O :iunmap `u :iunmap `U :iunmap ` :iunmap `` :iunmap ^a :iunmap ^A :iunmap ^e :iunmap ^E :iunmap ^i :iunmap ^I :iunmap ^o :iunmap ^O :iunmap ^u :iunmap ^U ":iunmap ^y :iunmap ^^ :iunmap ^ :iunmap ~n :iunmap ~N :iunmap ~~ :iunmap ~ endfunction