On 23/11/09 19:30, Tarlika Elisabeth Schmitz wrote:
>
> On Sun, 22 Nov 2009 18:44:56 -0800
> Gary Johnson wrote:
>
>>
>> On 2009-11-22, Tarlika Elisabeth Schmitz wrote:
>>> I would like to insert the output of a command at cursor position
>>> (either in normal or insert mode) and map the key sequence for this.
>>> [...]
>>
>> The expression [...] system(), which could be used to execute an
>> external command such as zenity, [...]
>>
>> Here's a command that will map that to F4:
>>
>> :imap<F4> <C-R>=substitute(system("zenity --calendar"), "\n", "",
>> "")<CR>
>
> Thanks for your help, Christian + Gary. I can't tell you how often I
> need this per day!
>
> It seems a bit of a phylosophical question whether to use :iab
> or :imap. When do you tend to use iab/imap?
>
Well, here's the way I see it:
With the ":map" family commands, you type one or more keys, _any_ keys,
in _any_ mode, and they trigger the {rhs} of the mapping.
Abbreviations are used only in "text-inserting" modes (mainly Insert and
Command-line); the abbreviation's {lhs} is restricted to three types,
and they are only triggered if they "stand out" in comparison with what
comes before and after after, as explained under ":help abbreviations".
Examples (all of them from my vimrc):
map <F2> :cnext<CR>
map <Down> gj
map! <F9> <C-]>
if version < 700
cnoreabbrev h bot h
else
cnoreabbrev <expr> h
\ ((getcmdtype() == ':' && getcmdpos() <= 2)?
\ 'bot h' : 'h')
endif
and from a session file
...
new kale-54.htm
iabbrev <buffer> VM Aĝa, saĝa Väinämöinen
...
In a mapping, I view the {lhs} as one or more _keys_ which produce a
certain effect when hit. In an abbreviation, it's _text_ which is used
as shorthand (as an "abbreviation" indeed) for something longer: ":h" in
command mode is expanded to ":bot h" if followed by a space or a
<Return> but not by another letter (as in ":hi" or ":hardcopy"); VM in
Insert mode in one particular file is expanded to three words (one of
them long and all of them with accents) plus two spaces and a comma.
Best regards,
Tony.
--
Megaton Man: "LOOK at them! Helpless, tender creatures, relying on
ME, waiting for ME to make my move!"
(from below): "Move your ASS, Fat-head!"
Megaton Man: "It is a MANDATE, and I am DUTY BOUND to OBEY!"
--
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php