EanderAlx.org

Linux, Virtualization and whatever I find interesting ...

User Tools


Site Tools


vim_befehle

vi Commands

Source: Vim Tipps by David Rayner and many other pages.

Commands for vi start

begin in line X:

  • By using vi +[line] [file] the vi will open your file in the given line e.g. vi +25 test.sh

jump form less to vi:

  • When you open a file using less and the vi is your primary editor than you are able to open the file in vi by typing “v” at the place in the document you want to edit something.

open multiple files:

  • If you want to open more the one file you can do this by typing vi test1.sh test2.sh test3.sh.
  • If the files you want edit have similar names you also can do it so: vi test*.sh.
  • To end one and go to an other file you can use “q” or “w” and “n” for the next file.

Insert Mode:

  • <ESC> and “i”

Command Mode

  • by typing <ESC> you get into Command Mode

undo:

  • with “u” you undo the last change
  • you also can undo the last N changes: “[N]u”

jump to file begin/end:

  • with “G” you go to file end and with “gg” got to begin

delete all from here to the end:

  • with “dG” you delete all from cursor position to file end

jump to line X:

  • with <ESC> 23 <RETURN> you will jump 23 lines forward
  • with an additional “G” e.g. <ESC> 23G you will jump to line 23

copy line:

  • to copy the current line press “yy”. To past after current line “p” or before the current line “P”

cut and past:

  • “x” or “d” to cut and “p” or “P” to past as write last

overwrite sign:

  • type “r” and the next character will overwrite the current

jump to the next wort same as current:

  • with “#” you will jump to the next wort which is the same as that in your current cursor position

delete signs until the end of the current line:

  • “D”

delete characters until the end of the line N:

  • “[N]D”
  • e.g. until the end of line 23 <ESC> 23D

Search:

  • with “/” you will search for the sting given after the “/” until the end of the document
  • with “?” you will search for the sting given after the “?” beyond the border
  • with “n” you show the next occurred string

For the next command you must type a “:” before the command

Tabs:

  • with “tabnew file.txt” you can open the file in a new tab
  • with “vi -p file.txt file2.txt” you can open more then one file in tabs
  • with “gt” in Command Mode you can switch between the tabs
  • and many more hier

write: “w”

  • you can give also a filename after: “w file.txt”

next file: “n”

end: “q”

end without write: “q!”

Search and replace:

  • in the whole document: “:%s/SEARCH/REPLACE/g”
  • in the current line: “:s/SEARCH/REPLACE/g”
  • between two lines: “:ZEILE,ZEILEs/SEARCH/REPLACE/g”
  • without the “g” only the next found search string

Commands Visual Mode

  • to get into this mode type “v” or “V” the difference is the way of marking lines ( “V” = whole line “v” = sign for sign)
  • with the cursor you now can mark text

text-indent:

  • with “<” or “>” you can indent the marked text

cut or copy blocks:

  • to get into the visual block mode type “<ESC> <STRG-V>”
  • mark the text an cut or copy it like as normal text

past blocks:

  • like as normal text past but it will influence more than one line

enter text in more than one line as a block:

  • e.g. you mus comment out 20 lines
  • mark the first sign to change using the visual block mode
  • type <SHIFT-I> and the sign you want to insert
  • leave visual modus by typing <ESC> and a cursor

Uppercase

  • Block markierten Text U
This website uses cookies. By using the website, you agree with storing cookies on your computer. Also you acknowledge that you have read and understand our Privacy Policy. If you do not agree leave the website.More information about cookies
vim_befehle.txt · Last modified: 26.05.2014 07:31 by eanderalx