From Speedy Treeshrew, 3 Months ago, written in Plain Text.
  1. #!/bin/bash
  2. # Desc: Use vim as pager for man(1)
  3. # Usage: vman [SECTION] PAGE
  4. # Example: vman 1 man
  5.  
  6. # /* FUNCDEF */
  7. msg(){ printf -- "%s\n" "$@"; }
  8. emsg(){ printf -- "%s\n" "$@" >&2 ; }
  9. bail(){ emsg "$@"; usage; exit 1; }
  10. usage(){ awk -F '# ' 'NR>2{print $2};$0==""{exit}' <"$0"; }
  11.  
  12. validate(){
  13.   # desc: check if a manpage exists
  14.   # usage: validate manpath page [section]
  15.   # example: validate "$MANPATH" man 1
  16.  
  17.   local p s dir
  18.   p="$2"; s="${3:-}"
  19.   tr ':' '\n' <<<"$1" | while read -r dir; do
  20.     if [[ -z "$3" ]]; then
  21.       for i in 0 1 2 3 4 5 6 7 8 9; do
  22.         read -n0 <"${dir}/man${i}/${p}.${i}.gz" 2<&- \
  23.         && printf -- "%s" "${dir}/man${i}/${p}.${i}.gz" \
  24.         && return 0
  25.       done
  26.     else
  27.         read -n0 <"${dir}/man${s}/${p}.${s}.gz" 2<&- \
  28.         && printf -- "%s" "${dir}/man${s}/${p}.${s}.gz" \
  29.         && return 0
  30.      fi
  31.   done
  32. }
  33.  
  34. extract(){
  35.   # desc: extract files from the end of this script
  36.   # usage: extract filename
  37.   # example: extract man.vim <"$0" >~/.vim/syntax/man.vim
  38.  
  39.   awk -v be="#=begin:${1}=" -v en="#=end:${1}=" '
  40.     $1==be{while((getline)>0)
  41.       {if($1==en)
  42.         {break}
  43.       else
  44.         {$1=""; print}
  45.       }
  46.   }' <"$0"
  47. }
  48.  
  49.  
  50. # /* ENV */
  51. declare page section dir rul
  52. declare -a manual syntax
  53. MANPATH="${MANPATH:-/usr/share/man}"
  54.  
  55.  
  56. # /* INIT */
  57. # Argparse
  58. while (($#)); do
  59.   case "$1" in
  60.     --help) usage; exit 0;;
  61.     [0-9]|[0-9][pnl]) section="$1"; page="$2"; shift 2; break;;
  62.     *) page="$1"; shift; break;;
  63.   esac
  64. done
  65.  
  66. # Ensure requested page exists
  67. mapfile -t manual < <(validate "$MANPATH" "$page" "$section" 2<&-)
  68. [[ -f "${manual[@]}" ]] || bail "E!: page not found"
  69.  
  70. # Cut syntax files from bottom of $0 if they dont exist
  71. if [[ ! -f "$HOME/.vim/syntax/vman.vim" ]]; then
  72.   read -p "OOPS! No such file '$HOME/.vim/syntax/vman.vim'. Extract it?(y/n): " -r
  73.   if [[ "$REPLY" == "y" ]]; then
  74.     extract "vman" >"$HOME/.vim/syntax/vman.vim"
  75.   else emesg "W:! Continuing with fucky syntax!"; fi
  76. fi
  77.  
  78. # Set ruler len... or not since its to long anyway...
  79. let rul="(${#page}+36)";
  80.  
  81.  
  82. # /* MAIN */
  83. # Dump the page into vim
  84. # NOTE: Calling feedkeys() autodismisses more prompt \o/
  85. # NOTE: Use :only! just in case
  86. # NOTE: Extracts vimrc from $0
  87. \command man -P cat "$manual" 2>/dev/null| vim - -n -R --not-a-term -u <(extract vimrc) \
  88.     --cmd "let manpagename = \"${page}\"" \
  89.     -c "set rulerformat=%${rul}(%=%-1*\ Manual\:%-3*\ %{\$page}\ %-3*\ \ \ line\ %-l/%-L\ \ [%p%%]\ %<%4*%)" \
  90.     -c 'call feedkeys("jk", "t")' \
  91.      +'only!'
  92.  
  93. exit
  94.  
  95.  
  96. #=begin:vimrc=
  97. # set nocompatible
  98. # set nonumber nocursorline nomore nomod nolist nonu nosc
  99. # set laststatus=0 virtualedit=all scrolloff=1000 sidescroll=1000 sidescrolloff=0
  100. # set ft=man dy=""
  101. # set ruler
  102. # syntax enable
  103. # colorscheme default
  104. #
  105. # nnoremap q :q!<cr>
  106. # nnoremap qq :q!<cr>
  107. #
  108. # hi User1 cterm=none ctermbg=8 ctermfg=231
  109. # hi User2 cterm=bold ctermbg=4 ctermfg=none
  110. # hi User3 cterm=none ctermbg=4 ctermfg=7
  111. # hi User4 ctermbg=none ctermfg=0
  112. #
  113. # hi Comment         cterm=none                                   ctermfg=8
  114. # hi Constant        cterm=none                                   ctermfg=5
  115. # hi Special         cterm=none                                   ctermfg=1
  116. # hi Identifier      cterm=none                                   ctermfg=14
  117. # hi Statement       cterm=none                                   ctermfg=6
  118. # hi PreProc         cterm=none                                   ctermfg=13
  119. # hi Type            cterm=none                                   ctermfg=10
  120. # hi Underlined      cterm=underline                              ctermfg=none
  121. # hi Ignore          cterm=none               ctermfg=none        ctermfg=12
  122. #
  123. # "#- Constant -#
  124. #  hi String          cterm=none                                   ctermfg=103
  125. #  hi Character       cterm=none                                   ctermfg=5
  126. #  hi Number          cterm=none                                   ctermfg=5
  127. #  hi Float           cterm=none                                   ctermfg=5
  128. #  hi Boolean         cterm=none                                   ctermfg=5
  129. # "#- Identifier -#
  130. #  hi Function        cterm=none                                   ctermfg=137
  131. # "#- Statement -#
  132. #  hi Conditional     cterm=none                                   ctermfg=7
  133. #  hi Repeat          cterm=underline                              ctermfg=7
  134. #  hi Label           cterm=none                                   ctermfg=6
  135. #  hi Operator        cterm=underline                              ctermfg=7
  136. #  hi Keyword         cterm=none                                   ctermfg=12
  137. #  hi Exception       cterm=none                                   ctermfg=7
  138. # "#- Preproc -#
  139. #  hi Include         cterm=none                                   ctermfg=13
  140. #  hi Define          cterm=none                                   ctermfg=5
  141. #  hi Macro           cterm=none                                   ctermfg=5
  142. #  hi PreConduit      cterm=none             ctermbg=5
  143. # "#- Type -#
  144. #  hi StorageClass    cterm=none                                   ctermfg=2
  145. #  hi Structure       cterm=none                                   ctermfg=137
  146. #  hi Typedef         cterm=none             ctermfg=28
  147. # "#- Special -#
  148. #  hi Tag             cterm=none             ctermfg=72
  149. #  hi SpecialCharacter cterm=underline                             ctermfg=231
  150. #  hi Delimiter       cterm=none                                   ctermfg=124
  151. #  hi SpecialComment  cterm=none                                   ctermfg=196
  152. #  hi Debug           cterm=none                                   ctermfg=196
  153. #
  154. #=end:vimrc=
  155.  
  156. #=begin:vman.vim=
  157. # if exists('b:current_syn')
  158. #   finish
  159. # endif
  160. # if exists('manpagename')
  161. # exe "syn match manPAGENAME /".manpagename."\ /"
  162. # exe "hi manPAGENAME ctermfg=14"
  163. # endif
  164. #
  165. #
  166. # syn case  ignore
  167. # syn match manReference       '\f\+(\%([0-8][a-z]\=\|n\))'
  168. # syn match manOptionDesc /-[[:alnum:]]\+/
  169. # syn match manOptionDesc /\.\.\./
  170. # syn match manOptionDesc /\ \|\[-[[:alnum:]]\+\(\ \+\|\)[[:alnum:]]\+/hs=s+1
  171. # syn match manOptionDesc /\[[[:alnum:]]\+\(\|\ \+\)[[:alnum:]]\+/hs=s+1
  172. # syn match manLongOptionDesc /--[[:alnum:]]\+/
  173. # syn match manLongOptionDesc /--[[:alnum:]]\+\ \|=[[:alnum:]]\+/
  174. # syn match manLongOptionDesc /--[[:alnum:]]\+\(\ \|-[[:alnum:]]\+\)/
  175. #
  176. #  " prevent manSectionHeading from matching last line
  177. # exe 'syn match manSectionHeading  "^\%(\%>1l\%<'.line('$').'l\)\%(\S.*\)\=\S$"'
  178. #
  179. # syn match manSubHeading      '^\s\{3\}\%(\S.*\)\=\S$'
  180. #
  181. # hi String ctermfg=6
  182. # hi manTitle          cterm=none ctermbg=0 ctermfg=250
  183. # hi manSectionHeading cterm=none ctermbg=none ctermfg=15
  184. # hi manOptionDesc     cterm=none ctermbg=none ctermfg=5
  185. # hi manLongOptionDesc cterm=none ctermbg=none ctermfg=5
  186. # hi manOptionOption cterm=none ctermbg=none ctermfg=62
  187. # hi manReference      cterm=none ctermbg=none ctermfg=2
  188. # hi manSubHeading     cterm=none ctermbg=none ctermfg=31
  189. # hi manNameSectionHeading cterm=none ctermbg=none ctermfg=32
  190. # hi manNameSectionHeadingText cterm=none ctermbg=none ctermfg=32
  191. # hi manOptionDescRLSqBrkt cterm=none ctermbg=none ctermfg=32
  192. # hi manOptionDescRSqBrkt cterm=none ctermbg=none ctermfg=32
  193. # hi manOptionDescLSqBrkt cterm=none ctermbg=none ctermfg=32
  194. #
  195. #
  196. #
  197. # if getline(1) =~ '^[a-zA-Z_]\+([23])'
  198. #   syn match manCFuncDefinition display '\<\h\w*\>\s*('me=e-1 contained
  199. #   syn region manSynopsis start="^SYNOPSIS"hs=s+8 end="^\u\+\s*$"me=e-12 keepend contains=manSectionHeading,@cCode,manCFuncDefinition
  200. #
  201. # let s:cpo_save = &cpo
  202. # set cpo&vim
  203. #
  204. # let s:ft = matchstr(&ft, '^\([^.]\)\+')
  205. #
  206. # " A bunch of useful C keywords
  207. # syn keyword   cStatement      goto break return continue asm
  208. # syn keyword   cLabel          case default
  209. # syn keyword   cConditional    if else switch
  210. # syn keyword   cRepeat         while for do
  211. #
  212. # syn keyword   cTodo           contained TODO FIXME XXX
  213. #
  214. # " It's easy to accidentally add a space after a backslash that was intended
  215. # " for line continuation.  Some compilers allow it, which makes it
  216. # " unpredictable and should be avoided.
  217. # syn match     cBadContinuation contained "\\\s\+$"
  218. #
  219. # " cCommentGroup allows adding matches for special things in comments
  220. # syn cluster   cCommentGroup   contains=cTodo,cBadContinuation
  221. #
  222. # " String and Character constants
  223. # " Highlight special characters (those which have a backslash) differently
  224. # syn match     cSpecial        display contained "\\\(x\x\+\|\o\{1,3}\|.\|$\)"
  225. # if !exists("c_no_utf")
  226. #   syn match   cSpecial        display contained "\\\(u\x\{4}\|U\x\{8}\)"
  227. # endif
  228. # if exists("c_no_cformat")
  229. #   syn region  cString         start=+L\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,@Spell extend
  230. #   " cCppString: same as cString, but ends at end of line
  231. #   if !exists("cpp_no_cpp11") " ISO C++11
  232. #     syn region cCppString     start=+\(L\|u\|u8\|U\|R\|LR\|u8R\|uR\|UR\)\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial,cFormat,@Spell
  233. #   else
  234. #     syn region cCppString     start=+L\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial,cFormat,@Spell
  235. #   endif
  236. #   syn region  cCppOut2        contained start="0" end="^\s*\(%:\|#\)\s*\(endif\>\|else\>\|elif\>\)" contains=cSpaceError,cCppSkip
  237. #   syn region  cCppSkip        contained start="^\s*\(%:\|#\)\s*\(if\>\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\(%:\|#\)\s*endif\>" contains=cSpaceError,cCppSkip
  238. # else
  239. #   if !exists("c_no_c99") " ISO C99
  240. #     syn match cFormat         display "%\(\d\+\$\)\=[-+' #0*]*\(\d*\|\*\|\*\d\+\$\)\(\.\(\d*\|\*\|\*\d\+\$\)\)\=\([hlLjzt]\|ll\|hh\)\=\([aAbdiuoxXDOUfFeEgGcCsSpn]\|\[\^\=.[^]]*\]\)" contained
  241. #   else
  242. #     syn match cFormat         display "%\(\d\+\$\)\=[-+' #0*]*\(\d*\|\*\|\*\d\+\$\)\(\.\(\d*\|\*\|\*\d\+\$\)\)\=\([hlL]\|ll\)\=\([bdiuoxXDOUfeEgGcCsSpn]\|\[\^\=.[^]]*\]\)" contained
  243. #   endif
  244. #   syn match   cFormat         display "%%" contained
  245. #   syn region  cString         start=+L\="+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,cFormat,@Spell extend
  246. #   " cCppString: same as cString, but ends at end of line
  247. #   syn region  cCppString      start=+L\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end='$' contains=cSpecial,cFormat,@Spell
  248. # endif
  249. #
  250. # syn match     cCharacter      "L\='[^\\]'"
  251. # syn match     cCharacter      "L'[^']*'" contains=cSpecial
  252. # if exists("c_gnu")
  253. #   syn match   cSpecialError   "L\='\\[^'\"?\\abefnrtv]'"
  254. #   syn match   cSpecialCharacter "L\='\\['\"?\\abefnrtv]'"
  255. # else
  256. #   syn match   cSpecialError   "L\='\\[^'\"?\\abfnrtv]'"
  257. #   syn match   cSpecialCharacter "L\='\\['\"?\\abfnrtv]'"
  258. # endif
  259. # syn match     cSpecialCharacter display "L\='\\\o\{1,3}'"
  260. # syn match     cSpecialCharacter display "'\\x\x\{1,2}'"
  261. # syn match     cSpecialCharacter display "L'\\x\x\+'"
  262. #
  263. # if !exists("c_no_c11") " ISO C11
  264. #   if exists("c_no_cformat")
  265. #     syn region        cString         start=+\%(U\|u8\=\)"+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,@Spell extend
  266. #   else
  267. #     syn region        cString         start=+\%(U\|u8\=\)"+ skip=+\\\\\|\\"+ end=+"+ contains=cSpecial,cFormat,@Spell extend
  268. #   endif
  269. #   syn match   cCharacter      "[Uu]'[^\\]'"
  270. #   syn match   cCharacter      "[Uu]'[^']*'" contains=cSpecial
  271. #   if exists("c_gnu")
  272. #     syn match cSpecialError   "[Uu]'\\[^'\"?\\abefnrtv]'"
  273. #     syn match cSpecialCharacter "[Uu]'\\['\"?\\abefnrtv]'"
  274. #   else
  275. #     syn match cSpecialError   "[Uu]'\\[^'\"?\\abfnrtv]'"
  276. #     syn match cSpecialCharacter "[Uu]'\\['\"?\\abfnrtv]'"
  277. #   endif
  278. #   syn match   cSpecialCharacter display "[Uu]'\\\o\{1,3}'"
  279. #   syn match   cSpecialCharacter display "[Uu]'\\x\x\+'"
  280. # endif
  281. #
  282. # "when wanted, highlight trailing white space
  283. # if exists("c_space_errors")
  284. #   if !exists("c_no_trail_space_error")
  285. #     syn match cSpaceError     display excludenl "\s\+$"
  286. #   endif
  287. #   if !exists("c_no_tab_space_error")
  288. #     syn match cSpaceError     display " \+\t"me=e-1
  289. #   endif
  290. # endif
  291. #
  292. # " This should be before cErrInParen to avoid problems with #define ({ xxx })
  293. # if exists("c_curly_error")
  294. #   syn match cCurlyError "}"
  295. #   syn region  cBlock          start="{" end="}" contains=ALLBUT,cBadBlock,cCurlyError,@cParenGroup,cErrInParen,cCppParen,cErrInBracket,cCppBracket,cCppString,@Spell fold
  296. # else
  297. #   syn region  cBlock          start="{" end="}" transparent fold
  298. # endif
  299. #
  300. # "catch errors caused by wrong parenthesis and brackets
  301. # " also accept <% for {, %> for }, <: for [ and :> for ] (C99)
  302. # " But avoid matching <::.
  303. # syn cluster   cParenGroup     contains=cParenError,cIncluded,cSpecial,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cUserLabel,cBitField,cOctalZero,@cCppOutInGroup,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom
  304. # if exists("c_no_curly_error")
  305. #   if s:ft ==# 'cpp' && !exists("cpp_no_cpp11")
  306. #     syn region        cParen          transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,cCppString,@Spell
  307. #     " cCppParen: same as cParen but ends at end-of-line; used in cDefine
  308. #     syn region        cCppParen       transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell
  309. #     syn match cParenError     display ")"
  310. #     syn match cErrInParen     display contained "^^<%\|^%>"
  311. #   else
  312. #     syn region        cParen          transparent start='(' end=')' end='}'me=s-1 contains=ALLBUT,cBlock,@cParenGroup,cCppParen,cCppString,@Spell
  313. #     " cCppParen: same as cParen but ends at end-of-line; used in cDefine
  314. #     syn region        cCppParen       transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell
  315. #     syn match cParenError     display ")"
  316. #     syn match cErrInParen     display contained "^[{}]\|^<%\|^%>"
  317. #   endif
  318. # elseif exists("c_no_bracket_error")
  319. #   if s:ft ==# 'cpp' && !exists("cpp_no_cpp11")
  320. #     syn region        cParen          transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,cCppString,@Spell
  321. #     " cCppParen: same as cParen but ends at end-of-line; used in cDefine
  322. #     syn region        cCppParen       transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell
  323. #     syn match cParenError     display ")"
  324. #     syn match cErrInParen     display contained "<%\|%>"
  325. #   else
  326. #     syn region        cParen          transparent start='(' end=')' end='}'me=s-1 contains=ALLBUT,cBlock,@cParenGroup,cCppParen,cCppString,@Spell
  327. #     " cCppParen: same as cParen but ends at end-of-line; used in cDefine
  328. #     syn region        cCppParen       transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cParen,cString,@Spell
  329. #     syn match cParenError     display ")"
  330. #     syn match cErrInParen     display contained "[{}]\|<%\|%>"
  331. #   endif
  332. # else
  333. #   if s:ft ==# 'cpp' && !exists("cpp_no_cpp11")
  334. #     syn region        cParen          transparent start='(' end=')' contains=ALLBUT,@cParenGroup,cCppParen,cErrInBracket,cCppBracket,cCppString,@Spell
  335. #     " cCppParen: same as cParen but ends at end-of-line; used in cDefine
  336. #     syn region        cCppParen       transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cErrInBracket,cParen,cBracket,cString,@Spell
  337. #     syn match cParenError     display "[\])]"
  338. #     syn match cErrInParen     display contained "<%\|%>"
  339. #     syn region        cBracket        transparent start='\[\|<::\@!' end=']\|:>' contains=ALLBUT,@cParenGroup,cErrInParen,cCppParen,cCppBracket,cCppString,@Spell
  340. #   else
  341. #     syn region        cParen          transparent start='(' end=')' end='}'me=s-1 contains=ALLBUT,cBlock,@cParenGroup,cCppParen,cErrInBracket,cCppBracket,cCppString,@Spell
  342. #     " cCppParen: same as cParen but ends at end-of-line; used in cDefine
  343. #     syn region        cCppParen       transparent start='(' skip='\\$' excludenl end=')' end='$' contained contains=ALLBUT,@cParenGroup,cErrInBracket,cParen,cBracket,cString,@Spell
  344. #     syn match cParenError     display "[\])]"
  345. #     syn match cErrInParen     display contained "[\]{}]\|<%\|%>"
  346. #     syn region        cBracket        transparent start='\[\|<::\@!' end=']\|:>' end='}'me=s-1 contains=ALLBUT,cBlock,@cParenGroup,cErrInParen,cCppParen,cCppBracket,cCppString,@Spell
  347. #   endif
  348. #   " cCppBracket: same as cParen but ends at end-of-line; used in cDefine
  349. #   syn region  cCppBracket     transparent start='\[\|<::\@!' skip='\\$' excludenl end=']\|:>' end='$' contained contains=ALLBUT,@cParenGroup,cErrInParen,cParen,cBracket,cString,@Spell
  350. #   syn match   cErrInBracket   display contained "[);{}]\|<%\|%>"
  351. # endif
  352. #
  353. # if s:ft ==# 'c' || exists("cpp_no_cpp11")
  354. #   syn region  cBadBlock       keepend start="{" end="}" contained containedin=cParen,cBracket,cBadBlock transparent fold
  355. # endif
  356. #
  357. # "integer number, or floating point number without a dot and with "f".
  358. # syn case ignore
  359. # syn match     cNumbers        display transparent "\<\d\|\.\d" contains=cNumber,cFloat,cOctalError,cOctal
  360. # " Same, but without octal error (for comments)
  361. # syn match     cNumbersCom     display contained transparent "\<\d\|\.\d" contains=cNumber,cFloat,cOctal
  362. # syn match     cNumber         display contained "\d\+\(u\=l\{0,2}\|ll\=u\)\>"
  363. # "hex number
  364. # syn match     cNumber         display contained "0x\x\+\(u\=l\{0,2}\|ll\=u\)\>"
  365. # " Flag the first zero of an octal number as something special
  366. # syn match     cOctal          display contained "0\o\+\(u\=l\{0,2}\|ll\=u\)\>" contains=cOctalZero
  367. # syn match     cOctalZero      display contained "\<0"
  368. # syn match     cFloat          display contained "\d\+f"
  369. # "floating point number, with dot, optional exponent
  370. # syn match     cFloat          display contained "\d\+\.\d*\(e[-+]\=\d\+\)\=[fl]\="
  371. # "floating point number, starting with a dot, optional exponent
  372. # syn match     cFloat          display contained "\.\d\+\(e[-+]\=\d\+\)\=[fl]\=\>"
  373. # "floating point number, without dot, with exponent
  374. # syn match     cFloat          display contained "\d\+e[-+]\=\d\+[fl]\=\>"
  375. # if !exists("c_no_c99")
  376. #   "hexadecimal floating point number, optional leading digits, with dot, with exponent
  377. #   syn match   cFloat          display contained "0x\x*\.\x\+p[-+]\=\d\+[fl]\=\>"
  378. #   "hexadecimal floating point number, with leading digits, optional dot, with exponent
  379. #   syn match   cFloat          display contained "0x\x\+\.\=p[-+]\=\d\+[fl]\=\>"
  380. # endif
  381. #
  382. # " flag an octal number with wrong digits
  383. # syn match     cOctalError     display contained "0\o*[89]\d*"
  384. # syn case match
  385. #
  386. # if exists("c_comment_strings")
  387. #   " A comment can contain cString, cCharacter and cNumber.
  388. #   " But a "*/" inside a cString in a cComment DOES end the comment!  So we
  389. #   " need to use a special type of cString: cCommentString, which also ends on
  390. #   " "*/", and sees a "*" at the start of the line as comment again.
  391. #   " Unfortunately this doesn't very well work for // type of comments :-(
  392. #   syn match   cCommentSkip    contained "^\s*\*\($\|\s\+\)"
  393. #   syn region cCommentString   contained start=+L\=\\\@<!"+ skip=+\\\\\|\\"+ end=+"+ end=+\*/+me=s-1 contains=cSpecial,cCommentSkip
  394. #   syn region cComment2String  contained start=+L\=\\\@<!"+ skip=+\\\\\|\\"+ end=+"+ end="$" contains=cSpecial
  395. #   syn region  cCommentL       start="//" skip="\\$" end="$" keepend contains=@cCommentGroup,cComment2String,cCharacter,cNumbersCom,cSpaceError,@Spell
  396. #   if exists("c_no_comment_fold")
  397. #     " Use "extend" here to have preprocessor lines not terminate halfway a
  398. #     " comment.
  399. #     syn region cComment       matchgroup=cCommentStart start="/\*" end="\*/" contains=@cCommentGroup,cCommentStartError,cCommentString,cCharacter,cNumbersCom,cSpaceError,@Spell extend
  400. #   else
  401. #     syn region cComment       matchgroup=cCommentStart start="/\*" end="\*/" contains=@cCommentGroup,cCommentStartError,cCommentString,cCharacter,cNumbersCom,cSpaceError,@Spell fold extend
  402. #   endif
  403. # else
  404. #   syn region  cCommentL       start="//" skip="\\$" end="$" keepend contains=@cCommentGroup,cSpaceError,@Spell
  405. #   if exists("c_no_comment_fold")
  406. #     syn region        cComment        matchgroup=cCommentStart start="/\*" end="\*/" contains=@cCommentGroup,cCommentStartError,cSpaceError,@Spell extend
  407. #   else
  408. #     syn region        cComment        matchgroup=cCommentStart start="/\*" end="\*/" contains=@cCommentGroup,cCommentStartError,cSpaceError,@Spell fold extend
  409. #   endif
  410. # endif
  411. # " keep a // comment separately, it terminates a preproc. conditional
  412. # syn match     cCommentError   display "\*/"
  413. # syn match     cCommentStartError display "/\*"me=e-1 contained
  414. #
  415. # syn keyword   cOperator       sizeof
  416. # if exists("c_gnu")
  417. #   syn keyword cStatement      __asm__
  418. #   syn keyword cOperator       typeof __real__ __imag__
  419. # endif
  420. # syn keyword   cType           int long short char void
  421. # syn keyword   cType           signed unsigned float double
  422. # if !exists("c_no_ansi") || exists("c_ansi_typedefs")
  423. #   syn keyword   cType         size_t ssize_t off_t wchar_t ptrdiff_t sig_atomic_t fpos_t
  424. #   syn keyword   cType         clock_t time_t va_list jmp_buf FILE DIR div_t ldiv_t
  425. #   syn keyword   cType         mbstate_t wctrans_t wint_t wctype_t
  426. # endif
  427. # if !exists("c_no_c99") " ISO C99
  428. #   syn keyword cType           _Bool bool _Complex complex _Imaginary imaginary
  429. #   syn keyword cType           int8_t int16_t int32_t int64_t
  430. #   syn keyword cType           uint8_t uint16_t uint32_t uint64_t
  431. #   syn keyword cType           int_least8_t int_least16_t int_least32_t int_least64_t
  432. #   syn keyword cType           uint_least8_t uint_least16_t uint_least32_t uint_least64_t
  433. #   syn keyword cType           int_fast8_t int_fast16_t int_fast32_t int_fast64_t
  434. #   syn keyword cType           uint_fast8_t uint_fast16_t uint_fast32_t uint_fast64_t
  435. #   syn keyword cType           intptr_t uintptr_t
  436. #   syn keyword cType           intmax_t uintmax_t
  437. # endif
  438. # if exists("c_gnu")
  439. #   syn keyword cType           __label__ __complex__ __volatile__
  440. # endif
  441. #
  442. # syn keyword   cStructure      struct union enum typedef
  443. # syn keyword   cStorageClass   static register auto volatile extern const
  444. # if exists("c_gnu")
  445. #   syn keyword cStorageClass   inline __attribute__
  446. # endif
  447. # if !exists("c_no_c99")
  448. #   syn keyword cStorageClass   inline restrict
  449. # endif
  450. # if !exists("c_no_c11")
  451. #   syn keyword cStorageClass   _Alignas alignas
  452. #   syn keyword cOperator       _Alignof alignof
  453. #   syn keyword cStorageClass   _Atomic
  454. #   syn keyword cOperator       _Generic
  455. #   syn keyword cStorageClass   _Noreturn noreturn
  456. #   syn keyword cOperator       _Static_assert static_assert
  457. #   syn keyword cStorageClass   _Thread_local thread_local
  458. #   syn keyword   cType         char16_t char32_t
  459. # endif
  460. #
  461. # if !exists("c_no_ansi") || exists("c_ansi_constants") || exists("c_gnu")
  462. #   if exists("c_gnu")
  463. #     syn keyword cConstant __GNUC__ __FUNCTION__ __PRETTY_FUNCTION__ __func__
  464. #   endif
  465. #   syn keyword cConstant __LINE__ __FILE__ __DATE__ __TIME__ __STDC__
  466. #   syn keyword cConstant __STDC_VERSION__
  467. #   syn keyword cConstant CHAR_BIT MB_LEN_MAX MB_CUR_MAX
  468. #   syn keyword cConstant UCHAR_MAX UINT_MAX ULONG_MAX USHRT_MAX
  469. #   syn keyword cConstant CHAR_MIN INT_MIN LONG_MIN SHRT_MIN
  470. #   syn keyword cConstant CHAR_MAX INT_MAX LONG_MAX SHRT_MAX
  471. #   syn keyword cConstant SCHAR_MIN SINT_MIN SLONG_MIN SSHRT_MIN
  472. #   syn keyword cConstant SCHAR_MAX SINT_MAX SLONG_MAX SSHRT_MAX
  473. #   if !exists("c_no_c99")
  474. #     syn keyword cConstant __func__
  475. #     syn keyword cConstant LLONG_MIN LLONG_MAX ULLONG_MAX
  476. #     syn keyword cConstant INT8_MIN INT16_MIN INT32_MIN INT64_MIN
  477. #     syn keyword cConstant INT8_MAX INT16_MAX INT32_MAX INT64_MAX
  478. #     syn keyword cConstant UINT8_MAX UINT16_MAX UINT32_MAX UINT64_MAX
  479. #     syn keyword cConstant INT_LEAST8_MIN INT_LEAST16_MIN INT_LEAST32_MIN INT_LEAST64_MIN
  480. #     syn keyword cConstant INT_LEAST8_MAX INT_LEAST16_MAX INT_LEAST32_MAX INT_LEAST64_MAX
  481. #     syn keyword cConstant UINT_LEAST8_MAX UINT_LEAST16_MAX UINT_LEAST32_MAX UINT_LEAST64_MAX
  482. #     syn keyword cConstant INT_FAST8_MIN INT_FAST16_MIN INT_FAST32_MIN INT_FAST64_MIN
  483. #     syn keyword cConstant INT_FAST8_MAX INT_FAST16_MAX INT_FAST32_MAX INT_FAST64_MAX
  484. #     syn keyword cConstant UINT_FAST8_MAX UINT_FAST16_MAX UINT_FAST32_MAX UINT_FAST64_MAX
  485. #     syn keyword cConstant INTPTR_MIN INTPTR_MAX UINTPTR_MAX
  486. #     syn keyword cConstant INTMAX_MIN INTMAX_MAX UINTMAX_MAX
  487. #     syn keyword cConstant PTRDIFF_MIN PTRDIFF_MAX SIG_ATOMIC_MIN SIG_ATOMIC_MAX
  488. #     syn keyword cConstant SIZE_MAX WCHAR_MIN WCHAR_MAX WINT_MIN WINT_MAX
  489. #   endif
  490. #   syn keyword cConstant FLT_RADIX FLT_ROUNDS
  491. #   syn keyword cConstant FLT_DIG FLT_MANT_DIG FLT_EPSILON
  492. #   syn keyword cConstant DBL_DIG DBL_MANT_DIG DBL_EPSILON
  493. #   syn keyword cConstant LDBL_DIG LDBL_MANT_DIG LDBL_EPSILON
  494. #   syn keyword cConstant FLT_MIN FLT_MAX FLT_MIN_EXP FLT_MAX_EXP
  495. #   syn keyword cConstant FLT_MIN_10_EXP FLT_MAX_10_EXP
  496. #   syn keyword cConstant DBL_MIN DBL_MAX DBL_MIN_EXP DBL_MAX_EXP
  497. #   syn keyword cConstant DBL_MIN_10_EXP DBL_MAX_10_EXP
  498. #   syn keyword cConstant LDBL_MIN LDBL_MAX LDBL_MIN_EXP LDBL_MAX_EXP
  499. #   syn keyword cConstant LDBL_MIN_10_EXP LDBL_MAX_10_EXP
  500. #   syn keyword cConstant HUGE_VAL CLOCKS_PER_SEC NULL
  501. #   syn keyword cConstant LC_ALL LC_COLLATE LC_CTYPE LC_MONETARY
  502. #   syn keyword cConstant LC_NUMERIC LC_TIME
  503. #   syn keyword cConstant SIG_DFL SIG_ERR SIG_IGN
  504. #   syn keyword cConstant SIGABRT SIGFPE SIGILL SIGHUP SIGINT SIGSEGV SIGTERM
  505. #   " Add POSIX signals as well...
  506. #   syn keyword cConstant SIGABRT SIGALRM SIGCHLD SIGCONT SIGFPE SIGHUP
  507. #   syn keyword cConstant SIGILL SIGINT SIGKILL SIGPIPE SIGQUIT SIGSEGV
  508. #   syn keyword cConstant SIGSTOP SIGTERM SIGTRAP SIGTSTP SIGTTIN SIGTTOU
  509. #   syn keyword cConstant SIGUSR1 SIGUSR2
  510. #   syn keyword cConstant _IOFBF _IOLBF _IONBF BUFSIZ EOF WEOF
  511. #   syn keyword cConstant FOPEN_MAX FILENAME_MAX L_tmpnam
  512. #   syn keyword cConstant SEEK_CUR SEEK_END SEEK_SET
  513. #   syn keyword cConstant TMP_MAX stderr stdin stdout
  514. #   syn keyword cConstant EXIT_FAILURE EXIT_SUCCESS RAND_MAX
  515. #   " Add POSIX errors as well
  516. #   syn keyword cConstant E2BIG EACCES EAGAIN EBADF EBADMSG EBUSY
  517. #   syn keyword cConstant ECANCELED ECHILD EDEADLK EDOM EEXIST EFAULT
  518. #   syn keyword cConstant EFBIG EILSEQ EINPROGRESS EINTR EINVAL EIO EISDIR
  519. #   syn keyword cConstant EMFILE EMLINK EMSGSIZE ENAMETOOLONG ENFILE ENODEV
  520. #   syn keyword cConstant ENOENT ENOEXEC ENOLCK ENOMEM ENOSPC ENOSYS
  521. #   syn keyword cConstant ENOTDIR ENOTEMPTY ENOTSUP ENOTTY ENXIO EPERM
  522. #   syn keyword cConstant EPIPE ERANGE EROFS ESPIPE ESRCH ETIMEDOUT EXDEV
  523. #   " math.h
  524. #   syn keyword cConstant M_E M_LOG2E M_LOG10E M_LN2 M_LN10 M_PI M_PI_2 M_PI_4
  525. #   syn keyword cConstant M_1_PI M_2_PI M_2_SQRTPI M_SQRT2 M_SQRT1_2
  526. # endif
  527. # if !exists("c_no_c99") " ISO C99
  528. #   syn keyword cConstant true false
  529. # endif
  530. #
  531. # " Accept %: for # (C99)
  532. # syn region    cPreCondit      start="^\s*\(%:\|#\)\s*\(if\|ifdef\|ifndef\|elif\)\>" skip="\\$" end="$" keepend contains=cComment,cCommentL,cCppString,cCharacter,cCppParen,cParenError,cNumbers,cCommentError,cSpaceError
  533. # syn match     cPreConditMatch display "^\s*\(%:\|#\)\s*\(else\|endif\)\>"
  534. # if !exists("c_no_if0")
  535. #   syn cluster cCppOutInGroup  contains=cCppInIf,cCppInElse,cCppInElse2,cCppOutIf,cCppOutIf2,cCppOutElse,cCppInSkip,cCppOutSkip
  536. #   syn region  cCppOutWrapper  start="^\s*\(%:\|#\)\s*if\s\+0\+\s*\($\|//\|/\*\|&\)" end=".\@=\|$" contains=cCppOutIf,cCppOutElse,@NoSpell fold
  537. #   syn region  cCppOutIf       contained start="0\+" matchgroup=cCppOutWrapper end="^\s*\(%:\|#\)\s*endif\>" contains=cCppOutIf2,cCppOutElse
  538. #   if !exists("c_no_if0_fold")
  539. #     syn region        cCppOutIf2      contained matchgroup=cCppOutWrapper start="0\+" end="^\s*\(%:\|#\)\s*\(else\>\|elif\s\+\(0\+\s*\($\|//\|/\*\|&\)\)\@!\|endif\>\)"me=s-1 contains=cSpaceError,cCppOutSkip,@Spell fold
  540. #   else
  541. #     syn region        cCppOutIf2      contained matchgroup=cCppOutWrapper start="0\+" end="^\s*\(%:\|#\)\s*\(else\>\|elif\s\+\(0\+\s*\($\|//\|/\*\|&\)\)\@!\|endif\>\)"me=s-1 contains=cSpaceError,cCppOutSkip,@Spell
  542. #   endif
  543. #   syn region  cCppOutElse     contained matchgroup=cCppOutWrapper start="^\s*\(%:\|#\)\s*\(else\|elif\)" end="^\s*\(%:\|#\)\s*endif\>"me=s-1 contains=TOP,cPreCondit
  544. #   syn region  cCppInWrapper   start="^\s*\(%:\|#\)\s*if\s\+0*[1-9]\d*\s*\($\|//\|/\*\||\)" end=".\@=\|$" contains=cCppInIf,cCppInElse fold
  545. #   syn region  cCppInIf        contained matchgroup=cCppInWrapper start="\d\+" end="^\s*\(%:\|#\)\s*endif\>" contains=TOP,cPreCondit
  546. #   if !exists("c_no_if0_fold")
  547. #     syn region        cCppInElse      contained start="^\s*\(%:\|#\)\s*\(else\>\|elif\s\+\(0*[1-9]\d*\s*\($\|//\|/\*\||\)\)\@!\)" end=".\@=\|$" containedin=cCppInIf contains=cCppInElse2 fold
  548. #   else
  549. #     syn region        cCppInElse      contained start="^\s*\(%:\|#\)\s*\(else\>\|elif\s\+\(0*[1-9]\d*\s*\($\|//\|/\*\||\)\)\@!\)" end=".\@=\|$" containedin=cCppInIf contains=cCppInElse2
  550. #   endif
  551. #   syn region  cCppInElse2     contained matchgroup=cCppInWrapper start="^\s*\(%:\|#\)\s*\(else\|elif\)\([^/]\|/[^/*]\)*" end="^\s*\(%:\|#\)\s*endif\>"me=s-1 contains=cSpaceError,cCppOutSkip,@Spell
  552. #   syn region  cCppOutSkip     contained start="^\s*\(%:\|#\)\s*\(if\>\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\(%:\|#\)\s*endif\>" contains=cSpaceError,cCppOutSkip
  553. #   syn region  cCppInSkip      contained matchgroup=cCppInWrapper start="^\s*\(%:\|#\)\s*\(if\s\+\(\d\+\s*\($\|//\|/\*\||\|&\)\)\@!\|ifdef\>\|ifndef\>\)" skip="\\$" end="^\s*\(%:\|#\)\s*endif\>" containedin=cCppOutElse,cCppInIf,cCppInSkip contains=TOP,cPreProc
  554. # endif
  555. # syn region    cIncluded       display contained start=+"+ skip=+\\\\\|\\"+ end=+"+
  556. # syn match     cIncluded       display contained "<[^>]*>"
  557. # syn match     cInclude        display "^\s*\(%:\|#\)\s*include\>\s*["<]" contains=cIncluded
  558. # "syn match cLineSkip  "\\$"
  559. # syn cluster   cPreProcGroup   contains=cPreCondit,cIncluded,cInclude,cDefine,cErrInParen,cErrInBracket,cUserLabel,cSpecial,cOctalZero,cCppOutWrapper,cCppInWrapper,@cCppOutInGroup,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom,cString,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cParen,cBracket,cMulti,cBadBlock
  560. # syn region    cDefine         start="^\s*\(%:\|#\)\s*\(define\|undef\)\>" skip="\\$" end="$" keepend contains=ALLBUT,@cPreProcGroup,@Spell
  561. # syn region    cPreProc        start="^\s*\(%:\|#\)\s*\(pragma\>\|line\>\|warning\>\|warn\>\|error\>\)" skip="\\$" end="$" keepend contains=ALLBUT,@cPreProcGroup,@Spell
  562. #
  563. # " Highlight User Labels
  564. # syn cluster   cMultiGroup     contains=cIncluded,cSpecial,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cUserCont,cUserLabel,cBitField,cOctalZero,cCppOutWrapper,cCppInWrapper,@cCppOutInGroup,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom,cCppParen,cCppBracket,cCppString
  565. # if s:ft ==# 'c' || exists("cpp_no_cpp11")
  566. #   syn region  cMulti          transparent start='?' skip='::' end=':' contains=ALLBUT,@cMultiGroup,@Spell
  567. # endif
  568. # " Avoid matching foo::bar() in C++ by requiring that the next char is not ':'
  569. # syn cluster   cLabelGroup     contains=cUserLabel
  570. # syn match     cUserCont       display "^\s*\I\i*\s*:$" contains=@cLabelGroup
  571. # syn match     cUserCont       display ";\s*\I\i*\s*:$" contains=@cLabelGroup
  572. # syn match     cUserCont       display "^\s*\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup
  573. # syn match     cUserCont       display ";\s*\I\i*\s*:[^:]"me=e-1 contains=@cLabelGroup
  574. #
  575. # syn match     cUserLabel      display "\I\i*" contained
  576. #
  577. # " Avoid recognizing most bitfields as labels
  578. # syn match     cBitField       display "^\s*\I\i*\s*:\s*[1-9]"me=e-1 contains=cType
  579. # syn match     cBitField       display ";\s*\I\i*\s*:\s*[1-9]"me=e-1 contains=cType
  580. #
  581. # if exists("c_minlines")
  582. #   let b:c_minlines = c_minlines
  583. # else
  584. #   if !exists("c_no_if0")
  585. #     let b:c_minlines = 50     " #if 0 constructs can be long
  586. #   else
  587. #     let b:c_minlines = 15     " mostly for () constructs
  588. #   endif
  589. # endif
  590. # if exists("c_curly_error")
  591. #   syn sync fromstart
  592. # else
  593. #   exec "syn sync ccomment cComment minlines=" . b:c_minlines
  594. # endif
  595. #
  596. # " Define the default highlighting.
  597. # " Only used when an item doesn't have highlighting yet
  598. # hi def link cFormat           cSpecial
  599. # hi def link cCppString                cString
  600. # hi def link cCommentL         cComment
  601. # hi def link cCommentStart     cComment
  602. # hi def link cLabel            Label
  603. # hi def link cUserLabel                Label
  604. # hi def link cConditional      Conditional
  605. # hi def link cRepeat           Repeat
  606. # hi def link cCharacter                Character
  607. # hi def link cSpecialCharacter cSpecial
  608. # hi def link cNumber           Number
  609. # hi def link cOctal            Number
  610. # hi def link cOctalZero                PreProc  " link this to Error if you want
  611. # hi def link cFloat            Float
  612. # hi def link cOctalError               cError
  613. # hi def link cParenError               cError
  614. # hi def link cErrInParen               cError
  615. # hi def link cErrInBracket     cError
  616. # hi def link cCommentError     cError
  617. # hi def link cCommentStartError        cError
  618. # hi def link cSpaceError               cError
  619. # hi def link cSpecialError     cError
  620. # hi def link cCurlyError               cError
  621. # hi def link cOperator         Operator
  622. # hi def link cStructure                Structure
  623. # hi def link cStorageClass     StorageClass
  624. # hi def link cInclude          Include
  625. # hi def link cPreProc          PreProc
  626. # hi def link cDefine           Macro
  627. # hi def link cIncluded         cString
  628. # hi def link cError            Error
  629. # hi def link cStatement                Statement
  630. # hi def link cCppInWrapper     cCppOutWrapper
  631. # hi def link cCppOutWrapper    cPreCondit
  632. # hi def link cPreConditMatch   cPreCondit
  633. # hi def link cPreCondit                PreCondit
  634. # hi def link cType             Type
  635. # hi def link cConstant         Constant
  636. # hi def link cCommentString    cString
  637. # hi def link cComment2String   cString
  638. # hi def link cCommentSkip      cComment
  639. # hi def link cString           String
  640. # hi def link cComment          Comment
  641. # hi def link cSpecial          SpecialChar
  642. # hi def link cTodo             Todo
  643. # hi def link cBadContinuation  Error
  644. # hi def link cCppOutSkip               cCppOutIf2
  645. # hi def link cCppInElse2               cCppOutIf2
  646. # hi def link cCppOutIf2                cCppOut2  " Old syntax group for #if 0 body
  647. # hi def link cCppOut2          cCppOut  " Old syntax group for #if of #if 0
  648. # hi def link cCppOut           Comment
  649. #
  650. # endif
  651. #
  652. # let b:current_syn = 'man'
  653. # unlet s:ft
  654. #
  655. # let &cpo = s:cpo_save
  656. # unlet s:cpo_save
  657. # " vim: ts=8
  658. #
  659. #=end:vman.vim=
captcha