Skip to content Gå til innhold


Get started using the Vim text editor Kom i gang med Vim tekstredigeringsprogram

LinuxMacWindows

Vim is one of the most powerful and popular command line text editors around. Vim er en av de mektigste og mest populære kommandolinje tekstredigeringsprogrammer rundt. It was initially only available for the Linux and UNIX platforms, but was then ported to Windows also. Det var først bare tilgjengelig for Linux-og UNIX-plattformer, men da var portert til Windows også. The interface is clean and simple, and you use a combination of keys to perform tasks such as copy-paste, search and replace, delete a bunch of lines, and much more. Grensesnittet er rent og enkelt, og du bruker en kombinasjon av tastene for å utføre oppgaver som kopier og lim, søk og erstatt, slette en gjeng linjer, og mye mer.

Vim comes pre-installed with most distributions of Linux and on Mac OS. Vim kommer pre-installert med de fleste distribusjoner av Linux og Mac OS. In case you don't have it or want to install it on another platform you can get the installer from I tilfelle du ikke har det eller ønsker å installere det på en annen plattform, kan du få installert fra here her . . For Windows users you need to go For Windows-brukere må du gå here her and download the latest release of Vim. og last ned den nyeste versjonen av Vim. Download the zip file for your version of Windows and extract it. Last ned zip-filen for din versjon av Windows og pakke det. Then run the installer. Deretter kjøre installasjonsprogrammet. The only thing different between the Linux/Mac version of Vim and the Windows version is that the Windows version runs in its own graphical window. Det eneste forskjellig mellom Linux / Mac-versjon av Vim og Windows-versjonen er at Windows-versjonen kjører i sin egen grafisk vindu. Let's take a closer look at its usage. La oss ta en nærmere titt på bruken sin.

Before we get to the actual usage of Vim let me briefly explain to you the two modes that Vim runs in – command and insert mode. Før vi kommer til den faktiske bruken av Vim la meg kort forklare deg de to modusene som Vim kjører i - kommando og sette modus. In the command mode you give instructions to Vim to take some action, such as delete a line, or search for a word. Inne kommandoen modus gir deg instruksjoner til Vim å foreta en handling, for eksempel slette en linje, eller søke etter et ord. When you are in the insert mode what you type goes in as text into the document you are editing. Når du er i modus setter det du skriver går inn som tekst i dokumentet du redigerer. When you launch Vim you are in the command mode. Når du starter Vim du er i kommando-modus. To switch to insert mode hit the 'i' key on your keyboard. For å bytte til sette modus trykke på "nøkkelen i" på tastaturet. You will see a notification at the bottom left of your screen like this: Du vil se en melding nederst til venstre på skjermen slik ut:

– INSERT – - Sett inn --

This means you can now begin editing the file. Dette betyr at du kan nå begynne å redigere filen. To switch back to the command mode just hit the Escape key. Hvis du vil bytte tilbake til kommando-modus trykker du bare på Esc. You will find that the “– INSERT –” notification at the bottom will disappear. Du vil finne at "- Sett inn -" varsel nederst vil forsvinne. You are now in the command mode and can instruct Vim to delete a line, or to save the file, or whatever you may want to do with the document. Du er nå i kommando-modus, og kan instruere Vim å slette en linje, eller lagre filen, eller hva det kan være lurt å gjøre med dokumentet.

To open an existing file or a to create a new one with Vim use the following syntax: Hvis du vil åpne en eksisterende fil eller å opprette en ny en med Vim bruke følgende syntaks:

# vim helloworld.txt # Vim helloworld.txt

If you opened an existing file you should see its content, or a blank page if you created a new one. Hvis du har åpnet en eksisterende fil, bør du se innholdet, eller en tom side hvis du opprettet en ny. Now before we proceed with using Vim, let's see how to exit Vim. Nå før vi fortsetter med å bruke Vim, la oss se hvordan å avslutte Vim. This is important because, unlike your standard graphical text editor, you cannot close the window to shut the application. Dette er viktig fordi, i motsetning til standard grafiske tekstredigeringsprogram, kan du ikke lukke vinduet for å lukke programmet. To exit Vim and return to the command line you need to enter the following key combination: For å avslutte Vim og gå tilbake til kommandolinjen må du angi følgende tastekombinasjon:

ESC :q ENTER ESC: q ENTER

In plain English the above command goes something like this, “Escape key, then a colon, followed immediately by a 'q', and then the Enter key to finish”. I vanlig engelsk ovenfor kommandoen går noe sånt som dette, «Escape-tasten og et kolon, umiddelbart etterfulgt av en 'Q', og deretter Enter-tasten for å fullføre". The “q” here stands for “quit”. The "q" her står for "quit". What Vim does here is that it exits without saving any changes you may have made to the file. Hva Vim gjør her er at det kommer ut uten å lagre eventuelle endringer du har gjort til filen. To save the file and quit add the 'w' or “write” option: Hvis du vil lagre filen, og avslutt legg til 'w' eller "skrive" alternativet:

ESC :wq ENTER ESC: WQ ENTER

You can also use the 'w' option without the 'q', if you just want to save the file while editing it and not quit Vim. Du kan også bruke 'w' alternativet uten "q", hvis du bare vil lagre filen mens du redigerer den og ikke avslutte Vim.

