j.vim 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. " Vim filetype plugin
  2. " Language: J
  3. " Maintainer: David Bürgin <dbuergin@gluet.ch>
  4. " URL: https://gitlab.com/glts/vim-j
  5. " Last Change: 2022-08-06
  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 suffixesadd< includeexpr< include< path< matchpairs< formatoptions< commentstring< comments< iskeyword<'
  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. if !exists('no_plugin_maps') && !exists('no_j_maps')
  27. let s:sectionstart = '\%(\s*Note\|.\{-}\<\%([0-4]\|13\|noun\|adverb\|conjunction\|verb\|monad\|dyad\)\s\+\%(:\s*0\|def\s\+0\|define\)\)\>.*'
  28. let s:sectionend = '\s*)\s*'
  29. function! s:SearchSection(end, backwards, visualmode) abort
  30. if a:visualmode !=# ''
  31. normal! gv
  32. endif
  33. let l:flags = a:backwards ? 'bsW' : 'sW'
  34. if a:end
  35. call search('^' . s:sectionend . (a:backwards ? '\n\_.\{-}\%#' : '$'), l:flags)
  36. else
  37. call search('^' . s:sectionstart . (a:backwards ? '\n\_.\{-}\%#' : '$'), l:flags)
  38. endif
  39. endfunction
  40. noremap <buffer> <silent> ]] :<C-U>call <SID>SearchSection(0, 0, '')<CR>
  41. xnoremap <buffer> <silent> ]] :<C-U>call <SID>SearchSection(0, 0, visualmode())<CR>
  42. sunmap <buffer> ]]
  43. noremap <buffer> <silent> ][ :<C-U>call <SID>SearchSection(1, 0, '')<CR>
  44. xnoremap <buffer> <silent> ][ :<C-U>call <SID>SearchSection(1, 0, visualmode())<CR>
  45. sunmap <buffer> ][
  46. noremap <buffer> <silent> [[ :<C-U>call <SID>SearchSection(0, 1, '')<CR>
  47. xnoremap <buffer> <silent> [[ :<C-U>call <SID>SearchSection(0, 1, visualmode())<CR>
  48. sunmap <buffer> [[
  49. noremap <buffer> <silent> [] :<C-U>call <SID>SearchSection(1, 1, '')<CR>
  50. xnoremap <buffer> <silent> [] :<C-U>call <SID>SearchSection(1, 1, visualmode())<CR>
  51. sunmap <buffer> []
  52. let b:undo_ftplugin .= ' | silent! execute "unmap <buffer> ]]"'
  53. \ . ' | silent! execute "unmap <buffer> ]["'
  54. \ . ' | silent! execute "unmap <buffer> [["'
  55. \ . ' | silent! execute "unmap <buffer> []"'
  56. endif
  57. " Browse dialog filter on Windows and GTK (see ":help browsefilter")
  58. if (has('gui_win32') || has('gui_gtk')) && !exists('b:browsefilter')
  59. let b:browsefilter = "J Script Files (*.ijs)\t*.ijs\n"
  60. \ . "All Files (*.*)\t*.*\n"
  61. let b:undo_ftplugin .= ' | unlet! b:browsefilter'
  62. endif
  63. " Enhanced "%" matching (see ":help matchit")
  64. if exists('loaded_matchit') && !exists('b:match_words')
  65. let b:match_ignorecase = 0
  66. 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*$'
  67. \ . ',\<\%(for\%(_\a\k*\)\=\|if\|select\|try\|whil\%(e\|st\)\)\.:\<\%(case\|catch[dt]\=\|else\%(if\)\=\|fcase\)\.:\<end\.'
  68. let b:undo_ftplugin .= ' | unlet! b:match_ignorecase b:match_words'
  69. endif
  70. let &cpo = s:save_cpo
  71. unlet s:save_cpo