Vim session

NO IMAGE
1 Star2 Stars3 Stars4 Stars5 Stars 給文章打分!
Loading...

vimtutor

intro

  1. vim history (where I can use vim, vi, git diff)
  2. how to install vim on atom/vs/chrome/terminal
  3. edit a file with vi
  4. vim/unix shortcut
  5. vim tips

vim vs other editors

so fast and lite
can open big file
write code without mouse
pipe(compose) everything (command, text)

related

http://www.vim.org/
http://www.openvim.com/

VIM 練級攻略
http://coolshell.cn/articles/…

vim cheatsheet
https://kapeli.com/cheat_shee…

vim notes
http://www.boydwang.com/2016/…

vimscript
http://learnvimscriptthehardw…

vim skills
http://vimcasts.org/

vim tips
http://vim.wikia.com/wiki/Bes…

meet surround
https://github.com/tpope/vim-…

Vim 的縱向編輯模式

Demo:
10.1.5.214
10.1.5.212
10.1.5.210
->
ping -c 4 10.5.5.214 >> result0
ping -c 4 10.5.5.212 >> result0
ping -c 4 10.5.5.210 >> result0

Solution:

  • 第一步:修改

將 IP 數列中第二段所有數字“1” 修改為“5”,將遊標定位第一個行的“1”,ctrl-v 進入縱向編輯模式,G 移動遊標到最後一行,可視塊覆蓋所要修改的列,r 進入修改模式, 輸入數字“5”

  • 第二步:前新增

在所有行之前新增“ping – c 4 ”,將遊標定位到第一行第一列,ctrl-v 進入縱向編輯模式,G 移動遊標到最後一行第一列,可視塊覆蓋了第一列, I 進入行首插入模式,輸入所要求字元“ping – c 4

  • 第三步:後新增“>> result0”:

將遊標定位到第一行最後一列, ctrl-v 進入縱向編輯模式, G 移動遊標到最後一行最後一列,覆蓋了最後一列, A 進入行尾插入模式輸入所要求字元“>> result0”
以上三個步驟有一個共同特點,就是都縱向為編輯方向

vim class1 -basic motions and commands

vim class2 巨集

  • g g (go to beginning)
  • G(jump to the end of file)
  • shift z z (= Esc : wq)
  • Esc q ! (force quit)
  • Esc(ctrl c)

Mode

  • Insert
  • Normal
  • Command(:w filename – save the file)
  • Visual

Insert -> Normal : ESC/Ctrl [ Insert -> Command : (Insert -> Normal) -> : Command -> Normal : Enter
Pen to the page

(i=insert、a=append、r=replace)

  • i-Enter insert mode at cursor
  • I-Enter insert mode at first non-blank character
  • a-Enter insert mode after cursor
  • A-Enter insert mode at the end of the line
  • o-Enter insert mode on the next line
  • O-Enter insert mode on the previous line
  • s-Delete character under cursor and enter insert mode
  • S-Delete line and begin insert at beginning of same line
  • C-Delete from cursor to end of line and begin insert

Scanning the canvas

——k

h———–L

——j
2j(move down two lines)
Basics

  • w – Forward to the beginning of next word(Example, cw-change word, diw-delete word)
  • W-Forward to the beginning of next WORD(after whiteSpace)
  • b-Backward to the next beginning of a word
  • B-Backward to the next beginning of a WORD
  • e-Forword to the next end of word
  • E-Forword to the next end of WORD
  • 0/home-Move to the zeroth character of the line
  • $-Move to the last character of the line
  • ^-Move to the first non-blank character of the line
  • H-游標移到當前螢幕最上方行的第一個字元
  • M-游標移到當前螢幕最中間行的第一個字元
  • L-游標移到當前螢幕最下方行的第一個字元
  • G-到此檔案最後一行
  • nG-移動到第n行
  • gg-相當於1G, 即回到行首

塊操作(ctrl v)

  • ctrl v(開啟塊操作)
  • hjkl移動游標
  • I— (插入—)
  • ESC鍵來使每一行生效

n Enter – 游標下移n行

  1. [n]f – Forward until (nth)(o) (Inclusive)
  2. [n]F – Backward until (nth)(o) (Inclusive)
  3. [n]t – Forward until (nth)(o) (Exclusive)
  4. [n]T – Backward until (nth)(o) (Exclusive)

Search:

  • / search forward
  • ? search backward
  • ‘*’ 聚焦當前cursor forword(bounded)
  • n-next result, forward
  • N-next result, backward
  • ‘#’ 當前cursor下的指令 backward(bounded)

:set ignorecase — will search ignore case /c forward — will case insensitive to find forward
Replace

  • :%s/foo/bar/g (在當前檔案查詢foo替換成bar)
  • :s/foo/bar/g (在當前行查詢foo替換成bar)
  • :%s/foo/bar/gc
  • :%s/<foo>/bar/gci/I (foo only whole words, ask for confirmation, case insensitive/sensitive)
  • n1,n2s/foo/bar/g(在n1行n2行查詢foo替換成bar)

Copy/Paste

  • y-Yank. Example: 2yy(copy current two lines)
  • p-將已複製的貼上到游標所在下一行
  • P-將已複製的貼上到游標所在上一行
  • v-visual selection

Delete:

  • x/X 刪除游標處字元, 游標前的字元
  • dd(刪除所在行)
  • ndd(刪除游標所在行以下n行)
  • d1G(刪除游標所在行到第一行所有資料)
  • dG(刪除游標所在行到最後一行所有資料)
  • d$(刪除游標所在行到同行最後一個字元)
  • d0(刪除游標所在行到同行第一個字元)
  • :1,8d(刪除1~8行) OR VggGd

Undo

  • u恢復前一次所做的刪除
  • ctrl R (undo change)
  • .(重複上一個操作)

Scroll

  • ctrl f(螢幕向上滾動一頁)
  • ctrl b(螢幕向下滾動一頁)
  • ctrl u(螢幕向下滾動半頁)
  • ctrl d(螢幕向下滾動半頁)

ifb

  • i向兩側擴張選擇能match的string,Example,(, {, [
  • f/t向左側擴張選擇, cursor就在當前character下/前
  • b向右側擴充套件選擇 Example:yiw(delete word)

vim symmary |

動詞 y p d
操作 i f b
選擇 ( ) sentence(.)
選擇 { } paragraphs(empty line)
選擇 [[ ]] section
format =
convenient

  • zz center window
  • ” y copy to system clipboard
  • *(search word)
  • :reg (look history copy record)
  • % (go to last matched braket)

VS

  • ctrl ‘-‘(last cursor)
  • ctrl y(undo change in vs)

System

  • cmd ctrl f (maximum screen)

vim tips

:g/^/m0: reverse all lines http://vim.wikia.com/wiki/Rev…
= (indent)
copy to system clipboard " y
clibboard history (:reg) “number p

相關文章

軟體開發工具 最新文章