Determining the command-line type from a cmap

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Determining the command-line type from a cmap

Yegappan Lakshmanan
Hi all,

Is it possible to distinguish between "/" and ":" command-line modes
in a function invoked from a cmap?

I need to map a key in command-line mode (using cmap) that should
work only in the "/" and "?" prompts.

Currently the getcmdpos(), getcmdline() and setcmdpos() functions
are available to manipulate the command-line. But a getcmdtype()
function to get the current command-line type is not available.

- Yegappan
Reply | Threaded
Open this post in threaded view
|

Re: Determining the command-line type from a cmap

Bram Moolenaar

Yegappan Laksmanan wrote:

> Is it possible to distinguish between "/" and ":" command-line modes
> in a function invoked from a cmap?
>
> I need to map a key in command-line mode (using cmap) that should=20
> work only in the "/" and "?" prompts.
>
> Currently the getcmdpos(), getcmdline() and setcmdpos() functions
> are available to manipulate the command-line. But a getcmdtype()
> function to get the current command-line type is not available.

No, this is not available.  Adding getcmdtype() sounds like a good idea.

The patch you sent looks good, thanks!

--
GALAHAD: No look, really, this isn't nescess ...
PIGLET:  We must examine you.
GALAHAD: There's nothing wrong with ... that.
                 "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

 /// Bram Moolenaar -- [hidden email] -- http://www.Moolenaar.net   \\\
///        Sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\              Project leader for A-A-P -- http://www.A-A-P.org        ///
 \\\     Buy LOTR 3 and help AIDS victims -- http://ICCF.nl/lotr.html   ///
Reply | Threaded
Open this post in threaded view
|

Re: Determining the command-line type from a cmap

Tim Chase-2
>> Is it possible to distinguish between "/" and ":"
>> command-line modes in a function invoked from a cmap?

While it's not available in vim-current, as Bram described, I've
done some hacking to get it to work via dark mapping magic :)

I map "/" to create the cnoremap that I want, and then have <cr>
(and/or <esc> and/or <c-c>) execute the search and then unmap
that command. Mappings that write mappings are bloody ugly. A
while back on the list, Eljay wanted to enter Insert mode upon
executing a search. I suggested something like the following:

nnoremap / :exec('cnoremap <'.'cr> <'.'cr>:exec("cunmap
<"."cr>")<'.'cr>i')<cr>/

in case you want to try the metamapping hack yourself :)

The patch would make this a heckuva lot easier (or if one could
do something like "snoremap" for "search-mode noremap" but that
would likely be a whole lot more code to vet.

-tim