Exit neon sign on brick wall background

Como sair do VIM e os atalhos mais populares do VIM

If you are reading this article then you are in trouble. You wanted to edit a file using vim editor but got stuck in it. Stop panicking and wait with re-installing the OS and starting all from scratch – in this article I will show you how to exit a vim trap.

google search with request "how to quit vim"
Vim é a segunda coisa mais difícil de parar depois de fumar

Saia do editor VIM usando combinações de teclas

O editor Vim é complicado para iniciantes, mas quando você aprende as combinações corretas de teclas, usar o VIM torna-se fácil. Aqui estão as combinações de teclas mais populares para sair do vim.

Saia do vim salvando as alterações

Para sair do vim salvando as alterações, pressione Esc para sair do modo de edição e mantenha pressionada Mudança e pressione cólon key (:). Then enter “qq” and press Enter. Here “w” stands for write and “q” stands for “quit”. On US keyboards the colon : é a mesma chave que ponto e vírgula ;, located right of the letter “L” key.

:wq

Saia do vim sem salvar as alterações

To exit vim without saving changes hold down Shift and press the colon key (:). Then enter “q!” and press Enter.

:q!
exit vim without saving changes
saia do vim sem salvar alterações

Salve as alterações sem o editor VIM existente

To save changes without exiting vim hold down Shift and press the colon key (:). Then enter “w” and press Enter.

:w

Tornando-se proficiente em VIM

Agora que abordei os fundamentos de sair do Vim e salvar as alterações, vamos prosseguir para alguns atalhos e recursos úteis adicionais do Vim para aprimorar sua proficiência.

Iniciando o VIM para editar o arquivo

Normalmente os desenvolvedores iniciam o vim para editar o arquivo usando o comando:

vim filename

Se o arquivo estiver faltando, ele será criado. Você pode especificar vários arquivos para editar:

vim file1 file2 file3

Para abrir o arquivo em uma linha específica, você pode adicionar [num] após o comando vim. Por exemplo, para abrir o arquivo na linha 127, digite:

vim filename +127

Once you’ve entered Vim, navigating efficiently is key. Here are some popular shortcuts:

  • Movendo o cursor:
    • Use as setas do teclado para mover nas respectivas direções (cima, baixo, esquerda, direita).
    • Alternatively, employ the h, j, k, and l keys for left, down, up, and right movements, respectively.
  • Navegação por palavras:
    • Move the cursor to the beginning of the next word with w.
    • Navigate to the end of the current word using e.
    • Jump to the beginning of the previous word with b.
  • Linhas de navegação:
    • Go to the start of the line by pressing 0.
    • Move to the end of the line with $.

Editando Texto no VIM

Once you’ve reached the desired location, these shortcuts will aid in text manipulation:

  • Entrando no modo de inserção:
    • Press i to enter insert mode before the cursor.
    • Use I to start inserting at the beginning of the line.
    • Employ a to append after the cursor.
    • A permite anexar no final da linha.
  • Excluindo Texto:
    • Delete the character under the cursor with x.
    • Erase the entire line with dd.
    • Cut (delete) the current line and enter insert mode with cc.
  • Copiar e Colar:
    • Copy a line with yy.
    • Paste the copied line below the current line using p.
  • Desfazer e refazer:
    • Undo the last action with u.
    • Redo with Ctrl + r.

Pesquisando no VIM

Uma pesquisa eficiente é crucial. Aqui estão alguns atalhos relacionados à pesquisa:

  • Procurando por texto:
    • Initiate a search with /, followed by the desired term.
    • Use n to jump to the next occurrence and N to go to the previous one.
  • Substituindo Texto:
    • Substitute the current word with a new one using :s/old/new/g.

Saindo do Vim

I have already covered the basics in the beginning, but here are a few more options:

  • Save and Quit All:
    • To save all changes and quit multiple files simultaneously, use :wa e :qa.
  • Sair sem salvar:
    • If you want to exit Vim without saving any changes made in any of the files, :qa! will do the trick.

Conclusão

Lembre-se de que dominar o Vim leva tempo e prática. Quanto mais você usa, mais confortável e poderoso ele se torna. Boa edição!