Vim Tips Wiki
Register
(Change <tt> to <code>, perhaps also minor tweak.)
 
(2 intermediate revisions by 2 users not shown)
Line 3: Line 3:
 
|previous=21
 
|previous=21
 
|next=23
 
|next=23
|created=February 27, 2001
+
|created=2001
 
|complexity=basic
 
|complexity=basic
 
|author=glennj
 
|author=glennj
Line 42: Line 42:
   
 
<pre>
 
<pre>
nnoremap <S-Up> V
+
nnoremap <S-up> V
nnoremap <S-Down> V
+
nnoremap <S-left> v
xnoremap <S-Up> k
+
nnoremap <S-down> V
xnoremap <S-Down> j
+
nnoremap <S-right> v
onoremap <S-Up> k
+
xnoremap <S-up> k
onoremap <S-Down> j
+
xnoremap <S-left> h
  +
xnoremap <S-down> j
 
nnoremap <S-Left> v
+
xnoremap <S-right> l
nnoremap <S-Right> v
+
snoremap <S-up> <up>
xnoremap <S-Left> h
+
snoremap <S-left> <left>
xnoremap <S-Right> l
+
snoremap <S-down> <down>
onoremap <S-Left> h
+
snoremap <S-right> <right>
  +
onoremap <S-up> k
  +
onoremap <S-left> h
  +
onoremap <S-down> j
 
onoremap <S-right> l
 
onoremap <S-right> l
  +
inoremap <S-up> <ESC>gH
  +
inoremap <S-left> <ESC>gh
  +
inoremap <S-down> <ESC>gH
  +
inoremap <S-right> <ESC>gh
 
</pre>
 
</pre>
   
Line 76: Line 83:
 
If you ever find that you actually need to type one of the typos you make, you'll need to [[Disabling cabbrev|disable cabbrev]] temporarily.
 
If you ever find that you actually need to type one of the typos you make, you'll need to [[Disabling cabbrev|disable cabbrev]] temporarily.
   
Most typos of the types shown above usually happen when entering a single, quick command like <tt>:w</tt>. It might be a good idea to use a [[Replace a builtin command using cabbrev|cabbrev that only triggers in the first column]] of the command line.
+
Most typos of the types shown above usually happen when entering a single, quick command like <code>:w</code>. It might be a good idea to use a [[Replace a builtin command using cabbrev|cabbrev that only triggers in the first column]] of the command line.
* Good idea +1
 
   
 
==Comments==
 
==Comments==

Latest revision as of 05:07, 13 July 2012

Tip 22 Printable Monobook Previous Next

created 2001 · complexity basic · author glennj · version 5.7


Since Vim uses nearly the entire keyboard to do different things depending on the mode it is in, simple typos can have much bigger effects than in most other editors. A one-letter difference can make Vim do something entirely different than what you intended. While it is normally easy enough to just undo the mistake, it can be better to avoid the mistake entirely.

Normal and insert modes[]

If you find yourself making a typo very frequently in a normal-mode command, and accidentally enter a command you almost never use, it is very easy to correct.

For example, if in insert mode you often miss the <Esc> key and hit <F1> instead, you can map <F1> to either a "do nothing" command, or to the intended <Esc> command:

inoremap <F1> <Nop>
inoremap <F1> <ESC>

If in visual or normal mode you accidentally hold down the <Shift> key while pressing the <Down> arrow, and you only intend to press <Down> and not <S-Down>:

" visual mode
vnoremap <S-Up> <Up>
vnoremap <S-Down> <Down>
" normal mode
nnoremap <S-Up> <Up>
nnoremap <S-Down> <Down>

This might occur often in practice if you use linewise-visual mode by pressing V, and then hold the <Shift> key too long.

It is worth noting that S-Up and S-Down are often unavailable on terminals. I would expand on these mappings like this:

nnoremap <S-up> V
nnoremap <S-left> v
nnoremap <S-down> V
nnoremap <S-right> v
xnoremap <S-up> k
xnoremap <S-left> h
xnoremap <S-down> j
xnoremap <S-right> l
snoremap <S-up> <up>
snoremap <S-left> <left>
snoremap <S-down> <down>
snoremap <S-right> <right>
onoremap <S-up> k
onoremap <S-left> h
onoremap <S-down> j
onoremap <S-right> l
inoremap <S-up> <ESC>gH
inoremap <S-left> <ESC>gh
inoremap <S-down> <ESC>gH
inoremap <S-right> <ESC>gh

Command-line mode[]

Use cabbrev to correct command typos that you commonly make.

For example, if you tend to hold the shift key too long:

cabbrev Q quit
cabbrev W write

or, if you tend to miss the "!" and hit the "@" as well:

cabbrev q!@ q!
cabbrev wq!@ wq!

If you ever find that you actually need to type one of the typos you make, you'll need to disable cabbrev temporarily.

Most typos of the types shown above usually happen when entering a single, quick command like :w. It might be a good idea to use a cabbrev that only triggers in the first column of the command line.

Comments[]

ja lubię

noremap J j
noremap <Leader>J J
noremap K k