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.
Sobre o autor
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).
Navegue por canal
Automação
Últimas novidades em automação de TI para empresas de tecnologia, equipes e ambientes
Inteligência artificial
Descubra as atualizações nas plataformas que proporcionam aos clientes executar suas cargas de trabalho de IA em qualquer ambiente
Nuvem híbrida aberta
Veja como construímos um futuro mais flexível com a nuvem híbrida
Segurança
Veja as últimas novidades sobre como reduzimos riscos em ambientes e tecnologias
Edge computing
Saiba quais são as atualizações nas plataformas que simplificam as operações na borda
Infraestrutura
Saiba o que há de mais recente na plataforma Linux empresarial líder mundial
Aplicações
Conheça nossas soluções desenvolvidas para ajudar você a superar os desafios mais complexos de aplicações
Programas originais
Veja as histórias divertidas de criadores e líderes em tecnologia empresarial
Produtos
- Red Hat Enterprise Linux
- Red Hat OpenShift
- Red Hat Ansible Automation Platform
- Red Hat Cloud Services
- Veja todos os produtos
Ferramentas
- Treinamento e certificação
- Minha conta
- Suporte ao cliente
- Recursos para desenvolvedores
- Encontre um parceiro
- Red Hat Ecosystem Catalog
- Calculadora de valor Red Hat
- Documentação
Experimente, compre, venda
Comunicação
- Contate o setor de vendas
- Fale com o Atendimento ao Cliente
- Contate o setor de treinamento
- Redes sociais
Sobre a Red Hat
A Red Hat é a líder mundial em soluções empresariais open source como Linux, nuvem, containers e Kubernetes. Fornecemos soluções robustas que facilitam o trabalho em diversas plataformas e ambientes, do datacenter principal até a borda da rede.
Selecione um idioma
Red Hat legal and privacy links
- Sobre a Red Hat
- Oportunidades de emprego
- Eventos
- Escritórios
- Fale com a Red Hat
- Blog da Red Hat
- Diversidade, equidade e inclusão
- Cool Stuff Store
- Red Hat Summit