Exit neon sign on brick wall background

VIM:stä poistuminen ja suosituimmat VIM-pikakuvakkeet

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 on toiseksi vaikein asia lopettaa tupakoinnin jälkeen

Poistu VIM-editorista näppäinyhdistelmien avulla

Vim-editori on hankala aloittelijoille, mutta kun opit oikeat näppäinyhdistelmät, VIM:n käyttäminen muuttuu helpoksi. Tässä ovat suosituimmat näppäinyhdistelmät vimistä poistumiseen.

Poistu vimistä tallentamalla muutokset

Poistu vimistä tallentamalla muutokset painamalla Esc näppäintä poistuaksesi muokkaustilasta, pidä sitten Shift painettuna ja paina kolmonen key (:). Then enter “wq” and press Enter. Here “w” stands for write and “q” stands for “quit”. On US keyboards the colon : on sama näppäin kuin puolipiste ;, located right of the letter “L” key.

:wq

Poistu vimistä tallentamatta muutoksia

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
poistu vimistä tallentamatta muutoksia

Tallenna muutokset ilman, että poistut VIM-editorista

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

:w

VIM:in taitavaksi tuleminen

Nyt kun olen käynyt läpi Vimin perusasiat ja tallentamisen, siirrytään joihinkin lisäkäteviin VIM-pikanäppäimiin ja ominaisuuksiin, jotka parantavat taitojasi.

VIM:in käynnistäminen tiedoston muokkaamista varten

Yleensä kehittäjät käynnistävät vim:in muokatakseen tiedostoa komennolla:

vim filename

Jos tiedostoa ei ole, se luodaan. Voit määrittää useita tiedostoja muokattavaksi:

vim file1 file2 file3

Avaa tiedosto tietyltä riviltä lisäämällä +[num] vim-komennon jälkeen. Esimerkiksi avaa tiedosto riviltä 127 kirjoittamalla:

vim filename +127

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

  • Kursorin siirtäminen:
    • Käytä nuolinäppäimiä liikkuaksesi vastaaviin suuntiin (ylös, alas, vasemmalle, oikealle).
    • Alternatively, employ the h, j, k, and l keys for left, down, up, and right movements, respectively.
  • Sanasiirtyminen:
    • 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.
  • Rivien navigointi:
    • Go to the start of the line by pressing 0.
    • Move to the end of the line with $.

Tekstin muokkaaminen VIMissä

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

  • Lisäystilaan siirtyminen:
    • 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 sallii lisäämisen rivin loppuun.
  • Tekstin poistaminen:
    • 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.
  • Kopioi ja liitä:
    • Copy a line with yy.
    • Paste the copied line below the current line using p.
  • Kumoa ja Uudelleen:
    • Undo the last action with u.
    • Redo with Ctrl + r.

Haku VIMissä

Tehokas haku on ratkaisevan tärkeää. Tässä on joitakin hakua koskevia pikanäppäimiä:

  • Tekstin haku:
    • 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.
  • Tekstin korvaaminen:
    • Substitute the current word with a new one using :s/old/new/g.

Vimistä poistuminen

Olen jo käsitellyt perusteet alussa, mutta tässä on vielä muutama vaihtoehto:

  • Tallenna ja poistu kaikista:
    • To save all changes and quit multiple files simultaneously, use :wa ja :qa.
  • Poistuminen tallentamatta:
    • If you want to exit Vim without saving any changes made in any of the files, :qa! will do the trick.

Johtopäätös

Muista, että Vimin hallitseminen vie aikaa ja harjoitusta. Mitä enemmän käytät sitä, sitä mukavammaksi ja tehokkaammaksi se muuttuu. Hyvää muokkaamista!