On 7/13/06, Peter Hodge <[EMAIL PROTECTED]> wrote:
However, if I type anything beginning with 'for', the letters disappear
until I
type something that is not part of the mapping.  I understand this is
the
standard behaviour, but is there any way to change it so I can see
 what I am
typing?

Although there is no stardard option for imap to do this (make incompete
mapping visible; yes I'd find it seful, too), I found  a weird trick that
does what you want.
Does the following do what you want:
-----------------------------
:imap h <c-r>=PrecedingChars(6) !=# 'foreac' ? 'h' : ExpandForeach() <cr>

function! ExpandForeach() " expansion of the foreach mapping
   " nb: 'foreac' is already there. So we don't need to repeat it
   return "h() {\n}\<Left>"
endfunction

function! PrecedingChars(n)
   " return n chars preceding cursor in rhs of :imap mapping
   return getline('.')[col('.')-1-a:n : col('.')-2]
endfunction
-------------------------------

Explanation: this remaps 'h' character to check 6 preceding chars.
If 6 preceding chars are 'foreac', then it is expanded into your you
foreach-template. Otherwise, literas 'h' is inserted. Since this is
1-char-length mapping, there's no delay and no invisibilities.

If you wonder where is expansion (rhs) of your template, it's
inside function ExpandForeach(). The function PrecedingChars()
is generic and doesn't change when you change rhs of your template.

2.
If you find this too complex, and you don't want to
press space or tab after 'foreach' (supposedly because it
makes 8 chars instead of 7?) , then can I suggest either this simple weirdity:

    :iab foreac foreach ...

(In which case, you get to type 'foreac' then space, which makes
total 7 characters not 8.), or this mapping

   :imap <ctrl-Z>f foreach ....

which is economy of 5 chars on the lhs side. (You type ctrl-z then f)

Yakov

Reply via email to