Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 1 | " Vim filetype plugin |
| 2 | " Language: Vim |
| 3 | " Maintainer: Bram Moolenaar <Bram@vim.org> |
Bram Moolenaar | c1a11ed | 2008-06-24 22:09:24 +0000 | [diff] [blame] | 4 | " Last Change: 2008 Feb 27 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 5 | |
| 6 | " Only do this when not done yet for this buffer |
| 7 | if exists("b:did_ftplugin") |
| 8 | finish |
| 9 | endif |
| 10 | |
| 11 | " Don't load another plugin for this buffer |
| 12 | let b:did_ftplugin = 1 |
| 13 | |
| 14 | let cpo_save = &cpo |
| 15 | set cpo-=C |
| 16 | |
| 17 | let b:undo_ftplugin = "setl fo< com< tw< commentstring<" |
| 18 | \ . "| unlet! b:match_ignorecase b:match_words b:match_skip" |
| 19 | |
| 20 | " Set 'formatoptions' to break comment lines but not other lines, |
| 21 | " and insert the comment leader when hitting <CR> or using "o". |
| 22 | setlocal fo-=t fo+=croql |
| 23 | |
| 24 | " Set 'comments' to format dashed lists in comments |
| 25 | setlocal com=sO:\"\ -,mO:\"\ \ ,eO:\"\",:\" |
| 26 | |
| 27 | " Format comments to be up to 78 characters long |
| 28 | if &tw == 0 |
| 29 | setlocal tw=78 |
| 30 | endif |
| 31 | |
| 32 | " Comments start with a double quote |
| 33 | setlocal commentstring=\"%s |
| 34 | |
| 35 | " Move around functions. |
Bram Moolenaar | c1a11ed | 2008-06-24 22:09:24 +0000 | [diff] [blame] | 36 | nnoremap <silent><buffer> [[ m':call search('^\s*fu\%[nction]\>', "bW")<CR> |
| 37 | vnoremap <silent><buffer> [[ m':<C-U>exe "normal! gv"<Bar>call search('^\s*fu\%[nction]\>', "bW")<CR> |
| 38 | nnoremap <silent><buffer> ]] m':call search('^\s*fu\%[nction]\>', "W")<CR> |
| 39 | vnoremap <silent><buffer> ]] m':<C-U>exe "normal! gv"<Bar>call search('^\s*fu\%[nction]\>', "W")<CR> |
| 40 | nnoremap <silent><buffer> [] m':call search('^\s*endf*\%[unction]\>', "bW")<CR> |
| 41 | vnoremap <silent><buffer> [] m':<C-U>exe "normal! gv"<Bar>call search('^\s*endf*\%[unction]\>', "bW")<CR> |
| 42 | nnoremap <silent><buffer> ][ m':call search('^\s*endf*\%[unction]\>', "W")<CR> |
| 43 | vnoremap <silent><buffer> ][ m':<C-U>exe "normal! gv"<Bar>call search('^\s*endf*\%[unction]\>', "W")<CR> |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 44 | |
| 45 | " Move around comments |
Bram Moolenaar | c1a11ed | 2008-06-24 22:09:24 +0000 | [diff] [blame] | 46 | nnoremap <silent><buffer> ]" :call search('^\(\s*".*\n\)\@<!\(\s*"\)', "W")<CR> |
| 47 | vnoremap <silent><buffer> ]" :<C-U>exe "normal! gv"<Bar>call search('^\(\s*".*\n\)\@<!\(\s*"\)', "W")<CR> |
| 48 | nnoremap <silent><buffer> [" :call search('\%(^\s*".*\n\)\%(^\s*"\)\@!', "bW")<CR> |
| 49 | vnoremap <silent><buffer> [" :<C-U>exe "normal! gv"<Bar>call search('\%(^\s*".*\n\)\%(^\s*"\)\@!', "bW")<CR> |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 50 | |
| 51 | " Let the matchit plugin know what items can be matched. |
| 52 | if exists("loaded_matchit") |
| 53 | let b:match_ignorecase = 0 |
| 54 | let b:match_words = |
| 55 | \ '\<fu\%[nction]\>:\<retu\%[rn]\>:\<endf\%[unction]\>,' . |
| 56 | \ '\<wh\%[ile]\>:\<brea\%[k]\>:\<con\%[tinue]\>:\<endw\%[hile]\>,' . |
Bram Moolenaar | c81e5e7 | 2007-05-05 18:24:42 +0000 | [diff] [blame] | 57 | \ '\<for\>:\<brea\%[k]\>:\<con\%[tinue]\>:\<endfo\%[r]\>,' . |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 58 | \ '\<if\>:\<el\%[seif]\>:\<en\%[dif]\>,' . |
| 59 | \ '\<try\>:\<cat\%[ch]\>:\<fina\%[lly]\>:\<endt\%[ry]\>,' . |
| 60 | \ '\<aug\%[roup]\s\+\%(END\>\)\@!\S:\<aug\%[roup]\s\+END\>,' . |
| 61 | \ '(:)' |
| 62 | " Ignore ":syntax region" commands, the 'end' argument clobbers if-endif |
| 63 | let b:match_skip = 'getline(".") =~ "^\\s*sy\\%[ntax]\\s\\+region" || |
| 64 | \ synIDattr(synID(line("."),col("."),1),"name") =~? "comment\\|string"' |
| 65 | endif |
| 66 | |
| 67 | let &cpo = cpo_save |
Bram Moolenaar | 26a60b4 | 2005-02-22 08:49:11 +0000 | [diff] [blame] | 68 | |
| 69 | " removed this, because 'cpoptions' is a global option. |
| 70 | " setlocal cpo+=M " makes \%( match \) |