imported>mutante mNo edit summary |
imported>DrOwl No edit summary |
||
(17 intermediate revisions by 6 users not shown) | |||
Line 1: | Line 1: | ||
http://www.friedhoff.org/img/viemacspolice.png |
|||
One of / The most popular [[console]] [[text editors]] in [[Unix]] / [[Linux]]. |
One of / The most popular [[console]] [[text editors]] in [[Unix]] / [[Linux]]. |
||
Line 24: | Line 26: | ||
Character |
Character |
||
h, j, k, l Left, down, up, right (, , , ) |
h, j, k, l Left, down, up, right (, , , ) |
||
Text |
Text |
||
w, W, b, B Forward, backward by word |
w, W, b, B Forward, backward by word |
||
Line 30: | Line 33: | ||
}, { Beginning of next, previous paragraph |
}, { Beginning of next, previous paragraph |
||
]], [[ Beginning of next, previous section |
]], [[ Beginning of next, previous section |
||
Lines |
Lines |
||
0, $ First, last position of current line |
0, $ First, last position of current line |
||
Line 40: | Line 45: | ||
nH n (number) of lines after top line |
nH n (number) of lines after top line |
||
nL n (number) of lines before last line |
nL n (number) of lines before last line |
||
Screens |
Screens |
||
[CTRL-F], [CTRL-B] Scroll forward, backward one screen |
[CTRL-F], [CTRL-B] Scroll forward, backward one screen |
||
Line 48: | Line 55: | ||
z- Reposition line with cursor: to bottom of screen |
z- Reposition line with cursor: to bottom of screen |
||
[CTRL-L] [CTRL-R] Redraw screen (without scrolling) |
[CTRL-L] [CTRL-R] Redraw screen (without scrolling) |
||
Searches |
Searches |
||
/pattern Search forward for pattern |
/pattern Search forward for pattern |
||
Line 59: | Line 68: | ||
; Repeat previous current-line search |
; Repeat previous current-line search |
||
' Repeat previous current-line search in opposite direction |
' Repeat previous current-line search in opposite direction |
||
Line number |
Line number |
||
[CTRL-G] Display current line number |
[CTRL-G] Display current line number |
||
Line 64: | Line 75: | ||
G Move to last line in file |
G Move to last line in file |
||
:n Move to line number n |
:n Move to line number n |
||
Marking position |
Marking position |
||
mx Mark current position as x |
mx Mark current position as x |
||
Line 70: | Line 83: | ||
'x Move to beginning of line containing mark x |
'x Move to beginning of line containing mark x |
||
'' Return to beginning of line containing previous mark |
'' Return to beginning of line containing previous mark |
||
Insert |
Insert |
||
Line 75: | Line 89: | ||
I, A Insert text at beginning, end of line |
I, A Insert text at beginning, end of line |
||
o, O Open new line for text below, above cursor |
o, O Open new line for text below, above cursor |
||
Change |
Change |
||
r Change character |
r Change character |
||
Line 83: | Line 99: | ||
s Delete character and substitute text |
s Delete character and substitute text |
||
S Delete current line and substitute text |
S Delete current line and substitute text |
||
Delete, move |
Delete, move |
||
x Delete character |
x Delete character |
||
Line 92: | Line 110: | ||
"np Put text from delete buffer number n after cursor (for last nine deletions) |
"np Put text from delete buffer number n after cursor (for last nine deletions) |
||
Yank |
Yank |
||
yw Yank (copy) word |
yw Yank (copy) word |
||
Line 98: | Line 117: | ||
p, P Put yanked text after, before cursor |
p, P Put yanked text after, before cursor |
||
"aP Put text from buffer a before cursor |
"aP Put text from buffer a before cursor |
||
Other commands |
Other commands |
||
. Repeat last edit command |
. Repeat last edit command |
||
Line 149: | Line 170: | ||
</pre> |
</pre> |
||
=== lol === |
|||
~$ vi |
|||
? |
|||
File empty: Nothing to search |
|||
help |
|||
The default buffer ist empty |
|||
Alt-Q |
|||
q isn't a vi command |
|||
Ctrl-Q |
|||
alt-x |
|||
alt-F4 |
|||
q |
|||
q isn't a vi command |
|||
ESC |
|||
F10 |
|||
*reset knopf drück* |
|||
:q! (ohne speichern raus) |
|||
=== VI cursor keys bug , ABCD instead of arrows === |
|||
If it happens to you that the cursor keys dont seem to work in Insert Mode anymore, but instead they insert the characters A,B,C and D, then use ''':set term=cons25''' and read here http://www.vim.org/tips/tip.php?tip_id=550 |
|||
<jargon /> |
|||
== remove empty lines == |
|||
<pre>:g/^$/d</pre> |
|||
== replace stuff with regex == |
|||
all of file |
|||
:%s/word/new word/g |
|||
from here to end of file |
|||
:,$s/word/new word/g |
|||
== tabulate lines == |
|||
To add tabs to the beging of lines (no need to be at the begining of the line) |
|||
:> |
|||
Add tabs to the begining of the next 4 lines |
|||
:,+3> |
|||
Add tabs to lines 5 to 8 |
|||
:5,8> |
|||
Add tabs to all lines |
|||
:%> |
|||
== Guides & HowTos == |
|||
http://www.gentoo.org/doc/en/vi-guide.xml |
|||
[[Category:Programs]] |
[[Category:Programs]] |
||
Line 156: | Line 230: | ||
[[Category:Linux]] |
[[Category:Linux]] |
||
[[Category:Manpages]] |
[[Category:Manpages]] |
||
== Tabbed vi / open multiple files == |
|||
If you open multiple files with vi(m) like <code>vim *.txt</code> you switch to the next file with ''':next''' or ''':wn'''. |
|||
If you start vim with the '''-p''' switch <code>vim -p *.txt</code> you get a tab for each file. You can switch between tabs with '''gt''' or just ''':q'''uit from a file and be automatically in the next file. ''':qa''' closes all tabs. |
Latest revision as of 10:13, 14 September 2009
http://www.friedhoff.org/img/viemacspolice.png
One of / The most popular console text editors in Unix / Linux.
- i edit befor cursor
- a edit after cursor
- o edit new line befor cursor
- O edit new line after cursor
- r replace char
- cw change word
- dw delete word
- x delete
- 7x dlete 7 chars
- dd delete line
- w write file
- wq write quit
- q! force quit
- [Ctrl]+ ZZ quit writing if needed
Use / [string] to search ( n for next)
Use [Ctrl+V] to enter escape codes Ie. [Ctrl+V] [backspace] makes a ^H (ie to use in .profile when you do a stty erase ^H)
Character h, j, k, l Left, down, up, right (, , , ) Text w, W, b, B Forward, backward by word e , E End of word ), ( Beginning of next, previous sentence }, { Beginning of next, previous paragraph ]], [[ Beginning of next, previous section Lines 0, $ First, last position of current line ^ First character of current line (ignore spaces) +, - First character of next, previous line n| Column n of current line H Top line of screen M Middle line of screen L Last line of screen nH n (number) of lines after top line nL n (number) of lines before last line Screens [CTRL-F], [CTRL-B] Scroll forward, backward one screen [CTRL-D] [CTRL-U] Scroll down, up one-half screen [CTRL-E] [CTRL-Y] Show one more line at bottom, top of window z [RETURN] Reposition line with cursor: to top of screen z. Reposition line with cursor: to middle of screen z- Reposition line with cursor: to bottom of screen [CTRL-L] [CTRL-R] Redraw screen (without scrolling) Searches /pattern Search forward for pattern ?pattern Search backward for pattern n, N Repeat last search in same, opposite direction /, ? Repeat previous search forward, backward fx Search forward for character x in current line Fx Search backward for character x in current line tx Search forward for character before x in current line Tx Search backward for character after x in current line ; Repeat previous current-line search ' Repeat previous current-line search in opposite direction Line number [CTRL-G] Display current line number nG Move to line number n G Move to last line in file :n Move to line number n Marking position mx Mark current position as x `x Move cursor to x `` Return to previous mark or context 'x Move to beginning of line containing mark x '' Return to beginning of line containing previous mark Insert i, a Insert text before, after cursor I, A Insert text at beginning, end of line o, O Open new line for text below, above cursor Change r Change character cw Change word cc Change current line C Change to end of line R Type over characters s Delete character and substitute text S Delete current line and substitute text Delete, move x Delete character X Delete character before cursor dw Delete word dd Delete current line D Delete to end of line p, P Put deleted text after, before cursor "np Put text from delete buffer number n after cursor (for last nine deletions) Yank yw Yank (copy) word yy Yank current line "ayy Yank current line into named buffer a p, P Put yanked text after, before cursor "aP Put text from buffer a before cursor Other commands . Repeat last edit command u, U Undo last edit; restore current line J Join two lines ex edit commands :d Delete lines :m Move lines :co or :t Copy lines :.,$d Delete from current line to end of file :30,60m0 Move lines 30 through 60 to top of file :.,/pattern/co$ Copy from current line through line containing pattern to end of file Exit Commands ZZ Write (save) and quit file :x Write (save) and quit file :wq Write (save) and quit file :w Write (save) file :w! Write (save) file (overriding protection) :30,60w newfile Write from line 30 through line 60 as newfile :30,60w>> file Write from line 30 through line 60 and append to file :w %.new Write current buffer named file as file.new :q Quit file :q! Quit file (overriding protection) Q Quit vi and invoke ex :e file2 Edit file2 without leaving vi :n Edit next file :e! Return to version of current file at time of last write (save) :e# Edit alternate file % Current filename # Alternate filename Command Line Options vi file Invoke vi editor on file vi file1 file2 Invoke vi editor on files sequentially view file Invoke vi editor on file in read-only mode vi -R file Invoke vi editor on file in read-only mode vi -r file Recover file and recent edits after system crash vi + file Open file at last line vi +n file Open file directly at line number n vi +/pattern file Open file directly at pattern ex file Invoke ex editor on file from UNIX
lol[edit]
~$ vi ? File empty: Nothing to search help The default buffer ist empty Alt-Q q isn't a vi command Ctrl-Q alt-x alt-F4 q q isn't a vi command ESC F10 *reset knopf drück*
:q! (ohne speichern raus)
VI cursor keys bug , ABCD instead of arrows[edit]
If it happens to you that the cursor keys dont seem to work in Insert Mode anymore, but instead they insert the characters A,B,C and D, then use :set term=cons25 and read here http://www.vim.org/tips/tip.php?tip_id=550
<jargon />
remove empty lines[edit]
:g/^$/d
replace stuff with regex[edit]
all of file
:%s/word/new word/g
from here to end of file
:,$s/word/new word/g
tabulate lines[edit]
To add tabs to the beging of lines (no need to be at the begining of the line)
:>
Add tabs to the begining of the next 4 lines
:,+3>
Add tabs to lines 5 to 8
:5,8>
Add tabs to all lines
:%>
Guides & HowTos[edit]
http://www.gentoo.org/doc/en/vi-guide.xml
Tabbed vi / open multiple files[edit]
If you open multiple files with vi(m) like vim *.txt
you switch to the next file with :next or :wn.
If you start vim with the -p switch vim -p *.txt
you get a tab for each file. You can switch between tabs with gt or just :quit from a file and be automatically in the next file. :qa closes all tabs.