Monday, March 1, 2010

Re: can I configure the "default" commands?

On 01/03/10 13:37, Jorge Timón wrote:
> Hi, Now I know how to map a command (for example :tabnext) to a key or
> combination of key (C-TAB). But can I change "default" commands like
> dd, w, $, 0...?
> I don't know if "default" is the right name for them.
> Is there a file where this mappings/bindings are done like
> map h :cursorleft
> map j :cursordown
> ...
> or something like that?
> Is there a list of all the default mappings?
>
> Maybe you're asking yourselves why would I want to change it.
> I use a spanish keyborad and some keys (like []{}) aren't very accessible.
>
> Thank you
>

To change what w does (instead of "move to word") you may have to remap
it in Normal, Visual and Operator-Pending modes, but not in Select mode
where it should (still) replace the selection by the letter w. The {rhs}
of the mapping may or may not be different for each mode, depending on
what you want to achieve. Similarly for $. It is not possible to map 0
in Normal mode (or it would make it impossible to type a zero as part of
a count), try mapping <Home> instead.

To change what dd does, remap d (the second d) in (only)
Operator-Pending mode using an <expr> mapping, because you want to remap
it to d (and allow remaps i.e. use :omap, not :onoremap) for all values
of v:operator (q.v.) except "d". Or else, remap dd in Normal and Visual
(but not Select or Operator-Pending).

The definition of what a key does when starting up (before sourcing any
vimrc or other script, and before any -c or -cmd command-line switch) is
defined in the C code, you cannot change it without recompiling (and I
don't recommend recompiling Vim after patching it for that purpose).

The list of all the default key bindings is in the index.txt helpfile
(see :help index.txt). To know what one particular key does in one
particular mode, you should probably use the helptag for that key in
that mode.

For "not very accessible keys", OTOH, you want to make some other key
function as if it were, let's say, Ctrl-], and that in all modes. The
following example shows what I use for my Belgian keyboard (where Ctrl-]
requires using Ctrl and AltGr together while pressing the key at the far
right end of the AZERTY row):

:noremap <F9> <C-]>
:noremap! <F9> <C-]>

IOW, I use F9 whenever I want to trigger the function of the Ctrl-] key.
Whether to use :map or :noremap here is a question of whether we want to
allow or disallow doing something else instead of (for Ctrl-]) jumping
to a tag (in Normal/Visual) or triggering an abbreviation (in
Insert/Replace/Command-line).

See
:help map-overview
:help :map-modes
:help v:operator
:help :map-<expr>

Best regards,
Tony.
--
ARTHUR: (as the MAN next to him is squashed by a sheep) Knights! Run away!
Midst echoing shouts of "run away" the KNIGHTS retreat to cover with
the odd
cow or goose hitting them still. The KNIGHTS crouch down under cover.
"Monty Python and the Holy Grail" PYTHON (MONTY)
PICTURES LTD

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment