Exit neon sign on brick wall background

Ako ukončiť VIM a najobľúbenejšie skratky 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 je po fajčení druhá najťažšia vec, ktorú treba prestať

Ukončite editor VIM pomocou kombinácií klávesov

Editor Vim je zložitý pre začiatočníkov, ale keď sa naučíte správne kombinácie klávesov pomocou VIM, bude to jednoduché. Tu sú najobľúbenejšie kombinácie klávesov na ukončenie vim.

Ukončite vim ukladanie zmien

Ak chcete ukončiť vim s uložením zmien, stlačte Esc , čím ukončíte režim úprav, potom ho podržte Shift a stlačte hrubého čreva key (:). Then enter “wq” and press Enter. Here “w” stands for write and “q” stands for “quit”. On US keyboards the colon : je rovnaký kľúč ako bodkočiarka ;, located right of the letter “L” key.

:wq

Ukončite vim bez uloženia zmien

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
ukončite vim bez zmien

Uložte zmeny bez existujúceho editora VIM

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

:w

Zdokonalenie vo VIM

Teraz, keď som prebral základy ukončenia Vimu a ukladania zmien, poďme prejsť k niektorým ďalším užitočným skratkám a funkciám Vimu na zlepšenie vašej odbornosti.

Spustenie VIM na úpravu súboru

Vývojári zvyčajne spúšťajú vim na úpravu súboru pomocou príkazu:

vim filename

Ak súbor chýba, vytvorí sa. Môžete zadať viacero súborov na úpravu:

vim file1 file2 file3

Ak chcete otvoriť súbor na konkrétnom riadku, môžete za príkaz vim pridať [num]. Napríklad na otvorenie súboru na riadku 127 zadajte:

vim filename +127

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

  • Pohyb kurzora:
    • Pomocou klávesov so šípkami sa môžete pohybovať v príslušných smeroch (hore, dole, vľavo, vpravo).
    • Alternatively, employ the h, j, k, and l keys for left, down, up, and right movements, respectively.
  • Navigácia v slovách:
    • 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.
  • Navigačné linky:
    • Go to the start of the line by pressing 0.
    • Move to the end of the line with $.

Úprava textu vo VIM

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

  • Vstup do režimu vkladania:
    • 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 umožňuje pripojiť na koniec riadku.
  • Odstránenie textu:
    • 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.
  • Kopírovať a prilepiť:
    • Copy a line with yy.
    • Paste the copied line below the current line using p.
  • Späť a Znova:
    • Undo the last action with u.
    • Redo with Ctrl + r.

Vyhľadávanie vo VIM

Rozhodujúce je efektívne vyhľadávanie. Tu sú niektoré skratky súvisiace s vyhľadávaním:

  • Hľadá sa text:
    • 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.
  • Nahradenie textu:
    • Substitute the current word with a new one using :s/old/new/g.

Ukončenie Vim

Základy som už prebral na začiatku, ale tu je niekoľko ďalších možností:

  • Uložiť a ukončiť všetko:
    • To save all changes and quit multiple files simultaneously, use :wa a :qa.
  • Ukončenie bez uloženia:
    • If you want to exit Vim without saving any changes made in any of the files, :qa! will do the trick.

Záver

Pamätajte, že zvládnutie Vima si vyžaduje čas a prax. Čím viac ho budete používať, tým bude pohodlnejší a výkonnejší. Veľa šťastia pri úpravách!