The Vi application is the default text editor on most Linux systems, so it's the primary interface you will use when you need to edit a configuration file. If you're used to a graphical text editor, such as Notepad++ or VS Code, Vi can be confusing at first.
In its default form, Vi launches and runs in a terminal and is entirely keyboard-driven. But once you learn the basics of Vi, you're likely to find that it's a fast, efficient, and flexible editor.
Start Vi
To start Vi, open a terminal and type vi
followed by a file path. If the file you provide doesn't exist, it's created when Vi opens:
$ vi example.txt
The vi
command is usually a symlink to the vim
(Vi improved) command, but many users refer to Vi as Vi, not Vim.
Command mode and insert mode
Vi has two different modes. There's command mode and insert mode. Command mode is the default, and you can think of it as Vi's menu. Because Vi doesn't have a menu bar like most applications have, you use command mode to tell Vi what you want to do next (move up or down a line, delete a character or a whole word, copy and paste, and so on.)
You can always get back to command mode by pressing Esc on your keyboard. Get used to that; you'll be pressing Esc a lot in Vi.
To enter insert mode, press i. In insert mode, you can type and edit text and use the arrow keys to navigate around your document. There's not much to say about insert mode. It's very much as its name advertises: In insert mode, you can insert text, so there's nothing to learn except, maybe, touch typing.
Command mode, however, has a wealth of keyboard shortcuts and commands for you to discover. Remember, to enter command mode, press Esc. If you're ever in doubt about which mode you're in, just press Esc, and you can be sure that you're now in command mode.
Keyboard shortcuts for command mode
In Vi, you don't use your mouse or any of the keyboard shortcuts you're used to in other editors. For instance, you don't copy with Ctrl+C and paste with Ctrl+V because Vi has its own set of quick shortcuts that optimize key presses. It's unquestionably a learning curve, but one that pays dividends. Once you've got the basic keyboard shortcuts committed to muscle memory, you'll work faster in Vi than you've worked in any editor.
Modes
- i: for insert mode
- I (that's an upper-case i): insert text at beginning of current line
- a: append text after cursor
- A: append text at end of current line
- Esc: command mode
[ Boost your Linux skills by downloading the Bash shell scripting cheat sheet. ]
Navigation
Navigation happens on the home row of your QWERTY keyboard:
- h: cursor left
- j: cursor down (j looks trivially like a down arrow)
- k: cursor up
- l (that's a lower-case L): cursor right
- b: cursor to beginning of current word
- e: cursor to end of current word
- $: go to end of line
- 0 (that's a zero): go to beginning of line
- gg: go to first line of file
- G: go to last line of file
- 9G: go to line 9 of file
Select
- v: select text
- V: select line
Copy and paste
- y: copy ("yank") selection
- yy: copy ("yank") the entire line
- p: paste
Delete
- x: delete character
- dw: delete word
- d$: delete from current position to end of line
- d0: delete from current position to beginning of line
- dG: delete to last line of file
Undo
- u: undo
Save
- :w: save
- :wq or :ZZ: save and quit
- :q!: force quit without saving
Get to know Vi
Knowing Vi is a valuable skill on Linux because it's on nearly every Linux system you're likely to encounter. Once you get comfortable with its key bindings and how they enable you to keep your hands on the keyboard instead of bouncing back and forth to your mouse or even to Function keys, you'll see why Vi has endured for so long.
About the author
Seth Kenlon is a Linux geek, open source enthusiast, free culture advocate, and tabletop gamer. Between gigs in the film industry and the tech industry (not necessarily exclusive of one another), he likes to design games and hack on code (also not necessarily exclusive of one another).
Browse by channel
Automation
The latest on IT automation for tech, teams, and environments
Artificial intelligence
Updates on the platforms that free customers to run AI workloads anywhere
Open hybrid cloud
Explore how we build a more flexible future with hybrid cloud
Security
The latest on how we reduce risks across environments and technologies
Edge computing
Updates on the platforms that simplify operations at the edge
Infrastructure
The latest on the world’s leading enterprise Linux platform
Applications
Inside our solutions to the toughest application challenges
Original shows
Entertaining stories from the makers and leaders in enterprise tech
Products
- Red Hat Enterprise Linux
- Red Hat OpenShift
- Red Hat Ansible Automation Platform
- Cloud services
- See all products
Tools
- Training and certification
- My account
- Customer support
- Developer resources
- Find a partner
- Red Hat Ecosystem Catalog
- Red Hat value calculator
- Documentation
Try, buy, & sell
Communicate
About Red Hat
We’re the world’s leading provider of enterprise open source solutions—including Linux, cloud, container, and Kubernetes. We deliver hardened solutions that make it easier for enterprises to work across platforms and environments, from the core datacenter to the network edge.
Select a language
Red Hat legal and privacy links
- About Red Hat
- Jobs
- Events
- Locations
- Contact Red Hat
- Red Hat Blog
- Diversity, equity, and inclusion
- Cool Stuff Store
- Red Hat Summit