From be4c7de98dde982a9d3cf20328680344626ae962 Mon Sep 17 00:00:00 2001 From: Tony Duckles Date: Sun, 8 Aug 2010 16:26:25 -0500 Subject: [PATCH] .vim: Initial .vimrc and .vim/* --- .vim/plugin/matchit.vim | 810 +++++++++++++++++++++++++++++++++++++ .vim/scripts/closetag.vim | 327 +++++++++++++++ .vim/syntax/javascript.vim | 246 +++++++++++ .vimrc | 239 +++++++++++ 4 files changed, 1622 insertions(+) create mode 100644 .vim/plugin/matchit.vim create mode 100644 .vim/scripts/closetag.vim create mode 100644 .vim/syntax/javascript.vim create mode 100644 .vimrc diff --git a/.vim/plugin/matchit.vim b/.vim/plugin/matchit.vim new file mode 100644 index 0000000..a2f2050 --- /dev/null +++ b/.vim/plugin/matchit.vim @@ -0,0 +1,810 @@ +" matchit.vim: (global plugin) Extended "%" matching +" Last Change: Sun Feb 26 10:00 AM 2006 EST +" Maintainer: Benji Fisher PhD +" Version: 1.10, for Vim 6.3 +" URL: http://www.vim.org/script.php?script_id=39 + +" Documentation: +" The documentation is in a separate file, matchit.txt . + +" Credits: +" Vim editor by Bram Moolenaar (Thanks, Bram!) +" Original script and design by Raul Segura Acevedo +" Support for comments by Douglas Potts +" Support for back references and other improvements by Benji Fisher +" Support for many languages by Johannes Zellner +" Suggestions for improvement, bug reports, and support for additional +" languages by Jordi-Albert Batalla, Neil Bird, Servatius Brandt, Mark +" Collett, Stephen Wall, Dany St-Amant, and Johannes Zellner. + +" Debugging: +" If you'd like to try the built-in debugging commands... +" :MatchDebug to activate debugging for the current buffer +" This saves the values of several key script variables as buffer-local +" variables. See the MatchDebug() function, below, for details. + +" TODO: I should think about multi-line patterns for b:match_words. +" This would require an option: how many lines to scan (default 1). +" This would be useful for Python, maybe also for *ML. +" TODO: Maybe I should add a menu so that people will actually use some of +" the features that I have implemented. +" TODO: Eliminate the MultiMatch function. Add yet another argument to +" Match_wrapper() instead. +" TODO: Allow :let b:match_words = '\(\(foo\)\(bar\)\):\3\2:end\1' +" TODO: Make backrefs safer by using '\V' (very no-magic). +" TODO: Add a level of indirection, so that custom % scripts can use my +" work but extend it. + +" allow user to prevent loading +" and prevent duplicate loading +if exists("loaded_matchit") || &cp + finish +endif +let loaded_matchit = 1 +let s:last_mps = "" +let s:last_words = "" + +let s:save_cpo = &cpo +set cpo&vim + +nnoremap % :call Match_wrapper('',1,'n') +nnoremap g% :call Match_wrapper('',0,'n') +vnoremap % :call Match_wrapper('',1,'v') m'gv`` +vnoremap g% :call Match_wrapper('',0,'v') m'gv`` +onoremap % v:call Match_wrapper('',1,'o') +onoremap g% v:call Match_wrapper('',0,'o') + +" Analogues of [{ and ]} using matching patterns: +nnoremap [% :call MultiMatch("bW", "n") +nnoremap ]% :call MultiMatch("W", "n") +vmap [% [%m'gv`` +vmap ]% ]%m'gv`` +" vnoremap [% :call MultiMatch("bW", "v") m'gv`` +" vnoremap ]% :call MultiMatch("W", "v") m'gv`` +onoremap [% v:call MultiMatch("bW", "o") +onoremap ]% v:call MultiMatch("W", "o") + +" text object: +vmap a% [%v]% + +" Auto-complete mappings: (not yet "ready for prime time") +" TODO Read :help write-plugin for the "right" way to let the user +" specify a key binding. +" let g:match_auto = '' +" let g:match_autoCR = '' +" if exists("g:match_auto") +" execute "inoremap " . g:match_auto . ' x"=Autocomplete()Pls' +" endif +" if exists("g:match_autoCR") +" execute "inoremap " . g:match_autoCR . ' =Autocomplete()' +" endif +" if exists("g:match_gthhoh") +" execute "inoremap " . g:match_gthhoh . ' :call Gthhoh()' +" endif " gthhoh = "Get the heck out of here!" + +let s:notslash = '\\\@" + endif + " In s:CleanUp(), we may need to check whether the cursor moved forward. + let startline = line(".") + let startcol = col(".") + " Use default behavior if called with a count or if no patterns are defined. + if v:count + exe "normal! " . v:count . "%" + return s:CleanUp(restore_options, a:mode, startline, startcol) + elseif !exists("b:match_words") || b:match_words == "" + silent! normal! % + return s:CleanUp(restore_options, a:mode, startline, startcol) + end + + " First step: if not already done, set the script variables + " s:do_BR flag for whether there are backrefs + " s:pat parsed version of b:match_words + " s:all regexp based on s:pat and the default groups + " + " Allow b:match_words = "GetVimMatchWords()" . + if b:match_words =~ ":" + let match_words = b:match_words + else + execute "let match_words =" b:match_words + endif +" Thanks to Preben "Peppe" Guldberg and Bram Moolenaar for this suggestion! + if (match_words != s:last_words) || (&mps != s:last_mps) || + \ exists("b:match_debug") + let s:last_words = match_words + let s:last_mps = &mps + if match_words !~ s:notslash . '\\\d' + let s:do_BR = 0 + let s:pat = match_words + else + let s:do_BR = 1 + let s:pat = s:ParseWords(match_words) + endif + " The next several lines were here before + " BF started messing with this script. + " quote the special chars in 'matchpairs', replace [,:] with \| and then + " append the builtin pairs (/*, */, #if, #ifdef, #else, #elif, #endif) + " let default = substitute(escape(&mps, '[$^.*~\\/?]'), '[,:]\+', + " \ '\\|', 'g').'\|\/\*\|\*\/\|#if\>\|#ifdef\>\|#else\>\|#elif\>\|#endif\>' + let default = escape(&mps, '[$^.*~\\/?]') . (strlen(&mps) ? "," : "") . + \ '\/\*:\*\/,#if\%(def\)\=:#else\>:#elif\>:#endif\>' + " s:all = pattern with all the keywords + let s:all = s:pat . (strlen(s:pat) ? "," : "") . default + let s:all = substitute(s:all, s:notslash . '\zs[,:]\+', '\\|', 'g') + let s:all = '\%(' . s:all . '\)' + " let s:all = '\%(' . substitute(s:all, '\\\ze[,:]', '', 'g') . '\)' + if exists("b:match_debug") + let b:match_pat = s:pat + endif + endif + + " Second step: set the following local variables: + " matchline = line on which the cursor started + " curcol = number of characters before match + " prefix = regexp for start of line to start of match + " suffix = regexp for end of match to end of line + " Require match to end on or after the cursor and prefer it to + " start on or before the cursor. + let matchline = getline(startline) + if a:word != '' + " word given + if a:word !~ s:all + echohl WarningMsg|echo 'Missing rule for word:"'.a:word.'"'|echohl NONE + return s:CleanUp(restore_options, a:mode, startline, startcol) + endif + let matchline = a:word + let curcol = 0 + let prefix = '^\%(' + let suffix = '\)$' + " Now the case when "word" is not given + else " Find the match that ends on or after the cursor and set curcol. + let regexp = s:Wholematch(matchline, s:all, startcol-1) + let curcol = match(matchline, regexp) + let suf = strlen(matchline) - matchend(matchline, regexp) + let prefix = (curcol ? '^.\{' . curcol . '}\%(' : '^\%(') + let suffix = (suf ? '\).\{' . suf . '}$' : '\)$') + " If the match comes from the defaults, bail out. + if matchline !~ prefix . + \ substitute(s:pat, s:notslash.'\zs[,:]\+', '\\|', 'g') . suffix + silent! norm! % + return s:CleanUp(restore_options, a:mode, startline, startcol) + endif + endif + if exists("b:match_debug") + let b:match_match = matchstr(matchline, regexp) + let b:match_col = curcol+1 + endif + + " Third step: Find the group and single word that match, and the original + " (backref) versions of these. Then, resolve the backrefs. + " Set the following local variable: + " group = colon-separated list of patterns, one of which matches + " = ini:mid:fin or ini:fin + " + " Reconstruct the version with unresolved backrefs. + let patBR = substitute(match_words.',', + \ s:notslash.'\zs[,:]*,[,:]*', ',', 'g') + let patBR = substitute(patBR, s:notslash.'\zs:\{2,}', ':', 'g') + " Now, set group and groupBR to the matching group: 'if:endif' or + " 'while:endwhile' or whatever. A bit of a kluge: s:Choose() returns + " group . "," . groupBR, and we pick it apart. + let group = s:Choose(s:pat, matchline, ",", ":", prefix, suffix, patBR) + let i = matchend(group, s:notslash . ",") + let groupBR = strpart(group, i) + let group = strpart(group, 0, i-1) + " Now, matchline =~ prefix . substitute(group,':','\|','g') . suffix + if s:do_BR " Do the hard part: resolve those backrefs! + let group = s:InsertRefs(groupBR, prefix, group, suffix, matchline) + endif + if exists("b:match_debug") + let b:match_wholeBR = groupBR + let i = matchend(groupBR, s:notslash . ":") + let b:match_iniBR = strpart(groupBR, 0, i-1) + endif + + " Fourth step: Set the arguments for searchpair(). + let i = matchend(group, s:notslash . ":") + let j = matchend(group, '.*' . s:notslash . ":") + let ini = strpart(group, 0, i-1) + let mid = substitute(strpart(group, i,j-i-1), s:notslash.'\zs:', '\\|', 'g') + let fin = strpart(group, j) + "Un-escape the remaining , and : characters. + let ini = substitute(ini, s:notslash . '\zs\\\(:\|,\)', '\1', 'g') + let mid = substitute(mid, s:notslash . '\zs\\\(:\|,\)', '\1', 'g') + let fin = substitute(fin, s:notslash . '\zs\\\(:\|,\)', '\1', 'g') + " searchpair() requires that these patterns avoid \(\) groups. + let ini = substitute(ini, s:notslash . '\zs\\(', '\\%(', 'g') + let mid = substitute(mid, s:notslash . '\zs\\(', '\\%(', 'g') + let fin = substitute(fin, s:notslash . '\zs\\(', '\\%(', 'g') + " Set mid. This is optimized for readability, not micro-efficiency! + if a:forward && matchline =~ prefix . fin . suffix + \ || !a:forward && matchline =~ prefix . ini . suffix + let mid = "" + endif + " Set flag. This is optimized for readability, not micro-efficiency! + if a:forward && matchline =~ prefix . fin . suffix + \ || !a:forward && matchline !~ prefix . ini . suffix + let flag = "bW" + else + let flag = "W" + endif + " Set skip. + if exists("b:match_skip") + let skip = b:match_skip + elseif exists("b:match_comment") " backwards compatibility and testing! + let skip = "r:" . b:match_comment + else + let skip = 's:comment\|string' + endif + let skip = s:ParseSkip(skip) + if exists("b:match_debug") + let b:match_ini = ini + let b:match_tail = (strlen(mid) ? mid.'\|' : '') . fin + endif + + " Fifth step: actually start moving the cursor and call searchpair(). + " Later, :execute restore_cursor to get to the original screen. + let restore_cursor = virtcol(".") . "|" + normal! g0 + let restore_cursor = line(".") . "G" . virtcol(".") . "|zs" . restore_cursor + normal! H + let restore_cursor = "normal!" . line(".") . "Gzt" . restore_cursor + execute restore_cursor + normal! 0 + if curcol + execute "normal!" . curcol . "l" + endif + if skip =~ 'synID' && !(has("syntax") && exists("g:syntax_on")) + let skip = "0" + else + execute "if " . skip . "| let skip = '0' | endif" + endif + let sp_return = searchpair(ini, mid, fin, flag, skip) + let final_position = "call cursor(" . line(".") . "," . col(".") . ")" + " Restore cursor position and original screen. + execute restore_cursor + normal! m' + if sp_return > 0 + execute final_position + endif + return s:CleanUp(restore_options, a:mode, startline, startcol, mid.'\|'.fin) +endfun + +" Restore options and do some special handling for Operator-pending mode. +" The optional argument is the tail of the matching group. +fun! s:CleanUp(options, mode, startline, startcol, ...) + execute "set" a:options + " Open folds, if appropriate. + if a:mode != "o" + if &foldopen =~ "percent" + normal! zv + endif + " In Operator-pending mode, we want to include the whole match + " (for example, d%). + " This is only a problem if we end up moving in the forward direction. + elseif (a:startline < line(".")) || + \ (a:startline == line(".") && a:startcol < col(".")) + if a:0 + " Check whether the match is a single character. If not, move to the + " end of the match. + let matchline = getline(".") + let currcol = col(".") + let regexp = s:Wholematch(matchline, a:1, currcol-1) + let endcol = matchend(matchline, regexp) + if endcol > currcol " This is NOT off by one! + execute "normal!" . (endcol - currcol) . "l" + endif + endif " a:0 + endif " a:mode != "o" && etc. + return 0 +endfun + +" Example (simplified HTML patterns): if +" a:groupBR = '<\(\k\+\)>:' +" a:prefix = '^.\{3}\(' +" a:group = '<\(\k\+\)>:' +" a:suffix = '\).\{2}$' +" a:matchline = "12312" or "12312" +" then extract "tag" from a:matchline and return ":" . +fun! s:InsertRefs(groupBR, prefix, group, suffix, matchline) + if a:matchline !~ a:prefix . + \ substitute(a:group, s:notslash . '\zs:', '\\|', 'g') . a:suffix + return a:group + endif + let i = matchend(a:groupBR, s:notslash . ':') + let ini = strpart(a:groupBR, 0, i-1) + let tailBR = strpart(a:groupBR, i) + let word = s:Choose(a:group, a:matchline, ":", "", a:prefix, a:suffix, + \ a:groupBR) + let i = matchend(word, s:notslash . ":") + let wordBR = strpart(word, i) + let word = strpart(word, 0, i-1) + " Now, a:matchline =~ a:prefix . word . a:suffix + if wordBR != ini + let table = s:Resolve(ini, wordBR, "table") + else + " let table = "----------" + let table = "" + let d = 0 + while d < 10 + if tailBR =~ s:notslash . '\\' . d + " let table[d] = d + let table = table . d + else + let table = table . "-" + endif + let d = d + 1 + endwhile + endif + let d = 9 + while d + if table[d] != "-" + let backref = substitute(a:matchline, a:prefix.word.a:suffix, + \ '\'.table[d], "") + " Are there any other characters that should be escaped? + let backref = escape(backref, '*,:') + execute s:Ref(ini, d, "start", "len") + let ini = strpart(ini, 0, start) . backref . strpart(ini, start+len) + let tailBR = substitute(tailBR, s:notslash . '\zs\\' . d, + \ escape(backref, '\\'), 'g') + endif + let d = d-1 + endwhile + if exists("b:match_debug") + if s:do_BR + let b:match_table = table + let b:match_word = word + else + let b:match_table = "" + let b:match_word = "" + endif + endif + return ini . ":" . tailBR +endfun + +" Input a comma-separated list of groups with backrefs, such as +" a:groups = '\(foo\):end\1,\(bar\):end\1' +" and return a comma-separated list of groups with backrefs replaced: +" return '\(foo\):end\(foo\),\(bar\):end\(bar\)' +fun! s:ParseWords(groups) + let groups = substitute(a:groups.",", s:notslash.'\zs[,:]*,[,:]*', ',', 'g') + let groups = substitute(groups, s:notslash . '\zs:\{2,}', ':', 'g') + let parsed = "" + while groups =~ '[^,:]' + let i = matchend(groups, s:notslash . ':') + let j = matchend(groups, s:notslash . ',') + let ini = strpart(groups, 0, i-1) + let tail = strpart(groups, i, j-i-1) . ":" + let groups = strpart(groups, j) + let parsed = parsed . ini + let i = matchend(tail, s:notslash . ':') + while i != -1 + " In 'if:else:endif', ini='if' and word='else' and then word='endif'. + let word = strpart(tail, 0, i-1) + let tail = strpart(tail, i) + let i = matchend(tail, s:notslash . ':') + let parsed = parsed . ":" . s:Resolve(ini, word, "word") + endwhile " Now, tail has been used up. + let parsed = parsed . "," + endwhile " groups =~ '[^,:]' + return parsed +endfun + +" TODO I think this can be simplified and/or made more efficient. +" TODO What should I do if a:start is out of range? +" Return a regexp that matches all of a:string, such that +" matchstr(a:string, regexp) represents the match for a:pat that starts +" as close to a:start as possible, before being preferred to after, and +" ends after a:start . +" Usage: +" let regexp = s:Wholematch(getline("."), 'foo\|bar', col(".")-1) +" let i = match(getline("."), regexp) +" let j = matchend(getline("."), regexp) +" let match = matchstr(getline("."), regexp) +fun! s:Wholematch(string, pat, start) + let group = '\%(' . a:pat . '\)' + let prefix = (a:start ? '\(^.\{,' . a:start . '}\)\zs' : '^') + let len = strlen(a:string) + let suffix = (a:start+1 < len ? '\(.\{,'.(len-a:start-1).'}$\)\@=' : '$') + if a:string !~ prefix . group . suffix + let prefix = '' + endif + return prefix . group . suffix +endfun + +" No extra arguments: s:Ref(string, d) will +" find the d'th occurrence of '\(' and return it, along with everything up +" to and including the matching '\)'. +" One argument: s:Ref(string, d, "start") returns the index of the start +" of the d'th '\(' and any other argument returns the length of the group. +" Two arguments: s:Ref(string, d, "foo", "bar") returns a string to be +" executed, having the effect of +" :let foo = s:Ref(string, d, "start") +" :let bar = s:Ref(string, d, "len") +fun! s:Ref(string, d, ...) + let len = strlen(a:string) + if a:d == 0 + let start = 0 + else + let cnt = a:d + let match = a:string + while cnt + let cnt = cnt - 1 + let index = matchend(match, s:notslash . '\\(') + if index == -1 + return "" + endif + let match = strpart(match, index) + endwhile + let start = len - strlen(match) + if a:0 == 1 && a:1 == "start" + return start - 2 + endif + let cnt = 1 + while cnt + let index = matchend(match, s:notslash . '\\(\|\\)') - 1 + if index == -2 + return "" + endif + " Increment if an open, decrement if a ')': + let cnt = cnt + (match[index]=="(" ? 1 : -1) " ')' + " let cnt = stridx('0(', match[index]) + cnt + let match = strpart(match, index+1) + endwhile + let start = start - 2 + let len = len - start - strlen(match) + endif + if a:0 == 1 + return len + elseif a:0 == 2 + return "let " . a:1 . "=" . start . "| let " . a:2 . "=" . len + else + return strpart(a:string, start, len) + endif +endfun + +" Count the number of disjoint copies of pattern in string. +" If the pattern is a literal string and contains no '0' or '1' characters +" then s:Count(string, pattern, '0', '1') should be faster than +" s:Count(string, pattern). +fun! s:Count(string, pattern, ...) + let pat = escape(a:pattern, '\\') + if a:0 > 1 + let foo = substitute(a:string, '[^'.a:pattern.']', "a:1", "g") + let foo = substitute(a:string, pat, a:2, "g") + let foo = substitute(foo, '[^' . a:2 . ']', "", "g") + return strlen(foo) + endif + let result = 0 + let foo = a:string + let index = matchend(foo, pat) + while index != -1 + let result = result + 1 + let foo = strpart(foo, index) + let index = matchend(foo, pat) + endwhile + return result +endfun + +" s:Resolve('\(a\)\(b\)', '\(c\)\2\1\1\2') should return table.word, where +" word = '\(c\)\(b\)\(a\)\3\2' and table = '-32-------'. That is, the first +" '\1' in target is replaced by '\(a\)' in word, table[1] = 3, and this +" indicates that all other instances of '\1' in target are to be replaced +" by '\3'. The hard part is dealing with nesting... +" Note that ":" is an illegal character for source and target, +" unless it is preceded by "\". +fun! s:Resolve(source, target, output) + let word = a:target + let i = matchend(word, s:notslash . '\\\d') - 1 + let table = "----------" + while i != -2 " There are back references to be replaced. + let d = word[i] + let backref = s:Ref(a:source, d) + " The idea is to replace '\d' with backref. Before we do this, + " replace any \(\) groups in backref with :1, :2, ... if they + " correspond to the first, second, ... group already inserted + " into backref. Later, replace :1 with \1 and so on. The group + " number w+b within backref corresponds to the group number + " s within a:source. + " w = number of '\(' in word before the current one + let w = s:Count( + \ substitute(strpart(word, 0, i-1), '\\\\', '', 'g'), '\(', '1') + let b = 1 " number of the current '\(' in backref + let s = d " number of the current '\(' in a:source + while b <= s:Count(substitute(backref, '\\\\', '', 'g'), '\(', '1') + \ && s < 10 + if table[s] == "-" + if w + b < 10 + " let table[s] = w + b + let table = strpart(table, 0, s) . (w+b) . strpart(table, s+1) + endif + let b = b + 1 + let s = s + 1 + else + execute s:Ref(backref, b, "start", "len") + let ref = strpart(backref, start, len) + let backref = strpart(backref, 0, start) . ":". table[s] + \ . strpart(backref, start+len) + let s = s + s:Count(substitute(ref, '\\\\', '', 'g'), '\(', '1') + endif + endwhile + let word = strpart(word, 0, i-1) . backref . strpart(word, i+1) + let i = matchend(word, s:notslash . '\\\d') - 1 + endwhile + let word = substitute(word, s:notslash . '\zs:', '\\', 'g') + if a:output == "table" + return table + elseif a:output == "word" + return word + else + return table . word + endif +endfun + +" Assume a:comma = ",". Then the format for a:patterns and a:1 is +" a:patterns = ",,..." +" a:1 = ",,..." +" If is the first pattern that matches a:string then return +" if no optional arguments are given; return , if a:1 is given. +fun! s:Choose(patterns, string, comma, branch, prefix, suffix, ...) + let tail = (a:patterns =~ a:comma."$" ? a:patterns : a:patterns . a:comma) + let i = matchend(tail, s:notslash . a:comma) + if a:0 + let alttail = (a:1 =~ a:comma."$" ? a:1 : a:1 . a:comma) + let j = matchend(alttail, s:notslash . a:comma) + endif + let current = strpart(tail, 0, i-1) + if a:branch == "" + let currpat = current + else + let currpat = substitute(current, s:notslash . a:branch, '\\|', 'g') + endif + while a:string !~ a:prefix . currpat . a:suffix + let tail = strpart(tail, i) + let i = matchend(tail, s:notslash . a:comma) + if i == -1 + return -1 + endif + let current = strpart(tail, 0, i-1) + if a:branch == "" + let currpat = current + else + let currpat = substitute(current, s:notslash . a:branch, '\\|', 'g') + endif + if a:0 + let alttail = strpart(alttail, j) + let j = matchend(alttail, s:notslash . a:comma) + endif + endwhile + if a:0 + let current = current . a:comma . strpart(alttail, 0, j-1) + endif + return current +endfun + +" Call this function to turn on debugging information. Every time the main +" script is run, buffer variables will be saved. These can be used directly +" or viewed using the menu items below. +if !exists(":MatchDebug") + command! -nargs=0 MatchDebug call s:Match_debug() +endif + +fun! s:Match_debug() + let b:match_debug = 1 " Save debugging information. + " pat = all of b:match_words with backrefs parsed + amenu &Matchit.&pat :echo b:match_pat + " match = bit of text that is recognized as a match + amenu &Matchit.&match :echo b:match_match + " curcol = cursor column of the start of the matching text + amenu &Matchit.&curcol :echo b:match_col + " wholeBR = matching group, original version + amenu &Matchit.wh&oleBR :echo b:match_wholeBR + " iniBR = 'if' piece, original version + amenu &Matchit.ini&BR :echo b:match_iniBR + " ini = 'if' piece, with all backrefs resolved from match + amenu &Matchit.&ini :echo b:match_ini + " tail = 'else\|endif' piece, with all backrefs resolved from match + amenu &Matchit.&tail :echo b:match_tail + " fin = 'endif' piece, with all backrefs resolved from match + amenu &Matchit.&word :echo b:match_word + " '\'.d in ini refers to the same thing as '\'.table[d] in word. + amenu &Matchit.t&able :echo '0:' . b:match_table . ':9' +endfun + +" Jump to the nearest unmatched "(" or "if" or "" if a:spflag == "bW" +" or the nearest unmatched "" or "endif" or ")" if a:spflag == "W". +" Return a "mark" for the original position, so that +" let m = MultiMatch("bW", "n") ... execute m +" will return to the original position. If there is a problem, do not +" move the cursor and return "", unless a count is given, in which case +" go up or down as many levels as possible and again return "". +" TODO This relies on the same patterns as % matching. It might be a good +" idea to give it its own matching patterns. +fun! s:MultiMatch(spflag, mode) + if !exists("b:match_words") || b:match_words == "" + return "" + end + let restore_options = (&ic ? "" : "no") . "ignorecase" + if exists("b:match_ignorecase") + let &ignorecase = b:match_ignorecase + endif + let startline = line(".") + let startcol = col(".") + + " First step: if not already done, set the script variables + " s:do_BR flag for whether there are backrefs + " s:pat parsed version of b:match_words + " s:all regexp based on s:pat and the default groups + " This part is copied and slightly modified from s:Match_wrapper(). + let default = escape(&mps, '[$^.*~\\/?]') . (strlen(&mps) ? "," : "") . + \ '\/\*:\*\/,#if\%(def\)\=:$else\>:#elif\>:#endif\>' + " Allow b:match_words = "GetVimMatchWords()" . + if b:match_words =~ ":" + let match_words = b:match_words + else + execute "let match_words =" b:match_words + endif + if (match_words != s:last_words) || (&mps != s:last_mps) || + \ exists("b:match_debug") + let s:last_words = match_words + let s:last_mps = &mps + if match_words !~ s:notslash . '\\\d' + let s:do_BR = 0 + let s:pat = match_words + else + let s:do_BR = 1 + let s:pat = s:ParseWords(match_words) + endif + let s:all = '\%(' . substitute(s:pat . (strlen(s:pat)?",":"") . default, + \ '[,:]\+','\\|','g') . '\)' + if exists("b:match_debug") + let b:match_pat = s:pat + endif + endif + + " Second step: figure out the patterns for searchpair() + " and save the screen, cursor position, and 'ignorecase'. + " - TODO: A lot of this is copied from s:Match_wrapper(). + " - maybe even more functionality should be split off + " - into separate functions! + let cdefault = (s:pat =~ '[^,]$' ? "," : "") . default + let open = substitute(s:pat . cdefault, ':[^,]*,', '\\),\\(', 'g') + let open = '\(' . substitute(open, ':[^,]*$', '\\)', '') + let close = substitute(s:pat . cdefault, ',[^,]*:', '\\),\\(', 'g') + let close = substitute(close, '[^,]*:', '\\(', '') . '\)' + if exists("b:match_skip") + let skip = b:match_skip + elseif exists("b:match_comment") " backwards compatibility and testing! + let skip = "r:" . b:match_comment + else + let skip = 's:comment\|string' + endif + let skip = s:ParseSkip(skip) + " let restore_cursor = line(".") . "G" . virtcol(".") . "|" + " normal! H + " let restore_cursor = "normal!" . line(".") . "Gzt" . restore_cursor + let restore_cursor = virtcol(".") . "|" + normal! g0 + let restore_cursor = line(".") . "G" . virtcol(".") . "|zs" . restore_cursor + normal! H + let restore_cursor = "normal!" . line(".") . "Gzt" . restore_cursor + execute restore_cursor + + " Third step: call searchpair(). + " Replace '\('--but not '\\('--with '\%(' and ',' with '\|'. + let openpat = substitute(open, '\(\\\@" or ... +" and return "endif" or "endwhile" or "" or ... . +" For now, this uses b:match_words and the same script variables +" as s:Match_wrapper() . Later, it may get its own patterns, +" either from a buffer variable or passed as arguments. +" fun! s:Autocomplete() +" echo "autocomplete not yet implemented :-(" +" if !exists("b:match_words") || b:match_words == "" +" return "" +" end +" let startpos = s:MultiMatch("bW") +" +" if startpos == "" +" return "" +" endif +" " - TODO: figure out whether 'if' or '' matched, and construct +" " - the appropriate closing. +" let matchline = getline(".") +" let curcol = col(".") - 1 +" " - TODO: Change the s:all argument if there is a new set of match pats. +" let regexp = s:Wholematch(matchline, s:all, curcol) +" let suf = strlen(matchline) - matchend(matchline, regexp) +" let prefix = (curcol ? '^.\{' . curcol . '}\%(' : '^\%(') +" let suffix = (suf ? '\).\{' . suf . '}$' : '\)$') +" " Reconstruct the version with unresolved backrefs. +" let patBR = substitute(b:match_words.',', '[,:]*,[,:]*', ',', 'g') +" let patBR = substitute(patBR, ':\{2,}', ':', "g") +" " Now, set group and groupBR to the matching group: 'if:endif' or +" " 'while:endwhile' or whatever. +" let group = s:Choose(s:pat, matchline, ",", ":", prefix, suffix, patBR) +" let i = matchend(group, s:notslash . ",") +" let groupBR = strpart(group, i) +" let group = strpart(group, 0, i-1) +" " Now, matchline =~ prefix . substitute(group,':','\|','g') . suffix +" if s:do_BR +" let group = s:InsertRefs(groupBR, prefix, group, suffix, matchline) +" endif +" " let g:group = group +" +" " - TODO: Construct the closing from group. +" let fake = "end" . expand("") +" execute startpos +" return fake +" endfun + +" Close all open structures. "Get the heck out of here!" +" fun! s:Gthhoh() +" let close = s:Autocomplete() +" while strlen(close) +" put=close +" let close = s:Autocomplete() +" endwhile +" endfun + +" Parse special strings as typical skip arguments for searchpair(): +" s:foo becomes (current syntax item) =~ foo +" S:foo becomes (current syntax item) !~ foo +" r:foo becomes (line before cursor) =~ foo +" R:foo becomes (line before cursor) !~ foo +fun! s:ParseSkip(str) + let skip = a:str + if skip[1] == ":" + if skip[0] == "s" + let skip = "synIDattr(synID(line('.'),col('.'),1),'name') =~? '" . + \ strpart(skip,2) . "'" + elseif skip[0] == "S" + let skip = "synIDattr(synID(line('.'),col('.'),1),'name') !~? '" . + \ strpart(skip,2) . "'" + elseif skip[0] == "r" + let skip = "strpart(getline('.'),0,col('.'))=~'" . strpart(skip,2). "'" + elseif skip[0] == "R" + let skip = "strpart(getline('.'),0,col('.'))!~'" . strpart(skip,2). "'" + endif + endif + return skip +endfun + +let &cpo = s:save_cpo + +" vim:sts=2:sw=2: diff --git a/.vim/scripts/closetag.vim b/.vim/scripts/closetag.vim new file mode 100644 index 0000000..6ce41fb --- /dev/null +++ b/.vim/scripts/closetag.vim @@ -0,0 +1,327 @@ +" File: closetag.vim +" Summary: Functions and mappings to close open HTML/XML tags +" Uses: -- close matching open tag +" Author: Steven Mueller +" Last Modified: Tue May 24 13:29:48 PDT 2005 +" Version: 0.9.1 +" XXX - breaks if close attempted while XIM is in preedit mode +" TODO - allow usability as a global plugin - +" Add g:unaryTagsStack - always contains html tags settings +" and g:closetag_default_xml - user should define this to default to xml +" When a close is attempted but b:unaryTagsStack undefined, +" use b:closetag_html_style to determine if the file is to be treated +" as html or xml. Failing that, check the filetype for xml or html. +" Finally, default to g:closetag_html_style. +" If the file is html, let b:unaryTagsStack=g:unaryTagsStack +" otherwise, let b:unaryTagsStack="" +" TODO - make matching work for all comments +" -- kinda works now, but needs syn sync minlines to be very long +" -- Only check whether in syntax in the beginning, then store comment tags +" in the tagstacks to determine whether to move into or out of comment mode +" TODO - The new normal mode mapping clears recent messages with its , and +" it doesn't fix the null-undo issue for vim 5.7 anyway. +" TODO - make use of the following neat features: +" -- the ternary ?: operator +" -- :echomsg and :echoerr +" -- curly brace expansion for variables and function name definitions? +" -- check up on map \FuncName +" +" Description: +" This script eases redundant typing when writing html or xml files (even if +" you're very good with ctrl-p and ctrl-n :). Hitting ctrl-_ will initiate a +" search for the most recent open tag above that is not closed in the +" intervening space and then insert the matching close tag at the cursor. In +" normal mode, the close tag is inserted one character after cursor rather than +" at it, as if a had been used. This allows putting close tags at the +" ends of lines while in normal mode, but disallows inserting them in the +" first column. +" +" For HTML, a configurable list of tags are ignored in the matching process. +" By default, the following tags will not be matched and thus not closed +" automatically: area, base, br, dd, dt, hr, img, input, link, meta, and +" param. +" +" For XML, all tags must have a closing match or be terminated by />, as in +" . These empty element tags are ignored for matching. +" +" Comment checking is now handled by vim's internal syntax checking. If tag +" closing is initiated outside a comment, only tags outside of comments will +" be matched. When closing tags in comments, only tags within comments will +" be matched, skipping any non-commented out code (wee!). However, the +" process of determining the syntax ID of an arbitrary position can still be +" erroneous if a comment is not detected because the syntax highlighting is +" out of sync, or really slow if syn sync minlines is large. +" Set the b:closetag_disable_synID variable to disable this feature if you +" have really big chunks of comment in your code and closing tags is too slow. +" +" If syntax highlighting is not enabled, comments will not be handled very +" well. Commenting out HTML in certain ways may cause a "tag mismatch" +" message and no completion. For example, '' +" between the cursor and the most recent unclosed open tag above causes +" trouble. Properly matched well formed tags in comments don't cause a +" problem. +" +" Install: +" To use, place this file in your standard vim scripts directory, and source +" it while editing the file you wish to close tags in. If the filetype is not +" set or the file is some sort of template with embedded HTML, you may force +" HTML style tag matching by first defining the b:closetag_html_style buffer +" variable. Otherwise, the default is XML style tag matching. +" +" Example: +" :let b:closetag_html_style=1 +" :source ~/.vim/scripts/closetag.vim +" +" For greater convenience, load this script in an autocommand: +" :au Filetype html,xml,xsl source ~/.vim/scripts/closetag.vim +" +" Also, set noignorecase for html files or edit b:unaryTagsStack to match your +" capitalization style. You may set this variable before or after loading the +" script, or simply change the file itself. +" +" Configuration Variables: +" +" b:unaryTagsStack Buffer local string containing a whitespace +" seperated list of element names that should be +" ignored while finding matching closetags. Checking +" is done according to the current setting of the +" ignorecase option. +" +" b:closetag_html_style Define this (as with let b:closetag_html_style=1) +" and source the script again to set the +" unaryTagsStack to its default value for html. +" +" b:closetag_disable_synID Define this to disable comment checking if tag +" closing is too slow. This can be set or unset +" without having to source again. +" +" Changelog: +" May 24, 2005 Tuesday +" * Changed function names to be script-local to avoid conflicts with other +" scripts' stack implementations. +" +" June 07, 2001 Thursday +" * Added comment handling. Currently relies on synID, so if syn sync +" minlines is small, the chance for failure is high, but if minlines is +" large, tagclosing becomes rather slow... +" +" * Changed normal mode closetag mapping to use in insert mode +" rather than p in normal mode. This has 2 implications: +" - Tag closing no longer clobbers the unnamed register +" - When tag closing fails or finds no match, no longer adds to the undo +" buffer for recent vim 6.0 development versions. +" - However, clears the last message when closing tags in normal mode +" +" * Changed the closetag_html_style variable to be buffer-local rather than +" global. +" +" * Expanded documentation + +"------------------------------------------------------------------------------ +" User configurable settings +"------------------------------------------------------------------------------ + +" if html, don't close certain tags. Works best if ignorecase is set. +" otherwise, capitalize these elements according to your html editing style +if !exists("b:unaryTagsStack") || exists("b:closetag_html_style") + if &filetype == "html" || exists("b:closetag_html_style") + let b:unaryTagsStack="area base br dd dt hr img input link meta param" + else " for xsl and xsl + let b:unaryTagsStack="" + endif +endif + +" Has this already been loaded? +if exists("loaded_closetag") + finish +endif +let loaded_closetag=1 + +" set up mappings for tag closing +inoremap =GetCloseTag() +map a + +"------------------------------------------------------------------------------ +" Tag closer - uses the stringstack implementation below +"------------------------------------------------------------------------------ + +" Returns the most recent unclosed tag-name +" (ignores tags in the variable referenced by a:unaryTagsStack) +function! GetLastOpenTag(unaryTagsStack) + " Search backwards through the file line by line using getline() + " Overall strategy (moving backwards through the file from the cursor): + " Push closing tags onto a stack. + " On an opening tag, if the tag matches the stack top, discard both. + " -- if the tag doesn't match, signal an error. + " -- if the stack is empty, use this tag + let linenum=line(".") + let lineend=col(".") - 1 " start: cursor position + let first=1 " flag for first line searched + let b:TagStack="" " main stack of tags + let startInComment=s:InComment() + + let tagpat='' + " Search for: closing tags + while (linenum>0) + " Every time we see an end-tag, we push it on the stack. When we see an + " open tag, if the stack isn't empty, we pop it and see if they match. + " If no, signal an error. + " If yes, continue searching backwards. + " If stack is empty, return this open tag as the one that needs closing. + let line=getline(linenum) + if first + let line=strpart(line,0,lineend) + else + let lineend=strlen(line) + endif + let b:lineTagStack="" + let mpos=0 + let b:TagCol=0 + " Search the current line in the forward direction, pushing any tags + " onto a special stack for the current line + while (mpos > -1) + let mpos=matchend(line,tagpat) + if mpos > -1 + let b:TagCol=b:TagCol+mpos + let tag=matchstr(line,tagpat) + + if exists("b:closetag_disable_synID") || startInComment==s:InCommentAt(linenum, b:TagCol) + let b:TagLine=linenum + call s:Push(matchstr(tag,'[^<>]\+'),"b:lineTagStack") + endif + "echo "Tag: ".tag." ending at position ".mpos." in '".line."'." + let lineend=lineend-mpos + let line=strpart(line,mpos,lineend) + endif + endwhile + " Process the current line stack + while (!s:EmptystackP("b:lineTagStack")) + let tag=s:Pop("b:lineTagStack") + if match(tag, "^/") == 0 "found end tag + call s:Push(tag,"b:TagStack") + "echo linenum." ".b:TagStack + elseif s:EmptystackP("b:TagStack") && !s:Instack(tag, a:unaryTagsStack) "found unclosed tag + return tag + else + let endtag=s:Peekstack("b:TagStack") + if endtag == "/".tag || endtag == "/" + call s:Pop("b:TagStack") "found a open/close tag pair + "echo linenum." ".b:TagStack + elseif !s:Instack(tag, a:unaryTagsStack) "we have a mismatch error + echohl Error + echon "\rError:" + echohl None + echo " tag mismatch: <".tag."> doesn't match <".endtag.">. (Line ".linenum." Tagstack: ".b:TagStack.")" + return "" + endif + endif + endwhile + let linenum=linenum-1 | let first=0 + endwhile + " At this point, we have exhausted the file and not found any opening tag + echo "No opening tags." + return "" +endfunction + +" Returns closing tag for most recent unclosed tag, respecting the +" current setting of b:unaryTagsStack for tags that should not be closed +function! GetCloseTag() + let tag=GetLastOpenTag("b:unaryTagsStack") + if tag == "" + return "" + else + return "" + endif +endfunction + +" return 1 if the cursor is in a syntactically identified comment field +" (fails for empty lines: always returns not-in-comment) +function! s:InComment() + return synIDattr(synID(line("."), col("."), 0), "name") =~ 'Comment' +endfunction + +" return 1 if the position specified is in a syntactically identified comment field +function! s:InCommentAt(line, col) + return synIDattr(synID(a:line, a:col, 0), "name") =~ 'Comment' +endfunction + +"------------------------------------------------------------------------------ +" String Stacks +"------------------------------------------------------------------------------ +" These are strings of whitespace-separated elements, matched using the \< and +" \> patterns after setting the iskeyword option. +" +" The sname argument should contain a symbolic reference to the stack variable +" on which method should operate on (i.e., sname should be a string containing +" a fully qualified (ie: g:, b:, etc) variable name.) + +" Helper functions +function! s:SetKeywords() + let g:IsKeywordBak=&iskeyword + let &iskeyword="33-255" +endfunction + +function! s:RestoreKeywords() + let &iskeyword=g:IsKeywordBak +endfunction + +" Push el onto the stack referenced by sname +function! s:Push(el, sname) + if !s:EmptystackP(a:sname) + exe "let ".a:sname."=a:el.' '.".a:sname + else + exe "let ".a:sname."=a:el" + endif +endfunction + +" Check whether the stack is empty +function! s:EmptystackP(sname) + exe "let stack=".a:sname + if match(stack,"^ *$") == 0 + return 1 + else + return 0 + endif +endfunction + +" Return 1 if el is in stack sname, else 0. +function! s:Instack(el, sname) + exe "let stack=".a:sname + call s:SetKeywords() + let m=match(stack, "\\<".a:el."\\>") + call s:RestoreKeywords() + if m < 0 + return 0 + else + return 1 + endif +endfunction + +" Return the first element in the stack +function! s:Peekstack(sname) + call s:SetKeywords() + exe "let stack=".a:sname + let top=matchstr(stack, "\\<.\\{-1,}\\>") + call s:RestoreKeywords() + return top +endfunction + +" Remove and return the first element in the stack +function! s:Pop(sname) + if s:EmptystackP(a:sname) + echo "Error! Stack ".a:sname." is empty and can't be popped." + return "" + endif + exe "let stack=".a:sname + " Find the first space, loc is 0-based. Marks the end of 1st elt in stack. + call s:SetKeywords() + let loc=matchend(stack,"\\<.\\{-1,}\\>") + exe "let ".a:sname."=strpart(stack, loc+1, strlen(stack))" + let top=strpart(stack, match(stack, "\\<"), loc) + call s:RestoreKeywords() + return top +endfunction + +function! s:Clearstack(sname) + exe "let ".a:sname."=''" +endfunction diff --git a/.vim/syntax/javascript.vim b/.vim/syntax/javascript.vim new file mode 100644 index 0000000..3ba7fca --- /dev/null +++ b/.vim/syntax/javascript.vim @@ -0,0 +1,246 @@ +" Vim syntax file +" Language: JavaScript +" Maintainer: Yi Zhao (ZHAOYI) +" Last Change: June 4, 2009 +" Version: 0.7.7 +" Changes: Add "undefined" as a type keyword +" +" TODO: +" - Add the HTML syntax inside the JSDoc + +if !exists("main_syntax") + if version < 600 + syntax clear + elseif exists("b:current_syntax") + finish + endif + let main_syntax = 'javascript' +endif + +"" Drop fold if it set but VIM doesn't support it. +let b:javascript_fold='true' +if version < 600 " Don't support the old version + unlet! b:javascript_fold +endif + +"" dollar sigh is permittd anywhere in an identifier +setlocal iskeyword+=$ + +syntax sync fromstart + +"" JavaScript comments +syntax keyword javaScriptCommentTodo TODO FIXME XXX TBD contained +syntax region javaScriptLineComment start=+\/\/+ end=+$+ keepend contains=javaScriptCommentTodo,@Spell +syntax region javaScriptLineComment start=+^\s*\/\/+ skip=+\n\s*\/\/+ end=+$+ keepend contains=javaScriptCommentTodo,@Spell fold +syntax region javaScriptCvsTag start="\$\cid:" end="\$" oneline contained +syntax region javaScriptComment start="/\*" end="\*/" contains=javaScriptCommentTodo,javaScriptCvsTag,@Spell fold + +"" JSDoc support start +if !exists("javascript_ignore_javaScriptdoc") + syntax case ignore + + "" syntax coloring for javadoc comments (HTML) + "syntax include @javaHtml :p:h/html.vim + "unlet b:current_syntax + + syntax region javaScriptDocComment matchgroup=javaScriptComment start="/\*\*\s*$" end="\*/" contains=javaScriptDocTags,javaScriptCommentTodo,javaScriptCvsTag,@javaScriptHtml,@Spell fold + syntax match javaScriptDocTags contained "@\(param\|argument\|requires\|exception\|throws\|type\|class\|extends\|see\|link\|member\|module\|method\|title\|namespace\|optional\|default\|base\|file\)\>" nextgroup=javaScriptDocParam,javaScriptDocSeeTag skipwhite + syntax match javaScriptDocTags contained "@\(beta\|deprecated\|description\|fileoverview\|author\|license\|version\|returns\=\|constructor\|private\|protected\|final\|ignore\|addon\|exec\)\>" + syntax match javaScriptDocParam contained "\%(#\|\w\|\.\|:\|\/\)\+" + syntax region javaScriptDocSeeTag contained matchgroup=javaScriptDocSeeTag start="{" end="}" contains=javaScriptDocTags + + syntax case match +endif "" JSDoc end + +syntax case match + +"" Syntax in the JavaScript code +syntax match javaScriptSpecial "\\\d\d\d\|\\x\x\{2\}\|\\u\x\{4\}\|\\." +syntax region javaScriptStringD start=+"+ skip=+\\\\\|\\$"+ end=+"+ contains=javaScriptSpecial,@htmlPreproc +syntax region javaScriptStringS start=+'+ skip=+\\\\\|\\$'+ end=+'+ contains=javaScriptSpecial,@htmlPreproc +syntax region javaScriptRegexpString start=+/\(\*\|/\)\@!+ skip=+\\\\\|\\/+ end=+/[gim]\{,3}+ contains=javaScriptSpecial,@htmlPreproc oneline +syntax match javaScriptNumber /\<-\=\d\+L\=\>\|\<0[xX]\x\+\>/ +syntax match javaScriptFloat /\<-\=\%(\d\+\.\d\+\|\d\+\.\|\.\d\+\)\%([eE][+-]\=\d\+\)\=\>/ +syntax match javaScriptLabel /\(?\s*\)\@/ + syntax match javaScriptDomElemFuncs contained /\%(insertBefore\|replaceChild\|removeChild\|appendChild\|hasChildNodes\|cloneNode\|normalize\|isSupported\|hasAttributes\|getAttribute\|setAttribute\|removeAttribute\|getAttributeNode\|setAttributeNode\|removeAttributeNode\|getElementsByTagName\|getAttributeNS\|setAttributeNS\|removeAttributeNS\|getAttributeNodeNS\|setAttributeNodeNS\|getElementsByTagNameNS\|hasAttribute\|hasAttributeNS\)\>/ nextgroup=javaScriptParen skipwhite + " HTML things + syntax match javaScriptHtmlElemAttrs contained /\%(className\|clientHeight\|clientLeft\|clientTop\|clientWidth\|dir\|id\|innerHTML\|lang\|length\|offsetHeight\|offsetLeft\|offsetParent\|offsetTop\|offsetWidth\|scrollHeight\|scrollLeft\|scrollTop\|scrollWidth\|style\|tabIndex\|title\)\>/ + syntax match javaScriptHtmlElemFuncs contained /\%(blur\|click\|focus\|scrollIntoView\|addEventListener\|dispatchEvent\|removeEventListener\|item\)\>/ nextgroup=javaScriptParen skipwhite + + " CSS Styles in JavaScript + syntax keyword javaScriptCssStyles contained color font fontFamily fontSize fontSizeAdjust fontStretch fontStyle fontVariant fontWeight letterSpacing lineBreak lineHeight quotes rubyAlign rubyOverhang rubyPosition + syntax keyword javaScriptCssStyles contained textAlign textAlignLast textAutospace textDecoration textIndent textJustify textJustifyTrim textKashidaSpace textOverflowW6 textShadow textTransform textUnderlinePosition + syntax keyword javaScriptCssStyles contained unicodeBidi whiteSpace wordBreak wordSpacing wordWrap writingMode + syntax keyword javaScriptCssStyles contained bottom height left position right top width zIndex + syntax keyword javaScriptCssStyles contained border borderBottom borderLeft borderRight borderTop borderBottomColor borderLeftColor borderTopColor borderBottomStyle borderLeftStyle borderRightStyle borderTopStyle borderBottomWidth borderLeftWidth borderRightWidth borderTopWidth borderColor borderStyle borderWidth borderCollapse borderSpacing captionSide emptyCells tableLayout + syntax keyword javaScriptCssStyles contained margin marginBottom marginLeft marginRight marginTop outline outlineColor outlineStyle outlineWidth padding paddingBottom paddingLeft paddingRight paddingTop + syntax keyword javaScriptCssStyles contained listStyle listStyleImage listStylePosition listStyleType + syntax keyword javaScriptCssStyles contained background backgroundAttachment backgroundColor backgroundImage gackgroundPosition backgroundPositionX backgroundPositionY backgroundRepeat + syntax keyword javaScriptCssStyles contained clear clip clipBottom clipLeft clipRight clipTop content counterIncrement counterReset cssFloat cursor direction display filter layoutGrid layoutGridChar layoutGridLine layoutGridMode layoutGridType + syntax keyword javaScriptCssStyles contained marks maxHeight maxWidth minHeight minWidth opacity MozOpacity overflow overflowX overflowY verticalAlign visibility zoom cssText + syntax keyword javaScriptCssStyles contained scrollbar3dLightColor scrollbarArrowColor scrollbarBaseColor scrollbarDarkShadowColor scrollbarFaceColor scrollbarHighlightColor scrollbarShadowColor scrollbarTrackColor + + " Highlight ways + syntax match javaScriptDotNotation "\." nextgroup=javaScriptPrototype,javaScriptDomElemAttrs,javaScriptDomElemFuncs,javaScriptHtmlElemAttrs,javaScriptHtmlElemFuncs + syntax match javaScriptDotNotation "\.style\." nextgroup=javaScriptCssStyles + +endif "DOM/HTML/CSS + +"" end DOM/HTML/CSS specified things + + +"" Code blocks +syntax cluster javaScriptAll contains=javaScriptComment,javaScriptLineComment,javaScriptDocComment,javaScriptStringD,javaScriptStringS,javaScriptRegexpString,javaScriptNumber,javaScriptFloat,javaScriptLabel,javaScriptSource,javaScriptType,javaScriptOperator,javaScriptBoolean,javaScriptNull,javaScriptFunction,javaScriptConditional,javaScriptRepeat,javaScriptBranch,javaScriptStatement,javaScriptGlobalObjects,javaScriptExceptions,javaScriptFutureKeys,javaScriptDomErrNo,javaScriptDomNodeConsts,javaScriptHtmlEvents,javaScriptDotNotation +syntax region javaScriptBracket matchgroup=javaScriptBracket transparent start="\[" end="\]" contains=@javaScriptAll,javaScriptParensErrB,javaScriptParensErrC,javaScriptBracket,javaScriptParen,javaScriptBlock,@htmlPreproc +syntax region javaScriptParen matchgroup=javaScriptParen transparent start="(" end=")" contains=@javaScriptAll,javaScriptParensErrA,javaScriptParensErrC,javaScriptParen,javaScriptBracket,javaScriptBlock,@htmlPreproc +syntax region javaScriptBlock matchgroup=javaScriptBlock transparent start="{" end="}" contains=@javaScriptAll,javaScriptParensErrA,javaScriptParensErrB,javaScriptParen,javaScriptBracket,javaScriptBlock,@htmlPreproc + +"" catch errors caused by wrong parenthesis +syntax match javaScriptParensError ")\|}\|\]" +syntax match javaScriptParensErrA contained "\]" +syntax match javaScriptParensErrB contained ")" +syntax match javaScriptParensErrC contained "}" + +if main_syntax == "javascript" + syntax sync clear + syntax sync ccomment javaScriptComment minlines=200 + syntax sync match javaScriptHighlight grouphere javaScriptBlock /{/ +endif + +"" Fold control +if exists("b:javascript_fold") + syntax match javaScriptFunction /\/ nextgroup=javaScriptFuncName skipwhite + syntax match javaScriptOpAssign /=\@= 508 || !exists("did_javascript_syn_inits") + if version < 508 + let did_javascript_syn_inits = 1 + command -nargs=+ HiLink hi link + else + command -nargs=+ HiLink hi def link + endif + HiLink javaScriptComment Comment + HiLink javaScriptLineComment Comment + HiLink javaScriptDocComment Comment + HiLink javaScriptCommentTodo Todo + HiLink javaScriptCvsTag Function + HiLink javaScriptDocTags Special + HiLink javaScriptDocSeeTag Function + HiLink javaScriptDocParam Function + HiLink javaScriptStringS String + HiLink javaScriptStringD String + HiLink javaScriptRegexpString String + HiLink javaScriptCharacter Character + HiLink javaScriptPrototype Type + HiLink javaScriptConditional Conditional + HiLink javaScriptBranch Conditional + HiLink javaScriptRepeat Repeat + HiLink javaScriptStatement Statement + HiLink javaScriptFunction Function + HiLink javaScriptError Error + HiLink javaScriptParensError Error + HiLink javaScriptParensErrA Error + HiLink javaScriptParensErrB Error + HiLink javaScriptParensErrC Error + HiLink javaScriptOperator Operator + HiLink javaScriptType Type + HiLink javaScriptNull Type + HiLink javaScriptNumber Number + HiLink javaScriptFloat Number + HiLink javaScriptBoolean Boolean + HiLink javaScriptLabel Label + HiLink javaScriptSpecial Special + HiLink javaScriptSource Special + HiLink javaScriptGlobalObjects Special + HiLink javaScriptExceptions Special + + HiLink javaScriptDomErrNo Constant + HiLink javaScriptDomNodeConsts Constant + HiLink javaScriptDomElemAttrs Label + HiLink javaScriptDomElemFuncs PreProc + + HiLink javaScriptHtmlEvents Special + HiLink javaScriptHtmlElemAttrs Label + HiLink javaScriptHtmlElemFuncs PreProc + + HiLink javaScriptCssStyles Label + + delcommand HiLink +endif + +" Define the htmlJavaScript for HTML syntax html.vim +"syntax clear htmlJavaScript +"syntax clear javaScriptExpression +syntax cluster htmlJavaScript contains=@javaScriptAll,javaScriptBracket,javaScriptParen,javaScriptBlock,javaScriptParenError +syntax cluster javaScriptExpression contains=@javaScriptAll,javaScriptBracket,javaScriptParen,javaScriptBlock,javaScriptParenError,@htmlPreproc + +let b:current_syntax = "javascript" +if main_syntax == 'javascript' + unlet main_syntax +endif + +" vim: ts=4 diff --git a/.vimrc b/.vimrc new file mode 100644 index 0000000..56b49a8 --- /dev/null +++ b/.vimrc @@ -0,0 +1,239 @@ +" --------------------------------------------------------------------------- +" General +" --------------------------------------------------------------------------- + +set nocompatible " essential +set history=1000 " lots of command line history +set confirm " error files / jumping +set fileformats=unix,dos,mac " support these files +filetype plugin indent on " load filetype plugin +set iskeyword+=_,$,@,%,#,- " none word dividers +set viminfo='1000,f1,:100,@100,/20 +set modeline " make sure modeline support is enabled +set autoread " reload files (no local changes only) +set tabpagemax=50 " open 50 tabs max + +" --------------------------------------------------------------------------- +" Colors / Theme +" --------------------------------------------------------------------------- + +if &t_Co > 2 || has("gui_running") + if has("terminfo") + set t_Co=16 + set t_AB=[%?%p1%{8}%<%t%p1%{40}%+%e%p1%{92}%+%;%dm + set t_AF=[%?%p1%{8}%<%t%p1%{30}%+%e%p1%{82}%+%;%dm + else + set t_Co=16 + set t_Sf=[3%dm + set t_Sb=[4%dm + endif + syntax on + set hlsearch " Highlight all search matches + " Press Space to turn off highlighting and clear any message already displayed. + :nnoremap :nohlsearch:echo + colorscheme slate2 +endif + +" --------------------------------------------------------------------------- +" Highlight +" --------------------------------------------------------------------------- + +highlight Comment ctermfg=DarkGrey guifg=#444444 +highlight StatusLineNC ctermfg=Black ctermbg=DarkGrey cterm=bold +highlight StatusLine ctermbg=Black ctermfg=LightGrey + +" ---------------------------------------------------------------------------- +" Highlight Trailing Whitespace +" ---------------------------------------------------------------------------- + +set list listchars=trail:.,tab:>. +highlight SpecialKey ctermfg=DarkGray ctermbg=Black + +" ---------------------------------------------------------------------------- +" Backups +" ---------------------------------------------------------------------------- + +set nobackup " do not keep backups after close +set nowritebackup " do not keep a backup while working +set noswapfile " don't keep swp files either +set backupdir=$HOME/.vim/backup " store backups under ~/.vim/backup +set backupcopy=yes " keep attributes of original file +set backupskip=/tmp/*,$TMPDIR/*,$TMP/*,$TEMP/* +set directory=~/.vim/swap,~/tmp,. " keep swp files under ~/.vim/swap + +" ---------------------------------------------------------------------------- +" UI +" ---------------------------------------------------------------------------- + +set ruler " show the cursor position all the time +set noshowcmd " don't display incomplete commands +set nolazyredraw " turn off lazy redraw +"set number " line numbers +set wildmenu " turn on wild menu +set wildmode=list:longest,full +set ch=2 " command line height +set backspace=2 " allow backspacing over everything in insert mode +set whichwrap+=<,>,h,l,[,] " backspace and cursor keys wrap to +set shortmess=filtIoOA " shorten messages +set report=0 " tell us about changes +set nostartofline " don't jump to the start of line when scrolling + +" ---------------------------------------------------------------------------- +" Visual Cues +" ---------------------------------------------------------------------------- + +set showmatch " brackets/braces that is +set mat=5 " duration to show matching brace (1/10 sec) +set incsearch " do incremental searching +set laststatus=2 " always show the status line +set ignorecase " ignore case when searching +set smartcase " case-sensitive if search contains an uppercase character +set visualbell " shut the heck up + +" ---------------------------------------------------------------------------- +" Text Formatting +" ---------------------------------------------------------------------------- + +set autoindent " automatic indent new lines +set smartindent " be smart about it +set nowrap " do not wrap lines +set softtabstop=2 " yep, two +set shiftwidth=2 " .. +set tabstop=4 +set expandtab " expand tabs to spaces +set nosmarttab " screw tabs +set formatoptions+=n " support for numbered/bullet lists +set textwidth=80 " wrap at 80 chars by default +set virtualedit=block " allow virtual edit in visual block .. + +" ---------------------------------------------------------------------------- +" Tabs +" ---------------------------------------------------------------------------- + + +" ---------------------------------------------------------------------------- +" Mappings +" ---------------------------------------------------------------------------- + +" to pastetoggle, to turn-off autoindent when pasting from system clipboard +nnoremap :set invpaste paste? +set pastetoggle= +set showmode + +" /- to navigation between buffers +set switchbuf=usetab +nnoremap :sbnext +nnoremap :sbprevious + +"" quickfix mappings +"map :cn +"map :cp +"map :copen + +"" emacs movement keybindings in insert mode +"imap 0 +"imap $ +"map $ +"map 0 + +" reflow paragraph with Q in normal and visual mode +nnoremap Q gqap +vnoremap Q gq + +"" sane movement with wrap turned on +"nnoremap j gj +"nnoremap k gk +"vnoremap j gj +"vnoremap k gk +"nnoremap gj +"nnoremap gk +"vnoremap gj +"vnoremap gk +"inoremap gj +"inoremap gk + +"" do not menu with left / right in command line +"cnoremap +"cnoremap + +" ---------------------------------------------------------------------------- +" Auto Commands +" ---------------------------------------------------------------------------- + +" jump to last position of buffer when opening +au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | + \ exe "normal g'\"" | endif + +" don't use cindent for javascript +autocmd FileType javascript setlocal nocindent + +" ---------------------------------------------------------------------------- +" LookupFile +" ---------------------------------------------------------------------------- + +"let g:LookupFile_TagExpr = '".ftags"' +"let g:LookupFile_MinPatLength = 2 +"let g:LookupFile_ShowFiller = 0 " fix menu flashiness +"let g:LookupFile_PreservePatternHistory = 1 " preserve sorted history? +"let g:LookupFile_PreserveLastPattern = 0 " start with last pattern? +" +"nmap LookupFile +"imap LookupFile + +" ---------------------------------------------------------------------------- +" PATH on MacOS X +" ---------------------------------------------------------------------------- + +if system('uname') =~ 'Darwin' + let $PATH = $HOME . + \ '/usr/local/bin:/usr/local/sbin:' . + \ '/usr/pkg/bin:' . + \ '/opt/local/bin:/opt/local/sbin:' . + \ $PATH +endif + +" --------------------------------------------------------------------------- +" sh config +" --------------------------------------------------------------------------- + +au Filetype sh,bash set ts=4 sts=4 sw=4 expandtab +let g:is_bash = 1 + +" --------------------------------------------------------------------------- +" Misc mappings +" --------------------------------------------------------------------------- + +"map ,f :tabnew +"map ,d :e %:h/ +"map ,dt :tabnew %:h/ + +"" I use these commands in my TODO file +"map ,a o:r!date +'\%A, \%B \%d, \%Y':r!date +'\%A, \%B \%d, \%Y' \| sed 's/./-/g'A +"map ,o o[ ] +"map ,O O[ ] +"map ,x :s/^\[ \]/[x]/ +"map ,X :s/^\[x\]/[ ]/ + +" --------------------------------------------------------------------------- +" Strip all trailing whitespace in file +" --------------------------------------------------------------------------- + +function! StripWhitespace () + exec ':%s/ \+$//gc' +endfunction +map ,s :call StripWhitespace () + +" --------------------------------------------------------------------------- +" File Types +" --------------------------------------------------------------------------- + +au Filetype gitcommit set tw=68 spell +"au Filetype html,xml,xsl,rhtml source $HOME/.vim/scripts/closetag.vim + +" -------------------------------------------------------------------------- +" ManPageView +" -------------------------------------------------------------------------- + +let g:manpageview_pgm= 'man -P "/usr/bin/less -is"' +let $MANPAGER = '/usr/bin/less -is' + -- 2.45.2