Vim Tips Wiki
(Change to TipImported template + severe manual clean)
No edit summary
Tag: sourceedit
(22 intermediate revisions by 13 users not shown)
Line 1: Line 1:
{{review}}
 
 
{{TipImported
 
{{TipImported
 
|id=278
 
|id=278
 
|previous=277
 
|previous=277
 
|next=279
 
|next=279
|created=July 9, 2002
+
|created=2002
 
|complexity=basic
 
|complexity=basic
 
|author=vim_power
 
|author=vim_power
|version=5.7
+
|version=6.0
 
|rating=78/45
 
|rating=78/45
  +
|category1=Getting started
  +
|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>
h move one character left
+
h move one character left
j move one row down
+
j move one row down
k move one row up
+
k move one row up
l move one char. right.
+
l move one character right
w move to begining of next word
+
w move to beginning of next word
b move to begining of previous word
+
b move to previous beginning of word
e move to end of word
+
e move to end of word
W move to begining of next word after a whitespace
+
W move to beginning of next word after a whitespace
B move to begining of pervious word before a whitespace
+
B move to beginning of previous word before a whitespace
E move to end of word before a whitespace.
+
E move to end of word before a whitespace
 
</pre>
 
</pre>
   
All the above movements can be preceeded by a numeric value. e.g. '4j' will move 4 rows down.
+
All the above movements can be preceded by a count; e.g. <code>4j</code> moves down 4 lines.
   
 
<pre>
 
<pre>
^ move to first non blank char of the line.
+
0 move to beginning of line
g_ move to last non blank char of the line.
+
$ move to end of line
0 moev to begining of line
+
_ move to first non-blank character of the line
$ move to end of line.
+
g_ move to last non-blank character of the line
  +
gg move to first line.
 
G move to last line.
+
gg move to first line
nG move to "n"th line.
+
G move to last line
  +
nG move to n'th line of file (n is a number; 12G moves to line 12)
H top of screen.
 
  +
M middle of screen
 
L bottom of screen
+
H move to top of screen
Ctrl-D move half page down
+
M move to middle of screen
Ctrl-U move half page up.
+
L move to bottom of screen
  +
Ctrl-B page-up
 
  +
z. scroll the line with the cursor to the center of the screen
Ctrl-F page down.
 
  +
zt scroll the line with the cursor to the top
Ctrl-o last cursor position.
 
  +
zb scroll the line with the cursor to the bottom
'[a-z,0-9,A-Z] jump to the marker. (you can set a marker on line by :- m[a-zA-Z,0-9] and then jump back to it by '[a-z,A-Z0-9]
 
  +
n next matching search pattern
 
  +
Ctrl-D move half-page down
N previous matching search pattern
 
  +
Ctrl-U move half-page up
* next word under cursor
 
 
Ctrl-B page up
# previous word under cursor.
 
 
Ctrl-F page down
g* next matching search pattern under cursor.
 
 
Ctrl-O jump to last (older) cursor position
g# previous matching search pattern under cursor.
 
  +
Ctrl-I jump to next cursor position (after Ctrl-O)
  +
 
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
 
</pre>
 
</pre>
   
  +
<pre>
==Comments==
 
 
% jump to matching bracket { } [ ] ( )
A very useful one for me is:
 
   
  +
fX to next 'X' after cursor, in the same line (X is any character)
% : jump to the matching bracket {}[]()
 
  +
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>
   
  +
See <code>:help {command}</code> (for example, {{help|g_}}) for all of the above if you want more details.
----
 
  +
 
==Comments==

Revision as of 00:38, 2 April 2016

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
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

z.  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)

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
%   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