Two simple questions with Map

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

Two simple questions with Map

Edward WIJAYA
Hi,

I have this following snippet which I put in my ~/.vimrc

" Deleting Perl subroutine
:map z  :Vj%d<CR>


Basically what it does is to delete (in visual mode ) a subroutine
in Perl script, that looks like this:

sub subroutine_name
{
  # some code
}


I have no problem running that map on-the-fly. But
after I put them in the vimrc script above it fails.
It says:

Not an editor command: Vj%d

How can I overcome the problem?


My second question is:
How can we find what function does a particular "letter" do in a map?
Say I want to check whether a particular letter 'z' has been mapped or not.

Typing :map list all of them..it's too much.


Thanks so much for your time.

--
Regards,
Edward WIJAYA
SINGAPORE
Reply | Threaded
Open this post in threaded view
|

Re: Two simple questions with Map

A.J.Mechelynck
Edward WIJAYA wrote:

> Hi,
>
> I have this following snippet which I put in my ~/.vimrc
>
> " Deleting Perl subroutine
> :map z  :Vj%d<CR>
>
>
> Basically what it does is to delete (in visual mode ) a subroutine
> in Perl script, that looks like this:
>
> sub subroutine_name
> {
>  # some code
> }
>
>
> I have no problem running that map on-the-fly. But
> after I put them in the vimrc script above it fails.
> It says:
>
> Not an editor command: Vj%d
>
> How can I overcome the problem?
>
>
> My second question is:
> How can we find what function does a particular "letter" do in a map?
> Say I want to check whether a particular letter 'z' has been mapped or not.
>
> Typing :map list all of them..it's too much.
>
>
> Thanks so much for your time.
>

I would expect the error to happen also when the mapping is invoked from
the keyboard.

As written, what it does is (IIUC)

Look for a "user command" named :Vj
Execute it with %d as argument

or maybe, if the % sign is in 'iskeyword'

Execute a "user command" named :Vj%d

Since you have defined no such command, it gives an error.

To produce the effect you want, delete the colon and the <CR>. Then the
same mapping will do the following:

V set linewise visual mode
j down one line (to the opening brace)
% to the matching closing brace
d delete the visually selected area

You might want to assign it to a different key, since there are several
Normal-mode command starting with z


Best regards,
Tony.

Reply | Threaded
Open this post in threaded view
|

Re: [2] Two simple questions with Map

A.J.Mechelynck
In reply to this post by Edward WIJAYA
Edward WIJAYA wrote:
[...]
> How can we find what function does a particular "letter" do in a map?
> Say I want to check whether a particular letter 'z' has been mapped or not.
>
> Typing :map list all of them..it's too much.
>
>
> Thanks so much for your time.
>

" for Normal, Visual and Operator-pending modes
:map z

" for Insert, Replace and Command-line modes
:map! z

" for keymaps
:lmap z



HTH,
Tony.

Reply | Threaded
Open this post in threaded view
|

Re: Two simple questions with Map

Eric Arnold
In reply to this post by Edward WIJAYA


--- Edward WIJAYA <[hidden email]> wrote:

> Hi,
>
> I have this following snippet which I put in my ~/.vimrc
>
> " Deleting Perl subroutine
> :map z  :Vj%d<CR>
>
>
> Basically what it does is to delete (in visual mode ) a subroutine
> in Perl script, that looks like this:
>
> sub subroutine_name
> {
>   # some code
> }
>
>
> I have no problem running that map on-the-fly. But
> after I put them in the vimrc script above it fails.
> It says:
>
> Not an editor command: Vj%d
>
> How can I overcome the problem?

Why do you have a colon preceding   Vj%d<CR>   in your map?
  map z  :Vj%d<CR>
         ^
         |
I think you mean:
  map z  Vj%d<CR>


>
> My second question is:
> How can we find what function does a particular "letter" do in a map?
> Say I want to check whether a particular letter 'z' has been mapped or not.
>
> Typing :map list all of them..it's too much.
>

Well, if all you want is the map definition of "z" then use simply,
    :map z

which shows only the requested mapping.  See
    :help map

If you're looking for a character embedded in a multi-char mapping,
you can do:

  :new
  :redir @a
  :map
  :redir end
  :put a

Then you can use normal Vim searching to look for "z"'s  in the
middle of mappings.

This finds all occurrences of "z", but it doesn't exactly answer:

> How can we find what function does a particular "letter" do in a map?

which is unclear to me, in the context of the other questions, but anyway...

If you're really asking how to to find out what the basic "function"
of a Vim "letter" command (as opposed to a mapped "letter"), one good
trick is to use control-D and/or tab when using the "help" command
to expand all "help" occurrences of that letter or word.  I.e.
  :help z^D

This will give a lot of output if you expand a single letter, and it will
often show you the associated characters accepted in pending mode (i.e.
z.   zt   etc. etc.), and if you're motivated to look through it all,
it can introduce you to a lot of new areas.


>
> Thanks so much for your time.
>
> --
> Regards,
> Edward WIJAYA
> SINGAPORE
>

Reply | Threaded
Open this post in threaded view
|

RE: Two simple questions with Map

Keith Roberts
In reply to this post by Edward WIJAYA
>-----Original Message-----
>From: Eric Arnold [mailto:[hidden email]]
>Sent: Friday, June 03, 2005 10:35 PM
>To: Edward WIJAYA; [hidden email]
>Subject: Re: Two simple questions with Map
>
>
>
>--- Edward WIJAYA <[hidden email]> wrote:
>
>> My second question is:
>> How can we find what function does a particular "letter" do in a map?
>
>If you're really asking how to to find out what the basic "function"
>of a Vim "letter" command (as opposed to a mapped "letter"),
>one good trick is to use control-D and/or tab when using the
>"help" command to expand all "help" occurrences of that letter
>or word.  I.e.
>  :help z^D
>
>This will give a lot of output if you expand a single letter,
>and it will often show you the associated characters accepted
>in pending mode (i.e.
>z.   zt   etc. etc.), and if you're motivated to look through it all,
>it can introduce you to a lot of new areas.

