j.vim 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. " Vim filetype plugin
  2. " Language: J
  3. " Maintainer: David Bürgin <676c7473@gmail.com>
  4. " URL: https://github.com/glts/vim-j
  5. " Last Change: 2015-09-27
  6. if exists('b:did_ftplugin')
  7. finish
  8. endif
  9. let b:did_ftplugin = 1
  10. let s:save_cpo = &cpo
  11. set cpo&vim
  12. setlocal iskeyword=48-57,A-Z,a-z,_
  13. setlocal comments=:NB.
  14. setlocal commentstring=NB.\ %s
  15. setlocal formatoptions-=t
  16. setlocal matchpairs=(:)
  17. setlocal path-=/usr/include
  18. " Includes. To make the shorthand form "require 'web/cgi'" work, double the
  19. " last path component. Also strip off leading folder names like "~addons/".
  20. setlocal include=\\v^\\s*(load\|require)\\s*'\\zs\\f+\\ze'
  21. setlocal includeexpr=substitute(substitute(tr(v:fname,'\\','/'),'\\v^[^~][^/.]*(/[^/.]+)$','&\\1',''),'\\v^\\~[^/]+/','','')
  22. setlocal suffixesadd=.ijs
  23. let b:undo_ftplugin = 'setlocal matchpairs< formatoptions< commentstring< comments< iskeyword< path< include< includeexpr< suffixesadd<'
  24. " Section movement with ]] ][ [[ []. The start/end patterns below are amended
  25. " inside the function in order to avoid matching on the current cursor line.
  26. let s:sectionstart = '\%(\s*Note\|.\{-}\<\%([0-4]\|13\|noun\|adverb\|conjunction\|verb\|monad\|dyad\)\s\+\%(:\s*0\|def\s\+0\|define\)\)\>.*'
  27. let s:sectionend = '\s*)\s*'
  28. function! s:SearchSection(end, backwards, visualmode) abort
  29. if a:visualmode !=# ''
  30. normal! gv
  31. endif
  32. let l:flags = a:backwards ? 'bsW' : 'sW'
  33. if a:end
  34. call search('^' . s:sectionend . (a:backwards ? '\n\_.\{-}\%#' : '$'), l:flags)
  35. else
  36. call search('^' . s:sectionstart . (a:backwards ? '\n\_.\{-}\%#' : '$'), l:flags)
  37. endif
  38. endfunction
  39. noremap <buffer> <silent> ]] :<C-U>call <SID>SearchSection(0, 0, '')<CR>
  40. xnoremap <buffer> <silent> ]] :<C-U>call <SID>SearchSection(0, 0, visualmode())<CR>
  41. sunmap <buffer> ]]
  42. noremap <buffer> <silent> ][ :<C-U>call <SID>SearchSection(1, 0, '')<CR>
  43. xnoremap <buffer> <silent> ][ :<C-U>call <SID>SearchSection(1, 0, visualmode())<CR>
  44. sunmap <buffer> ][
  45. noremap <buffer> <silent> [[ :<C-U>call <SID>SearchSection(0, 1, '')<CR>
  46. xnoremap <buffer> <silent> [[ :<C-U>call <SID>SearchSection(0, 1, visualmode())<CR>
  47. sunmap <buffer> [[
  48. noremap <buffer> <silent> [] :<C-U>call <SID>SearchSection(1, 1, '')<CR>
  49. xnoremap <buffer> <silent> [] :<C-U>call <SID>SearchSection(1, 1, visualmode())<CR>
  50. sunmap <buffer> []
  51. let b:undo_ftplugin .= ' | silent! execute "unmap <buffer> ]]"'
  52. \ . ' | silent! execute "unmap <buffer> ]["'
  53. \ . ' | silent! execute "unmap <buffer> [["'
  54. \ . ' | silent! execute "unmap <buffer> []"'
  55. " Browse dialog filter on Windows (see ":help browsefilter")
  56. if has('gui_win32') && !exists('b:browsefilter')
  57. let b:browsefilter = "J Script Files (*.ijs)\t*.ijs\n"
  58. \ . "All Files (*.*)\t*.*\n"
  59. let b:undo_ftplugin .= ' | unlet! b:browsefilter'
  60. endif
  61. " Enhanced "%" matching (see ":help matchit")
  62. if exists('loaded_matchit') && !exists('b:match_words')
  63. let b:match_ignorecase = 0
  64. let b:match_words = '^\%(\s*Note\|.\{-}\<\%([0-4]\|13\|noun\|adverb\|conjunction\|verb\|monad\|dyad\)\s\+\%(\:\s*0\|def\s\+0\|define\)\)\>:^\s*\:\s*$:^\s*)\s*$'
  65. \ . ',\<\%(for\%(_\a\k*\)\=\|if\|select\|try\|whil\%(e\|st\)\)\.:\<\%(case\|catch[dt]\=\|else\%(if\)\=\|fcase\)\.:\<end\.'
  66. let b:undo_ftplugin .= ' | unlet! b:match_ignorecase b:match_words'
  67. endif
  68. let &cpo = s:save_cpo
  69. unlet s:save_cpo