Vi: Difference between revisions
→Basics
(→Basics) |
|||
(13 intermediate revisions by the same user not shown) | |||
Line 1:
[[Category:Linux]]
__TOC__
<br />
= Basics =
Line 11 ⟶ 14:
set autoindent Automatic indentation in insert mode
set noautoindent Removes the automatic indentation feature in insert mode
syntax on Turns on highlighting of syntax
syntax off Turns off highlighting of syntax
set shiftwidth=4 The size of the indent, measured in spaces
set list List all Special characters except for white space.
*The .vimrc file
The EX commands (those that you key in after typing : in the Vi editor), which you want to
* Pages:
Control + F Next Page
Control + B Previous Page
== Searching ==
/string Search for "string"
Enter Highlight the first keyword match
N Scroll through next keyword matches
Shift + G Go to bottom of the file
Shift + N Search from Bottom to top for keyword matches
= Intermediate =
Line 35 ⟶ 51:
To decrypt the encrypted file, open the file and type below command and hit the Enter key twice; then save and exit the Vi editor by typing :wq, the file will be saved in the decrypted format:
:X
* Inserting the contents of an existing file
: r filename
* Opening Vi directly at a particular line
vim filename +5
* Opening Vi at the end of the file
vim + filename
* Writing the buffer to a new file
:w newname
You can now quit the original file by typing :q.
* Indenting the source code
gg=G
Where gg indicates the beginning of the file, = is for indenting and G indicates the end of the file.
* Repeating the last change
. (period) key to repeat the last change.
* Undoing and redoing
u undo the last change.
Ctrl-R repeat a change that has been undone.
* Jumping to matching braces
% can jump to curly brace or square bracket
* Preventing auto-indent
:set pastetoggle=<F2>
You can then press <F2> in the insert mode when you are ready to paste.
After pasting, you can press <F2> again to go to the auto-indent mode.
= Advanced =
Line 40 ⟶ 93:
*Going to any line
:50
* Show Line Numbers:
:set nu
*In the command mode to get the same result:
Line 118 ⟶ 174:
*Recovering a file, after a crash, from the swap file of the file being edited:
$vi -r filename
<br />
;References
<references/>
<br />
<br />
<br />
{{DISQUS}}
|