![]() |
![]() |
![]() |
![]() |
![]() |
$ cat -n /etc/man_db.conf | col -x > vi_practice |
$ vi vi_practice ↵ Enter 1 # 2 # Generated automatically from man.conf.in by the 3 # configure script. 4 # 5 # man.conf from man-1.6e 6 # 7 # For more information about this file, see the man pages man(1) 8 # and man.conf(5). 9 # 10 # This file is read by man to configure the default manpath (also used 11 # when MANPATH contains an empty substring), to find out where the cat 12 # pages corresponding to given man pages should be stored, 13 # and to map each PATH element to a manpath element. 14 # It may also record the pathname of the man binary. [This is unused.] 15 # The format is: 16 # 17 # MANBIN pathname 18 # MANPATH manpath_element [corresponding_catdir] 19 # MANPATH_MAP path_element manpath_element 20 # 21 # If no catdir is given, it is assumed to be equal to the mandir 22 # (so that this dir has both man1 etc. and cat1 etc. subdirs). 23 # This is the traditional Unix setup. 24 # Certain versions of the FSSTND recommend putting formatted versions "vi_practice" 30L, 1745C 24,5 Top |
1 # 2 # Generated automatically from man.uconf.in by the 3 # configure script. |
1 # 2 # Generated automatically from man.conf.in by the 3 # configure m iscript. 4 # 5 # man.conf from man-1.6e 6 # 7 # For more information about this file, see the man pages man(1) 8 # and man.conf(5). 9 # 10 # This file is read by man m j to configure the default manpath (also used 11 # when MANPATH contains an empty substring), to find out where the cat 12 # pages corresponding to given man pages should be stored, 以下略 |
3 # configure 4 # 以下略 |
3 # d w 4 # 以下略 |
1 # 2 # Generated automaticJally from man.uconf.in by the 3 # configure script. 以下略 |
3 # c w 4 # 以下略 |
$ ex vi_practice↵ Enter ←用 ex 編輯練習檔,其畫面如下 Entering Ex mode. Type "visual" to go to Normal mode. :_ |
:2p ←輸出第 2 行(其中〝p〞是 print 的意思可省略) 2 # Generated automatically from man.conf.in by theg :1,5 ←輸出 1 ~ 5 行 (省略〝p〞) 1 # 2 # Generated automatically from man.conf.in by the 3 # configure script. 4 # 5 # man.conf from man-1.6e |
:% ←顯示第一行到最後一行(全部的內容) :1,. ←顯示第一行到游標所在的行 :100,$ ←顯示第 100 行到最後一行 |
:args ←顯示目前編輯的檔名(args 可簡寫成 ar) [vi_practice] := ←顯示檔案總行數 151 :.= ←顯示游標所在的位置 5 |
$ vi vi_practice↵ Enter 1 # 2 # Generated automatically from man.conf.in by the 3 # configure script. 中間略 23 # This is the traditional Unix setup. 24 # Certain versions of the FSSTND recommend putting formatted versions : ←在 vi 任一地方按 <:> 螢幕最左下出現冒號〝:〞,就是進入〝命令模式〞可執行 ex 的命令, 按 <ESC> 就可回到一般模式 |
:1,10d ←刪除 1~10 行 :.,$d ←刪除游標所在的位置到最後一行 :5,10m15 ←5~10 行,搬移到第 15 行之後(從第 16 行插入) :.,$m1 ←游標所在的位置到最後一行搬移到第 1 行之後 :1,10t15 ←1~10 行複製到第 15 行之後 :.,$co20 ←游標所在的位置到最後一行複製到第 20 行之後 |
:1,10w My_file ←將 1~10 行另存為〝My_file〞 :.,$w File1 ←游標所在的位置到最後一行,另存為〝File1〞 :5,13w >> MyFile.txt ←5~13 行,輸出累加重定向到檔案 |
:g/The\|the ←用正規表示法搜尋單字〝The〞或〝the〞 :/The\|the ←同上(省略〝g〞) :50,100/linux ←搜尋 500~100 行中有〝linux〞的字串 :.,$g/HELLO ←游標所在的位置到最後一行,搜尋〝HELLO〞 :10,15g!/is/nu ←列出 10~15 行內不含〝is〞字串的行,並列出行號 |
:.,$s/is/are/gi ←游標所在的位置到最後一行,〝is〞或〝Is〞(不管小寫)全用 are 取代 :1,$ s/colou*red/COLOURED/g ←壹到最後一行用正規表示法搜尋〝coloured〞或〝colored〞並用〝COLOURED〞取代 :5,20s/the/The/c ←5~20 行中〝the〞以〝The〞取代並要求確認 replace with The (y/n/a/q/l/^E/^Y) ←按 <y>取代,<n>不取代,<a>全取代,<q>全放棄,<l>(小寫L)只取代一行或按 <Ctrl+E>/<Ctrl+Y>上下翻頁 |
:g/apple/s/banana/orange/g ←先用搜尋指令〝:g〞搜尋那一行有〝apple〞字串,如存在此字串則同一行中有〝banana〞用〝orange〞取代, (如無〝apple〞字串,就算有〝banana〞也不會取代) |
:!cp fileA fileB↵ Enter Press ENTER or type command to continue |
:r !seq 1 10↵ Enter |
$ vi file1 file2 file3 ←載入 file1 file2 & file3 (如某個檔案不存在,則是建立一新的檔案) |
:e file2 ←載入 file2 |
:ls ←列出已載入的檔案,如列出的檔案中有〝%a〞表示目前正在編輯的檔案,〝#〞為上一次編輯的檔案 1 %a "file1" line 1 2 # "file2" line 0 3 "file3" line 0 |
HAMLET: To be, or not to be: that is the question: Whether 'tis nobler in the mind to suffer The slings and arrows of outrageous fortune, ↓按 <Ctrl+v>進入區塊編輯模式,移動游標即可反白的框起文字 Or to take arms against a sea of troubles, And by opposing end them? To die: to sleep; No more; and by a sleep to say we end The heart-ache and the thousand natural shocks That flesh is heir to, 'tis a consummation Devoutly to be wish'd. To die, to sleep; To sleep: perchance to dream: ay, there's the rub; For in that sleep of death what dreams may come When we have shuffled off this mortal coil, Must give us pause: there's the respect -- VISUAL BLOCK -- 82,39 36% |
80 # NOCACHE keeps man from creating cache pages ("cat pages") 81 # (generally one enables/disable cat page creation by creating/deleting 82 # the directory they would live in - man never does mkdir) 83 # 84 #NOCACHE 85 # 86 # Useful paths - note that COL should not be defined when 87 # NROFF is defined as "groff -Tascii" or "groff -Tlatin1"; 88 # not only is it superfluous, but it actually damages the output. 89 # For use with utf-8, NROFF should be "nroff -mandoc" without -T option. vi_practice 79,5 55% HAMLET: To be, or not to be: that is the question: Whether 'tis nobler in the mind to suffer The slings and arrows of outrageous fortune, Or to take arms against a sea of troubles, And by opposing end them? To die: to sleep; No more; and by a sleep to say we end The heart-ache and the thousand natural shocks That flesh is heir to, 'tis a consummation Devoutly to be wish'd. To die, to sleep; To sleep: perchance to dream: ay, there's the rub; For in that sleep of death what dreams may come hamlet.txt 82,39 36% |
Set | Default | Description |
---|---|---|
:set ai :set noai |
noai | 自動縮排(indentation)。 取消自動縮排。 |
:set all | 顯示目前所有的環境設定值。 | |
:set aw :set noaw |
noaw | 當編輯其他檔案時自動儲存目前的檔案。 當編輯其他檔案時不自動儲存目前的檔案。 |
:set bf :set nobf |
nobf | 不接受輸入的控制字元。 接受控制字元。 |
:set dir=tmp | dir = /tmp | 設定暫存檔的目錄。 |
:set eb :set noeb |
noeb | 錯誤訊息發出 beep 聲。 錯誤訊息不發出 beep 聲。 |
:set hlsearch :set nohlsearch |
hlsearch | 反白顯示搜尋時符合的文字。 不反白顯示搜尋時符合的文字。 |
:set ht= | ht = 8 | 設定水平定位(TAB)的空隔。 |
:set ic set noic |
noic | 搜尋時不管大小寫。 搜尋時大小寫有區別。 |
:set list :set nolist |
nolist | 水平定位顯示〝^I〞換行顯示〝$〞,CR顯示〝^M〞。 不顯示。 |
:set nu :set nonu |
nonu | 顯示行號。 不顯示行號。 |
:set ro :set noro |
noro | 把編輯中的檔案改成〝唯讀〞(read only)。 取消唯讀。 |
:set sh=shell_path | sh = /bin/sh | 設定 shell 路徑(錯誤的 shell 路徑會導致 :!COMMAND失效)。 |
:set fileencoding= | utf-8 | 設定 vim 的編碼格式。 |
:set fileformat= | unix | 有效的 file format 有〝unix〞,〝dos〞和〝mac〞,此會影響到換行的方式。 |
:set syntax= | 設定 vim 為何種語言編輯器 ,例如 html,c,cpp,java 等(所支援的程式語言記錄在 〝/usr/share/vim/vimXX/syntax〞)。 | |
:syntax off | 取消〝:set syntax=XXX〞的設定(XXX=html,c,cpp 等)。 |
<strong> Products </strong> <table cellpadding="3" border="1"> <tbody> :set syntax=html↵ Enter ←設定 vim 為 html 編輯器 |
^GCTRL V CTRL G ←按完<Ctrl>+V馬上再按 <Ctrl>+G 即可輸入控制字元〝BEL〞(以〝^G〞顯示) |
vim 輸入控制字元 | ||||
ASCII 十進制 | ASCII 十六進制 | 符號 | vi 顯示 | 按鍵 |
---|---|---|---|---|
000 | 00 | NULL | ^@ | <Ctrl>+@ |
001 | 01 | SOH | ^A | <Ctrl>+A |
002 | 02 | STX | ^B | <Ctrl>+B |
003 | 03 | ETX | ^C | <Ctrl>+C |
004 | 04 | EOT | ^D | <Ctrl>+D |
005 | 05 | ENQ | ^E | <Ctrl>+E |
006 | 06 | ACK | ^F | <Ctrl>+F |
007 | 07 | BEL | ^G | <Ctrl>+G |
008 | 08 | BS | ^H | <Ctrl>+H |
009 | 09 | HT | TAB | <Ctrl>+I |
010 | 0A | LF | <LF> | <Ctrl>+J |
011 | 0B | VT | <VT> | <Ctrl>+K |
012 | 0C | FF | <FF> | <Ctrl>+L |
013 | 0D | CR | <CR> | <Ctrl>+M |
014 | 0E | SO | ^N | <Ctrl>+N |
015 | 0F | SI | ^O | <Ctrl>+O |
016 | 10 | DLE | ^P | <Ctrl>+P |
017 | 11 | DC1 | ^Q | <Ctrl>+Q |
018 | 12 | DC2 | ^R | <Ctrl>+R |
019 | 13 | DC3 | ^S | <Ctrl>+S |
020 | 14 | DC4 | ^T | <Ctrl>+T |
021 | 15 | NAK | ^U | <Ctrl>+U |
022 | 16 | SYN | ^V | <Ctrl>+V |
023 | 17 | ETB | ^W | <Ctrl>+W |
024 | 18 | CAN | ^X | <Ctrl>+X |
025 | 19 | EM | ^Y | <Ctrl>+Y |
026 | 1A | SUB | ^Z | <ctrl>+Z |
027 | 1B | ESC | ^[ | <Ctrl>+<ESC> |
028 | 1C | FS | ^\ | <Ctrl>+\ |
029 | 1D | GS | ^] | <Ctrl>+] |
030 | 1E | RS | ^^ | <Ctrl>+6 (鍵盤〝T〞和〝Y〞中間上面的數字 〝6〞) |
031 | 1F | US | ^_ | <Ctrl>+_(〝_〞為 under-line) |
127 | 7F | DEL | ~ | <Ctrl>+? |
±CTRL V x b 1 ←按完<Ctrl>+V馬上再按 <x><b><1> 即可輸入〝±〞 |