Linux Tutorial
Linux File/Directory Management
Linux Packaging And Compression
Vim Text Editor
Linux Text Processing
Linux Software Installation
Linux User/User Group Management
Linux Permission Management
Linux Filesystem Management
Linux Advanced Filesystem Management
Linux System Management
Linux Backup and Recovery
Linux System Service Management
Linux System Log Management
Linux Boot Management
LAMP/LNMP Environment
SELinux Management
Vim, a powerful text editor for Linux, offers many navigation shortcuts that help you move the cursor efficiently within a file. In this tutorial, we will cover some useful Vim cursor movement shortcuts.
Basic movement commands
h
- Move the cursor left one character.j
- Move the cursor down one line.k
- Move the cursor up one line.l
- Move the cursor right one character.Word navigation
w
- Move the cursor to the beginning of the next word.b
- Move the cursor to the beginning of the current or previous word.e
- Move the cursor to the end of the current or next word.W
, B
, and E
- Similar to w
, b
, and e
, but consider whitespace-separated items as words, ignoring punctuation.Line navigation
0
(zero) - Move the cursor to the beginning of the line.^
- Move the cursor to the first non-whitespace character of the line.$
- Move the cursor to the end of the line.g_
- Move the cursor to the last non-whitespace character of the line.Jump to specific line
:NUMBER
- Replace NUMBER
with the line number you want to jump to and press Enter
.gg
- Move the cursor to the first line of the file.G
- Move the cursor to the last line of the file.NUMBERgg
or NUMBERG
- Replace NUMBER
with the line number you want to jump to.Screen navigation
H
- Move the cursor to the first line of the screen.M
- Move the cursor to the middle line of the screen.L
- Move the cursor to the last line of the screen.CTRL+U
- Move the cursor up half a screen.CTRL+D
- Move the cursor down half a screen.CTRL+F
- Move the cursor forward one screen (scroll down).CTRL+B
- Move the cursor backward one screen (scroll up).Search navigation
/PATTERN
- Search forward for the specified PATTERN
.?PATTERN
- Search backward for the specified PATTERN
.n
- Move the cursor to the next occurrence of the last searched pattern.N
- Move the cursor to the previous occurrence of the last searched pattern.Matching brackets, parentheses, and braces
%
- Move the cursor to the matching bracket, parenthesis, or brace. If the cursor is already on a matching item, it will jump to the corresponding match.These are just a few of the many cursor movement shortcuts available in Vim. Mastering these shortcuts will help you navigate and edit your files more efficiently. Remember that you can also customize these shortcuts or create your own by editing your Vim configuration file (vimrc
).
Vim cursor movement shortcuts:
# Example: Basic cursor movement h - left j - down k - up l - right
How to move the cursor in Vim quickly:
# Example: Move cursor quickly 10j - move down 10 lines w - move to the beginning of the next word
Navigating lines and words in Vim:
# Example: Navigate lines and words 5k - move up 5 lines 3w - move forward 3 words
Jumping to specific locations with cursor shortcuts:
gg
and G
to jump to the beginning and end of a file, respectively.# Example: Jump to specific locations gg - move to the beginning of the file G - move to the end of the file
Vim cursor shortcuts for beginning and end of lines:
0
and $
move the cursor to the beginning and end of the current line.# Example: Move to beginning and end of lines 0 - move to the beginning of the line $ - move to the end of the line
Using marks for efficient cursor movement in Vim:
ma
, ``a`) for quick navigation to specific locations in the file.# Example: Set and use marks ma - set mark 'a' `a - jump to mark 'a'
Scrolling and page navigation shortcuts in Vim:
# Example: Scroll and page navigation Ctrl + u - scroll up half a page Ctrl + d - scroll down half a page
Jumping between matching brackets and parentheses in Vim:
%
to jump between matching brackets, parentheses, and curly braces.# Example: Jump between matching brackets % - jump to matching bracket
Moving to specific characters with cursor shortcuts:
f
and t
to move to the next occurrence of a character or up to a character in a line.# Example: Move to specific characters fa - move to the next 'a' in the line t) - move just before the next ')' in the line
Customizing cursor movement keys in Vim: