[lug] Vim Modes Question

Sean Reifschneider jafo at tummy.com
Mon Sep 26 16:16:50 MDT 2005


On Fri, Sep 23, 2005 at 08:06:17PM -0600, Bill Thoen wrote:
>I'm trying to understand key mapping in Vim, but I don't understand what
>Normal and Visual modes are. For example, if I define a key mapping with
>cmap, it works fine when I press Esc and then : and then enter it. But I
>don't know how to invoke key mappings created with nmap or vmap. So what
>are Normal and Visual modes and how do I get nmap and vmap key mappings to

Do ":help modes" and scroll up a page.  It should display information about
the modes:

There are five sets of mappings
- For Normal mode: When typing commands.
- For Visual mode: When typing commands while the Visual area is
  highlighted.
- For Operator-pending mode: When an operator is pending (after "d", "y",
  "c",
  etc.).  Example: ":omap { w" makes "y{" work like "yw" and "d{" like "dw".
- For Insert mode. These are also used in Replace mode.
- For Command-line mode: When entering a ":" or "/" command.

As it says, visual mode is when you type 'v' and select a region (visual
region selection).  Normal mode is when you are in the normal command mode.
You can tell what mode you are in by typing "set showmode", it will display
the mode you are in in the lower left corner of the display, except normal
mode which shows nothing.

I believe "cmap" is for setting mappings for the command-line mode, hence
your having to use ":macro".  If you just want to map a key to do
something, us ":map t xp" (for example).  Another way you can set up macros
is to do "qa", then do the things you want the macro to do, then type "q"
again to finish recording the macro.  To invoke it you run "@a", so you
could ":map t @a", for example.  You can record a macro to any buffer, in
the above we were using buffer "a".

Sean
-- 
 Fire at the celuloud factory.  No film at eleven.
                 -- _Kentucky_Fried_Movie_
Sean Reifschneider, Member of Technical Staff <jafo at tummy.com>
tummy.com, ltd. - Linux Consulting since 1995: Ask me about High Availability




More information about the LUG mailing list