Vim session

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)html

related

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

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

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

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

vimscript
http://learnvimscriptthehardw...canvas

vim skills
http://vimcasts.org/vim

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

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

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 >> result0atom

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 "+yclibboard history (:reg) "number p

相關文章
相關標籤/搜索