A better option, since we know there will be a large number of
possibilities, is to (in a help window) do:

        :ta /z

...and then use :tn and :tp to navigate thru the possibilities.  [I have
these mapped to two adjacent F-keys, since I do this so often.]

I also find these very helpful:

        :help normal-index
        :help visual-index
        :help index<tab>       (or ^D)

-Keith

Reply | Threaded
Open this post in threaded view
|

RE: Two simple questions with Map

Hari Krishna Dara
In reply to this post by Edward WIJAYA

On Wed, 8 Jun 2005 at 8:49am, Keith Roberts wrote:

> >-----Original Message-----
> >From: Eric Arnold [mailto:[hidden email]]
> >Sent: Friday, June 03, 2005 10:35 PM
> >To: Edward WIJAYA; [hidden email]
> >Subject: Re: Two simple questions with Map
> >
> >
> >
> >--- Edward WIJAYA <[hidden email]> wrote:
> >
> >> My second question is:
> >> How can we find what function does a particular "letter" do in a map?
> >
> >If you're really asking how to to find out what the basic "function"
> >of a Vim "letter" command (as opposed to a mapped "letter"),
> >one good trick is to use control-D and/or tab when using the
> >"help" command to expand all "help" occurrences of that letter
> >or word.  I.e.
> >  :help z^D
> >
> >This will give a lot of output if you expand a single letter,
> >and it will often show you the associated characters accepted
> >in pending mode (i.e.
> >z.   zt   etc. etc.), and if you're motivated to look through it all,
> >it can introduce you to a lot of new areas.
>
> A better option, since we know there will be a large number of
> possibilities, is to (in a help window) do:
>
> :ta /z
>
> ...and then use :tn and :tp to navigate thru the possibilities.  [I have
> these mapped to two adjacent F-keys, since I do this so often.]
>
> I also find these very helpful:
>
> :help normal-index
> :help visual-index
> :help index<tab>       (or ^D)
>
> -Keith

May I suggest combining this approach with my tagselect.vim plugin? When
there is a large number of matches (such as 133 matches for "z" in my
version of vim), you might find it easier to do the below:

:h
:Tselect /z

The above gives all the matching results in a new window in which you
can search and select for a particular tag. Here is a tip with this and
more information: http://www.vim.org/tips/tip.php?tip_id=937

Once selected you can use :tn, :tp or run :Tselect again.

--
HTH,
Hari


               
__________________________________
Do you Yahoo!?
Yahoo! Mail - Find what you need with new enhanced search.
http://info.mail.yahoo.com/mail_250
Reply | Threaded
Open this post in threaded view
|

RE: Using tagselect for help tags [was: Two simple questions with Map]

Eric Arnold


--- Hari Krishna Dara <[hidden email]> wrote:
[...]

> May I suggest combining this approach with my tagselect.vim plugin? When
> there is a large number of matches (such as 133 matches for "z" in my
> version of vim), you might find it easier to do the below:
>
> :h
> :Tselect /z
>
> The above gives all the matching results in a new window in which you
> can search and select for a particular tag. Here is a tip with this and
> more information: http://www.vim.org/tips/tip.php?tip_id=937
>
> Once selected you can use :tn, :tp or run :Tselect again.
>

It sounds like a good idea, but doesn't look like it's ready to drop in
as an adjunct to "help".  I don't have ctags set up, or any tags other
than what "help" automatically builds.  "tagselect.vim" seems to be
expecting a tags file in the current directory, as do other tags
commands.  So, :Tselect  simply complains about no tag for   /z   unless
I change directory to   $VIM/vim63/doc .  

BTW, is there a way to open the tag's file in another window, leaving
the :Tselect   window as it was.

I don't know if there is a way to tell Vim about where all tags
files reside.



Reply | Threaded
Open this post in threaded view
|

RE: Using tagselect for help tags [was: Two simple questions with Map]

Keith Roberts
>-----Original Message-----
>From: Eric Arnold [mailto:[hidden email]]
>Sent: Wednesday, June 08, 2005 9:46 PM
>To: Hari Krishna Dara
>Cc: [hidden email]
>Subject: RE: Using tagselect for help tags [was: Two simple
>questions with Map]
>
>
>
>--- Hari Krishna Dara <[hidden email]> wrote:
>[...]
>> May I suggest combining this approach with my tagselect.vim plugin?
>> When there is a large number of matches (such as 133 matches for "z"
>> in my version of vim), you might find it easier to do the below:
>>
>> :h
>> :Tselect /z
>>
>> The above gives all the matching results in a new window in
>which you
>> can search and select for a particular tag. Here is a tip with this
>> and more information: http://www.vim.org/tips/tip.php?tip_id=937
>>
>> Once selected you can use :tn, :tp or run :Tselect again.
>>
>
>It sounds like a good idea, but doesn't look like it's ready
>to drop in as an adjunct to "help".  I don't have ctags set
>up, or any tags other than what "help" automatically builds.  
>"tagselect.vim" seems to be expecting a tags file in the
>current directory, as do other tags
>commands.  So, :Tselect  simply complains about no tag for  
>/z   unless
>I change directory to   $VIM/vim63/doc .  


:h 'tags'


>BTW, is there a way to open the tag's file in another window, leaving
>the :Tselect   window as it was.
>
>I don't know if there is a way to tell Vim about where all
>tags files reside.

Ibid.

-Keith