mirror of
https://github.com/mhinz/vim-galore.git
synced 2025-02-24 01:59:28 +08:00
Basics: rework mappings section
This commit is contained in:
parent
314636ea7b
commit
e4b39c2ef9
30
README.md
30
README.md
@ -133,16 +133,16 @@ buffer.
|
|||||||
|
|
||||||
You can define your own mappings with the `:map` family of commands. Each
|
You can define your own mappings with the `:map` family of commands. Each
|
||||||
command of that family defines a mappping for a certain set of modes.
|
command of that family defines a mappping for a certain set of modes.
|
||||||
Technically Vim comes with a whopping 12 modes, 6 of them can be mapped.
|
Technically Vim comes with a whopping 12 modes, 6 of them can be mapped:
|
||||||
|
|
||||||
| Command | Modes |
|
| Recursive | Non-recursive | Modes |
|
||||||
|---------|----------------------------------|
|
|-----------|---------------|----------------------------------|
|
||||||
| `:map` | normal, visual, operator-pending |
|
| `:map` | `:noremap` | normal, visual, operator-pending |
|
||||||
| `:nmap` | normal |
|
| `:nmap` | `:nnoremap` | normal |
|
||||||
| `:xmap` | visual |
|
| `:xmap` | `:xnoremap` | visual |
|
||||||
| `:cmap` | command-line |
|
| `:cmap` | `:cnoremap` | command-line |
|
||||||
| `:omap` | operator-pending |
|
| `:omap` | `:onoremap` | operator-pending |
|
||||||
| `:imap` | insert |
|
| `:imap` | `:inoremap` | insert |
|
||||||
|
|
||||||
E.g. this defines the mapping for normal mode only:
|
E.g. this defines the mapping for normal mode only:
|
||||||
|
|
||||||
@ -151,8 +151,8 @@ E.g. this defines the mapping for normal mode only:
|
|||||||
```
|
```
|
||||||
|
|
||||||
So far, so good. There's only one problem that can be pretty confusing to
|
So far, so good. There's only one problem that can be pretty confusing to
|
||||||
beginners: All the commands listed above are _recursive_. That is, the
|
beginners: `:nmap` is _recursive_! That is, the right-hand side takes other
|
||||||
right-hand side takes other mappings into account.
|
mappings into account.
|
||||||
|
|
||||||
So you defined a mapping that simply echoes "Foo":
|
So you defined a mapping that simply echoes "Foo":
|
||||||
|
|
||||||
@ -172,15 +172,15 @@ If you hit <kbd>a</kbd>, we expect the cursor to go back a word, but instead
|
|||||||
mapped to another action already, namely `:echo "Foo"<cr>`.
|
mapped to another action already, namely `:echo "Foo"<cr>`.
|
||||||
|
|
||||||
The proper way to resolve this problem is to use a _non-recursive_ mapping
|
The proper way to resolve this problem is to use a _non-recursive_ mapping
|
||||||
instead. Take the commands from above and put a `nore` in front of the `map`, so
|
instead:
|
||||||
`:noremap`, `:nnoremap`, `:xnoremap`, `:cnoremap`, `:onoremap`, `:inoremap`.
|
|
||||||
|
|
||||||
Putting it in a nutshell, this solves our problem:
|
|
||||||
|
|
||||||
```viml
|
```viml
|
||||||
:nnoremap a b
|
:nnoremap a b
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Rule of thumb: Always use non-recursive mappings unless recursing is actually
|
||||||
|
desired.
|
||||||
|
|
||||||
#### Mapleader?
|
#### Mapleader?
|
||||||
|
|
||||||
The mapleader is simply a placeholder than can be used with custom mappings and
|
The mapleader is simply a placeholder than can be used with custom mappings and
|
||||||
|
Loading…
x
Reference in New Issue
Block a user