Now that we know how to get in an out of Vim let's see how to use it. Nå som vi vet hvordan å komme i en av Vim la oss se hvordan den skal brukes. Let's create a new document with Vim and begin writing: La oss lage et nytt dokument med Vim og begynne å skrive:

# vim newdocument.txt # Vim newdocument.txt

Now hit 'i' on your keyboard to get into the insert mode. Nå trykk 'i' på tastaturet for å komme inn i sette modus. Write a few lines of text in the file. Skriv noen linjer med tekst i filen. Once you are done hit the Escape key to go into the command mode, and then “:wq” to save and exit the file. Når du er ferdig med å trykke på Esc-tasten for å gå inn i kommando-modus, og deretter ": WQ" for å lagre og avslutte filen. Now let's see if the file was written correctly. La oss nå se om filen ble skrevet riktig. Windows users can open the document we created using Notepad. Windows-brukere kan åpne dokumentet vi opprettet ved hjelp av Notisblokk. If you are using Linux or a Mac run the following command to check out the contents of the file: Hvis du bruker Linux eller Mac kjøre følgende kommando for å sjekke ut innholdet av filen:

# cat newdocument.txt # Cat newdocument.txt

You should see the contents of the file you just created. Du skal kunne se innholdet i filen du nettopp opprettet. Now open the same file using Vim and let's see what more Vim do do. Nå åpner den samme filen ved hjelp av Vim og la oss se hva mer Vim gjør. Let's delete a few words and lines. Let's slette noen ord og linjer. While in command mode navigate you cursor to he beginning of a word and hit the key combination “dw” followed by Enter. Mens du er i kommando-modus navigere deg markøren til han begynnelsen av et ord og trykke tastekombinasjonen "dw" etterfulgt av Enter. This should delete the word. Dette bør slette ordet. Now let's delete a whole line. La oss nå slette en hel linje. Pick a line you want to delete and take the cursor to any location in that line and hit the key combination “dd” followed by Enter. Velg en linje du vil slette, og ta markøren til en plassering i den linjen og trykke tastekombinasjonen "dd" etterfulgt av Enter. Line deleted. Line slettet.

Sometimes you make a mistake that you want to undo, say you want to bring back the line you just deleted. Noen ganger du gjør en feil som du vil angre, si at du vil bringe tilbake den linjen du nettopp slettet. To undo your last action go to the command mode and hit the key “u”. Hvis du vil angre den siste handlingen gå til kommando-modus og trykke tasten "u". You can continue hitting “u” to undo more changes. Du kan fortsette å trykke "u" for å angre flere endringer.

These commands will get you started with Vim. Disse kommandoene vil komme i gang med Vim. Practice what you learned here. Praksis det du har lært her. I will return with more cool stuff such as finding and replacing words, searching a text, and more. Jeg kommer tilbake med flere kule ting som å finne og erstatte ord, søker en tekst, og mer.

A quick recap of the commands you learned here: En rask oppsummering av kommandoene du har lært her:

1. 1. Save file – “:w” Lagre filen - ": w"
2. 2. Quit file without saving – “:q” Avslutt filen uten å lagre - ": q"
3. 3. Save and quit file – “:wq” Lagre og avslutt arkiv - ": WQ"
4. 4. Go into insert mode – “i” Gå inn sette modus - "i"
5. 5. Go into command mode – ESC Gå inn i kommando-modus - ESC
6. 6. Delete word – “dw” Slett ord - "dw"
7. 7. Delete line – “dd” Slett linje - "dd"
8. 8. Undo change – “u” Angre endring - "u"

Posted in Posted in Linux Linux , , Mac Mac , , Windows Windows . .

Related Posts: Relaterte innlegg:

How to edit iPhoto images using another application Hvordan redigere iPhoto bilder ved hjelp av et annet program
How to use your Home folder as your Desktop in Ubuntu Hvordan bruke Hjem-mappen som skrivebordet i Ubuntu
How to disable the balloon tips in Windows XP Slik deaktiverer du bobletips i Windows XP
Overview: CoolMon 2 – a Windows system monitoring utility Oversikt: 2 CoolMon - et Windows-system avlytting verktøyet
How to display your system info on your Linux desktop Slik viser systemet info på din Linux-skrivebordet

2 Responses 2 Svar

Stay in touch with the conversation, subscribe to the Holde kontakten med samtalen, abonnere på RSS feed for comments on this post RSS feed for kommentarer til dette innlegget . .

  1. James says James sier

    Come on ! Kom igjen! Is there someone who still use vi (& its clones) ? Er det noen som fremdeles bruker vi (og dens kloner)? There's hundred of editors out there who can ease much more the work for a writer…!!! Det er hundre av redaktører der ute som kan lette mye av arbeidet for en forfatter ...!

    Yeah, I know you can do more with Vi than any other editor, but believe me you still have to memorize a bunch of keyboard keys… Ja, jeg vet du kan gjøre mer med Vi enn noen annen redaktør, men tro meg, du har fremdeles huske en haug med tastaturet ...

  2. lamberto says Lamberto sier

    compliments for a very useful start, but i'm unable to find the rest of the tutorial? compliments for en veldig nyttig start, men jeg kan ikke finne resten av opplæringen?
    lam Lam



Some HTML is OK Some HTML is OK

or, reply to this post via eller svare på dette innlegget via trackback styrekule . .