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.
Afslut VIM-editor ved hjælp af tastekombinationer
Vim editor er vanskelig for begyndere, men når du lærer de rigtige tastekombinationer, bliver det nemt at bruge VIM. Her er de mest populære tastekombinationer for at afslutte vim.
Afslut vim gemme ændringer
Tryk på for at afslutte vim med at gemme ændringer Esc tasten for at afslutte redigeringstilstand, og hold derefter nede Flytte og tryk tyktarm key (:). Then enter “wq” and press Enter. Here “w” stands for write and “q” stands for “quit”. On US keyboards the colon : er den samme nøgle som semikolon ;, located right of the letter “L” key.
:wq
Afslut vim uden at gemme ændringer
To exit vim without saving changes hold down Shift and press the colon key (:). Then enter “q!” and press Enter.
:q!

Gem ændringer uden eksisterende VIM-editor
To save changes without exiting vim hold down Shift and press the colon key (:). Then enter “w” and press Enter.
:w
Bliv dygtig til VIM
Nu hvor jeg dækkede det grundlæggende om at afslutte Vim og gemme ændringer, lad os fortsætte til nogle yderligere nyttige Vim-genveje og funktioner for at forbedre dine færdigheder.
Starter VIM for at redigere filen
Normalt starter udviklere vim for at redigere filen ved hjælp af kommandoen:
vim filename
Hvis filen mangler, bliver den oprettet. Du kan angive flere filer, der skal redigeres:
vim file1 file2 file3
For at åbne en fil på en bestemt linje kan du tilføje [num] efter vim-kommandoen. For eksempel for at åbne fil på linje 127 skal du indtaste:
vim filename +127
Navigerer i VIM
Once you’ve entered Vim, navigating efficiently is key. Here are some popular shortcuts:
- Flytning af markøren:
- Brug piletasterne til at flytte i de respektive retninger (op, ned, venstre, højre).
- Alternatively, employ the
h,j,k, andlkeys for left, down, up, and right movements, respectively.
- Ordnavigation:
- 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.
- Move the cursor to the beginning of the next word with
- Navigering af linjer:
- Go to the start of the line by pressing
0. - Move to the end of the line with
$.
- Go to the start of the line by pressing
Redigering af tekst i VIM
Once you’ve reached the desired location, these shortcuts will aid in text manipulation:
- Går ind i indsættelsestilstand:
- Press
ito enter insert mode before the cursor. - Use
Ito start inserting at the beginning of the line. - Employ
ato append after the cursor. Atillader tilføjelse i slutningen af linjen.
- Press
- Sletning af tekst:
- 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.
- Delete the character under the cursor with
- Kopiér og indsæt:
- Copy a line with
yy. - Paste the copied line below the current line using
p.
- Copy a line with
- Fortryd og fortryd:
- Undo the last action with
u. - Redo with
Ctrl + r.
- Undo the last action with
Søger i VIM
Effektiv søgning er afgørende. Her er nogle søgerelaterede genveje:
- Søger efter tekst:
- Initiate a search with
/, followed by the desired term. - Use
nto jump to the next occurrence andNto go to the previous one.
- Initiate a search with
- Udskiftning af tekst:
- Substitute the current word with a new one using
:s/old/new/g.
- Substitute the current word with a new one using
Afslutter Vim
Jeg har allerede dækket det grundlæggende i begyndelsen, men her er et par flere muligheder:
- Gem og luk alt:
- To save all changes and quit multiple files simultaneously, use
:waog:qa.
- To save all changes and quit multiple files simultaneously, use
- Afslut uden at gemme:
- If you want to exit Vim without saving any changes made in any of the files,
:qa!will do the trick.
- If you want to exit Vim without saving any changes made in any of the files,
Konklusion
Husk, at mestre Vim tager tid og øvelse. Jo mere du bruger den, jo mere komfortabel og kraftfuld bliver den. God redigering!






