คำสั่ง
1. สร้าง file
vi <filename>
$ vi test
หลังจากเข้าสู่หน้า vi prompt แล้วจะจะพบว่าเราไม่สามาถพิมพ์ข้อมูลลงไปได้โดยตรง จะต้องเลือกคำสั่งก่อนว่าจะทำอะไรกับ file ข้อมูล เมื่อเลือกคำสั่งแล้วถ้าจะกลับสู่ vi prompt ใหม่ก็ให้กด ESC
2. คำสั่งจัดการ file
:w | save file |
:wq | save file และออกจาก vi |
:q | ออกจาก vi ถ้าไม่มีการแก้ไขข้อมูล |
:q! | ออกจาก vi โดยไม่สนว่าข้อมูลมีการแก้ไขหรือไม่ |
:e name | เปลี่ยนชื่อ file |
:e! | เอา save file version ล่าสุดกลับมา |
:e + name | โหลด file เพื่อแก้ไข และเลือน cursor ไปบรรทัดสุดท้าย |
:e +n name | โหลด file เพื่อแก้ไข และเลือน cursor ไปบรรทัด n |
:e # | แก้ไข file อันใหม่ |
^^ | เหมือน :e # |
:w name | save ข้อมูลลง file ใหม่ |
:w! name | save ข้อมูลทับลง file เดิม |
3. เขียนหรือแทรกข้อมูลลง file
i | แทรกข้อมูลก่อน cursor |
a | เพิ่มข้อมูลหลัง cursor |
A | เพิ่มข้อมูลท้ายบรรทัด |
I | แทรกข้อมูลหน้าบรรทัด |
o | แทรกบรรทัดถัดไปของ cursor |
O | แทรกบรรถัดก้อน cursor |
rx | เปลี่ยนตัวอักษรทับ 1 ตัว |
R | เปลี่ยนตัวอักษรทับหลายๆตัว |
4. ลบข้อมูล หรือ บรรทัดใน file
x | ลบตัวอักษรด้านขวา cursor 1 ตัว |
nx | ลบตัวอักษรด้านขวา cursor n ตัว |
X | ลบตัวอักษรด้านซ้าย cursor 1 ตัว |
nX | ลบตัวอักษรด้านซ้าย cursor n ตัว |
D | ลบบรรทัด 1 บรรทัดสุดท้าย |
d$ | ลบบรรทัด สุดท้ายจนถึง บรรทัด cursor |
dd or :d | ลบบรรทัด cursor |
ndw | ลบคำถัดไปจาก cursor n คำ |
ndb | ลบคำก่อนหน้า cursor n คำ |
ndd | ลบบรรทัดแรกจนถึง บรรทัด cursor |
:n,md | ลบบรรทัดที่ n จนถึง m |
5. การย้าย cursor
h | Move left |
j | Move down |
k | Move up |
l | Move right |
Arrow Keys | These do work, but they may be too slow on big files. Also may have unpredictable results when arrow keys are not mapped correctly in client. |
w | Move to next word |
W | Move to next blank delimited word |
b | Move to the beginning of the word |
B | Move to the beginning of blank delimted word |
^ | Moves to the first non-blank character in the current line |
+ or | Moves to the first character in the next line |
– | Moves to the first non-blank character in the previous line |
e | Move to the end of the word |
E | Move to the end of Blank delimited word |
( | Move a sentence back |
) | Move a sentence forward |
{ | Move a paragraph back |
} | Move a paragraph forward |
[[ | Move a section back |
]] | Move a section forward |
0 or | | Move to the begining of the line |
n| | Moves to the column n in the current line |
$ | Move to the end of the line |
1G | Move to the first line of the file |
G | Move to the last line of the file |
nG | Move to nth line of the file |
:n | Move to nth line of the file |
fc | Move forward to c |
Fc | Move back to c |
H | Move to top of screen |
nH | Moves to nth line from the top of the screen |
M | Move to middle of screen |
L | Move to botton of screen |
nL | Moves to nth line from the bottom of the screen |
Control-d | Move forward ½ screen |
Control-f | Move forward one full screen |
Control-u | Move backward ½ screen |
Control-b | Move backward one full screen |
CTRL-e | Moves screen up one line |
CTRL-y | Moves screen down one line |
CTRL-u | Moves screen up ½ page |
CTRL-d | Moves screen down ½ page |
CTRL-b | Moves screen up one page |
CTRL-f | Moves screen down one page |
CTRL-I | Redraws screen |
z | z-carriage return makes the current line the top line on the page |
nz | Makes the line n the top line on the page |
z. | Makes the current line the middle line on the page |
nz. | Makes the line n the middle line on the page |
z- | Makes the current line the bottom line on the page |
nz- | Makes the line n the bottom line on the page |
% | Move to associated ( ), { }, [ ] |
โครงสร้างคำสั่ง
vim [options] [file ..]
vim [options] -
vim [options] -t tag
vim [options] -q [errorfile]
รายละเอียด
เป็นคำสั่งที่ใช้ในการสร้างหรือแก้ไข file ข้อมูล text จัดอยู่ในกลุ่ม editor พื้นฐานบนระบบ Unix และ Linux