vim.ok 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890
  1. " vim: set ft=vim sw=4 :
  2. " START_INDENT
  3. func Some()
  4. let x = 1
  5. endfunc
  6. let cmd =
  7. \ 'some '
  8. \ 'string'
  9. if 1
  10. let x = [
  11. \ ]
  12. endif
  13. for x in [
  14. {key: 'value'},
  15. ]
  16. eval 0
  17. endfor
  18. let t = [
  19. \ {
  20. \ 'k': 'val',
  21. \ },
  22. \ ]
  23. def Func()
  24. var d = dd
  25. ->extend({
  26. })
  27. eval 0
  28. enddef
  29. " END_INDENT
  30. " START_INDENT
  31. " INDENT_EXE let g:vim_indent_cont = 6
  32. let cmd =
  33. \ 'some '
  34. \ 'string'
  35. " END_INDENT
  36. " START_INDENT
  37. " INDENT_EXE let g:vim_indent_cont = 5
  38. let list = [
  39. \ 'one',
  40. \ 'two']
  41. " END_INDENT
  42. " START_INDENT
  43. " INDENT_EXE unlet g:vim_indent_cont
  44. let list = [
  45. 'one',
  46. 'two',
  47. ]
  48. echo
  49. " END_INDENT
  50. " START_INDENT
  51. " INDENT_AT this-line
  52. func Some()
  53. let f = x " this-line
  54. endfunc
  55. " END_INDENT
  56. " START_INDENT
  57. " INDENT_NEXT next-line
  58. func Some()
  59. " next-line
  60. let f = x
  61. endfunc
  62. " END_INDENT
  63. " START_INDENT
  64. " INDENT_PREV prev-line
  65. func Some()
  66. let f = x
  67. " prev-line
  68. endfunc
  69. " END_INDENT
  70. " START_INDENT
  71. let a =<< END
  72. nothing
  73. END
  74. " END_INDENT
  75. " START_INDENT
  76. let a =<< trim END
  77. nothing
  78. END
  79. " END_INDENT
  80. " START_INDENT
  81. " INDENT_AT this-line
  82. let a=<< trim END
  83. blah
  84. blah
  85. blah this-line
  86. END
  87. " END_INDENT
  88. " START_INDENT
  89. if v:true
  90. echo 0
  91. end
  92. " END_INDENT
  93. " START_INDENT
  94. var result = Func(
  95. arg1,
  96. arg2
  97. )
  98. " END_INDENT
  99. " START_INDENT
  100. var result = Func(arg1,
  101. arg2)
  102. " END_INDENT
  103. " START_INDENT
  104. filter(list, (k, v) =>
  105. v > 0)
  106. " END_INDENT
  107. " START_INDENT
  108. filter(list, (k, v) => {
  109. const x = get(list, k, 0)
  110. return x > 0
  111. })
  112. " END_INDENT
  113. " START_INDENT
  114. if x > 0
  115. filter(list, (k, v) => {
  116. const x = get(list, k, 1)
  117. return x > 0
  118. })
  119. endif
  120. " END_INDENT
  121. " START_INDENT
  122. {
  123. var temp = 'temp'
  124. }
  125. " END_INDENT
  126. " START_INDENT
  127. var text = lead
  128. .. middle
  129. .. end
  130. " END_INDENT
  131. " START_INDENT
  132. var text = lead ..
  133. middle ..
  134. end
  135. " END_INDENT
  136. " START_INDENT
  137. var total = start +
  138. end -
  139. correction
  140. " END_INDENT
  141. " START_INDENT
  142. var result = start
  143. :+ print
  144. " END_INDENT
  145. " START_INDENT
  146. var result = positive
  147. ? PosFunc(arg)
  148. : NegFunc(arg)
  149. " END_INDENT
  150. " START_INDENT
  151. var result = GetBuilder()
  152. ->BuilderSetWidth(333)
  153. ->BuilderSetHeight(777)
  154. ->BuilderBuild()
  155. " END_INDENT
  156. " START_INDENT
  157. var result = MyDict
  158. .member
  159. " END_INDENT
  160. " START_INDENT
  161. autocmd BufNewFile *.match if condition
  162. | echo 'match'
  163. | endif
  164. " END_INDENT
  165. " START_INDENT
  166. set cpo+=C
  167. var lines =<< trim END
  168. | this works
  169. END
  170. set cpo-=C
  171. " END_INDENT
  172. " START_INDENT
  173. syn region Text
  174. \ start='foo'
  175. #\ comment
  176. \ end='bar'
  177. " END_INDENT
  178. " START_INDENT
  179. au CursorHold * echom 'BEFORE bar'
  180. #\ some comment
  181. | echom 'AFTER bar'
  182. " END_INDENT
  183. " START_INDENT
  184. def MyFunc(text: string,
  185. separator = '-'
  186. ): string
  187. enddef
  188. " END_INDENT
  189. " START_INDENT
  190. def MyFunc(
  191. text: string,
  192. separator = '-'
  193. ): string
  194. enddef
  195. " END_INDENT
  196. " START_INDENT
  197. [var1, var2] =
  198. Func()
  199. " END_INDENT
  200. " START_INDENT
  201. const list = ['one',
  202. 'two']
  203. " END_INDENT
  204. " START_INDENT
  205. const list = [
  206. 'one',
  207. 'two',
  208. ]
  209. " END_INDENT
  210. " START_INDENT
  211. const dict = {one: 1,
  212. two: 2
  213. }
  214. " END_INDENT
  215. " START_INDENT
  216. const dict = {
  217. one: 1,
  218. two: 2
  219. }
  220. " END_INDENT
  221. " START_INDENT
  222. if true
  223. const dict =
  224. {
  225. one: 1,
  226. two: 2
  227. }
  228. endif
  229. " END_INDENT
  230. " START_INDENT
  231. def Func()
  232. return {
  233. one: 1
  234. }
  235. enddef
  236. " END_INDENT
  237. " START_INDENT
  238. echo {
  239. a: 0,
  240. # b
  241. # c
  242. }
  243. " END_INDENT
  244. " START_INDENT
  245. echo search(
  246. # comment
  247. '1'
  248. .. '2'
  249. )
  250. " END_INDENT
  251. " START_INDENT
  252. if true
  253. var v = ( # trailing "(" starts line continuation
  254. 3 + 4 # nothing special
  255. ) # end of expression indicates continued line
  256. var x: number # needs to align with previous "var"
  257. endif
  258. " END_INDENT
  259. " START_INDENT
  260. def Func() # {{{
  261. # comment
  262. if true
  263. return
  264. endif
  265. enddef
  266. " END_INDENT
  267. " START_INDENT
  268. echo {
  269. key:
  270. 'value',
  271. }
  272. " END_INDENT
  273. " START_INDENT
  274. var id = time
  275. ->timer_start((_) => {
  276. n = 0
  277. })
  278. " END_INDENT
  279. " START_INDENT
  280. augroup Name
  281. autocmd!
  282. augroup END
  283. " END_INDENT
  284. " START_INDENT
  285. var n =
  286. # comment
  287. 1
  288. + 2
  289. var s = ''
  290. " END_INDENT
  291. " START_INDENT
  292. var keys = {
  293. J: 'j',
  294. "\<Home>": '1G',
  295. "\<End>": 'G',
  296. z: 'zz'
  297. }
  298. " END_INDENT
  299. " START_INDENT
  300. export def Func(
  301. n: number,
  302. s: string,
  303. ...l: list<bool>
  304. )
  305. enddef
  306. " END_INDENT
  307. " START_INDENT
  308. var heredoc =<< trim ENDD
  309. var nested_heredoc =<< trim END
  310. END
  311. ENDD
  312. " END_INDENT
  313. " START_INDENT
  314. if true
  315. else " comment
  316. endif
  317. " END_INDENT
  318. " START_INDENT
  319. if true | echo 'one' | endif
  320. if true | echo 'two' | endif
  321. if true | echo 'three' | endif
  322. " END_INDENT
  323. " START_INDENT
  324. if true
  325. :'<-1 mark <
  326. else
  327. echo ''
  328. endif
  329. " END_INDENT
  330. " START_INDENT
  331. substitute/pat /rep /
  332. echo
  333. " END_INDENT
  334. " START_INDENT
  335. try
  336. echo 1
  337. catch /pat / # comment
  338. echo 2
  339. endtry
  340. " END_INDENT
  341. " START_INDENT
  342. def Func()
  343. Cmd %
  344. enddef
  345. " END_INDENT
  346. " START_INDENT
  347. if end == 'xxx' || end == 'yyy'
  348. echo
  349. endif
  350. " END_INDENT
  351. " START_INDENT
  352. if true
  353. popup_move(id, {col: 1,
  354. line: 2})
  355. endif
  356. setwinvar(id, 'name', 3)
  357. " END_INDENT
  358. " START_INDENT
  359. var d = [
  360. {a: 'x',
  361. b: 'y'},
  362. FuncA(),
  363. FuncB(),
  364. ]
  365. " END_INDENT
  366. " START_INDENT
  367. var ll = [[
  368. 1,
  369. 2,
  370. 3], [
  371. 4,
  372. 5,
  373. 6], [
  374. 7,
  375. 8,
  376. 9]]
  377. " END_INDENT
  378. " START_INDENT
  379. var ld = [{
  380. a: 'xxx',
  381. b: 'yyy'}, {
  382. c: 'xxx',
  383. d: 'yyy'}, {
  384. e: 'xxx',
  385. f: 'yyy'}, {
  386. }]
  387. " END_INDENT
  388. " START_INDENT
  389. var d = {
  390. a: {
  391. b: {
  392. c: [{
  393. d: 'e',
  394. f: 'g',
  395. h: 'i'
  396. }],
  397. j: 'k',
  398. },
  399. },
  400. }
  401. " END_INDENT
  402. " START_INDENT
  403. if true
  404. var end: any
  405. if true
  406. end = 0
  407. elseif true
  408. echo
  409. endif
  410. endif
  411. " END_INDENT
  412. " START_INDENT
  413. nunmap <buffer> (
  414. nunmap <buffer> )
  415. inoremap [ {
  416. inoremap ] }
  417. silent! xunmap i{
  418. silent! xunmap a{
  419. " END_INDENT
  420. " START_INDENT
  421. def Func(
  422. s: string,
  423. n = 1,
  424. m = 2
  425. )
  426. enddef
  427. " END_INDENT
  428. " START_INDENT
  429. var h =<< END
  430. text
  431. END
  432. def Func()
  433. echo
  434. enddef
  435. " END_INDENT
  436. " START_INDENT
  437. def Func()
  438. var h =<< END
  439. text
  440. END
  441. echo 'test'
  442. enddef
  443. " END_INDENT
  444. " START_INDENT
  445. def Foo()
  446. lcd -
  447. enddef
  448. def Bar()
  449. echo
  450. enddef
  451. " END_INDENT
  452. " START_INDENT
  453. if true
  454. n = Func(1, 2,
  455. 3)
  456. endif
  457. " END_INDENT
  458. " START_INDENT
  459. def Func(s: string,
  460. n: number): bool
  461. if true
  462. return false
  463. endif
  464. enddef
  465. " END_INDENT
  466. " START_INDENT
  467. def Func(
  468. n: number)
  469. #
  470. echo
  471. enddef
  472. " END_INDENT
  473. " START_INDENT
  474. " INDENT_AT this-line
  475. def Func(
  476. n: number)
  477. #
  478. echo # this-line
  479. enddef
  480. " END_INDENT
  481. " START_INDENT
  482. if true
  483. if true
  484. normal! ==
  485. endif
  486. endif
  487. " END_INDENT
  488. " START_INDENT
  489. var d = {
  490. a: () => true,
  491. b: () => true
  492. && true
  493. && Foo(),
  494. c: () => Bar(),
  495. e: () => Baz(),
  496. }
  497. " END_INDENT
  498. " START_INDENT
  499. def Select(Cont: func(func(any)), Pred: func(any): bool): func(func(any))
  500. return (Emit: func(any)) => {
  501. Cont((t: any) => {
  502. if Pred(t)
  503. Emit(t)
  504. endif
  505. })
  506. }
  507. enddef
  508. " END_INDENT
  509. " START_INDENT
  510. " INDENT_EXE let g:vim_indent = {'more_in_bracket_block': v:true}
  511. def Select(Cont: func(func(any)), Pred: func(any): bool): func(func(any))
  512. return (Emit: func(any)) => {
  513. Cont((t: any) => {
  514. if Pred(t)
  515. Emit(t)
  516. endif
  517. })
  518. }
  519. enddef
  520. " END_INDENT
  521. " START_INDENT
  522. " INDENT_EXE unlet! g:vim_indent
  523. " END_INDENT
  524. " START_INDENT
  525. g:lightline = {
  526. 'active': {
  527. 'left': [ [ 'mode', 'paste' ], [ 'readonly', 'relativepath', 'modified' ] ],
  528. },
  529. 'inactive': {
  530. 'left': [ [ 'readonly', 'relativepath', 'modified' ] ],
  531. }
  532. }
  533. " END_INDENT
  534. " START_INDENT
  535. if getline(1, 10)
  536. ->map((_, v: string): number => strcharlen(v))
  537. ->max() > 1'000
  538. &l:breakindent = false
  539. &l:linebreak = false
  540. else
  541. &l:breakindent = true
  542. &l:linebreak = true
  543. endif
  544. " END_INDENT
  545. " START_INDENT
  546. var ext2cmd: dict<string> = {
  547. doc: $'antiword {fname}',
  548. docx: $'pandoc --from=docx --to=markdown {fname}',
  549. epub: $'pandoc --from=epub --to=markdown {fname}',
  550. odp: $'odt2txt {fname}',
  551. odt: $'odt2txt {fname}',
  552. pdf: $'pdftotext -nopgbrk -layout -q -eol unix {fname} -',
  553. rtf: 'unrtf --text',
  554. }
  555. " END_INDENT
  556. " START_INDENT
  557. const ptybuf: number = term_start(&shell, {
  558. hidden: true,
  559. exit_cb: (_, _) => {
  560. if true
  561. close
  562. else
  563. help
  564. endif
  565. }
  566. })
  567. " END_INDENT
  568. " START_INDENT
  569. var d = {
  570. a: 0,
  571. # a ' quote {{{
  572. #}}}
  573. b: 0,
  574. }
  575. " END_INDENT
  576. " START_INDENT
  577. echo printf('%s () %s',
  578. 1,
  579. 2
  580. )
  581. " END_INDENT
  582. " START_INDENT
  583. prop_add(1, col('.'), {
  584. length: 2,
  585. type: 'test'
  586. })
  587. " END_INDENT
  588. " START_INDENT
  589. echo (() => " string starting with space")()
  590. echo
  591. " END_INDENT
  592. " START_INDENT
  593. var variables = deepcopy(g:)
  594. ->filter((k: string, _): bool =>
  595. k =~ '\c\V' .. keyword->escape('\')
  596. && k !~ '\%(loaded\|did_plugin_\)')
  597. ->items()
  598. ->map((_, v): string => v[0] .. ' = ' .. string(v[1]))
  599. new
  600. " END_INDENT
  601. " START_INDENT
  602. var d = freq
  603. ->map((_, v) =>
  604. v * (
  605. 1
  606. + 2
  607. ))
  608. for item in d
  609. ->items()
  610. ->sort((a, b) => b[1] - a[1])
  611. echo
  612. endfor
  613. " END_INDENT
  614. " START_INDENT
  615. make_job = job_start([&shell, &shellcmdflag, make_cmd], {
  616. callback: function(MakeProcessOutput, [qfid]),
  617. close_cb: function(MakeCloseCb, [qfid]),
  618. exit_cb: MakeCompleted,
  619. in_io: 'null'
  620. })
  621. " END_INDENT
  622. " START_INDENT
  623. var matching_abbrev: list<dict<string>> = copy(ABBREV)
  624. ->filter((_, v: dict<string>): bool =>
  625. stridx(v.lhs, word_to_complete) == 0)
  626. ->map((_, v: dict<string>) => ({
  627. word: v.lhs,
  628. menu: AbbrevRhs(v.rhs)->stridx('expand_') >= 0
  629. ? AbbrevRhs(v.rhs)->matchstr('.*,\s*''\zs.*\ze'')')
  630. : AbbrevRhs(v.rhs)
  631. }))
  632. " END_INDENT
  633. " START_INDENT
  634. def Func()
  635. if true
  636. vimgrep /^\C\s*\%(fu\%[nction]\|def\)\s\+/ file
  637. endif
  638. enddef
  639. " END_INDENT
  640. " START_INDENT
  641. setlocal iskeyword+=[
  642. cword = expand('<cword>')
  643. " END_INDENT
  644. " START_INDENT
  645. silent if true
  646. echo
  647. endif
  648. " END_INDENT
  649. " START_INDENT
  650. def Func()
  651. sort :^.*[\/]:
  652. enddef
  653. " END_INDENT
  654. " START_INDENT
  655. def Func()
  656. d = {
  657. }
  658. hd =<< trim END
  659. ['
  660. ]'
  661. END
  662. enddef
  663. " END_INDENT
  664. " START_INDENT
  665. def Func()
  666. if true
  667. var hd =<< trim END
  668. if get(b:, 'current_syntax', '')
  669. endif
  670. END
  671. elseif true
  672. echo
  673. endif
  674. enddef
  675. " END_INDENT
  676. " START_INDENT
  677. # test for control-flow keyword followed by commented fold marker {{{
  678. if true
  679. echo
  680. endif #}}}
  681. " END_INDENT
  682. " START_INDENT
  683. if winsz == 0|let winsz= ""|endif
  684. exe "noswapfile ".winsz."wincmd s"
  685. " END_INDENT
  686. " START_INDENT
  687. if true
  688. if true
  689. windo if true | echo | endif
  690. augroup Name
  691. autocmd WinLeave * if true | eval 1 + 2 | endif
  692. augroup END
  693. endif
  694. endif
  695. " END_INDENT
  696. " START_INDENT
  697. if true
  698. echo ' =<< trim END'
  699. ->len()
  700. endif
  701. " END_INDENT
  702. " START_INDENT
  703. function Func()
  704. if true
  705. if true
  706. if true | echo com | endif
  707. if true | echo com | endif
  708. endif
  709. else
  710. endif
  711. endfunction
  712. " END_INDENT
  713. " START_INDENT
  714. function Func()
  715. if v:true
  716. +
  717. echo
  718. -
  719. endif
  720. endfunction
  721. " END_INDENT
  722. " START_INDENT
  723. var matchpairs: string = &matchpairs
  724. var pairs: dict<list<string>>
  725. for [opening: string, closing: string]
  726. in matchpairs
  727. ->split(',')
  728. ->map((_, v: string): list<string> => split(v, ':'))
  729. pairs[opening] = [escape(opening, '[]'), escape(closing, '[]'), 'nW', 'w$']
  730. pairs[closing] = [escape(opening, '[]'), escape(closing, '[]'), 'bnW', 'w0']
  731. endfor
  732. " END_INDENT
  733. " START_INDENT
  734. {
  735. echo []
  736. + []
  737. + [{a: 1,
  738. b: 2}]
  739. }
  740. " END_INDENT
  741. " START_INDENT
  742. silent! argdel *
  743. edit file
  744. " END_INDENT
  745. " START_INDENT
  746. def Foo()
  747. Bar(1,
  748. []->filter((_, v) => {
  749. return true
  750. }),
  751. () => {
  752. echo
  753. })
  754. enddef
  755. " END_INDENT
  756. " START_INDENT
  757. echo {
  758. k: () => {
  759. if true
  760. echo
  761. popup_setoptions(id,
  762. {title: 'title'})
  763. endif
  764. }
  765. }
  766. " END_INDENT
  767. " START_INDENT
  768. if true
  769. elseif
  770. endif
  771. " END_INDENT