On 27/02/10 21:27, rameo wrote:
I would like to map a few menu commands.
p.e.
A menu command is:
an<silent> 10.330&File.&Close<Tab>:close
\ :if winheight(2) < 0<Bar>
\ confirm enew<Bar>
\ else<Bar>
\ confirm close<Bar>
\ endif<CR>
How can I map this command to a shortcut (ctrl-w)?
I'm surprised that after so long, this question hasn't yet got an answer.
Mapping this to Ctrl-W is a bad idea, because Ctrl-W is too useful with
its standard bindings: see
:help CTRL-W
:help i_CTRL-W
:help c_CTRL-W
In fact, in normal mode, Ctrl-W c would probably do more or less what
you want without any mapping; but if you want one key, not two, or if
you want it in Insert mode too, you could for instance map it to F4 by using
:noremap <F4>
\ :if winheight(2) < 0<Bar>
\ confirm enew<Bar>
\ else<Bar>
\ confirm close<Bar>
\ endif<CR>
:inoremap <F4>
\ <C-O>:if winheight(2) < 0<Bar>
\ confirm enew<Bar>
\ else<Bar>
\ confirm close<Bar>
\ endif<CR>
or, to mimic even more closely what this menu does, you would write in
(for instance) your vimrc
nnoremap <F4>
\ :if winheight(2) < 0 <Bar>
\ confirm enew <Bar>
\ else <Bar>
\ confirm close <Bar>
\ endif<CR>
vnoremap <F4>
\ <C-C>:if winheight(2) < 0 <Bar>
\ confirm enew <Bar>
\ else <Bar>
\ confirm close <Bar>
\ endif<CR><C-\><C-G>
snoremap <F4>
\ <C-C>:if winheight(2) < 0 <Bar>
\ confirm enew <Bar>
\ else <Bar>
\ confirm close <Bar>
\ endif<CR><C-\><C-G>
onoremap <F4>
\ <C-C>:if winheight(2) < 0 <Bar>
\ confirm enew <Bar>
\ else <Bar>
\ confirm close <Bar>
\ endif<CR><C-\><C-G>
inoremap <F4>
\ <C-O>:if winheight(2) < 0 <Bar>
\ confirm enew <Bar>
\ else <Bar>
\ confirm close <Bar>
\ endif<CR>
cnoremap <F4>
\ <C-C>:if winheight(2) < 0 <Bar>
\ confirm enew <Bar>
\ else <Bar>
\ confirm close <Bar>
\ endif<CR><C-\><C-G>
(see
:amenu File.Close
to find out how I got the above),
or, if you can afford to assume that menus have been sourced (which is
usually the case in gvim but not in Console vim):
noremap <F4> :emenu File.Close<CR>
vnoremap <F4> :<C-U>emenu File.Close<CR>
inoremap <F4> <C-O>:emenu File.Close<CR>
though in any case it would probably be easier to simply use either
:q
to close the current window (and close the current tab if this is its
only window, and quit Vim if there is no other non-help window), or
:enew
to replace the current contents of the current window by an empty buffer.
Best regards,
Tony.
--
Never be led astray onto the path of virtue.
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Subscription settings: http://groups.google.com/group/vim_use/subscribe?hl=en