On 2/18/07, Yegappan Lakshmanan <[EMAIL PROTECTED]> wrote:
Hi Tim,
On 2/18/07, Tim Chase <[EMAIL PROTECTED]> wrote:
> > Normal mode (sometimes called Command mode) is when hittinh h j k l will go
> > one character cell left, down, up or right, respectively.
> >
> > Command-LINE mode is what you enter by hitting : and quit by hitting <Enter>
> > (to execute a command) or <Esc> (to abandon what you were typing on the
> > command-line at the bottom of the Vim screen).
>
> Just to further muddy the waters... :)
>
> Command-line mode is entered with a colon to get into ex mode,
> but can also be entered into via "/" or "?" to search. One can
> also enter a pseudo-command-line mode by attempting to insert the
> contents of the expression register (control+R followed by "=")
>
> Somewhat irksomely, it's difficult to discern between these, so
> if you want a mapping that only applies on the Ex command-line,
> but that doesn't apply in the others, you have to fiddle with
> mappings dynamically. I've experienced this most when wanting to
> remap <CR> upon searching. To do as much, one has to create a
> mapping that does the following
>
> 1) create a cnoremap for <cr> to do what one wants and then once
> done, deletes these 3 temporary cnoremap mappings.
>
> 2) create a cnoremap for <esc> and for control+C to clean up the
> 3 temporary mappings
>
> and 3) then issues the "/" or "?" as asked for.
>
> It would be handy to have a "exnoremap" and "searchnoremap"
> command for mappings that would only apply in only when
> command-line mode was entered via that particular means (the
> former, via the colon, and the latter, via a "/" or "?").
>
> Just more ramble for ya'll. :)
>
In Vim7, the getcmdtype() function was added to solve this problem.
Now, from a command-line map, you can use this function to distinguish
between the ":", "/", "?", ">", "@" and "-" types.
To demonstrate this, try using the following map and function:
cnoremap <expr> <F7> ShowMode()
function ShowMode()
return 'mode = "' . getcmdtype() . '"'
endfunction
Now, in the various command-line modes, try pressing <F7>
- Yegappan