menu.vim 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210
  1. " Vim support file to define the default menus
  2. " You can also use this as a start for your own set of menus.
  3. "
  4. " Maintainer: Bram Moolenaar <Bram@vim.org>
  5. " Last Change: 2022 Nov 27
  6. " Note that ":an" (short for ":anoremenu") is often used to make a menu work
  7. " in all modes and avoid side effects from mappings defined by the user.
  8. " Make sure the '<' and 'C' flags are not included in 'cpoptions', otherwise
  9. " <CR> would not be recognized. See ":help 'cpoptions'".
  10. let s:cpo_save = &cpo
  11. set cpo&vim
  12. " Avoid installing the menus twice
  13. if !exists("did_install_default_menus")
  14. let did_install_default_menus = 1
  15. if exists("v:lang") || &langmenu != ""
  16. " Try to find a menu translation file for the current language.
  17. if &langmenu != ""
  18. if &langmenu =~ "none"
  19. let s:lang = ""
  20. else
  21. let s:lang = &langmenu
  22. endif
  23. else
  24. let s:lang = v:lang
  25. endif
  26. " A language name must be at least two characters, don't accept "C"
  27. " Also skip "en_US" to avoid picking up "en_gb" translations.
  28. if strlen(s:lang) > 1 && s:lang !~? '^en_us'
  29. " When the language does not include the charset add 'encoding'
  30. if s:lang =~ '^\a\a$\|^\a\a_\a\a$'
  31. let s:lang = s:lang . '.' . &enc
  32. endif
  33. " We always use a lowercase name.
  34. " Change "iso-8859" to "iso_8859" and "iso8859" to "iso_8859", some
  35. " systems appear to use this.
  36. " Change spaces to underscores.
  37. let s:lang = substitute(tolower(s:lang), '\.iso-', ".iso_", "")
  38. let s:lang = substitute(s:lang, '\.iso8859', ".iso_8859", "")
  39. let s:lang = substitute(s:lang, " ", "_", "g")
  40. " Remove "@euro", otherwise "LC_ALL=de_DE@euro gvim" will show English menus
  41. let s:lang = substitute(s:lang, "@euro", "", "")
  42. " Change "iso_8859-1" and "iso_8859-15" to "latin1", we always use the
  43. " same menu file for them.
  44. let s:lang = substitute(s:lang, 'iso_8859-15\=$', "latin1", "")
  45. menutrans clear
  46. exe "runtime! lang/menu_" . s:lang . ".vim"
  47. if !exists("did_menu_trans")
  48. " There is no exact match, try matching with a wildcard added
  49. " (e.g. find menu_de_de.iso_8859-1.vim if s:lang == de_DE).
  50. let s:lang = substitute(s:lang, '\.[^.]*', "", "")
  51. exe "runtime! lang/menu_" . s:lang . "[^a-z]*vim"
  52. if !exists("did_menu_trans") && s:lang =~ '_'
  53. " If the language includes a region try matching without that region.
  54. " (e.g. find menu_de.vim if s:lang == de_DE).
  55. let langonly = substitute(s:lang, '_.*', "", "")
  56. exe "runtime! lang/menu_" . langonly . "[^a-z]*vim"
  57. endif
  58. if !exists("did_menu_trans") && strlen($LANG) > 1 && s:lang !~ '^en_us'
  59. " On windows locale names are complicated, try using $LANG, it might
  60. " have been set by set_init_1(). But don't do this for "en" or "en_us".
  61. " But don't match "slovak" when $LANG is "sl".
  62. exe "runtime! lang/menu_" . tolower($LANG) . "[^a-z]*vim"
  63. endif
  64. endif
  65. endif
  66. endif
  67. " Help menu
  68. an 9999.10 &Help.&Overview<Tab><F1> :help<CR>
  69. an 9999.20 &Help.&User\ Manual :help usr_toc<CR>
  70. an 9999.30 &Help.&How-To\ Links :help how-to<CR>
  71. an <silent> 9999.40 &Help.&Find\.\.\. :call <SID>Helpfind()<CR>
  72. an 9999.45 &Help.-sep1- <Nop>
  73. an 9999.50 &Help.&Credits :help credits<CR>
  74. an 9999.60 &Help.Co&pying :help copying<CR>
  75. an 9999.70 &Help.&Sponsor/Register :help sponsor<CR>
  76. an 9999.70 &Help.O&rphans :help kcc<CR>
  77. an 9999.75 &Help.-sep2- <Nop>
  78. an 9999.80 &Help.&Version :version<CR>
  79. an 9999.90 &Help.&About :intro<CR>
  80. if exists(':tlmenu')
  81. tlnoremenu 9999.10 &Help.&Overview<Tab><F1> <C-W>:help<CR>
  82. tlnoremenu 9999.20 &Help.&User\ Manual <C-W>:help usr_toc<CR>
  83. tlnoremenu 9999.30 &Help.&How-To\ Links <C-W>:help how-to<CR>
  84. tlnoremenu <silent> 9999.40 &Help.&Find\.\.\. <C-W>:call <SID>Helpfind()<CR>
  85. tlnoremenu 9999.45 &Help.-sep1- <Nop>
  86. tlnoremenu 9999.50 &Help.&Credits <C-W>:help credits<CR>
  87. tlnoremenu 9999.60 &Help.Co&pying <C-W>:help copying<CR>
  88. tlnoremenu 9999.70 &Help.&Sponsor/Register <C-W>:help sponsor<CR>
  89. tlnoremenu 9999.70 &Help.O&rphans <C-W>:help kcc<CR>
  90. tlnoremenu 9999.75 &Help.-sep2- <Nop>
  91. tlnoremenu 9999.80 &Help.&Version <C-W>:version<CR>
  92. tlnoremenu 9999.90 &Help.&About <C-W>:intro<CR>
  93. endif
  94. fun! s:Helpfind()
  95. if !exists("g:menutrans_help_dialog")
  96. let g:menutrans_help_dialog = "Enter a command or word to find help on:\n\nPrepend i_ for Input mode commands (e.g.: i_CTRL-X)\nPrepend c_ for command-line editing commands (e.g.: c_<Del>)\nPrepend ' for an option name (e.g.: 'shiftwidth')"
  97. endif
  98. let h = inputdialog(g:menutrans_help_dialog)
  99. if h != ""
  100. let v:errmsg = ""
  101. silent! exe "help " . h
  102. if v:errmsg != ""
  103. echo v:errmsg
  104. endif
  105. endif
  106. endfun
  107. " File menu
  108. an 10.310 &File.&Open\.\.\.<Tab>:e :browse confirm e<CR>
  109. an 10.320 &File.Sp&lit-Open\.\.\.<Tab>:sp :browse sp<CR>
  110. an 10.320 &File.Open\ Tab\.\.\.<Tab>:tabnew :browse tabnew<CR>
  111. an 10.325 &File.&New<Tab>:enew :confirm enew<CR>
  112. an <silent> 10.330 &File.&Close<Tab>:close
  113. \ :if winheight(2) < 0 && tabpagewinnr(2) == 0 <Bar>
  114. \ confirm enew <Bar>
  115. \ else <Bar>
  116. \ confirm close <Bar>
  117. \ endif<CR>
  118. an 10.335 &File.-SEP1- <Nop>
  119. an <silent> 10.340 &File.&Save<Tab>:w :if expand("%") == ""<Bar>browse confirm w<Bar>else<Bar>confirm w<Bar>endif<CR>
  120. an 10.350 &File.Save\ &As\.\.\.<Tab>:sav :browse confirm saveas<CR>
  121. if has("diff")
  122. an 10.400 &File.-SEP2- <Nop>
  123. an 10.410 &File.Split\ &Diff\ With\.\.\. :browse vert diffsplit<CR>
  124. an 10.420 &File.Split\ Patched\ &By\.\.\. :browse vert diffpatch<CR>
  125. endif
  126. if has("unix")
  127. an 10.500 &File.-SEP3- <Nop>
  128. an 10.510 &File.&Print :w !lpr<CR>
  129. vunmenu &File.&Print
  130. vnoremenu &File.&Print :w !lpr<CR>
  131. endif
  132. an 10.600 &File.-SEP4- <Nop>
  133. an 10.610 &File.Sa&ve-Exit<Tab>:wqa :confirm wqa<CR>
  134. an 10.620 &File.E&xit<Tab>:qa :confirm qa<CR>
  135. func s:SelectAll()
  136. exe "norm! gg" . (&slm == "" ? "VG" : "gH\<C-O>G")
  137. endfunc
  138. func s:FnameEscape(fname)
  139. if exists('*fnameescape')
  140. return fnameescape(a:fname)
  141. endif
  142. return escape(a:fname, " \t\n*?[{`$\\%#'\"|!<")
  143. endfunc
  144. " Edit menu
  145. an 20.310 &Edit.&Undo<Tab>u u
  146. an 20.320 &Edit.&Redo<Tab>^R <C-R>
  147. an 20.330 &Edit.Rep&eat<Tab>\. .
  148. an 20.335 &Edit.-SEP1- <Nop>
  149. vnoremenu 20.340 &Edit.Cu&t<Tab>"+x "+x
  150. vnoremenu 20.350 &Edit.&Copy<Tab>"+y "+y
  151. cnoremenu 20.350 &Edit.&Copy<Tab>"+y <C-Y>
  152. if exists(':tlmenu')
  153. tlnoremenu 20.350 &Edit.&Copy<Tab>"+y <C-W>:<C-Y><CR>
  154. endif
  155. nnoremenu 20.360 &Edit.&Paste<Tab>"+gP "+gP
  156. cnoremenu &Edit.&Paste<Tab>"+gP <C-R>+
  157. if exists(':tlmenu')
  158. tlnoremenu &Edit.&Paste<Tab>"+gP <C-W>"+
  159. endif
  160. exe 'vnoremenu <script> &Edit.&Paste<Tab>"+gP ' . paste#paste_cmd['v']
  161. exe 'inoremenu <script> &Edit.&Paste<Tab>"+gP ' . paste#paste_cmd['i']
  162. nnoremenu 20.370 &Edit.Put\ &Before<Tab>[p [p
  163. inoremenu &Edit.Put\ &Before<Tab>[p <C-O>[p
  164. nnoremenu 20.380 &Edit.Put\ &After<Tab>]p ]p
  165. inoremenu &Edit.Put\ &After<Tab>]p <C-O>]p
  166. if has("win32")
  167. vnoremenu 20.390 &Edit.&Delete<Tab>x x
  168. endif
  169. noremenu <script> <silent> 20.400 &Edit.&Select\ All<Tab>ggVG :<C-U>call <SID>SelectAll()<CR>
  170. inoremenu <script> <silent> 20.400 &Edit.&Select\ All<Tab>ggVG <C-O>:call <SID>SelectAll()<CR>
  171. cnoremenu <script> <silent> 20.400 &Edit.&Select\ All<Tab>ggVG <C-U>call <SID>SelectAll()<CR>
  172. an 20.405 &Edit.-SEP2- <Nop>
  173. if has("win32") || has("gui_gtk") || has("gui_kde") || has("gui_motif")
  174. an 20.410 &Edit.&Find\.\.\. :promptfind<CR>
  175. vunmenu &Edit.&Find\.\.\.
  176. vnoremenu <silent> &Edit.&Find\.\.\. y:promptfind <C-R>=<SID>FixFText()<CR><CR>
  177. an 20.420 &Edit.Find\ and\ Rep&lace\.\.\. :promptrepl<CR>
  178. vunmenu &Edit.Find\ and\ Rep&lace\.\.\.
  179. vnoremenu <silent> &Edit.Find\ and\ Rep&lace\.\.\. y:promptrepl <C-R>=<SID>FixFText()<CR><CR>
  180. else
  181. an 20.410 &Edit.&Find<Tab>/ /
  182. an 20.420 &Edit.Find\ and\ Rep&lace<Tab>:%s :%s/
  183. vunmenu &Edit.Find\ and\ Rep&lace<Tab>:%s
  184. vnoremenu &Edit.Find\ and\ Rep&lace<Tab>:s :s/
  185. endif
  186. an 20.425 &Edit.-SEP3- <Nop>
  187. an 20.430 &Edit.Settings\ &Window :options<CR>
  188. an 20.435 &Edit.Startup\ &Settings :call <SID>EditVimrc()<CR>
  189. fun! s:EditVimrc()
  190. if $MYVIMRC != ''
  191. let fname = $MYVIMRC
  192. elseif has("win32")
  193. if $HOME != ''
  194. let fname = $HOME . "/_vimrc"
  195. else
  196. let fname = $VIM . "/_vimrc"
  197. endif
  198. elseif has("amiga")
  199. let fname = "s:.vimrc"
  200. else
  201. let fname = $HOME . "/.vimrc"
  202. endif
  203. let fname = s:FnameEscape(fname)
  204. if &mod
  205. exe "split " . fname
  206. else
  207. exe "edit " . fname
  208. endif
  209. endfun
  210. fun! s:FixFText()
  211. " Fix text in nameless register to be used with :promptfind.
  212. return substitute(@", "[\r\n]", '\\n', 'g')
  213. endfun
  214. " Edit/Global Settings
  215. an 20.440.100 &Edit.&Global\ Settings.Toggle\ Pattern\ &Highlight<Tab>:set\ hls! :set hls! hls?<CR>
  216. an 20.440.110 &Edit.&Global\ Settings.Toggle\ &Ignoring\ Case<Tab>:set\ ic! :set ic! ic?<CR>
  217. an 20.440.110 &Edit.&Global\ Settings.Toggle\ &Showing\ Matched\ Pairs<Tab>:set\ sm! :set sm! sm?<CR>
  218. an 20.440.120 &Edit.&Global\ Settings.&Context\ Lines.\ 1\ :set so=1<CR>
  219. an 20.440.120 &Edit.&Global\ Settings.&Context\ Lines.\ 2\ :set so=2<CR>
  220. an 20.440.120 &Edit.&Global\ Settings.&Context\ Lines.\ 3\ :set so=3<CR>
  221. an 20.440.120 &Edit.&Global\ Settings.&Context\ Lines.\ 4\ :set so=4<CR>
  222. an 20.440.120 &Edit.&Global\ Settings.&Context\ Lines.\ 5\ :set so=5<CR>
  223. an 20.440.120 &Edit.&Global\ Settings.&Context\ Lines.\ 7\ :set so=7<CR>
  224. an 20.440.120 &Edit.&Global\ Settings.&Context\ Lines.\ 10\ :set so=10<CR>
  225. an 20.440.120 &Edit.&Global\ Settings.&Context\ Lines.\ 100\ :set so=100<CR>
  226. an 20.440.130.40 &Edit.&Global\ Settings.&Virtual\ Edit.Never :set ve=<CR>
  227. an 20.440.130.50 &Edit.&Global\ Settings.&Virtual\ Edit.Block\ Selection :set ve=block<CR>
  228. an 20.440.130.60 &Edit.&Global\ Settings.&Virtual\ Edit.Insert\ Mode :set ve=insert<CR>
  229. an 20.440.130.70 &Edit.&Global\ Settings.&Virtual\ Edit.Block\ and\ Insert :set ve=block,insert<CR>
  230. an 20.440.130.80 &Edit.&Global\ Settings.&Virtual\ Edit.Always :set ve=all<CR>
  231. an 20.440.140 &Edit.&Global\ Settings.Toggle\ Insert\ &Mode<Tab>:set\ im! :set im!<CR>
  232. an 20.440.145 &Edit.&Global\ Settings.Toggle\ Vi\ C&ompatibility<Tab>:set\ cp! :set cp!<CR>
  233. an <silent> 20.440.150 &Edit.&Global\ Settings.Search\ &Path\.\.\. :call <SID>SearchP()<CR>
  234. an <silent> 20.440.160 &Edit.&Global\ Settings.Ta&g\ Files\.\.\. :call <SID>TagFiles()<CR>
  235. "
  236. " GUI options
  237. an 20.440.300 &Edit.&Global\ Settings.-SEP1- <Nop>
  238. an <silent> 20.440.310 &Edit.&Global\ Settings.Toggle\ &Toolbar :call <SID>ToggleGuiOption("T")<CR>
  239. an <silent> 20.440.320 &Edit.&Global\ Settings.Toggle\ &Bottom\ Scrollbar :call <SID>ToggleGuiOption("b")<CR>
  240. an <silent> 20.440.330 &Edit.&Global\ Settings.Toggle\ &Left\ Scrollbar :call <SID>ToggleGuiOption("l")<CR>
  241. an <silent> 20.440.340 &Edit.&Global\ Settings.Toggle\ &Right\ Scrollbar :call <SID>ToggleGuiOption("r")<CR>
  242. fun! s:SearchP()
  243. if !exists("g:menutrans_path_dialog")
  244. let g:menutrans_path_dialog = "Enter search path for files.\nSeparate directory names with a comma."
  245. endif
  246. let n = inputdialog(g:menutrans_path_dialog, substitute(&path, '\\ ', ' ', 'g'))
  247. if n != ""
  248. let &path = substitute(n, ' ', '\\ ', 'g')
  249. endif
  250. endfun
  251. fun! s:TagFiles()
  252. if !exists("g:menutrans_tags_dialog")
  253. let g:menutrans_tags_dialog = "Enter names of tag files.\nSeparate the names with a comma."
  254. endif
  255. let n = inputdialog(g:menutrans_tags_dialog, substitute(&tags, '\\ ', ' ', 'g'))
  256. if n != ""
  257. let &tags = substitute(n, ' ', '\\ ', 'g')
  258. endif
  259. endfun
  260. fun! s:ToggleGuiOption(option)
  261. " If a:option is already set in guioptions, then we want to remove it
  262. if match(&guioptions, "\\C" . a:option) > -1
  263. exec "set go-=" . a:option
  264. else
  265. exec "set go+=" . a:option
  266. endif
  267. endfun
  268. " Edit/File Settings
  269. " Boolean options
  270. an 20.440.100 &Edit.F&ile\ Settings.Toggle\ Line\ &Numbering<Tab>:set\ nu! :set nu! nu?<CR>
  271. an 20.440.105 &Edit.F&ile\ Settings.Toggle\ Relati&ve\ Line\ Numbering<Tab>:set\ rnu! :set rnu! rnu?<CR>
  272. an 20.440.110 &Edit.F&ile\ Settings.Toggle\ &List\ Mode<Tab>:set\ list! :set list! list?<CR>
  273. an 20.440.120 &Edit.F&ile\ Settings.Toggle\ Line\ &Wrapping<Tab>:set\ wrap! :set wrap! wrap?<CR>
  274. an 20.440.130 &Edit.F&ile\ Settings.Toggle\ W&rapping\ at\ Word<Tab>:set\ lbr! :set lbr! lbr?<CR>
  275. an 20.440.160 &Edit.F&ile\ Settings.Toggle\ Tab\ &Expanding<Tab>:set\ et! :set et! et?<CR>
  276. an 20.440.170 &Edit.F&ile\ Settings.Toggle\ &Auto\ Indenting<Tab>:set\ ai! :set ai! ai?<CR>
  277. an 20.440.180 &Edit.F&ile\ Settings.Toggle\ &C-Style\ Indenting<Tab>:set\ cin! :set cin! cin?<CR>
  278. " other options
  279. an 20.440.600 &Edit.F&ile\ Settings.-SEP2- <Nop>
  280. an 20.440.610.20 &Edit.F&ile\ Settings.&Shiftwidth.2 :set sw=2 sw?<CR>
  281. an 20.440.610.30 &Edit.F&ile\ Settings.&Shiftwidth.3 :set sw=3 sw?<CR>
  282. an 20.440.610.40 &Edit.F&ile\ Settings.&Shiftwidth.4 :set sw=4 sw?<CR>
  283. an 20.440.610.50 &Edit.F&ile\ Settings.&Shiftwidth.5 :set sw=5 sw?<CR>
  284. an 20.440.610.60 &Edit.F&ile\ Settings.&Shiftwidth.6 :set sw=6 sw?<CR>
  285. an 20.440.610.80 &Edit.F&ile\ Settings.&Shiftwidth.8 :set sw=8 sw?<CR>
  286. an 20.440.620.20 &Edit.F&ile\ Settings.Soft\ &Tabstop.2 :set sts=2 sts?<CR>
  287. an 20.440.620.30 &Edit.F&ile\ Settings.Soft\ &Tabstop.3 :set sts=3 sts?<CR>
  288. an 20.440.620.40 &Edit.F&ile\ Settings.Soft\ &Tabstop.4 :set sts=4 sts?<CR>
  289. an 20.440.620.50 &Edit.F&ile\ Settings.Soft\ &Tabstop.5 :set sts=5 sts?<CR>
  290. an 20.440.620.60 &Edit.F&ile\ Settings.Soft\ &Tabstop.6 :set sts=6 sts?<CR>
  291. an 20.440.620.80 &Edit.F&ile\ Settings.Soft\ &Tabstop.8 :set sts=8 sts?<CR>
  292. an <silent> 20.440.630 &Edit.F&ile\ Settings.Te&xt\ Width\.\.\. :call <SID>TextWidth()<CR>
  293. an <silent> 20.440.640 &Edit.F&ile\ Settings.&File\ Format\.\.\. :call <SID>FileFormat()<CR>
  294. fun! s:TextWidth()
  295. if !exists("g:menutrans_textwidth_dialog")
  296. let g:menutrans_textwidth_dialog = "Enter new text width (0 to disable formatting): "
  297. endif
  298. let n = inputdialog(g:menutrans_textwidth_dialog, &tw)
  299. if n != ""
  300. " Remove leading zeros to avoid it being used as an octal number.
  301. " But keep a zero by itself.
  302. let tw = substitute(n, "^0*", "", "")
  303. let &tw = tw == '' ? 0 : tw
  304. endif
  305. endfun
  306. fun! s:FileFormat()
  307. if !exists("g:menutrans_fileformat_dialog")
  308. let g:menutrans_fileformat_dialog = "Select format for writing the file"
  309. endif
  310. if !exists("g:menutrans_fileformat_choices")
  311. let g:menutrans_fileformat_choices = "&Unix\n&Dos\n&Mac\n&Cancel"
  312. endif
  313. if &ff == "dos"
  314. let def = 2
  315. elseif &ff == "mac"
  316. let def = 3
  317. else
  318. let def = 1
  319. endif
  320. let n = confirm(g:menutrans_fileformat_dialog, g:menutrans_fileformat_choices, def, "Question")
  321. if n == 1
  322. set ff=unix
  323. elseif n == 2
  324. set ff=dos
  325. elseif n == 3
  326. set ff=mac
  327. endif
  328. endfun
  329. let s:did_setup_color_schemes = 0
  330. " Setup the Edit.Color Scheme submenu
  331. func s:SetupColorSchemes() abort
  332. if s:did_setup_color_schemes
  333. return
  334. endif
  335. let s:did_setup_color_schemes = 1
  336. let n = globpath(&runtimepath, "colors/*.vim", 1, 1)
  337. let n += globpath(&packpath, "pack/*/start/*/colors/*.vim", 1, 1)
  338. let n += globpath(&packpath, "pack/*/opt/*/colors/*.vim", 1, 1)
  339. " Ignore case for VMS and windows, sort on name
  340. let names = sort(map(n, 'substitute(v:val, "\\c.*[/\\\\:\\]]\\([^/\\\\:]*\\)\\.vim", "\\1", "")'), 1)
  341. " define all the submenu entries
  342. let idx = 100
  343. for name in names
  344. exe "an 20.450." . idx . ' &Edit.C&olor\ Scheme.' . name . " :colors " . name . "<CR>"
  345. let idx = idx + 10
  346. endfor
  347. silent! aunmenu &Edit.Show\ C&olor\ Schemes\ in\ Menu
  348. endfun
  349. if exists("do_no_lazyload_menus")
  350. call s:SetupColorSchemes()
  351. else
  352. an <silent> 20.450 &Edit.Show\ C&olor\ Schemes\ in\ Menu :call <SID>SetupColorSchemes()<CR>
  353. endif
  354. " Setup the Edit.Keymap submenu
  355. if has("keymap")
  356. let s:did_setup_keymaps = 0
  357. func s:SetupKeymaps() abort
  358. if s:did_setup_keymaps
  359. return
  360. endif
  361. let s:did_setup_keymaps = 1
  362. let n = globpath(&runtimepath, "keymap/*.vim", 1, 1)
  363. if !empty(n)
  364. let idx = 100
  365. an 20.460.90 &Edit.&Keymap.None :set keymap=<CR>
  366. for name in n
  367. " Ignore case for VMS and windows
  368. let name = substitute(name, '\c.*[/\\:\]]\([^/\\:_]*\)\(_[0-9a-zA-Z-]*\)\=\.vim', '\1', '')
  369. exe "an 20.460." . idx . ' &Edit.&Keymap.' . name . " :set keymap=" . name . "<CR>"
  370. let idx = idx + 10
  371. endfor
  372. endif
  373. silent! aunmenu &Edit.Show\ &Keymaps\ in\ Menu
  374. endfun
  375. if exists("do_no_lazyload_menus")
  376. call s:SetupKeymaps()
  377. else
  378. an <silent> 20.460 &Edit.Show\ &Keymaps\ in\ Menu :call <SID>SetupKeymaps()<CR>
  379. endif
  380. endif
  381. if has("win32") || has("gui_motif") || has("gui_gtk") || has("gui_kde") || has("gui_photon") || has("gui_mac")
  382. an 20.470 &Edit.Select\ Fo&nt\.\.\. :set guifont=*<CR>
  383. endif
  384. " Programming menu
  385. if !exists("g:ctags_command")
  386. if has("vms")
  387. let g:ctags_command = "mc vim:ctags *.*"
  388. else
  389. let g:ctags_command = "ctags -R ."
  390. endif
  391. endif
  392. an 40.300 &Tools.&Jump\ to\ This\ Tag<Tab>g^] g<C-]>
  393. vunmenu &Tools.&Jump\ to\ This\ Tag<Tab>g^]
  394. vnoremenu &Tools.&Jump\ to\ This\ Tag<Tab>g^] g<C-]>
  395. an 40.310 &Tools.Jump\ &Back<Tab>^T <C-T>
  396. an 40.320 &Tools.Build\ &Tags\ File :exe "!" . g:ctags_command<CR>
  397. if has("folding") || has("spell")
  398. an 40.330 &Tools.-SEP1- <Nop>
  399. endif
  400. " Tools.Spelling Menu
  401. if has("spell")
  402. an 40.335.110 &Tools.&Spelling.&Spell\ Check\ On :set spell<CR>
  403. an 40.335.120 &Tools.&Spelling.Spell\ Check\ &Off :set nospell<CR>
  404. an 40.335.130 &Tools.&Spelling.To\ &Next\ Error<Tab>]s ]s
  405. an 40.335.130 &Tools.&Spelling.To\ &Previous\ Error<Tab>[s [s
  406. an 40.335.140 &Tools.&Spelling.Suggest\ &Corrections<Tab>z= z=
  407. an 40.335.150 &Tools.&Spelling.&Repeat\ Correction<Tab>:spellrepall :spellrepall<CR>
  408. an 40.335.200 &Tools.&Spelling.-SEP1- <Nop>
  409. an 40.335.210 &Tools.&Spelling.Set\ Language\ to\ "en" :set spl=en spell<CR>
  410. an 40.335.220 &Tools.&Spelling.Set\ Language\ to\ "en_au" :set spl=en_au spell<CR>
  411. an 40.335.230 &Tools.&Spelling.Set\ Language\ to\ "en_ca" :set spl=en_ca spell<CR>
  412. an 40.335.240 &Tools.&Spelling.Set\ Language\ to\ "en_gb" :set spl=en_gb spell<CR>
  413. an 40.335.250 &Tools.&Spelling.Set\ Language\ to\ "en_nz" :set spl=en_nz spell<CR>
  414. an 40.335.260 &Tools.&Spelling.Set\ Language\ to\ "en_us" :set spl=en_us spell<CR>
  415. an <silent> 40.335.270 &Tools.&Spelling.&Find\ More\ Languages :call <SID>SpellLang()<CR>
  416. let s:undo_spelllang = ['aun &Tools.&Spelling.&Find\ More\ Languages']
  417. func s:SpellLang()
  418. for cmd in s:undo_spelllang
  419. exe "silent! " . cmd
  420. endfor
  421. let s:undo_spelllang = []
  422. if &enc == "iso-8859-15"
  423. let enc = "latin1"
  424. else
  425. let enc = &enc
  426. endif
  427. if !exists("g:menutrans_set_lang_to")
  428. let g:menutrans_set_lang_to = 'Set Language to'
  429. endif
  430. let found = 0
  431. let s = globpath(&runtimepath, "spell/*." . enc . ".spl", 1, 1)
  432. if !empty(s)
  433. let n = 300
  434. for f in s
  435. let nm = substitute(f, '.*spell[/\\]\(..\)\.[^/\\]*\.spl', '\1', "")
  436. if nm != "en" && nm !~ '/'
  437. let _nm = nm
  438. let found += 1
  439. let menuname = '&Tools.&Spelling.' . escape(g:menutrans_set_lang_to, "\\. \t|") . '\ "' . nm . '"'
  440. exe 'an 40.335.' . n . ' ' . menuname . ' :set spl=' . nm . ' spell<CR>'
  441. let s:undo_spelllang += ['aun ' . menuname]
  442. endif
  443. let n += 10
  444. endfor
  445. endif
  446. if found == 0
  447. echomsg "Could not find other spell files"
  448. elseif found == 1
  449. echomsg "Found spell file " . _nm
  450. else
  451. echomsg "Found " . found . " more spell files"
  452. endif
  453. " Need to redo this when 'encoding' is changed.
  454. augroup spellmenu
  455. au! EncodingChanged * call <SID>SpellLang()
  456. augroup END
  457. endfun
  458. endif
  459. " Tools.Fold Menu
  460. if has("folding")
  461. " open close folds
  462. an 40.340.110 &Tools.&Folding.&Enable/Disable\ Folds<Tab>zi zi
  463. an 40.340.120 &Tools.&Folding.&View\ Cursor\ Line<Tab>zv zv
  464. an 40.340.120 &Tools.&Folding.Vie&w\ Cursor\ Line\ Only<Tab>zMzx zMzx
  465. inoremenu 40.340.120 &Tools.&Folding.Vie&w\ Cursor\ Line\ Only<Tab>zMzx <C-O>zM<C-O>zx
  466. an 40.340.130 &Tools.&Folding.C&lose\ More\ Folds<Tab>zm zm
  467. an 40.340.140 &Tools.&Folding.&Close\ All\ Folds<Tab>zM zM
  468. an 40.340.150 &Tools.&Folding.O&pen\ More\ Folds<Tab>zr zr
  469. an 40.340.160 &Tools.&Folding.&Open\ All\ Folds<Tab>zR zR
  470. " fold method
  471. an 40.340.200 &Tools.&Folding.-SEP1- <Nop>
  472. an 40.340.210 &Tools.&Folding.Fold\ Met&hod.M&anual :set fdm=manual<CR>
  473. an 40.340.210 &Tools.&Folding.Fold\ Met&hod.I&ndent :set fdm=indent<CR>
  474. an 40.340.210 &Tools.&Folding.Fold\ Met&hod.E&xpression :set fdm=expr<CR>
  475. an 40.340.210 &Tools.&Folding.Fold\ Met&hod.S&yntax :set fdm=syntax<CR>
  476. an 40.340.210 &Tools.&Folding.Fold\ Met&hod.&Diff :set fdm=diff<CR>
  477. an 40.340.210 &Tools.&Folding.Fold\ Met&hod.Ma&rker :set fdm=marker<CR>
  478. " create and delete folds
  479. vnoremenu 40.340.220 &Tools.&Folding.Create\ &Fold<Tab>zf zf
  480. an 40.340.230 &Tools.&Folding.&Delete\ Fold<Tab>zd zd
  481. an 40.340.240 &Tools.&Folding.Delete\ &All\ Folds<Tab>zD zD
  482. " moving around in folds
  483. an 40.340.300 &Tools.&Folding.-SEP2- <Nop>
  484. an 40.340.310.10 &Tools.&Folding.Fold\ Col&umn\ Width.\ &0\ :set fdc=0<CR>
  485. an 40.340.310.20 &Tools.&Folding.Fold\ Col&umn\ Width.\ &2\ :set fdc=2<CR>
  486. an 40.340.310.30 &Tools.&Folding.Fold\ Col&umn\ Width.\ &3\ :set fdc=3<CR>
  487. an 40.340.310.40 &Tools.&Folding.Fold\ Col&umn\ Width.\ &4\ :set fdc=4<CR>
  488. an 40.340.310.50 &Tools.&Folding.Fold\ Col&umn\ Width.\ &5\ :set fdc=5<CR>
  489. an 40.340.310.60 &Tools.&Folding.Fold\ Col&umn\ Width.\ &6\ :set fdc=6<CR>
  490. an 40.340.310.70 &Tools.&Folding.Fold\ Col&umn\ Width.\ &7\ :set fdc=7<CR>
  491. an 40.340.310.80 &Tools.&Folding.Fold\ Col&umn\ Width.\ &8\ :set fdc=8<CR>
  492. endif " has folding
  493. if has("diff")
  494. an 40.350.100 &Tools.&Diff.&Update :diffupdate<CR>
  495. an 40.350.110 &Tools.&Diff.&Get\ Block :diffget<CR>
  496. vunmenu &Tools.&Diff.&Get\ Block
  497. vnoremenu &Tools.&Diff.&Get\ Block :diffget<CR>
  498. an 40.350.120 &Tools.&Diff.&Put\ Block :diffput<CR>
  499. vunmenu &Tools.&Diff.&Put\ Block
  500. vnoremenu &Tools.&Diff.&Put\ Block :diffput<CR>
  501. endif
  502. an 40.358 &Tools.-SEP2- <Nop>
  503. an 40.360 &Tools.&Make<Tab>:make :make<CR>
  504. an 40.370 &Tools.&List\ Errors<Tab>:cl :cl<CR>
  505. an 40.380 &Tools.L&ist\ Messages<Tab>:cl! :cl!<CR>
  506. an 40.390 &Tools.&Next\ Error<Tab>:cn :cn<CR>
  507. an 40.400 &Tools.&Previous\ Error<Tab>:cp :cp<CR>
  508. an 40.410 &Tools.&Older\ List<Tab>:cold :colder<CR>
  509. an 40.420 &Tools.N&ewer\ List<Tab>:cnew :cnewer<CR>
  510. an 40.430.50 &Tools.Error\ &Window.&Update<Tab>:cwin :cwin<CR>
  511. an 40.430.60 &Tools.Error\ &Window.&Open<Tab>:copen :copen<CR>
  512. an 40.430.70 &Tools.Error\ &Window.&Close<Tab>:cclose :cclose<CR>
  513. an 40.520 &Tools.-SEP3- <Nop>
  514. an <silent> 40.530 &Tools.&Convert\ to\ HEX<Tab>:%!xxd
  515. \ :call <SID>XxdConv()<CR>
  516. an <silent> 40.540 &Tools.Conve&rt\ Back<Tab>:%!xxd\ -r
  517. \ :call <SID>XxdBack()<CR>
  518. " Use a function to do the conversion, so that it also works with 'insertmode'
  519. " set.
  520. func s:XxdConv()
  521. let mod = &mod
  522. if has("vms")
  523. %!mc vim:xxd
  524. else
  525. call s:XxdFind()
  526. exe ':%!' . g:xxdprogram
  527. endif
  528. if getline(1) =~ "^00000000:" " only if it worked
  529. set ft=xxd
  530. endif
  531. let &mod = mod
  532. endfun
  533. func s:XxdBack()
  534. let mod = &mod
  535. if has("vms")
  536. %!mc vim:xxd -r
  537. else
  538. call s:XxdFind()
  539. exe ':%!' . g:xxdprogram . ' -r'
  540. endif
  541. set ft=
  542. doautocmd filetypedetect BufReadPost
  543. let &mod = mod
  544. endfun
  545. func s:XxdFind()
  546. if !exists("g:xxdprogram")
  547. " On the PC xxd may not be in the path but in the install directory
  548. if has("win32") && !executable("xxd")
  549. let g:xxdprogram = $VIMRUNTIME . (&shellslash ? '/' : '\') . "xxd.exe"
  550. if g:xxdprogram =~ ' '
  551. let g:xxdprogram = '"' .. g:xxdprogram .. '"'
  552. endif
  553. else
  554. let g:xxdprogram = "xxd"
  555. endif
  556. endif
  557. endfun
  558. let s:did_setup_compilers = 0
  559. " Setup the Tools.Compiler submenu
  560. func s:SetupCompilers() abort
  561. if s:did_setup_compilers
  562. return
  563. endif
  564. let s:did_setup_compilers = 1
  565. let n = globpath(&runtimepath, "compiler/*.vim", 1, 1)
  566. let idx = 100
  567. for name in n
  568. " Ignore case for VMS and windows
  569. let name = substitute(name, '\c.*[/\\:\]]\([^/\\:]*\)\.vim', '\1', '')
  570. exe "an 30.440." . idx . ' &Tools.Se&t\ Compiler.' . name . " :compiler " . name . "<CR>"
  571. let idx = idx + 10
  572. endfor
  573. silent! aunmenu &Tools.Show\ Compiler\ Se&ttings\ in\ Menu
  574. endfun
  575. if exists("do_no_lazyload_menus")
  576. call s:SetupCompilers()
  577. else
  578. an <silent> 30.440 &Tools.Show\ Compiler\ Se&ttings\ in\ Menu :call <SID>SetupCompilers()<CR>
  579. endif
  580. " Load ColorScheme, Compiler Setting and Keymap menus when idle.
  581. if !exists("do_no_lazyload_menus")
  582. func s:SetupLazyloadMenus()
  583. call s:SetupColorSchemes()
  584. call s:SetupCompilers()
  585. if has("keymap")
  586. call s:SetupKeymaps()
  587. endif
  588. endfunc
  589. augroup SetupLazyloadMenus
  590. au!
  591. au CursorHold,CursorHoldI * call <SID>SetupLazyloadMenus() | au! SetupLazyloadMenus
  592. augroup END
  593. endif
  594. if !exists("no_buffers_menu")
  595. " Buffer list menu -- Setup functions & actions
  596. " wait with building the menu until after loading 'session' files. Makes
  597. " startup faster.
  598. let s:bmenu_wait = 1
  599. " Dictionary of buffer number to name. This helps prevent problems where a
  600. " buffer as renamed and we didn't keep track of that.
  601. let s:bmenu_items = {}
  602. if !exists("bmenu_priority")
  603. let bmenu_priority = 60
  604. endif
  605. " invoked from a BufCreate or BufFilePost autocommand
  606. func s:BMAdd()
  607. if s:bmenu_wait == 0
  608. " when adding too many buffers, redraw in short format
  609. if s:bmenu_count == &menuitems && s:bmenu_short == 0
  610. call s:BMShow()
  611. else
  612. let name = expand("<afile>")
  613. let num = expand("<abuf>") + 0 " add zero to convert to a number type
  614. if s:BMCanAdd(name, num)
  615. call <SID>BMFilename(name, num)
  616. let s:bmenu_count += 1
  617. endif
  618. endif
  619. endif
  620. endfunc
  621. " invoked from a BufDelete or BufFilePre autocommand
  622. func s:BMRemove()
  623. if s:bmenu_wait == 0
  624. let bufnum = expand("<abuf>")
  625. if s:bmenu_items->has_key(bufnum)
  626. let menu_name = s:bmenu_items[bufnum]
  627. exe 'silent! aun &Buffers.' . menu_name
  628. let s:bmenu_count = s:bmenu_count - 1
  629. unlet s:bmenu_items[bufnum]
  630. endif
  631. endif
  632. endfunc
  633. " Return non-zero if buffer with number "name" / "num" is useful to add in the
  634. " buffer menu.
  635. func s:BMCanAdd(name, num)
  636. " no directory or unlisted buffer
  637. if isdirectory(a:name) || !buflisted(a:num)
  638. return 0
  639. endif
  640. " no name with control characters
  641. if a:name =~ '[\x01-\x1f]'
  642. return 0
  643. endif
  644. " no special buffer, such as terminal or popup
  645. let buftype = getbufvar(a:num, '&buftype')
  646. if buftype != '' && buftype != 'nofile' && buftype != 'nowrite'
  647. return 0
  648. endif
  649. " only existing buffers
  650. return bufexists(a:num)
  651. endfunc
  652. " Create the buffer menu (delete an existing one first).
  653. func s:BMShow(...)
  654. let s:bmenu_wait = 1
  655. let s:bmenu_short = 1
  656. let s:bmenu_count = 0
  657. let s:bmenu_items = {}
  658. "
  659. " get new priority, if exists
  660. if a:0 == 1
  661. let g:bmenu_priority = a:1
  662. endif
  663. " Remove old menu, if it exists; keep one entry to avoid a torn off menu to
  664. " disappear. Use try/catch to avoid setting v:errmsg
  665. try | unmenu &Buffers | catch | endtry
  666. exe 'noremenu ' . g:bmenu_priority . ".1 &Buffers.Dummy l"
  667. try | unmenu! &Buffers | catch | endtry
  668. " create new menu; set 'cpo' to include the <CR>
  669. let cpo_save = &cpo
  670. set cpo&vim
  671. exe 'an <silent> ' . g:bmenu_priority . ".2 &Buffers.&Refresh\\ menu :call <SID>BMShow()<CR>"
  672. exe 'an ' . g:bmenu_priority . ".4 &Buffers.&Delete :confirm bd<CR>"
  673. exe 'an ' . g:bmenu_priority . ".6 &Buffers.&Alternate :confirm b #<CR>"
  674. exe 'an ' . g:bmenu_priority . ".7 &Buffers.&Next :confirm bnext<CR>"
  675. exe 'an ' . g:bmenu_priority . ".8 &Buffers.&Previous :confirm bprev<CR>"
  676. exe 'an ' . g:bmenu_priority . ".9 &Buffers.-SEP- :"
  677. let &cpo = cpo_save
  678. unmenu &Buffers.Dummy
  679. " figure out how many buffers there are
  680. let buf = 1
  681. while buf <= bufnr('$')
  682. if s:BMCanAdd(bufname(buf), buf)
  683. let s:bmenu_count = s:bmenu_count + 1
  684. endif
  685. let buf = buf + 1
  686. endwhile
  687. if s:bmenu_count <= &menuitems
  688. let s:bmenu_short = 0
  689. endif
  690. " iterate through buffer list, adding each buffer to the menu:
  691. let buf = 1
  692. while buf <= bufnr('$')
  693. let name = bufname(buf)
  694. if s:BMCanAdd(name, buf)
  695. call <SID>BMFilename(name, buf)
  696. endif
  697. let buf = buf + 1
  698. endwhile
  699. let s:bmenu_wait = 0
  700. aug buffer_list
  701. au!
  702. au BufCreate,BufFilePost * call <SID>BMAdd()
  703. au BufDelete,BufFilePre * call <SID>BMRemove()
  704. aug END
  705. endfunc
  706. func s:BMHash(name)
  707. " Make name all upper case, so that chars are between 32 and 96
  708. let nm = substitute(a:name, ".*", '\U\0', "")
  709. if has("ebcdic")
  710. " HACK: Replace all non alphabetics with 'Z'
  711. " Just to make it work for now.
  712. let nm = substitute(nm, "[^A-Z]", 'Z', "g")
  713. let sp = char2nr('A') - 1
  714. else
  715. let sp = char2nr(' ')
  716. endif
  717. " convert first six chars into a number for sorting:
  718. return (char2nr(nm[0]) - sp) * 0x800000 + (char2nr(nm[1]) - sp) * 0x20000 + (char2nr(nm[2]) - sp) * 0x1000 + (char2nr(nm[3]) - sp) * 0x80 + (char2nr(nm[4]) - sp) * 0x20 + (char2nr(nm[5]) - sp)
  719. endfunc
  720. func s:BMHash2(name)
  721. let nm = substitute(a:name, ".", '\L\0', "")
  722. " Not exactly right for EBCDIC...
  723. if nm[0] < 'a' || nm[0] > 'z'
  724. return '&others.'
  725. elseif nm[0] <= 'd'
  726. return '&abcd.'
  727. elseif nm[0] <= 'h'
  728. return '&efgh.'
  729. elseif nm[0] <= 'l'
  730. return '&ijkl.'
  731. elseif nm[0] <= 'p'
  732. return '&mnop.'
  733. elseif nm[0] <= 't'
  734. return '&qrst.'
  735. else
  736. return '&u-z.'
  737. endif
  738. endfunc
  739. " Insert a buffer name into the buffer menu.
  740. func s:BMFilename(name, num)
  741. let munge = <SID>BMMunge(a:name, a:num)
  742. let hash = <SID>BMHash(munge)
  743. if s:bmenu_short == 0
  744. let s:bmenu_items[a:num] = munge
  745. let cmd = 'an ' . g:bmenu_priority . '.' . hash . ' &Buffers.' . munge
  746. else
  747. let menu_name = <SID>BMHash2(munge) . munge
  748. let s:bmenu_items[a:num] = menu_name
  749. let cmd = 'an ' . g:bmenu_priority . '.' . hash . '.' . hash . ' &Buffers.' . menu_name
  750. endif
  751. " set 'cpo' to include the <CR>
  752. let cpo_save = &cpo
  753. set cpo&vim
  754. exe cmd . ' :confirm b' . a:num . '<CR>'
  755. let &cpo = cpo_save
  756. endfunc
  757. " Truncate a long path to fit it in a menu item.
  758. if !exists("g:bmenu_max_pathlen")
  759. let g:bmenu_max_pathlen = 35
  760. endif
  761. func s:BMTruncName(fname)
  762. let name = a:fname
  763. if g:bmenu_max_pathlen < 5
  764. let name = ""
  765. else
  766. let len = strlen(name)
  767. if len > g:bmenu_max_pathlen
  768. let amountl = (g:bmenu_max_pathlen / 2) - 2
  769. let amountr = g:bmenu_max_pathlen - amountl - 3
  770. let pattern = '^\(.\{,' . amountl . '}\).\{-}\(.\{,' . amountr . '}\)$'
  771. let left = substitute(name, pattern, '\1', '')
  772. let right = substitute(name, pattern, '\2', '')
  773. if strlen(left) + strlen(right) < len
  774. let name = left . '...' . right
  775. endif
  776. endif
  777. endif
  778. return name
  779. endfunc
  780. func s:BMMunge(fname, bnum)
  781. let name = a:fname
  782. if name == ''
  783. if !exists("g:menutrans_no_file")
  784. let g:menutrans_no_file = "[No Name]"
  785. endif
  786. let name = g:menutrans_no_file
  787. else
  788. let name = fnamemodify(name, ':p:~')
  789. endif
  790. " detach file name and separate it out:
  791. let name2 = fnamemodify(name, ':t')
  792. if a:bnum >= 0
  793. let name2 = name2 . ' (' . a:bnum . ')'
  794. endif
  795. let name = name2 . "\t" . <SID>BMTruncName(fnamemodify(name,':h'))
  796. let name = escape(name, "\\. \t|")
  797. let name = substitute(name, "&", "&&", "g")
  798. let name = substitute(name, "\n", "^@", "g")
  799. return name
  800. endfunc
  801. " When just starting Vim, load the buffer menu later
  802. if has("vim_starting")
  803. augroup LoadBufferMenu
  804. au! VimEnter * if !exists("no_buffers_menu") | call <SID>BMShow() | endif
  805. au VimEnter * au! LoadBufferMenu
  806. augroup END
  807. else
  808. call <SID>BMShow()
  809. endif
  810. endif " !exists("no_buffers_menu")
  811. " Window menu
  812. an 70.300 &Window.&New<Tab>^Wn <C-W>n
  813. an 70.310 &Window.S&plit<Tab>^Ws <C-W>s
  814. an 70.320 &Window.Sp&lit\ To\ #<Tab>^W^^ <C-W><C-^>
  815. an 70.330 &Window.Split\ &Vertically<Tab>^Wv <C-W>v
  816. an <silent> 70.332 &Window.Split\ File\ E&xplorer :call MenuExplOpen()<CR>
  817. if !exists("*MenuExplOpen")
  818. fun MenuExplOpen()
  819. if @% == ""
  820. 20vsp .
  821. else
  822. exe "20vsp " . s:FnameEscape(expand("%:p:h"))
  823. endif
  824. endfun
  825. endif
  826. an 70.335 &Window.-SEP1- <Nop>
  827. an 70.340 &Window.&Close<Tab>^Wc :confirm close<CR>
  828. an 70.345 &Window.Close\ &Other(s)<Tab>^Wo :confirm only<CR>
  829. an 70.350 &Window.-SEP2- <Nop>
  830. an 70.355 &Window.Move\ &To.&Top<Tab>^WK <C-W>K
  831. an 70.355 &Window.Move\ &To.&Bottom<Tab>^WJ <C-W>J
  832. an 70.355 &Window.Move\ &To.&Left\ Side<Tab>^WH <C-W>H
  833. an 70.355 &Window.Move\ &To.&Right\ Side<Tab>^WL <C-W>L
  834. an 70.360 &Window.Rotate\ &Up<Tab>^WR <C-W>R
  835. an 70.362 &Window.Rotate\ &Down<Tab>^Wr <C-W>r
  836. an 70.365 &Window.-SEP3- <Nop>
  837. an 70.370 &Window.&Equal\ Size<Tab>^W= <C-W>=
  838. an 70.380 &Window.&Max\ Height<Tab>^W_ <C-W>_
  839. an 70.390 &Window.M&in\ Height<Tab>^W1_ <C-W>1_
  840. an 70.400 &Window.Max\ &Width<Tab>^W\| <C-W>\|
  841. an 70.410 &Window.Min\ Widt&h<Tab>^W1\| <C-W>1\|
  842. " The popup menu
  843. an 1.10 PopUp.&Undo u
  844. an 1.15 PopUp.-SEP1- <Nop>
  845. vnoremenu 1.20 PopUp.Cu&t "+x
  846. vnoremenu 1.30 PopUp.&Copy "+y
  847. cnoremenu 1.30 PopUp.&Copy <C-Y>
  848. nnoremenu 1.40 PopUp.&Paste "+gP
  849. cnoremenu 1.40 PopUp.&Paste <C-R>+
  850. exe 'vnoremenu <script> 1.40 PopUp.&Paste ' . paste#paste_cmd['v']
  851. exe 'inoremenu <script> 1.40 PopUp.&Paste ' . paste#paste_cmd['i']
  852. vnoremenu 1.50 PopUp.&Delete x
  853. an 1.55 PopUp.-SEP2- <Nop>
  854. vnoremenu 1.60 PopUp.Select\ Blockwise <C-V>
  855. nnoremenu 1.70 PopUp.Select\ &Word vaw
  856. onoremenu 1.70 PopUp.Select\ &Word aw
  857. vnoremenu 1.70 PopUp.Select\ &Word <C-C>vaw
  858. inoremenu 1.70 PopUp.Select\ &Word <C-O>vaw
  859. cnoremenu 1.70 PopUp.Select\ &Word <C-C>vaw
  860. nnoremenu 1.73 PopUp.Select\ &Sentence vas
  861. onoremenu 1.73 PopUp.Select\ &Sentence as
  862. vnoremenu 1.73 PopUp.Select\ &Sentence <C-C>vas
  863. inoremenu 1.73 PopUp.Select\ &Sentence <C-O>vas
  864. cnoremenu 1.73 PopUp.Select\ &Sentence <C-C>vas
  865. nnoremenu 1.77 PopUp.Select\ Pa&ragraph vap
  866. onoremenu 1.77 PopUp.Select\ Pa&ragraph ap
  867. vnoremenu 1.77 PopUp.Select\ Pa&ragraph <C-C>vap
  868. inoremenu 1.77 PopUp.Select\ Pa&ragraph <C-O>vap
  869. cnoremenu 1.77 PopUp.Select\ Pa&ragraph <C-C>vap
  870. nnoremenu 1.80 PopUp.Select\ &Line V
  871. onoremenu 1.80 PopUp.Select\ &Line <C-C>V
  872. vnoremenu 1.80 PopUp.Select\ &Line <C-C>V
  873. inoremenu 1.80 PopUp.Select\ &Line <C-O>V
  874. cnoremenu 1.80 PopUp.Select\ &Line <C-C>V
  875. nnoremenu 1.90 PopUp.Select\ &Block <C-V>
  876. onoremenu 1.90 PopUp.Select\ &Block <C-C><C-V>
  877. vnoremenu 1.90 PopUp.Select\ &Block <C-C><C-V>
  878. inoremenu 1.90 PopUp.Select\ &Block <C-O><C-V>
  879. cnoremenu 1.90 PopUp.Select\ &Block <C-C><C-V>
  880. noremenu <script> <silent> 1.100 PopUp.Select\ &All :<C-U>call <SID>SelectAll()<CR>
  881. inoremenu <script> <silent> 1.100 PopUp.Select\ &All <C-O>:call <SID>SelectAll()<CR>
  882. cnoremenu <script> <silent> 1.100 PopUp.Select\ &All <C-U>call <SID>SelectAll()<CR>
  883. if has("spell")
  884. " Spell suggestions in the popup menu. Note that this will slow down the
  885. " appearance of the menu!
  886. func s:SpellPopup()
  887. if exists("s:changeitem") && s:changeitem != ''
  888. call <SID>SpellDel()
  889. endif
  890. " Return quickly if spell checking is not enabled.
  891. if !&spell || &spelllang == ''
  892. return
  893. endif
  894. let curcol = col('.')
  895. let [w, a] = spellbadword()
  896. if col('.') > curcol " don't use word after the cursor
  897. let w = ''
  898. endif
  899. if w != ''
  900. if a == 'caps'
  901. let s:suglist = [substitute(w, '.*', '\u&', '')]
  902. else
  903. let s:suglist = spellsuggest(w, 10)
  904. endif
  905. if len(s:suglist) > 0
  906. if !exists("g:menutrans_spell_change_ARG_to")
  907. let g:menutrans_spell_change_ARG_to = 'Change\ "%s"\ to'
  908. endif
  909. let s:changeitem = printf(g:menutrans_spell_change_ARG_to, escape(w, ' .'))
  910. let s:fromword = w
  911. let pri = 1
  912. " set 'cpo' to include the <CR>
  913. let cpo_save = &cpo
  914. set cpo&vim
  915. for sug in s:suglist
  916. exe 'anoremenu 1.5.' . pri . ' PopUp.' . s:changeitem . '.' . escape(sug, ' .')
  917. \ . ' :call <SID>SpellReplace(' . pri . ')<CR>'
  918. let pri += 1
  919. endfor
  920. if !exists("g:menutrans_spell_add_ARG_to_word_list")
  921. let g:menutrans_spell_add_ARG_to_word_list = 'Add\ "%s"\ to\ Word\ List'
  922. endif
  923. let s:additem = printf(g:menutrans_spell_add_ARG_to_word_list, escape(w, ' .'))
  924. exe 'anoremenu 1.6 PopUp.' . s:additem . ' :spellgood ' . w . '<CR>'
  925. if !exists("g:menutrans_spell_ignore_ARG")
  926. let g:menutrans_spell_ignore_ARG = 'Ignore\ "%s"'
  927. endif
  928. let s:ignoreitem = printf(g:menutrans_spell_ignore_ARG, escape(w, ' .'))
  929. exe 'anoremenu 1.7 PopUp.' . s:ignoreitem . ' :spellgood! ' . w . '<CR>'
  930. anoremenu 1.8 PopUp.-SpellSep- :
  931. let &cpo = cpo_save
  932. endif
  933. endif
  934. call cursor(0, curcol) " put the cursor back where it was
  935. endfunc
  936. func s:SpellReplace(n)
  937. let l = getline('.')
  938. " Move the cursor to the start of the word.
  939. call spellbadword()
  940. call setline('.', strpart(l, 0, col('.') - 1) . s:suglist[a:n - 1]
  941. \ . strpart(l, col('.') + len(s:fromword) - 1))
  942. endfunc
  943. func s:SpellDel()
  944. exe "aunmenu PopUp." . s:changeitem
  945. exe "aunmenu PopUp." . s:additem
  946. exe "aunmenu PopUp." . s:ignoreitem
  947. aunmenu PopUp.-SpellSep-
  948. let s:changeitem = ''
  949. endfun
  950. augroup SpellPopupMenu
  951. au! MenuPopup * call <SID>SpellPopup()
  952. augroup END
  953. endif
  954. " The GUI toolbar (for MS-Windows and GTK)
  955. if has("toolbar")
  956. an 1.10 ToolBar.Open :browse confirm e<CR>
  957. an <silent> 1.20 ToolBar.Save :if expand("%") == ""<Bar>browse confirm w<Bar>else<Bar>confirm w<Bar>endif<CR>
  958. an 1.30 ToolBar.SaveAll :browse confirm wa<CR>
  959. if has("unix")
  960. an 1.40 ToolBar.Print :w !lpr<CR>
  961. vunmenu ToolBar.Print
  962. vnoremenu ToolBar.Print :w !lpr<CR>
  963. endif
  964. an 1.45 ToolBar.-sep1- <Nop>
  965. an 1.50 ToolBar.Undo u
  966. an 1.60 ToolBar.Redo <C-R>
  967. an 1.65 ToolBar.-sep2- <Nop>
  968. vnoremenu 1.70 ToolBar.Cut "+x
  969. vnoremenu 1.80 ToolBar.Copy "+y
  970. cnoremenu 1.80 ToolBar.Copy <C-Y>
  971. nnoremenu 1.90 ToolBar.Paste "+gP
  972. cnoremenu ToolBar.Paste <C-R>+
  973. exe 'vnoremenu <script> ToolBar.Paste ' . paste#paste_cmd['v']
  974. exe 'inoremenu <script> ToolBar.Paste ' . paste#paste_cmd['i']
  975. if !has("gui_athena")
  976. an 1.95 ToolBar.-sep3- <Nop>
  977. an 1.100 ToolBar.Replace :promptrepl<CR>
  978. vunmenu ToolBar.Replace
  979. vnoremenu ToolBar.Replace y:promptrepl <C-R>=<SID>FixFText()<CR><CR>
  980. an 1.110 ToolBar.FindNext n
  981. an 1.120 ToolBar.FindPrev N
  982. endif
  983. an 1.215 ToolBar.-sep5- <Nop>
  984. an <silent> 1.220 ToolBar.LoadSesn :call <SID>LoadVimSesn()<CR>
  985. an <silent> 1.230 ToolBar.SaveSesn :call <SID>SaveVimSesn()<CR>
  986. an 1.240 ToolBar.RunScript :browse so<CR>
  987. an 1.245 ToolBar.-sep6- <Nop>
  988. an 1.250 ToolBar.Make :make<CR>
  989. an 1.270 ToolBar.RunCtags :exe "!" . g:ctags_command<CR>
  990. an 1.280 ToolBar.TagJump g<C-]>
  991. an 1.295 ToolBar.-sep7- <Nop>
  992. an 1.300 ToolBar.Help :help<CR>
  993. an <silent> 1.310 ToolBar.FindHelp :call <SID>Helpfind()<CR>
  994. " Only set the tooltips here if not done in a language menu file
  995. if exists("*Do_toolbar_tmenu")
  996. call Do_toolbar_tmenu()
  997. else
  998. let did_toolbar_tmenu = 1
  999. tmenu ToolBar.Open Open file
  1000. tmenu ToolBar.Save Save current file
  1001. tmenu ToolBar.SaveAll Save all files
  1002. tmenu ToolBar.Print Print
  1003. tmenu ToolBar.Undo Undo
  1004. tmenu ToolBar.Redo Redo
  1005. tmenu ToolBar.Cut Cut to clipboard
  1006. tmenu ToolBar.Copy Copy to clipboard
  1007. tmenu ToolBar.Paste Paste from Clipboard
  1008. if !has("gui_athena")
  1009. tmenu ToolBar.Replace Find / Replace...
  1010. tmenu ToolBar.FindNext Find Next
  1011. tmenu ToolBar.FindPrev Find Previous
  1012. endif
  1013. tmenu ToolBar.LoadSesn Choose a session to load
  1014. tmenu ToolBar.SaveSesn Save current session
  1015. tmenu ToolBar.RunScript Choose a Vim Script to run
  1016. tmenu ToolBar.Make Make current project (:make)
  1017. tmenu ToolBar.RunCtags Build tags in current directory tree (!ctags -R .)
  1018. tmenu ToolBar.TagJump Jump to tag under cursor
  1019. tmenu ToolBar.Help Vim Help
  1020. tmenu ToolBar.FindHelp Search Vim Help
  1021. endif
  1022. " Select a session to load; default to current session name if present
  1023. fun! s:LoadVimSesn()
  1024. if strlen(v:this_session) > 0
  1025. let name = s:FnameEscape(v:this_session)
  1026. else
  1027. let name = "Session.vim"
  1028. endif
  1029. execute "browse so " . name
  1030. endfun
  1031. " Select a session to save; default to current session name if present
  1032. fun! s:SaveVimSesn()
  1033. if strlen(v:this_session) == 0
  1034. let v:this_session = "Session.vim"
  1035. endif
  1036. execute "browse mksession! " . s:FnameEscape(v:this_session)
  1037. endfun
  1038. endif
  1039. endif " !exists("did_install_default_menus")
  1040. " Define these items always, so that syntax can be switched on when it wasn't.
  1041. " But skip them when the Syntax menu was disabled by the user.
  1042. if !exists("did_install_syntax_menu")
  1043. an 50.212 &Syntax.&Manual :syn manual<CR>
  1044. an 50.214 &Syntax.A&utomatic :syn on<CR>
  1045. an <silent> 50.216 &Syntax.On/Off\ for\ &This\ File :call <SID>SynOnOff()<CR>
  1046. if !exists("*s:SynOnOff")
  1047. fun s:SynOnOff()
  1048. if has("syntax_items")
  1049. syn clear
  1050. else
  1051. if !exists("g:syntax_on")
  1052. syn manual
  1053. endif
  1054. set syn=ON
  1055. endif
  1056. endfun
  1057. endif
  1058. endif
  1059. " Install the Syntax menu only when filetype.vim has been loaded or when
  1060. " manual syntax highlighting is enabled.
  1061. " Avoid installing the Syntax menu twice.
  1062. if (exists("did_load_filetypes") || exists("syntax_on"))
  1063. \ && !exists("did_install_syntax_menu")
  1064. let did_install_syntax_menu = 1
  1065. " Skip setting up the individual syntax selection menus unless
  1066. " do_syntax_sel_menu is defined (it takes quite a bit of time).
  1067. if exists("do_syntax_sel_menu")
  1068. runtime! synmenu.vim
  1069. else
  1070. an <silent> 50.10 &Syntax.&Show\ File\ Types\ in\ Menu :let do_syntax_sel_menu = 1<Bar>runtime! synmenu.vim<Bar>aunmenu &Syntax.&Show\ File\ Types\ in\ Menu<CR>
  1071. an 50.195 &Syntax.-SEP1- <Nop>
  1072. endif
  1073. an 50.210 &Syntax.&Off :syn off<CR>
  1074. an 50.700 &Syntax.-SEP3- <Nop>
  1075. an 50.710 &Syntax.Co&lor\ Test :sp $VIMRUNTIME/syntax/colortest.vim<Bar>so %<CR>
  1076. an 50.720 &Syntax.&Highlight\ Test :runtime syntax/hitest.vim<CR>
  1077. an 50.730 &Syntax.&Convert\ to\ HTML :runtime syntax/2html.vim<CR>
  1078. endif " !exists("did_install_syntax_menu")
  1079. " Restore the previous value of 'cpoptions'.
  1080. let &cpo = s:cpo_save
  1081. unlet s:cpo_save
  1082. " vim: set sw=2 :