This short command summary of the vi editor (and his clones VIM, calvin, elvis, lemmy, Nvi, WinVi, ...) is not intended as a compendium to document all the commands and the honored readers alike to take the courage that was indeed documented with countless here commands the reference of the writer, but also at the same time the desire to learn this editor was taken.
How to start with vi
First we open the editor on the console with this command and create the non existing file "test.txt".Then we want to insert something by first press the key "i", now we are in the insert mode, now we write the words "Hello World".
Now we leave the insert mode, by press the "ESC" button, save the results and close the vi editor by insert the keys ":", "w" and "q".
Now you are ready to perform more experiments and experiences.
subtitle | command | description |
---|---|---|
help | vi -h | start help page of vi editor (man vim) |
modi | normal mode | vi knows three different modi, the normal mode (usally to open a file and navigate in the lines) |
insert mode | switch from normal mode to insert mode or to use command line mode by press one of this characters "i", "I", "a", "A", "o", "O", "c", "C", "s" or "S", to go back to normal mode use the ESC button | |
command mode | usally used to save a file with insert :w or leave a file with :p or do both with :wq, to view file in coloured mode set :syntax on | |
start | vi myfile.txt | open vi editor with file myfile.txt OR create a new file when file does not exits |
vi -R myfile.txt | open vi editor with file myfile.txt in read-only modus | |
vim myfile.txt | open vim editor (vi clone) | |
vi +99 myfile.txt | open vi editor with file myfile.txt on line 99 | |
vi -r myfile.txt | recovery of a corrupt file myfile.txt (after a crash of vi) | |
vi +/PADERN myfile.txt | opens file myfile on first position with PADERN | |
basic | :q | quit editor |
:q! | quit editor force | |
i | start insert mode (more on subtitle insert) | |
ESC | leave the current insert mode | |
:w | write to file | |
:w! | write to file force | |
:w myfile.txt | write to file myfile.txt | |
:wq | write to file and quite VI | |
:syntax on | start coloured mode | |
navigation | h | go left |
j | go down | |
k | go top | |
l | ro right | |
:99 | jump to line 99 | |
99 | takes you 99 lines down from your current position | |
0 | go to first character of line | |
$ | go to last character of line | |
/PADERN | search "PADERN" forward in file | |
?PADERN | search "PADERN" backward in file | |
n | same search as before forward | |
N | same search as before backward | |
5G | go to the 5 line in file | |
G | go to the end of the file | |
redo, undo | . | redo last command |
u | undo last change | |
U | undo last change in whole line | |
delete | dw | delete word |
dd | delete line | |
dgg | delete everthing from your current line to the top of your line | |
D | delete until end of line | |
:g/^$/d | delete all empty lines | |
:g/with this/d | delete all lines with this | |
:g/^\s*$/d | delete all lines that are empty or contains white space | |
:v/^\s*"/d | delete all lines that are not empty or contains white spare | |
:v/this\|that\othersl/d | delete all lines that not this, that or others | |
copy and paste | "ayy | copy current line in named buffer a (vi could work with several buffers a,b,c) |
"add | delete current line in named buffer a | |
"ap | paste from buffer a in | |
"ayG | copy all lines to the end of the file in buffer a | |
replace | :g/old text/s//new text/g | combined with ex command :g, replace "old text" with "new text" in all lines |
:s/replace this// | "replace this" with nothing in all lines | |
:%s/r/s | replace r with s | |
:%s/ | replace all ^M, therefore you must enter | |
enhanced insert | i | start insert mode before current position |
I | start insert at the beginning of the current line | |
a | append after current character | |
A | append after current line | |
o | start insert on a new line below | |
O | start insert on a new line before | |
s | substitute one character and start insert mode | |
S | substitute line and start insert mode | |
several files | vi file.1 file.2 file.3 | open vi with file.1, file.2 and file.3, file.1 is first visible |
:n | open next file.2, and so on (maybe it is necessary to save the file that you edit before) | |
:rew | rewind, at the end of all file.*, show file.1 again | |
:e# | open file before (opposite from :n) | |
:e nextfile.txt | opens nextfile.txt, maybe it is necessary to save the file that you edit before or you open it with :e! nextfile.txt | |
:r myfile.txt | insert file myfile.txt on current position | |
:! ls -ltr | enable you to call the shell command ls -ltr from vi |
If, despite all the care one error have crept in, so I ask this to be made known to me.
No comments:
Post a Comment