Vim Navigation

Table of Contents What Is Vim? Vim Modes Overview Opening and Creating Files with Vim Switching Insert Mode Switching back to Command Mode Accessing Extended Mode Saving and Quitting Files Showing Line Numbers Essential Vim Commands Scenario:Editing Configuration Files Conclusion Let’s Connect on LinkedIn What Is Vim? Vim (Vi Improved) is a powerful text editor used in Unix-like systems. It's an upgraded version of the vi editor with more features like syntax highlighting, better navigation, and plugin support. It’s used for creating and editing files Vim Modes Overview 1. Command Mode (default when you open Vim) You navigate, delete, copy, paste, etc. You cannot type text directly here. Example actions: dd (delete line), yy (copy line), u (undo) 2. Insert Mode (i) You type actual text. Enter it by pressing i, a, o, etc. Exit it using ESC to return to Command Mode. 3. Extended Mode (some call it Last Line Mode or Ex Mode) You issue commands like save, quit, search, etc. Access it by pressing : in Command Mode. You’ll see : appear at the bottom of Vim. Opening and Creating Files with Vim To start Vim, you need to open a terminal, use the command : vim filename.txt or vim /filename If the file doesn’t exist, Vim creates it. If it does, you open it for editing. Switching Insert Mode i You can now type text. Switching back to Command Mode ESC You're now back to navigating and issuing Vim commands. Accessing Extended Mode Access it with: "Shift" + ":" This lets you save, quit, and do more advanced operations. Saving and Quitting Files :w — Save :q — Quit (only if there are no unsaved changes) :wq — Save and Quit :q! — Quit Without Saving Scenario: You accidentally modified a config file. Use :q! to exit without applying those changes. Showing Line Numbers :set nu or :set number — Show line numbers :set nonu or :set nonumber — Hide line numbers In troubleshooting or editing long scripts, it's helpful to know what's on line 45, especially when error logs refer to line numbers. Essential Vim Commands Command Description yy Copy current line yw Copy current word nyy Copy n lines dd Delete current line dw Delete word from cursor ndd Delete n line gg Go to top of file G Go to bottom nG or ngg Go to line n p Paste below cursor u Undo last change Ctrl + r Redo Scenario: Editing Configuration File You're managing a Linux server and need to configure NGINX. vim /etc/nginx/nginx.conf Press i to start editing the config Paste server block using p Save with :wq Restart nginx with sudo systemctl restart nginx Conclusion Getting comfortable with Vim takes time, but once you do, it becomes an incredibly powerful tool for editing files efficiently. With practice, navigating between modes and mastering shortcuts will become second nature. Let’s Connect on LinkedIn As I automate my journey into RHCE and Ansible, I’d love to connect with fellow learners and professionals. Feel free to reach out and join me as I share tips, resources, and insights throughout this 30-day challenge. cloudwhistler #30daysLinuxchallenge

Apr 10, 2025 - 14:49
 0
Vim Navigation

Table of Contents

  • What Is Vim?
  • Vim Modes Overview
  • Opening and Creating Files with Vim
  • Switching Insert Mode
  • Switching back to Command Mode
  • Accessing Extended Mode
  • Saving and Quitting Files
  • Showing Line Numbers
  • Essential Vim Commands
  • Scenario:Editing Configuration Files
  • Conclusion
  • Let’s Connect on LinkedIn

What Is Vim?

Vim (Vi Improved) is a powerful text editor used in Unix-like systems. It's an upgraded version of the vi editor with more features like syntax highlighting, better navigation, and plugin support.

It’s used for creating and editing files

Vim Modes Overview

1. Command Mode (default when you open Vim)

You navigate, delete, copy, paste, etc.

You cannot type text directly here.

Example actions: dd (delete line), yy (copy line), u (undo)

2. Insert Mode (i)

You type actual text.

Enter it by pressing i, a, o, etc.

Exit it using ESC to return to Command Mode.

3. Extended Mode (some call it Last Line Mode or Ex Mode)

You issue commands like save, quit, search, etc.

Access it by pressing : in Command Mode.

You’ll see : appear at the bottom of Vim.

Opening and Creating Files with Vim

To start Vim, you need to open a terminal, use the command :
vim filename.txt or vim /filename

Vim Command

If the file doesn’t exist, Vim creates it. If it does, you open it for editing.

Switching Insert Mode

i

Insert Mode

You can now type text.

Switching back to Command Mode

ESC

You're now back to navigating and issuing Vim commands.

Accessing Extended Mode

Access it with:

"Shift" + ":"

Image description

This lets you save, quit, and do more advanced operations.

Saving and Quitting Files

  1. :w — Save

  2. :q — Quit (only if there are no unsaved changes)

  3. :wq — Save and Quit

  4. :q! — Quit Without Saving

Scenario: You accidentally modified a config file. Use :q! to exit without applying those changes.

Showing Line Numbers

  • :set nu or :set number — Show line numbers

Image description

  • :set nonu or :set nonumber — Hide line numbers

In troubleshooting or editing long scripts, it's helpful to know what's on line 45, especially when error logs refer to line numbers.

Essential Vim Commands

Command Description
yy Copy current line
yw Copy current word
nyy Copy n lines
dd Delete current line
dw Delete word from cursor
ndd Delete n line
gg Go to top of file
G Go to bottom
nG or ngg Go to line n
p Paste below cursor
u Undo last change
Ctrl + r Redo

Scenario: Editing Configuration File

You're managing a Linux server and need to configure NGINX.

vim /etc/nginx/nginx.conf

Press i to start editing the config

Paste server block using p

Save with :wq

Restart nginx with sudo systemctl restart nginx

Conclusion

Getting comfortable with Vim takes time, but once you do, it becomes an incredibly powerful tool for editing files efficiently. With practice, navigating between modes and mastering shortcuts will become second nature.

Let’s Connect on LinkedIn

As I automate my journey into RHCE and Ansible, I’d love to connect with fellow learners and professionals. Feel free to reach out and join me as I share tips, resources, and insights throughout this 30-day challenge.

cloudwhistler #30daysLinuxchallenge