blob: 5e4bd1f11b4d4b907f5206c37f2fdb9ceda50793 [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" 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>
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +02005" Last Change: 2018 May 17
Bram Moolenaar071d4272004-06-13 20:20:40 +00006
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
10" Make sure the '<' and 'C' flags are not included in 'cpoptions', otherwise
11" <CR> would not be recognized. See ":help 'cpoptions'".
12let s:cpo_save = &cpo
13set cpo&vim
14
15" Avoid installing the menus twice
16if !exists("did_install_default_menus")
17let did_install_default_menus = 1
18
19
20if exists("v:lang") || &langmenu != ""
21 " Try to find a menu translation file for the current language.
22 if &langmenu != ""
23 if &langmenu =~ "none"
24 let s:lang = ""
25 else
26 let s:lang = &langmenu
27 endif
28 else
29 let s:lang = v:lang
30 endif
31 " A language name must be at least two characters, don't accept "C"
32 if strlen(s:lang) > 1
33 " When the language does not include the charset add 'encoding'
34 if s:lang =~ '^\a\a$\|^\a\a_\a\a$'
35 let s:lang = s:lang . '.' . &enc
36 endif
37
38 " We always use a lowercase name.
39 " Change "iso-8859" to "iso_8859" and "iso8859" to "iso_8859", some
40 " systems appear to use this.
41 " Change spaces to underscores.
42 let s:lang = substitute(tolower(s:lang), '\.iso-', ".iso_", "")
43 let s:lang = substitute(s:lang, '\.iso8859', ".iso_8859", "")
44 let s:lang = substitute(s:lang, " ", "_", "g")
45 " Remove "@euro", otherwise "LC_ALL=de_DE@euro gvim" will show English menus
46 let s:lang = substitute(s:lang, "@euro", "", "")
47 " Change "iso_8859-1" and "iso_8859-15" to "latin1", we always use the
48 " same menu file for them.
49 let s:lang = substitute(s:lang, 'iso_8859-15\=$', "latin1", "")
50 menutrans clear
51 exe "runtime! lang/menu_" . s:lang . ".vim"
52
53 if !exists("did_menu_trans")
54 " There is no exact match, try matching with a wildcard added
55 " (e.g. find menu_de_de.iso_8859-1.vim if s:lang == de_DE).
56 let s:lang = substitute(s:lang, '\.[^.]*', "", "")
Bram Moolenaar05159a02005-02-26 23:04:13 +000057 exe "runtime! lang/menu_" . s:lang . "[^a-z]*vim"
Bram Moolenaar071d4272004-06-13 20:20:40 +000058
Bram Moolenaar68f1b1b2018-07-23 05:10:14 +020059 if !exists("did_menu_trans") && s:lang =~ '_'
60 " If the language includes a region try matching without that region.
61 " (e.g. find menu_de.vim if s:lang == de_DE).
62 let langonly = substitute(s:lang, '_.*', "", "")
63 exe "runtime! lang/menu_" . langonly . "[^a-z]*vim"
64 endif
65
Bram Moolenaare2cc9702005-03-15 22:43:58 +000066 if !exists("did_menu_trans") && strlen($LANG) > 1 && s:lang !~ '^en_us'
Bram Moolenaar071d4272004-06-13 20:20:40 +000067 " On windows locale names are complicated, try using $LANG, it might
Bram Moolenaare2cc9702005-03-15 22:43:58 +000068 " have been set by set_init_1(). But don't do this for "en" or "en_us".
Bram Moolenaar2ce06f62005-01-31 19:19:04 +000069 " But don't match "slovak" when $LANG is "sl".
70 exe "runtime! lang/menu_" . tolower($LANG) . "[^a-z]*vim"
Bram Moolenaar071d4272004-06-13 20:20:40 +000071 endif
72 endif
73 endif
74endif
75
76
77" Help menu
78an 9999.10 &Help.&Overview<Tab><F1> :help<CR>
79an 9999.20 &Help.&User\ Manual :help usr_toc<CR>
Bram Moolenaar214641f2017-03-05 17:04:09 +010080an 9999.30 &Help.&How-To\ Links :help how-to<CR>
Bram Moolenaar071d4272004-06-13 20:20:40 +000081an <silent> 9999.40 &Help.&Find\.\.\. :call <SID>Helpfind()<CR>
82an 9999.45 &Help.-sep1- <Nop>
83an 9999.50 &Help.&Credits :help credits<CR>
84an 9999.60 &Help.Co&pying :help copying<CR>
85an 9999.70 &Help.&Sponsor/Register :help sponsor<CR>
86an 9999.70 &Help.O&rphans :help kcc<CR>
87an 9999.75 &Help.-sep2- <Nop>
88an 9999.80 &Help.&Version :version<CR>
89an 9999.90 &Help.&About :intro<CR>
90
91fun! s:Helpfind()
92 if !exists("g:menutrans_help_dialog")
93 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')"
94 endif
95 let h = inputdialog(g:menutrans_help_dialog)
96 if h != ""
97 let v:errmsg = ""
98 silent! exe "help " . h
99 if v:errmsg != ""
100 echo v:errmsg
101 endif
102 endif
103endfun
104
105" File menu
106an 10.310 &File.&Open\.\.\.<Tab>:e :browse confirm e<CR>
107an 10.320 &File.Sp&lit-Open\.\.\.<Tab>:sp :browse sp<CR>
Bram Moolenaar5c8837f2006-02-25 21:52:33 +0000108an 10.320 &File.Open\ Tab\.\.\.<Tab>:tabnew :browse tabnew<CR>
Bram Moolenaar071d4272004-06-13 20:20:40 +0000109an 10.325 &File.&New<Tab>:enew :confirm enew<CR>
110an <silent> 10.330 &File.&Close<Tab>:close
Bram Moolenaarcab49df2011-03-22 17:40:10 +0100111 \ :if winheight(2) < 0 && tabpagewinnr(2) == 0 <Bar>
Bram Moolenaar071d4272004-06-13 20:20:40 +0000112 \ confirm enew <Bar>
113 \ else <Bar>
114 \ confirm close <Bar>
115 \ endif<CR>
116an 10.335 &File.-SEP1- <Nop>
117an <silent> 10.340 &File.&Save<Tab>:w :if expand("%") == ""<Bar>browse confirm w<Bar>else<Bar>confirm w<Bar>endif<CR>
118an 10.350 &File.Save\ &As\.\.\.<Tab>:sav :browse confirm saveas<CR>
119
120if has("diff")
121 an 10.400 &File.-SEP2- <Nop>
Bram Moolenaar214641f2017-03-05 17:04:09 +0100122 an 10.410 &File.Split\ &Diff\ With\.\.\. :browse vert diffsplit<CR>
Bram Moolenaar071d4272004-06-13 20:20:40 +0000123 an 10.420 &File.Split\ Patched\ &By\.\.\. :browse vert diffpatch<CR>
124endif
125
126if has("printer")
127 an 10.500 &File.-SEP3- <Nop>
128 an 10.510 &File.&Print :hardcopy<CR>
129 vunmenu &File.&Print
130 vnoremenu &File.&Print :hardcopy<CR>
131elseif has("unix")
132 an 10.500 &File.-SEP3- <Nop>
133 an 10.510 &File.&Print :w !lpr<CR>
134 vunmenu &File.&Print
135 vnoremenu &File.&Print :w !lpr<CR>
136endif
137an 10.600 &File.-SEP4- <Nop>
138an 10.610 &File.Sa&ve-Exit<Tab>:wqa :confirm wqa<CR>
139an 10.620 &File.E&xit<Tab>:qa :confirm qa<CR>
140
Bram Moolenaar071d4272004-06-13 20:20:40 +0000141func! <SID>SelectAll()
Bram Moolenaara3e6bc92013-01-30 14:18:00 +0100142 exe "norm! gg" . (&slm == "" ? "VG" : "gH\<C-O>G")
Bram Moolenaar071d4272004-06-13 20:20:40 +0000143endfunc
144
Bram Moolenaaraba88572008-06-25 20:13:35 +0000145func! s:FnameEscape(fname)
146 if exists('*fnameescape')
147 return fnameescape(a:fname)
Bram Moolenaar5c736222010-01-06 20:54:52 +0100148 endif
Bram Moolenaaraba88572008-06-25 20:13:35 +0000149 return escape(a:fname, " \t\n*?[{`$\\%#'\"|!<")
150endfunc
Bram Moolenaar071d4272004-06-13 20:20:40 +0000151
152" Edit menu
153an 20.310 &Edit.&Undo<Tab>u u
154an 20.320 &Edit.&Redo<Tab>^R <C-R>
155an 20.330 &Edit.Rep&eat<Tab>\. .
156
157an 20.335 &Edit.-SEP1- <Nop>
158vnoremenu 20.340 &Edit.Cu&t<Tab>"+x "+x
159vnoremenu 20.350 &Edit.&Copy<Tab>"+y "+y
160cnoremenu 20.350 &Edit.&Copy<Tab>"+y <C-Y>
161nnoremenu 20.360 &Edit.&Paste<Tab>"+gP "+gP
162cnoremenu &Edit.&Paste<Tab>"+gP <C-R>+
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000163exe 'vnoremenu <script> &Edit.&Paste<Tab>"+gP ' . paste#paste_cmd['v']
164exe 'inoremenu <script> &Edit.&Paste<Tab>"+gP ' . paste#paste_cmd['i']
Bram Moolenaar071d4272004-06-13 20:20:40 +0000165nnoremenu 20.370 &Edit.Put\ &Before<Tab>[p [p
166inoremenu &Edit.Put\ &Before<Tab>[p <C-O>[p
167nnoremenu 20.380 &Edit.Put\ &After<Tab>]p ]p
168inoremenu &Edit.Put\ &After<Tab>]p <C-O>]p
Bram Moolenaar040c1fe2017-11-09 19:45:48 +0100169if has("win32")
Bram Moolenaar071d4272004-06-13 20:20:40 +0000170 vnoremenu 20.390 &Edit.&Delete<Tab>x x
171endif
172noremenu <script> <silent> 20.400 &Edit.&Select\ All<Tab>ggVG :<C-U>call <SID>SelectAll()<CR>
173inoremenu <script> <silent> 20.400 &Edit.&Select\ All<Tab>ggVG <C-O>:call <SID>SelectAll()<CR>
174cnoremenu <script> <silent> 20.400 &Edit.&Select\ All<Tab>ggVG <C-U>call <SID>SelectAll()<CR>
175
176an 20.405 &Edit.-SEP2- <Nop>
Bram Moolenaar040c1fe2017-11-09 19:45:48 +0100177if has("win32") || has("gui_gtk") || has("gui_kde") || has("gui_motif")
Bram Moolenaar071d4272004-06-13 20:20:40 +0000178 an 20.410 &Edit.&Find\.\.\. :promptfind<CR>
179 vunmenu &Edit.&Find\.\.\.
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000180 vnoremenu <silent> &Edit.&Find\.\.\. y:promptfind <C-R>=<SID>FixFText()<CR><CR>
Bram Moolenaar071d4272004-06-13 20:20:40 +0000181 an 20.420 &Edit.Find\ and\ Rep&lace\.\.\. :promptrepl<CR>
182 vunmenu &Edit.Find\ and\ Rep&lace\.\.\.
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000183 vnoremenu <silent> &Edit.Find\ and\ Rep&lace\.\.\. y:promptrepl <C-R>=<SID>FixFText()<CR><CR>
Bram Moolenaar071d4272004-06-13 20:20:40 +0000184else
185 an 20.410 &Edit.&Find<Tab>/ /
186 an 20.420 &Edit.Find\ and\ Rep&lace<Tab>:%s :%s/
187 vunmenu &Edit.Find\ and\ Rep&lace<Tab>:%s
188 vnoremenu &Edit.Find\ and\ Rep&lace<Tab>:s :s/
189endif
190
191an 20.425 &Edit.-SEP3- <Nop>
192an 20.430 &Edit.Settings\ &Window :options<CR>
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000193an 20.435 &Edit.Startup\ &Settings :call <SID>EditVimrc()<CR>
194
195fun! s:EditVimrc()
196 if $MYVIMRC != ''
Bram Moolenaare30de2d2008-07-01 19:56:57 +0000197 let fname = $MYVIMRC
Bram Moolenaar42ebd062016-07-17 13:35:14 +0200198 elseif has("win32")
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000199 if $HOME != ''
Bram Moolenaare30de2d2008-07-01 19:56:57 +0000200 let fname = $HOME . "/_vimrc"
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000201 else
Bram Moolenaare30de2d2008-07-01 19:56:57 +0000202 let fname = $VIM . "/_vimrc"
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000203 endif
204 elseif has("amiga")
205 let fname = "s:.vimrc"
206 else
Bram Moolenaare30de2d2008-07-01 19:56:57 +0000207 let fname = $HOME . "/.vimrc"
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000208 endif
Bram Moolenaaraba88572008-06-25 20:13:35 +0000209 let fname = s:FnameEscape(fname)
Bram Moolenaar910f66f2006-04-05 20:41:53 +0000210 if &mod
211 exe "split " . fname
212 else
213 exe "edit " . fname
214 endif
215endfun
Bram Moolenaar071d4272004-06-13 20:20:40 +0000216
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000217fun! s:FixFText()
218 " Fix text in nameless register to be used with :promptfind.
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000219 return substitute(@", "[\r\n]", '\\n', 'g')
Bram Moolenaar5b8d8fd2005-08-16 23:01:50 +0000220endfun
221
Bram Moolenaar071d4272004-06-13 20:20:40 +0000222" Edit/Global Settings
223an 20.440.100 &Edit.&Global\ Settings.Toggle\ Pattern\ &Highlight<Tab>:set\ hls! :set hls! hls?<CR>
Bram Moolenaar214641f2017-03-05 17:04:09 +0100224an 20.440.110 &Edit.&Global\ Settings.Toggle\ &Ignoring\ Case<Tab>:set\ ic! :set ic! ic?<CR>
225an 20.440.110 &Edit.&Global\ Settings.Toggle\ &Showing\ Matched\ Pairs<Tab>:set\ sm! :set sm! sm?<CR>
Bram Moolenaar071d4272004-06-13 20:20:40 +0000226
Bram Moolenaar214641f2017-03-05 17:04:09 +0100227an 20.440.120 &Edit.&Global\ Settings.&Context\ Lines.\ 1\ :set so=1<CR>
228an 20.440.120 &Edit.&Global\ Settings.&Context\ Lines.\ 2\ :set so=2<CR>
229an 20.440.120 &Edit.&Global\ Settings.&Context\ Lines.\ 3\ :set so=3<CR>
230an 20.440.120 &Edit.&Global\ Settings.&Context\ Lines.\ 4\ :set so=4<CR>
231an 20.440.120 &Edit.&Global\ Settings.&Context\ Lines.\ 5\ :set so=5<CR>
232an 20.440.120 &Edit.&Global\ Settings.&Context\ Lines.\ 7\ :set so=7<CR>
233an 20.440.120 &Edit.&Global\ Settings.&Context\ Lines.\ 10\ :set so=10<CR>
234an 20.440.120 &Edit.&Global\ Settings.&Context\ Lines.\ 100\ :set so=100<CR>
Bram Moolenaar071d4272004-06-13 20:20:40 +0000235
236an 20.440.130.40 &Edit.&Global\ Settings.&Virtual\ Edit.Never :set ve=<CR>
237an 20.440.130.50 &Edit.&Global\ Settings.&Virtual\ Edit.Block\ Selection :set ve=block<CR>
Bram Moolenaar214641f2017-03-05 17:04:09 +0100238an 20.440.130.60 &Edit.&Global\ Settings.&Virtual\ Edit.Insert\ Mode :set ve=insert<CR>
Bram Moolenaar071d4272004-06-13 20:20:40 +0000239an 20.440.130.70 &Edit.&Global\ Settings.&Virtual\ Edit.Block\ and\ Insert :set ve=block,insert<CR>
240an 20.440.130.80 &Edit.&Global\ Settings.&Virtual\ Edit.Always :set ve=all<CR>
241an 20.440.140 &Edit.&Global\ Settings.Toggle\ Insert\ &Mode<Tab>:set\ im! :set im!<CR>
Bram Moolenaar214641f2017-03-05 17:04:09 +0100242an 20.440.145 &Edit.&Global\ Settings.Toggle\ Vi\ C&ompatibility<Tab>:set\ cp! :set cp!<CR>
Bram Moolenaar071d4272004-06-13 20:20:40 +0000243an <silent> 20.440.150 &Edit.&Global\ Settings.Search\ &Path\.\.\. :call <SID>SearchP()<CR>
244an <silent> 20.440.160 &Edit.&Global\ Settings.Ta&g\ Files\.\.\. :call <SID>TagFiles()<CR>
245"
246" GUI options
247an 20.440.300 &Edit.&Global\ Settings.-SEP1- <Nop>
248an <silent> 20.440.310 &Edit.&Global\ Settings.Toggle\ &Toolbar :call <SID>ToggleGuiOption("T")<CR>
249an <silent> 20.440.320 &Edit.&Global\ Settings.Toggle\ &Bottom\ Scrollbar :call <SID>ToggleGuiOption("b")<CR>
250an <silent> 20.440.330 &Edit.&Global\ Settings.Toggle\ &Left\ Scrollbar :call <SID>ToggleGuiOption("l")<CR>
251an <silent> 20.440.340 &Edit.&Global\ Settings.Toggle\ &Right\ Scrollbar :call <SID>ToggleGuiOption("r")<CR>
252
253fun! s:SearchP()
254 if !exists("g:menutrans_path_dialog")
255 let g:menutrans_path_dialog = "Enter search path for files.\nSeparate directory names with a comma."
256 endif
257 let n = inputdialog(g:menutrans_path_dialog, substitute(&path, '\\ ', ' ', 'g'))
258 if n != ""
259 let &path = substitute(n, ' ', '\\ ', 'g')
260 endif
261endfun
262
263fun! s:TagFiles()
264 if !exists("g:menutrans_tags_dialog")
265 let g:menutrans_tags_dialog = "Enter names of tag files.\nSeparate the names with a comma."
266 endif
267 let n = inputdialog(g:menutrans_tags_dialog, substitute(&tags, '\\ ', ' ', 'g'))
268 if n != ""
269 let &tags = substitute(n, ' ', '\\ ', 'g')
270 endif
271endfun
272
273fun! s:ToggleGuiOption(option)
274 " If a:option is already set in guioptions, then we want to remove it
275 if match(&guioptions, "\\C" . a:option) > -1
276 exec "set go-=" . a:option
277 else
278 exec "set go+=" . a:option
279 endif
280endfun
281
282" Edit/File Settings
283
284" Boolean options
285an 20.440.100 &Edit.F&ile\ Settings.Toggle\ Line\ &Numbering<Tab>:set\ nu! :set nu! nu?<CR>
Bram Moolenaar214641f2017-03-05 17:04:09 +0100286an 20.440.105 &Edit.F&ile\ Settings.Toggle\ Relati&ve\ Line\ Numbering<Tab>:set\ rnu! :set rnu! rnu?<CR>
Bram Moolenaar071d4272004-06-13 20:20:40 +0000287an 20.440.110 &Edit.F&ile\ Settings.Toggle\ &List\ Mode<Tab>:set\ list! :set list! list?<CR>
Bram Moolenaar214641f2017-03-05 17:04:09 +0100288an 20.440.120 &Edit.F&ile\ Settings.Toggle\ Line\ &Wrapping<Tab>:set\ wrap! :set wrap! wrap?<CR>
289an 20.440.130 &Edit.F&ile\ Settings.Toggle\ W&rapping\ at\ Word<Tab>:set\ lbr! :set lbr! lbr?<CR>
290an 20.440.160 &Edit.F&ile\ Settings.Toggle\ Tab\ &Expanding<Tab>:set\ et! :set et! et?<CR>
291an 20.440.170 &Edit.F&ile\ Settings.Toggle\ &Auto\ Indenting<Tab>:set\ ai! :set ai! ai?<CR>
292an 20.440.180 &Edit.F&ile\ Settings.Toggle\ &C-Style\ Indenting<Tab>:set\ cin! :set cin! cin?<CR>
Bram Moolenaar071d4272004-06-13 20:20:40 +0000293
294" other options
295an 20.440.600 &Edit.F&ile\ Settings.-SEP2- <Nop>
296an 20.440.610.20 &Edit.F&ile\ Settings.&Shiftwidth.2 :set sw=2 sw?<CR>
297an 20.440.610.30 &Edit.F&ile\ Settings.&Shiftwidth.3 :set sw=3 sw?<CR>
298an 20.440.610.40 &Edit.F&ile\ Settings.&Shiftwidth.4 :set sw=4 sw?<CR>
299an 20.440.610.50 &Edit.F&ile\ Settings.&Shiftwidth.5 :set sw=5 sw?<CR>
300an 20.440.610.60 &Edit.F&ile\ Settings.&Shiftwidth.6 :set sw=6 sw?<CR>
301an 20.440.610.80 &Edit.F&ile\ Settings.&Shiftwidth.8 :set sw=8 sw?<CR>
302
303an 20.440.620.20 &Edit.F&ile\ Settings.Soft\ &Tabstop.2 :set sts=2 sts?<CR>
304an 20.440.620.30 &Edit.F&ile\ Settings.Soft\ &Tabstop.3 :set sts=3 sts?<CR>
305an 20.440.620.40 &Edit.F&ile\ Settings.Soft\ &Tabstop.4 :set sts=4 sts?<CR>
306an 20.440.620.50 &Edit.F&ile\ Settings.Soft\ &Tabstop.5 :set sts=5 sts?<CR>
307an 20.440.620.60 &Edit.F&ile\ Settings.Soft\ &Tabstop.6 :set sts=6 sts?<CR>
308an 20.440.620.80 &Edit.F&ile\ Settings.Soft\ &Tabstop.8 :set sts=8 sts?<CR>
309
310an <silent> 20.440.630 &Edit.F&ile\ Settings.Te&xt\ Width\.\.\. :call <SID>TextWidth()<CR>
311an <silent> 20.440.640 &Edit.F&ile\ Settings.&File\ Format\.\.\. :call <SID>FileFormat()<CR>
312fun! s:TextWidth()
313 if !exists("g:menutrans_textwidth_dialog")
314 let g:menutrans_textwidth_dialog = "Enter new text width (0 to disable formatting): "
315 endif
316 let n = inputdialog(g:menutrans_textwidth_dialog, &tw)
317 if n != ""
Bram Moolenaarad3b3662013-05-17 18:14:19 +0200318 " Remove leading zeros to avoid it being used as an octal number.
319 " But keep a zero by itself.
320 let tw = substitute(n, "^0*", "", "")
Bram Moolenaar214641f2017-03-05 17:04:09 +0100321 let &tw = tw == '' ? 0 : tw
Bram Moolenaar071d4272004-06-13 20:20:40 +0000322 endif
323endfun
324
325fun! s:FileFormat()
326 if !exists("g:menutrans_fileformat_dialog")
327 let g:menutrans_fileformat_dialog = "Select format for writing the file"
328 endif
329 if !exists("g:menutrans_fileformat_choices")
330 let g:menutrans_fileformat_choices = "&Unix\n&Dos\n&Mac\n&Cancel"
331 endif
332 if &ff == "dos"
333 let def = 2
334 elseif &ff == "mac"
335 let def = 3
336 else
337 let def = 1
338 endif
339 let n = confirm(g:menutrans_fileformat_dialog, g:menutrans_fileformat_choices, def, "Question")
340 if n == 1
341 set ff=unix
342 elseif n == 2
343 set ff=dos
344 elseif n == 3
345 set ff=mac
346 endif
347endfun
348
Bram Moolenaar040c1fe2017-11-09 19:45:48 +0100349let s:did_setup_color_schemes = 0
Bram Moolenaarc5604bc2010-07-17 15:20:30 +0200350
Bram Moolenaar071d4272004-06-13 20:20:40 +0000351" Setup the Edit.Color Scheme submenu
Bram Moolenaar040c1fe2017-11-09 19:45:48 +0100352func! s:SetupColorSchemes() abort
353 if s:did_setup_color_schemes
354 return
355 endif
356 let s:did_setup_color_schemes = 1
Bram Moolenaarc5604bc2010-07-17 15:20:30 +0200357
Bram Moolenaar040c1fe2017-11-09 19:45:48 +0100358 let n = globpath(&runtimepath, "colors/*.vim", 1, 1)
Bram Moolenaarfc65cab2018-08-28 22:58:02 +0200359 let n += globpath(&runtimepath, "pack/*/start/*/colors/*.vim", 1, 1)
360 let n += globpath(&runtimepath, "pack/*/opt/*/colors/*.vim", 1, 1)
Bram Moolenaarc5604bc2010-07-17 15:20:30 +0200361
Bram Moolenaar040c1fe2017-11-09 19:45:48 +0100362 " Ignore case for VMS and windows, sort on name
363 let names = sort(map(n, 'substitute(v:val, "\\c.*[/\\\\:\\]]\\([^/\\\\:]*\\)\\.vim", "\\1", "")'), 1)
Bram Moolenaarc5604bc2010-07-17 15:20:30 +0200364
Bram Moolenaar040c1fe2017-11-09 19:45:48 +0100365 " define all the submenu entries
366 let idx = 100
367 for name in names
368 exe "an 20.450." . idx . ' &Edit.C&olor\ Scheme.' . name . " :colors " . name . "<CR>"
369 let idx = idx + 10
370 endfor
371 silent! aunmenu &Edit.Show\ C&olor\ Schemes\ in\ Menu
372endfun
373if exists("do_no_lazyload_menus")
374 call s:SetupColorSchemes()
375else
376 an <silent> 20.450 &Edit.Show\ C&olor\ Schemes\ in\ Menu :call <SID>SetupColorSchemes()<CR>
377endif
Bram Moolenaarc5604bc2010-07-17 15:20:30 +0200378
Bram Moolenaar071d4272004-06-13 20:20:40 +0000379
380" Setup the Edit.Keymap submenu
381if has("keymap")
Bram Moolenaar040c1fe2017-11-09 19:45:48 +0100382 let s:did_setup_keymaps = 0
383
384 func! s:SetupKeymaps() abort
385 if s:did_setup_keymaps
386 return
387 endif
388 let s:did_setup_keymaps = 1
389
390 let n = globpath(&runtimepath, "keymap/*.vim", 1, 1)
391 if !empty(n)
392 let idx = 100
393 an 20.460.90 &Edit.&Keymap.None :set keymap=<CR>
394 for name in n
395 " Ignore case for VMS and windows
396 let name = substitute(name, '\c.*[/\\:\]]\([^/\\:_]*\)\(_[0-9a-zA-Z-]*\)\=\.vim', '\1', '')
397 exe "an 20.460." . idx . ' &Edit.&Keymap.' . name . " :set keymap=" . name . "<CR>"
398 let idx = idx + 10
399 endfor
400 endif
401 silent! aunmenu &Edit.Show\ &Keymaps\ in\ Menu
402 endfun
403 if exists("do_no_lazyload_menus")
404 call s:SetupKeymaps()
405 else
406 an <silent> 20.460 &Edit.Show\ &Keymaps\ in\ Menu :call <SID>SetupKeymaps()<CR>
Bram Moolenaar071d4272004-06-13 20:20:40 +0000407 endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000408endif
Bram Moolenaar040c1fe2017-11-09 19:45:48 +0100409if has("win32") || has("gui_motif") || has("gui_gtk") || has("gui_kde") || has("gui_photon") || has("gui_mac")
Bram Moolenaar071d4272004-06-13 20:20:40 +0000410 an 20.470 &Edit.Select\ Fo&nt\.\.\. :set guifont=*<CR>
411endif
412
413" Programming menu
414if !exists("g:ctags_command")
415 if has("vms")
Bram Moolenaard675e2c2007-01-09 14:09:25 +0000416 let g:ctags_command = "mc vim:ctags *.*"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000417 else
418 let g:ctags_command = "ctags -R ."
419 endif
420endif
421
Bram Moolenaar214641f2017-03-05 17:04:09 +0100422an 40.300 &Tools.&Jump\ to\ This\ Tag<Tab>g^] g<C-]>
423vunmenu &Tools.&Jump\ to\ This\ Tag<Tab>g^]
424vnoremenu &Tools.&Jump\ to\ This\ Tag<Tab>g^] g<C-]>
425an 40.310 &Tools.Jump\ &Back<Tab>^T <C-T>
Bram Moolenaar071d4272004-06-13 20:20:40 +0000426an 40.320 &Tools.Build\ &Tags\ File :exe "!" . g:ctags_command<CR>
427
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000428if has("folding") || has("spell")
429 an 40.330 &Tools.-SEP1- <Nop>
430endif
431
Bram Moolenaarf3681cc2005-06-08 22:03:13 +0000432" Tools.Spelling Menu
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000433if has("spell")
434 an 40.335.110 &Tools.&Spelling.&Spell\ Check\ On :set spell<CR>
435 an 40.335.120 &Tools.&Spelling.Spell\ Check\ &Off :set nospell<CR>
Bram Moolenaar214641f2017-03-05 17:04:09 +0100436 an 40.335.130 &Tools.&Spelling.To\ &Next\ Error<Tab>]s ]s
437 an 40.335.130 &Tools.&Spelling.To\ &Previous\ Error<Tab>[s [s
Bram Moolenaar362e1a32006-03-06 23:29:24 +0000438 an 40.335.140 &Tools.&Spelling.Suggest\ &Corrections<Tab>z= z=
Bram Moolenaar214641f2017-03-05 17:04:09 +0100439 an 40.335.150 &Tools.&Spelling.&Repeat\ Correction<Tab>:spellrepall :spellrepall<CR>
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000440 an 40.335.200 &Tools.&Spelling.-SEP1- <Nop>
Bram Moolenaar214641f2017-03-05 17:04:09 +0100441 an 40.335.210 &Tools.&Spelling.Set\ Language\ to\ "en" :set spl=en spell<CR>
442 an 40.335.220 &Tools.&Spelling.Set\ Language\ to\ "en_au" :set spl=en_au spell<CR>
443 an 40.335.230 &Tools.&Spelling.Set\ Language\ to\ "en_ca" :set spl=en_ca spell<CR>
444 an 40.335.240 &Tools.&Spelling.Set\ Language\ to\ "en_gb" :set spl=en_gb spell<CR>
445 an 40.335.250 &Tools.&Spelling.Set\ Language\ to\ "en_nz" :set spl=en_nz spell<CR>
446 an 40.335.260 &Tools.&Spelling.Set\ Language\ to\ "en_us" :set spl=en_us spell<CR>
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000447 an <silent> 40.335.270 &Tools.&Spelling.&Find\ More\ Languages :call <SID>SpellLang()<CR>
448
Bram Moolenaar5a8684e2005-07-30 22:43:24 +0000449 let s:undo_spellang = ['aun &Tools.&Spelling.&Find\ More\ Languages']
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000450 func! s:SpellLang()
Bram Moolenaar5a8684e2005-07-30 22:43:24 +0000451 for cmd in s:undo_spellang
452 exe "silent! " . cmd
453 endfor
454 let s:undo_spellang = []
455
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000456 if &enc == "iso-8859-15"
457 let enc = "latin1"
458 else
459 let enc = &enc
460 endif
Bram Moolenaar5a8684e2005-07-30 22:43:24 +0000461
Bram Moolenaarf3408e72012-10-21 01:21:59 +0200462 if !exists("g:menutrans_set_lang_to")
Bram Moolenaar214641f2017-03-05 17:04:09 +0100463 let g:menutrans_set_lang_to = 'Set Language to'
Bram Moolenaarf3408e72012-10-21 01:21:59 +0200464 endif
465
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000466 let found = 0
Bram Moolenaar040c1fe2017-11-09 19:45:48 +0100467 let s = globpath(&runtimepath, "spell/*." . enc . ".spl", 1, 1)
468 if !empty(s)
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000469 let n = 300
Bram Moolenaar040c1fe2017-11-09 19:45:48 +0100470 for f in s
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000471 let nm = substitute(f, '.*spell[/\\]\(..\)\.[^/\\]*\.spl', '\1', "")
Bram Moolenaar5a8684e2005-07-30 22:43:24 +0000472 if nm != "en" && nm !~ '/'
Bram Moolenaarf3408e72012-10-21 01:21:59 +0200473 let _nm = nm
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000474 let found += 1
Bram Moolenaarf3408e72012-10-21 01:21:59 +0200475 let menuname = '&Tools.&Spelling.' . escape(g:menutrans_set_lang_to, "\\. \t|") . '\ "' . nm . '"'
Bram Moolenaar5a8684e2005-07-30 22:43:24 +0000476 exe 'an 40.335.' . n . ' ' . menuname . ' :set spl=' . nm . ' spell<CR>'
477 let s:undo_spellang += ['aun ' . menuname]
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000478 endif
479 let n += 10
480 endfor
481 endif
482 if found == 0
483 echomsg "Could not find other spell files"
484 elseif found == 1
Bram Moolenaarf3408e72012-10-21 01:21:59 +0200485 echomsg "Found spell file " . _nm
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000486 else
487 echomsg "Found " . found . " more spell files"
488 endif
Bram Moolenaar5a8684e2005-07-30 22:43:24 +0000489 " Need to redo this when 'encoding' is changed.
490 augroup spellmenu
491 au! EncodingChanged * call <SID>SpellLang()
492 augroup END
Bram Moolenaar82cf9b62005-06-07 21:09:25 +0000493 endfun
494
495endif
496
Bram Moolenaar071d4272004-06-13 20:20:40 +0000497" Tools.Fold Menu
498if has("folding")
Bram Moolenaar071d4272004-06-13 20:20:40 +0000499 " open close folds
Bram Moolenaar214641f2017-03-05 17:04:09 +0100500 an 40.340.110 &Tools.&Folding.&Enable/Disable\ Folds<Tab>zi zi
Bram Moolenaar071d4272004-06-13 20:20:40 +0000501 an 40.340.120 &Tools.&Folding.&View\ Cursor\ Line<Tab>zv zv
Bram Moolenaar214641f2017-03-05 17:04:09 +0100502 an 40.340.120 &Tools.&Folding.Vie&w\ Cursor\ Line\ Only<Tab>zMzx zMzx
503 inoremenu 40.340.120 &Tools.&Folding.Vie&w\ Cursor\ Line\ Only<Tab>zMzx <C-O>zM<C-O>zx
504 an 40.340.130 &Tools.&Folding.C&lose\ More\ Folds<Tab>zm zm
505 an 40.340.140 &Tools.&Folding.&Close\ All\ Folds<Tab>zM zM
506 an 40.340.150 &Tools.&Folding.O&pen\ More\ Folds<Tab>zr zr
Bram Moolenaar3df01732017-02-17 22:47:16 +0100507 an 40.340.160 &Tools.&Folding.&Open\ All\ Folds<Tab>zR zR
Bram Moolenaar071d4272004-06-13 20:20:40 +0000508 " fold method
509 an 40.340.200 &Tools.&Folding.-SEP1- <Nop>
510 an 40.340.210 &Tools.&Folding.Fold\ Met&hod.M&anual :set fdm=manual<CR>
511 an 40.340.210 &Tools.&Folding.Fold\ Met&hod.I&ndent :set fdm=indent<CR>
512 an 40.340.210 &Tools.&Folding.Fold\ Met&hod.E&xpression :set fdm=expr<CR>
513 an 40.340.210 &Tools.&Folding.Fold\ Met&hod.S&yntax :set fdm=syntax<CR>
514 an 40.340.210 &Tools.&Folding.Fold\ Met&hod.&Diff :set fdm=diff<CR>
515 an 40.340.210 &Tools.&Folding.Fold\ Met&hod.Ma&rker :set fdm=marker<CR>
516 " create and delete folds
517 vnoremenu 40.340.220 &Tools.&Folding.Create\ &Fold<Tab>zf zf
518 an 40.340.230 &Tools.&Folding.&Delete\ Fold<Tab>zd zd
519 an 40.340.240 &Tools.&Folding.Delete\ &All\ Folds<Tab>zD zD
520 " moving around in folds
521 an 40.340.300 &Tools.&Folding.-SEP2- <Nop>
Bram Moolenaar214641f2017-03-05 17:04:09 +0100522 an 40.340.310.10 &Tools.&Folding.Fold\ Col&umn\ Width.\ &0\ :set fdc=0<CR>
523 an 40.340.310.20 &Tools.&Folding.Fold\ Col&umn\ Width.\ &2\ :set fdc=2<CR>
524 an 40.340.310.30 &Tools.&Folding.Fold\ Col&umn\ Width.\ &3\ :set fdc=3<CR>
525 an 40.340.310.40 &Tools.&Folding.Fold\ Col&umn\ Width.\ &4\ :set fdc=4<CR>
526 an 40.340.310.50 &Tools.&Folding.Fold\ Col&umn\ Width.\ &5\ :set fdc=5<CR>
527 an 40.340.310.60 &Tools.&Folding.Fold\ Col&umn\ Width.\ &6\ :set fdc=6<CR>
528 an 40.340.310.70 &Tools.&Folding.Fold\ Col&umn\ Width.\ &7\ :set fdc=7<CR>
529 an 40.340.310.80 &Tools.&Folding.Fold\ Col&umn\ Width.\ &8\ :set fdc=8<CR>
Bram Moolenaar071d4272004-06-13 20:20:40 +0000530endif " has folding
531
532if has("diff")
533 an 40.350.100 &Tools.&Diff.&Update :diffupdate<CR>
534 an 40.350.110 &Tools.&Diff.&Get\ Block :diffget<CR>
535 vunmenu &Tools.&Diff.&Get\ Block
536 vnoremenu &Tools.&Diff.&Get\ Block :diffget<CR>
537 an 40.350.120 &Tools.&Diff.&Put\ Block :diffput<CR>
538 vunmenu &Tools.&Diff.&Put\ Block
539 vnoremenu &Tools.&Diff.&Put\ Block :diffput<CR>
540endif
541
542an 40.358 &Tools.-SEP2- <Nop>
543an 40.360 &Tools.&Make<Tab>:make :make<CR>
544an 40.370 &Tools.&List\ Errors<Tab>:cl :cl<CR>
545an 40.380 &Tools.L&ist\ Messages<Tab>:cl! :cl!<CR>
546an 40.390 &Tools.&Next\ Error<Tab>:cn :cn<CR>
547an 40.400 &Tools.&Previous\ Error<Tab>:cp :cp<CR>
548an 40.410 &Tools.&Older\ List<Tab>:cold :colder<CR>
549an 40.420 &Tools.N&ewer\ List<Tab>:cnew :cnewer<CR>
550an 40.430.50 &Tools.Error\ &Window.&Update<Tab>:cwin :cwin<CR>
551an 40.430.60 &Tools.Error\ &Window.&Open<Tab>:copen :copen<CR>
552an 40.430.70 &Tools.Error\ &Window.&Close<Tab>:cclose :cclose<CR>
553
554an 40.520 &Tools.-SEP3- <Nop>
555an <silent> 40.530 &Tools.&Convert\ to\ HEX<Tab>:%!xxd
556 \ :call <SID>XxdConv()<CR>
Bram Moolenaar214641f2017-03-05 17:04:09 +0100557an <silent> 40.540 &Tools.Conve&rt\ Back<Tab>:%!xxd\ -r
Bram Moolenaar071d4272004-06-13 20:20:40 +0000558 \ :call <SID>XxdBack()<CR>
559
560" Use a function to do the conversion, so that it also works with 'insertmode'
561" set.
562func! s:XxdConv()
563 let mod = &mod
564 if has("vms")
565 %!mc vim:xxd
566 else
567 call s:XxdFind()
568 exe '%!"' . g:xxdprogram . '"'
569 endif
570 if getline(1) =~ "^0000000:" " only if it worked
571 set ft=xxd
572 endif
573 let &mod = mod
574endfun
575
576func! s:XxdBack()
577 let mod = &mod
578 if has("vms")
579 %!mc vim:xxd -r
580 else
581 call s:XxdFind()
582 exe '%!"' . g:xxdprogram . '" -r'
583 endif
584 set ft=
585 doautocmd filetypedetect BufReadPost
586 let &mod = mod
587endfun
588
589func! s:XxdFind()
590 if !exists("g:xxdprogram")
591 " On the PC xxd may not be in the path but in the install directory
Bram Moolenaar42ebd062016-07-17 13:35:14 +0200592 if has("win32") && !executable("xxd")
Bram Moolenaar071d4272004-06-13 20:20:40 +0000593 let g:xxdprogram = $VIMRUNTIME . (&shellslash ? '/' : '\') . "xxd.exe"
594 else
595 let g:xxdprogram = "xxd"
596 endif
597 endif
598endfun
599
Bram Moolenaar040c1fe2017-11-09 19:45:48 +0100600let s:did_setup_compilers = 0
601
Bram Moolenaar071d4272004-06-13 20:20:40 +0000602" Setup the Tools.Compiler submenu
Bram Moolenaar040c1fe2017-11-09 19:45:48 +0100603func! s:SetupCompilers() abort
604 if s:did_setup_compilers
605 return
Bram Moolenaar071d4272004-06-13 20:20:40 +0000606 endif
Bram Moolenaar040c1fe2017-11-09 19:45:48 +0100607 let s:did_setup_compilers = 1
608
609 let n = globpath(&runtimepath, "compiler/*.vim", 1, 1)
610 let idx = 100
611 for name in n
612 " Ignore case for VMS and windows
613 let name = substitute(name, '\c.*[/\\:\]]\([^/\\:]*\)\.vim', '\1', '')
614 exe "an 30.440." . idx . ' &Tools.Se&t\ Compiler.' . name . " :compiler " . name . "<CR>"
615 let idx = idx + 10
616 endfor
617 silent! aunmenu &Tools.Show\ Compiler\ Se&ttings\ in\ Menu
618endfun
619if exists("do_no_lazyload_menus")
620 call s:SetupCompilers()
621else
622 an <silent> 30.440 &Tools.Show\ Compiler\ Se&ttings\ in\ Menu :call <SID>SetupCompilers()<CR>
623endif
624
625" Load ColorScheme, Compiler Setting and Keymap menus when idle.
626if !exists("do_no_lazyload_menus")
627 func! s:SetupLazyloadMenus()
628 call s:SetupColorSchemes()
629 call s:SetupCompilers()
630 if has("keymap")
631 call s:SetupKeymaps()
632 endif
633 endfunc
634 augroup SetupLazyloadMenus
635 au!
636 au CursorHold,CursorHoldI * call <SID>SetupLazyloadMenus() | au! SetupLazyloadMenus
637 augroup END
638endif
639
Bram Moolenaar071d4272004-06-13 20:20:40 +0000640
641if !exists("no_buffers_menu")
642
643" Buffer list menu -- Setup functions & actions
644
645" wait with building the menu until after loading 'session' files. Makes
646" startup faster.
647let s:bmenu_wait = 1
648
649if !exists("bmenu_priority")
650 let bmenu_priority = 60
651endif
652
653func! s:BMAdd()
654 if s:bmenu_wait == 0
655 " when adding too many buffers, redraw in short format
656 if s:bmenu_count == &menuitems && s:bmenu_short == 0
657 call s:BMShow()
658 else
659 call <SID>BMFilename(expand("<afile>"), expand("<abuf>"))
660 let s:bmenu_count = s:bmenu_count + 1
661 endif
662 endif
663endfunc
664
665func! s:BMRemove()
666 if s:bmenu_wait == 0
667 let name = expand("<afile>")
668 if isdirectory(name)
669 return
670 endif
671 let munge = <SID>BMMunge(name, expand("<abuf>"))
672
673 if s:bmenu_short == 0
674 exe 'silent! aun &Buffers.' . munge
675 else
676 exe 'silent! aun &Buffers.' . <SID>BMHash2(munge) . munge
677 endif
678 let s:bmenu_count = s:bmenu_count - 1
679 endif
680endfunc
681
682" Create the buffer menu (delete an existing one first).
683func! s:BMShow(...)
684 let s:bmenu_wait = 1
685 let s:bmenu_short = 1
686 let s:bmenu_count = 0
687 "
688 " get new priority, if exists
689 if a:0 == 1
690 let g:bmenu_priority = a:1
691 endif
692
693 " remove old menu, if exists; keep one entry to avoid a torn off menu to
694 " disappear.
695 silent! unmenu &Buffers
696 exe 'noremenu ' . g:bmenu_priority . ".1 &Buffers.Dummy l"
697 silent! unmenu! &Buffers
698
699 " create new menu; set 'cpo' to include the <CR>
700 let cpo_save = &cpo
701 set cpo&vim
702 exe 'an <silent> ' . g:bmenu_priority . ".2 &Buffers.&Refresh\\ menu :call <SID>BMShow()<CR>"
703 exe 'an ' . g:bmenu_priority . ".4 &Buffers.&Delete :confirm bd<CR>"
704 exe 'an ' . g:bmenu_priority . ".6 &Buffers.&Alternate :confirm b #<CR>"
705 exe 'an ' . g:bmenu_priority . ".7 &Buffers.&Next :confirm bnext<CR>"
706 exe 'an ' . g:bmenu_priority . ".8 &Buffers.&Previous :confirm bprev<CR>"
707 exe 'an ' . g:bmenu_priority . ".9 &Buffers.-SEP- :"
708 let &cpo = cpo_save
709 unmenu &Buffers.Dummy
710
711 " figure out how many buffers there are
712 let buf = 1
713 while buf <= bufnr('$')
714 if bufexists(buf) && !isdirectory(bufname(buf)) && buflisted(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000715 let s:bmenu_count = s:bmenu_count + 1
716 endif
717 let buf = buf + 1
718 endwhile
719 if s:bmenu_count <= &menuitems
720 let s:bmenu_short = 0
721 endif
722
723 " iterate through buffer list, adding each buffer to the menu:
724 let buf = 1
725 while buf <= bufnr('$')
726 if bufexists(buf) && !isdirectory(bufname(buf)) && buflisted(buf)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000727 call <SID>BMFilename(bufname(buf), buf)
728 endif
729 let buf = buf + 1
730 endwhile
731 let s:bmenu_wait = 0
732 aug buffer_list
733 au!
734 au BufCreate,BufFilePost * call <SID>BMAdd()
735 au BufDelete,BufFilePre * call <SID>BMRemove()
736 aug END
737endfunc
738
739func! s:BMHash(name)
740 " Make name all upper case, so that chars are between 32 and 96
741 let nm = substitute(a:name, ".*", '\U\0', "")
742 if has("ebcdic")
743 " HACK: Replace all non alphabetics with 'Z'
744 " Just to make it work for now.
745 let nm = substitute(nm, "[^A-Z]", 'Z', "g")
746 let sp = char2nr('A') - 1
747 else
748 let sp = char2nr(' ')
749 endif
750 " convert first six chars into a number for sorting:
751 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)
752endfunc
753
754func! s:BMHash2(name)
755 let nm = substitute(a:name, ".", '\L\0', "")
756 " Not exactly right for EBCDIC...
757 if nm[0] < 'a' || nm[0] > 'z'
758 return '&others.'
759 elseif nm[0] <= 'd'
760 return '&abcd.'
761 elseif nm[0] <= 'h'
762 return '&efgh.'
763 elseif nm[0] <= 'l'
764 return '&ijkl.'
765 elseif nm[0] <= 'p'
766 return '&mnop.'
767 elseif nm[0] <= 't'
768 return '&qrst.'
769 else
770 return '&u-z.'
771 endif
772endfunc
773
774" insert a buffer name into the buffer menu:
775func! s:BMFilename(name, num)
776 if isdirectory(a:name)
777 return
778 endif
779 let munge = <SID>BMMunge(a:name, a:num)
780 let hash = <SID>BMHash(munge)
781 if s:bmenu_short == 0
782 let name = 'an ' . g:bmenu_priority . '.' . hash . ' &Buffers.' . munge
783 else
784 let name = 'an ' . g:bmenu_priority . '.' . hash . '.' . hash . ' &Buffers.' . <SID>BMHash2(munge) . munge
785 endif
786 " set 'cpo' to include the <CR>
787 let cpo_save = &cpo
788 set cpo&vim
789 exe name . ' :confirm b' . a:num . '<CR>'
790 let &cpo = cpo_save
791endfunc
792
793" Truncate a long path to fit it in a menu item.
794if !exists("g:bmenu_max_pathlen")
795 let g:bmenu_max_pathlen = 35
796endif
797func! s:BMTruncName(fname)
798 let name = a:fname
799 if g:bmenu_max_pathlen < 5
800 let name = ""
801 else
802 let len = strlen(name)
803 if len > g:bmenu_max_pathlen
804 let amountl = (g:bmenu_max_pathlen / 2) - 2
805 let amountr = g:bmenu_max_pathlen - amountl - 3
806 let pattern = '^\(.\{,' . amountl . '}\).\{-}\(.\{,' . amountr . '}\)$'
807 let left = substitute(name, pattern, '\1', '')
808 let right = substitute(name, pattern, '\2', '')
809 if strlen(left) + strlen(right) < len
810 let name = left . '...' . right
811 endif
812 endif
813 endif
814 return name
815endfunc
816
817func! s:BMMunge(fname, bnum)
818 let name = a:fname
819 if name == ''
820 if !exists("g:menutrans_no_file")
Bram Moolenaar6dc819b2018-07-03 16:42:19 +0200821 let g:menutrans_no_file = "[No Name]"
Bram Moolenaar071d4272004-06-13 20:20:40 +0000822 endif
823 let name = g:menutrans_no_file
824 else
825 let name = fnamemodify(name, ':p:~')
826 endif
827 " detach file name and separate it out:
828 let name2 = fnamemodify(name, ':t')
829 if a:bnum >= 0
830 let name2 = name2 . ' (' . a:bnum . ')'
831 endif
832 let name = name2 . "\t" . <SID>BMTruncName(fnamemodify(name,':h'))
833 let name = escape(name, "\\. \t|")
834 let name = substitute(name, "&", "&&", "g")
835 let name = substitute(name, "\n", "^@", "g")
836 return name
837endfunc
838
839" When just starting Vim, load the buffer menu later
840if has("vim_starting")
841 augroup LoadBufferMenu
842 au! VimEnter * if !exists("no_buffers_menu") | call <SID>BMShow() | endif
843 au VimEnter * au! LoadBufferMenu
844 augroup END
845else
846 call <SID>BMShow()
847endif
848
849endif " !exists("no_buffers_menu")
850
851" Window menu
852an 70.300 &Window.&New<Tab>^Wn <C-W>n
853an 70.310 &Window.S&plit<Tab>^Ws <C-W>s
854an 70.320 &Window.Sp&lit\ To\ #<Tab>^W^^ <C-W><C-^>
855an 70.330 &Window.Split\ &Vertically<Tab>^Wv <C-W>v
856if has("vertsplit")
857 an <silent> 70.332 &Window.Split\ File\ E&xplorer :call MenuExplOpen()<CR>
858 if !exists("*MenuExplOpen")
859 fun MenuExplOpen()
860 if @% == ""
861 20vsp .
862 else
Bram Moolenaaraba88572008-06-25 20:13:35 +0000863 exe "20vsp " . s:FnameEscape(expand("%:p:h"))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000864 endif
865 endfun
866 endif
867endif
868an 70.335 &Window.-SEP1- <Nop>
869an 70.340 &Window.&Close<Tab>^Wc :confirm close<CR>
870an 70.345 &Window.Close\ &Other(s)<Tab>^Wo :confirm only<CR>
871an 70.350 &Window.-SEP2- <Nop>
872an 70.355 &Window.Move\ &To.&Top<Tab>^WK <C-W>K
873an 70.355 &Window.Move\ &To.&Bottom<Tab>^WJ <C-W>J
Bram Moolenaar214641f2017-03-05 17:04:09 +0100874an 70.355 &Window.Move\ &To.&Left\ Side<Tab>^WH <C-W>H
875an 70.355 &Window.Move\ &To.&Right\ Side<Tab>^WL <C-W>L
Bram Moolenaar071d4272004-06-13 20:20:40 +0000876an 70.360 &Window.Rotate\ &Up<Tab>^WR <C-W>R
877an 70.362 &Window.Rotate\ &Down<Tab>^Wr <C-W>r
878an 70.365 &Window.-SEP3- <Nop>
879an 70.370 &Window.&Equal\ Size<Tab>^W= <C-W>=
880an 70.380 &Window.&Max\ Height<Tab>^W_ <C-W>_
881an 70.390 &Window.M&in\ Height<Tab>^W1_ <C-W>1_
882an 70.400 &Window.Max\ &Width<Tab>^W\| <C-W>\|
883an 70.410 &Window.Min\ Widt&h<Tab>^W1\| <C-W>1\|
884
885" The popup menu
886an 1.10 PopUp.&Undo u
887an 1.15 PopUp.-SEP1- <Nop>
888vnoremenu 1.20 PopUp.Cu&t "+x
889vnoremenu 1.30 PopUp.&Copy "+y
890cnoremenu 1.30 PopUp.&Copy <C-Y>
891nnoremenu 1.40 PopUp.&Paste "+gP
892cnoremenu 1.40 PopUp.&Paste <C-R>+
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +0000893exe 'vnoremenu <script> 1.40 PopUp.&Paste ' . paste#paste_cmd['v']
894exe 'inoremenu <script> 1.40 PopUp.&Paste ' . paste#paste_cmd['i']
Bram Moolenaar071d4272004-06-13 20:20:40 +0000895vnoremenu 1.50 PopUp.&Delete x
896an 1.55 PopUp.-SEP2- <Nop>
897vnoremenu 1.60 PopUp.Select\ Blockwise <C-V>
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000898
899nnoremenu 1.70 PopUp.Select\ &Word vaw
900onoremenu 1.70 PopUp.Select\ &Word aw
901vnoremenu 1.70 PopUp.Select\ &Word <C-C>vaw
902inoremenu 1.70 PopUp.Select\ &Word <C-O>vaw
903cnoremenu 1.70 PopUp.Select\ &Word <C-C>vaw
904
905nnoremenu 1.73 PopUp.Select\ &Sentence vas
906onoremenu 1.73 PopUp.Select\ &Sentence as
907vnoremenu 1.73 PopUp.Select\ &Sentence <C-C>vas
908inoremenu 1.73 PopUp.Select\ &Sentence <C-O>vas
909cnoremenu 1.73 PopUp.Select\ &Sentence <C-C>vas
910
911nnoremenu 1.77 PopUp.Select\ Pa&ragraph vap
912onoremenu 1.77 PopUp.Select\ Pa&ragraph ap
913vnoremenu 1.77 PopUp.Select\ Pa&ragraph <C-C>vap
914inoremenu 1.77 PopUp.Select\ Pa&ragraph <C-O>vap
915cnoremenu 1.77 PopUp.Select\ Pa&ragraph <C-C>vap
916
917nnoremenu 1.80 PopUp.Select\ &Line V
918onoremenu 1.80 PopUp.Select\ &Line <C-C>V
919vnoremenu 1.80 PopUp.Select\ &Line <C-C>V
920inoremenu 1.80 PopUp.Select\ &Line <C-O>V
921cnoremenu 1.80 PopUp.Select\ &Line <C-C>V
922
923nnoremenu 1.90 PopUp.Select\ &Block <C-V>
924onoremenu 1.90 PopUp.Select\ &Block <C-C><C-V>
925vnoremenu 1.90 PopUp.Select\ &Block <C-C><C-V>
926inoremenu 1.90 PopUp.Select\ &Block <C-O><C-V>
927cnoremenu 1.90 PopUp.Select\ &Block <C-C><C-V>
928
Bram Moolenaar071d4272004-06-13 20:20:40 +0000929noremenu <script> <silent> 1.100 PopUp.Select\ &All :<C-U>call <SID>SelectAll()<CR>
930inoremenu <script> <silent> 1.100 PopUp.Select\ &All <C-O>:call <SID>SelectAll()<CR>
931cnoremenu <script> <silent> 1.100 PopUp.Select\ &All <C-U>call <SID>SelectAll()<CR>
932
Bram Moolenaar45360022005-07-21 21:08:21 +0000933if has("spell")
934 " Spell suggestions in the popup menu. Note that this will slow down the
935 " appearance of the menu!
936 func! <SID>SpellPopup()
937 if exists("s:changeitem") && s:changeitem != ''
938 call <SID>SpellDel()
939 endif
Bram Moolenaarb38dea22006-09-14 11:35:25 +0000940
941 " Return quickly if spell checking is not enabled.
Bram Moolenaard8c00872005-07-22 21:52:15 +0000942 if !&spell || &spelllang == ''
943 return
944 endif
Bram Moolenaar45360022005-07-21 21:08:21 +0000945
946 let curcol = col('.')
Bram Moolenaar1c7715d2005-10-03 22:02:18 +0000947 let [w, a] = spellbadword()
Bram Moolenaar45360022005-07-21 21:08:21 +0000948 if col('.') > curcol " don't use word after the cursor
949 let w = ''
Bram Moolenaar45360022005-07-21 21:08:21 +0000950 endif
951 if w != ''
Bram Moolenaara93fa7e2006-04-17 22:14:47 +0000952 if a == 'caps'
953 let s:suglist = [substitute(w, '.*', '\u&', '')]
954 else
955 let s:suglist = spellsuggest(w, 10)
956 endif
Bram Moolenaar62292582010-07-10 16:36:59 +0200957 if len(s:suglist) > 0
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200958 if !exists("g:menutrans_spell_change_ARG_to")
959 let g:menutrans_spell_change_ARG_to = 'Change\ "%s"\ to'
960 endif
961 let s:changeitem = printf(g:menutrans_spell_change_ARG_to, escape(w, ' .'))
Bram Moolenaar45360022005-07-21 21:08:21 +0000962 let s:fromword = w
963 let pri = 1
Bram Moolenaar62292582010-07-10 16:36:59 +0200964 " set 'cpo' to include the <CR>
965 let cpo_save = &cpo
966 set cpo&vim
Bram Moolenaar45360022005-07-21 21:08:21 +0000967 for sug in s:suglist
Bram Moolenaarb38dea22006-09-14 11:35:25 +0000968 exe 'anoremenu 1.5.' . pri . ' PopUp.' . s:changeitem . '.' . escape(sug, ' .')
Bram Moolenaar45360022005-07-21 21:08:21 +0000969 \ . ' :call <SID>SpellReplace(' . pri . ')<CR>'
970 let pri += 1
971 endfor
972
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200973 if !exists("g:menutrans_spell_add_ARG_to_word_list")
974 let g:menutrans_spell_add_ARG_to_word_list = 'Add\ "%s"\ to\ Word\ List'
975 endif
976 let s:additem = printf(g:menutrans_spell_add_ARG_to_word_list, escape(w, ' .'))
Bram Moolenaarb38dea22006-09-14 11:35:25 +0000977 exe 'anoremenu 1.6 PopUp.' . s:additem . ' :spellgood ' . w . '<CR>'
Bram Moolenaar45360022005-07-21 21:08:21 +0000978
Bram Moolenaar7c63fbc2018-05-17 13:15:23 +0200979 if !exists("g:menutrans_spell_ignore_ARG")
980 let g:menutrans_spell_ignore_ARG = 'Ignore\ "%s"'
981 endif
982 let s:ignoreitem = printf(g:menutrans_spell_ignore_ARG, escape(w, ' .'))
Bram Moolenaarb38dea22006-09-14 11:35:25 +0000983 exe 'anoremenu 1.7 PopUp.' . s:ignoreitem . ' :spellgood! ' . w . '<CR>'
Bram Moolenaar45360022005-07-21 21:08:21 +0000984
Bram Moolenaarb38dea22006-09-14 11:35:25 +0000985 anoremenu 1.8 PopUp.-SpellSep- :
Bram Moolenaar62292582010-07-10 16:36:59 +0200986 let &cpo = cpo_save
Bram Moolenaar45360022005-07-21 21:08:21 +0000987 endif
988 endif
Bram Moolenaar62292582010-07-10 16:36:59 +0200989 call cursor(0, curcol) " put the cursor back where it was
Bram Moolenaar45360022005-07-21 21:08:21 +0000990 endfunc
991
992 func! <SID>SpellReplace(n)
993 let l = getline('.')
Bram Moolenaar62292582010-07-10 16:36:59 +0200994 " Move the cursor to the start of the word.
995 call spellbadword()
Bram Moolenaar45360022005-07-21 21:08:21 +0000996 call setline('.', strpart(l, 0, col('.') - 1) . s:suglist[a:n - 1]
997 \ . strpart(l, col('.') + len(s:fromword) - 1))
998 endfunc
999
1000 func! <SID>SpellDel()
1001 exe "aunmenu PopUp." . s:changeitem
1002 exe "aunmenu PopUp." . s:additem
1003 exe "aunmenu PopUp." . s:ignoreitem
1004 aunmenu PopUp.-SpellSep-
1005 let s:changeitem = ''
1006 endfun
1007
Bram Moolenaarb38dea22006-09-14 11:35:25 +00001008 augroup SpellPopupMenu
1009 au! MenuPopup * call <SID>SpellPopup()
1010 augroup END
Bram Moolenaar45360022005-07-21 21:08:21 +00001011endif
Bram Moolenaar071d4272004-06-13 20:20:40 +00001012
1013" The GUI toolbar (for MS-Windows and GTK)
1014if has("toolbar")
1015 an 1.10 ToolBar.Open :browse confirm e<CR>
1016 an <silent> 1.20 ToolBar.Save :if expand("%") == ""<Bar>browse confirm w<Bar>else<Bar>confirm w<Bar>endif<CR>
1017 an 1.30 ToolBar.SaveAll :browse confirm wa<CR>
1018
1019 if has("printer")
1020 an 1.40 ToolBar.Print :hardcopy<CR>
1021 vunmenu ToolBar.Print
1022 vnoremenu ToolBar.Print :hardcopy<CR>
1023 elseif has("unix")
1024 an 1.40 ToolBar.Print :w !lpr<CR>
1025 vunmenu ToolBar.Print
1026 vnoremenu ToolBar.Print :w !lpr<CR>
1027 endif
1028
1029 an 1.45 ToolBar.-sep1- <Nop>
1030 an 1.50 ToolBar.Undo u
1031 an 1.60 ToolBar.Redo <C-R>
1032
1033 an 1.65 ToolBar.-sep2- <Nop>
1034 vnoremenu 1.70 ToolBar.Cut "+x
1035 vnoremenu 1.80 ToolBar.Copy "+y
1036 cnoremenu 1.80 ToolBar.Copy <C-Y>
1037 nnoremenu 1.90 ToolBar.Paste "+gP
1038 cnoremenu ToolBar.Paste <C-R>+
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001039 exe 'vnoremenu <script> ToolBar.Paste ' . paste#paste_cmd['v']
1040 exe 'inoremenu <script> ToolBar.Paste ' . paste#paste_cmd['i']
Bram Moolenaar071d4272004-06-13 20:20:40 +00001041
1042 if !has("gui_athena")
1043 an 1.95 ToolBar.-sep3- <Nop>
Bram Moolenaare2cc9702005-03-15 22:43:58 +00001044 an 1.100 ToolBar.Replace :promptrepl<CR>
Bram Moolenaar071d4272004-06-13 20:20:40 +00001045 vunmenu ToolBar.Replace
Bram Moolenaar4ea8fe12006-03-09 22:32:39 +00001046 vnoremenu ToolBar.Replace y:promptrepl <C-R>=<SID>FixFText()<CR><CR>
Bram Moolenaare2cc9702005-03-15 22:43:58 +00001047 an 1.110 ToolBar.FindNext n
1048 an 1.120 ToolBar.FindPrev N
Bram Moolenaar071d4272004-06-13 20:20:40 +00001049 endif
1050
Bram Moolenaar071d4272004-06-13 20:20:40 +00001051 an 1.215 ToolBar.-sep5- <Nop>
1052 an <silent> 1.220 ToolBar.LoadSesn :call <SID>LoadVimSesn()<CR>
1053 an <silent> 1.230 ToolBar.SaveSesn :call <SID>SaveVimSesn()<CR>
1054 an 1.240 ToolBar.RunScript :browse so<CR>
1055
1056 an 1.245 ToolBar.-sep6- <Nop>
1057 an 1.250 ToolBar.Make :make<CR>
1058 an 1.270 ToolBar.RunCtags :exe "!" . g:ctags_command<CR>
1059 an 1.280 ToolBar.TagJump g<C-]>
1060
1061 an 1.295 ToolBar.-sep7- <Nop>
1062 an 1.300 ToolBar.Help :help<CR>
1063 an <silent> 1.310 ToolBar.FindHelp :call <SID>Helpfind()<CR>
1064
1065" Only set the tooltips here if not done in a language menu file
1066if exists("*Do_toolbar_tmenu")
1067 call Do_toolbar_tmenu()
1068else
1069 let did_toolbar_tmenu = 1
1070 tmenu ToolBar.Open Open file
1071 tmenu ToolBar.Save Save current file
1072 tmenu ToolBar.SaveAll Save all files
1073 tmenu ToolBar.Print Print
1074 tmenu ToolBar.Undo Undo
1075 tmenu ToolBar.Redo Redo
1076 tmenu ToolBar.Cut Cut to clipboard
1077 tmenu ToolBar.Copy Copy to clipboard
1078 tmenu ToolBar.Paste Paste from Clipboard
1079 if !has("gui_athena")
Bram Moolenaar5c736222010-01-06 20:54:52 +01001080 tmenu ToolBar.Replace Find / Replace...
Bram Moolenaar071d4272004-06-13 20:20:40 +00001081 tmenu ToolBar.FindNext Find Next
1082 tmenu ToolBar.FindPrev Find Previous
Bram Moolenaar071d4272004-06-13 20:20:40 +00001083 endif
Bram Moolenaarb38dea22006-09-14 11:35:25 +00001084 tmenu ToolBar.LoadSesn Choose a session to load
Bram Moolenaar071d4272004-06-13 20:20:40 +00001085 tmenu ToolBar.SaveSesn Save current session
Bram Moolenaarb38dea22006-09-14 11:35:25 +00001086 tmenu ToolBar.RunScript Choose a Vim Script to run
Bram Moolenaare2cc9702005-03-15 22:43:58 +00001087 tmenu ToolBar.Make Make current project (:make)
1088 tmenu ToolBar.RunCtags Build tags in current directory tree (!ctags -R .)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001089 tmenu ToolBar.TagJump Jump to tag under cursor
1090 tmenu ToolBar.Help Vim Help
1091 tmenu ToolBar.FindHelp Search Vim Help
1092endif
1093
1094" Select a session to load; default to current session name if present
1095fun! s:LoadVimSesn()
1096 if strlen(v:this_session) > 0
Bram Moolenaaraba88572008-06-25 20:13:35 +00001097 let name = s:FnameEscape(v:this_session)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001098 else
1099 let name = "Session.vim"
1100 endif
1101 execute "browse so " . name
1102endfun
1103
1104" Select a session to save; default to current session name if present
1105fun! s:SaveVimSesn()
1106 if strlen(v:this_session) == 0
1107 let v:this_session = "Session.vim"
1108 endif
Bram Moolenaaraba88572008-06-25 20:13:35 +00001109 execute "browse mksession! " . s:FnameEscape(v:this_session)
Bram Moolenaar071d4272004-06-13 20:20:40 +00001110endfun
1111
1112endif
1113
1114endif " !exists("did_install_default_menus")
1115
1116" Define these items always, so that syntax can be switched on when it wasn't.
1117" But skip them when the Syntax menu was disabled by the user.
1118if !exists("did_install_syntax_menu")
1119 an 50.212 &Syntax.&Manual :syn manual<CR>
1120 an 50.214 &Syntax.A&utomatic :syn on<CR>
Bram Moolenaar214641f2017-03-05 17:04:09 +01001121 an <silent> 50.216 &Syntax.On/Off\ for\ &This\ File :call <SID>SynOnOff()<CR>
Bram Moolenaar071d4272004-06-13 20:20:40 +00001122 if !exists("*s:SynOnOff")
1123 fun s:SynOnOff()
1124 if has("syntax_items")
1125 syn clear
1126 else
1127 if !exists("g:syntax_on")
1128 syn manual
1129 endif
1130 set syn=ON
1131 endif
1132 endfun
1133 endif
1134endif
1135
1136
1137" Install the Syntax menu only when filetype.vim has been loaded or when
1138" manual syntax highlighting is enabled.
1139" Avoid installing the Syntax menu twice.
1140if (exists("did_load_filetypes") || exists("syntax_on"))
1141 \ && !exists("did_install_syntax_menu")
1142 let did_install_syntax_menu = 1
1143
1144" Skip setting up the individual syntax selection menus unless
1145" do_syntax_sel_menu is defined (it takes quite a bit of time).
1146if exists("do_syntax_sel_menu")
1147 runtime! synmenu.vim
1148else
Bram Moolenaar040c1fe2017-11-09 19:45:48 +01001149 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>
Bram Moolenaar071d4272004-06-13 20:20:40 +00001150 an 50.195 &Syntax.-SEP1- <Nop>
1151endif
1152
1153an 50.210 &Syntax.&Off :syn off<CR>
1154an 50.700 &Syntax.-SEP3- <Nop>
Bram Moolenaar214641f2017-03-05 17:04:09 +01001155an 50.710 &Syntax.Co&lor\ Test :sp $VIMRUNTIME/syntax/colortest.vim<Bar>so %<CR>
1156an 50.720 &Syntax.&Highlight\ Test :runtime syntax/hitest.vim<CR>
Bram Moolenaar071d4272004-06-13 20:20:40 +00001157an 50.730 &Syntax.&Convert\ to\ HTML :runtime syntax/2html.vim<CR>
1158
1159endif " !exists("did_install_syntax_menu")
1160
Bram Moolenaar071d4272004-06-13 20:20:40 +00001161" Restore the previous value of 'cpoptions'.
1162let &cpo = s:cpo_save
1163unlet s:cpo_save
1164
1165" vim: set sw=2 :