m (Reverted edits by Emprego.curitiba (talk | block) to last version by 188.220.34.159) |
m (Add comments.) Tag: Visual edit |
||
(15 intermediate revisions by 11 users not shown) | |||
Line 9: | Line 9: | ||
|rating=78/45 |
|rating=78/45 |
||
|category1=Getting started |
|category1=Getting started |
||
− | |category2= |
+ | |category2=Moving |
}} |
}} |
||
+ | Vim provides many ways to move the cursor. Becoming familiar with them leads to more effective text editing. |
||
− | One of the principles of effective text editing is moving around very efficiently. |
||
− | |||
− | Following are some pointers which may help you do that. |
||
<pre> |
<pre> |
||
Line 21: | Line 19: | ||
l move one character right |
l move one character right |
||
w move to beginning of next word |
w move to beginning of next word |
||
− | b move to beginning of |
+ | b move to previous beginning of word |
e move to end of word |
e move to end of word |
||
W move to beginning of next word after a whitespace |
W move to beginning of next word after a whitespace |
||
Line 28: | Line 26: | ||
</pre> |
</pre> |
||
− | All the above movements can be preceded by a count; e.g. < |
+ | All the above movements can be preceded by a count; e.g. <code>4j</code> moves down 4 lines. |
<pre> |
<pre> |
||
0 move to beginning of line |
0 move to beginning of line |
||
$ move to end of line |
$ move to end of line |
||
− | + | _ move to first non-blank character of the line |
|
⚫ | |||
− | _ same as above, but can take a count to go to a different line |
||
⚫ | |||
gg move to first line |
gg move to first line |
||
G move to last line |
G move to last line |
||
+ | </pre> |
||
⚫ | |||
+ | <pre> |
||
+ | ngg move to n'th line of file (n is a number; 12gg moves to line 12) |
||
⚫ | |||
+ | </pre> |
||
+ | |||
+ | <pre> |
||
H move to top of screen |
H move to top of screen |
||
M move to middle of screen |
M move to middle of screen |
||
L move to bottom of screen |
L move to bottom of screen |
||
+ | |||
+ | zz scroll the line with the cursor to the center of the screen |
||
+ | zt scroll the line with the cursor to the top |
||
+ | zb scroll the line with the cursor to the bottom |
||
Ctrl-D move half-page down |
Ctrl-D move half-page down |
||
Line 49: | Line 56: | ||
Ctrl-B page up |
Ctrl-B page up |
||
Ctrl-F page down |
Ctrl-F page down |
||
− | Ctrl- |
+ | Ctrl-O jump to last (older) cursor position |
− | Ctrl- |
+ | Ctrl-I jump to next cursor position (after Ctrl-O) |
+ | Ctrl-Y move view pane up |
||
+ | Ctrl-E move view pane down |
||
n next matching search pattern |
n next matching search pattern |
||
N previous matching search pattern |
N previous matching search pattern |
||
− | * next word under cursor |
+ | * next whole word under cursor |
− | # previous word under cursor |
+ | # previous whole word under cursor |
− | g* next matching search pattern under cursor |
+ | g* next matching search (not whole word) pattern under cursor |
− | g# previous matching search pattern under cursor |
+ | g# previous matching search (not whole word) pattern under cursor |
+ | gd go to definition/first occurrence of the word under cursor |
||
+ | </pre> |
||
+ | <pre> |
||
% jump to matching bracket { } [ ] ( ) |
% jump to matching bracket { } [ ] ( ) |
||
+ | |||
+ | fX to next 'X' after cursor, in the same line (X is any character) |
||
+ | FX to previous 'X' before cursor (f and F put the cursor on X) |
||
+ | tX til next 'X' (similar to above, but cursor is before X) |
||
+ | TX til previous 'X' |
||
+ | ; repeat above, in same direction |
||
+ | , repeat above, in reverse direction |
||
</pre> |
</pre> |
||
− | See < |
+ | See <code>:help {command}</code> (for example, {{help|g_}}) for all of the above if you want more details. |
==Comments== |
==Comments== |
||
+ | These instructions are just awesome! |
||
− | Ctrl-i jump to previous cursor position |
||
− | <C-i> (or <Tab>) goes to the next cursor position in the jump list, and does nothing unless you've already moved to an older position in the jump list using <C-o>. ([[User:Spiiph|Spiiph]] 12:37, October 5, 2009 (UTC)) |
Latest revision as of 10:27, 4 April 2019
Tip 278 Printable Monobook Previous Next
created 2002 · complexity basic · author vim_power · version 6.0
Vim provides many ways to move the cursor. Becoming familiar with them leads to more effective text editing.
h move one character left j move one row down k move one row up l move one character right w move to beginning of next word b move to previous beginning of word e move to end of word W move to beginning of next word after a whitespace B move to beginning of previous word before a whitespace E move to end of word before a whitespace
All the above movements can be preceded by a count; e.g. 4j
moves down 4 lines.
0 move to beginning of line $ move to end of line _ move to first non-blank character of the line g_ move to last non-blank character of the line gg move to first line G move to last line
ngg move to n'th line of file (n is a number; 12gg moves to line 12) nG move to n'th line of file (n is a number; 12G moves to line 12)
H move to top of screen M move to middle of screen L move to bottom of screen zz scroll the line with the cursor to the center of the screen zt scroll the line with the cursor to the top zb scroll the line with the cursor to the bottom Ctrl-D move half-page down Ctrl-U move half-page up Ctrl-B page up Ctrl-F page down Ctrl-O jump to last (older) cursor position Ctrl-I jump to next cursor position (after Ctrl-O) Ctrl-Y move view pane up Ctrl-E move view pane down n next matching search pattern N previous matching search pattern * next whole word under cursor # previous whole word under cursor g* next matching search (not whole word) pattern under cursor g# previous matching search (not whole word) pattern under cursor gd go to definition/first occurrence of the word under cursor
% jump to matching bracket { } [ ] ( ) fX to next 'X' after cursor, in the same line (X is any character) FX to previous 'X' before cursor (f and F put the cursor on X) tX til next 'X' (similar to above, but cursor is before X) TX til previous 'X' ; repeat above, in same direction , repeat above, in reverse direction
See :help {command}
(for example, :help g_) for all of the above if you want more details.
Comments[]
These instructions are just awesome!