vi
vi x.c
: edit file βx.cβ
vi
λ 3κ°μ§μ λͺ¨λκ° μλ€.
μ²μ vi
λ₯Ό μ€ννλ©΄ command modeλ‘ μ§νλλ€.
j
(down), k
(up), h
(left), l
(right)x
(delete one character), dd
(delete a line)3yy
: νμ¬ μ€λΆν° μμν΄μ β3βμ€μ 볡μ¬νλ€. (Copy 3 lines starting from the current line.)p
: paste them after the current line recoveru
: recover what you have just deletedi
, a
, o
i
: νμ¬ μ»€μ μμ (before) μ½μ
a
: νμ¬ μ»€μ λ€μ (after) μ½μ
o
: μλ‘μ΄ μ€ (new line) μ½μ
/
or :
now you can type
ESC key
:q!
: μ μ₯νμ§ μκ³ λκ°κΈ° (quit without saving):w
: μ°κΈ° (write):wq
: μ μ₯νκ³ λκ°κΈ° (save and exit)/pat
: βpatβμ΄λΌλ ν¨ν΄ μ°ΎκΈ° (search the pattern in βpatβ):set number
: μ€λ²νΈ λνλ΄κΈ° (display line numbers):40
: β40βλ² μ€λ‘ μ΄λνκΈ° (go to line β40β)vi
.vi f1
(when you open a file with vi
, sometimes you see Open, Edit, β¦ etc. at the bottom of the screen, in that case just type βeβ in order to start editing)
i
key and type following.Hello, this is my first session in the vi editor.
This is the second line of text.
esc
key which is located at the top left position of your keyboard. Save and exit with :wq
esc
:wq
vi f1
j
, k
, h
, l
to move the cursor around. Move the cursor to the word βfirstβ. Use x
key to delete the word βfirstβ. The result should be as follows.Hello, this is my session in the vi editor.
This is the second line of text.
o
key.Hello, this is my third session in the vi editor.
Insert a new line here.
This is the second line of text.
x
and i
key.Hi there, this is my third session in the vi editor.
Insert a new line here.
This is the second line of text.
a
key.Hi there, this is my third session in the vi editor. Adding more at the end.
Insert a new line here.
This is the second line of text.
dd
.Hi there, this is my third session in the vi editor. Adding more at the end.
Insert a new line here.
o
.Hi there, this is my third session in the vi editor. Adding more at the end.
Insert a new line here.
One more line.
Another line.
And yet another line.
Hi there, this is my third session in the vi editor. Adding more at the end.
Insert a new line here.
One more line.
Another line.
And yet another but last line. And this is the end.
2yy
to copy two lines at the current cursor; move the cursor to another location and use p
to paste them at that location.Hi there, this is my third session in the vi editor. Adding more at the end.
One more line.
Another line.
Insert a new line here.
One more line.
Another line.
And yet another but last line. And this is the end.
:6
and make change as follows.Hi there, this is my third session in the vi editor. Adding more at the end.
One more line.
Another line.
Insert a new line here.
One more line.
The 6th line.
And yet another but last line. And this is the end.
Write a program:
$ vi ex1.c
#include <stdio.h>
void main(){
printf("hi there\n");
}
Compile:
$ gcc βo ex1 ex1.c
Run:
$ ./ex1
hi there