menu.vim 41 KB

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