SlideShare a Scribd company logo
1 of 16
Vim簡介
SamChien (陳政謙)
Vim是什麼? 為什麼要學Vim?
• 一個文字(程式)編輯器
• 手指完全不用離開鍵盤
• 強大的編輯能力
• 支援 400種以上純文字檔案語法高亮
• 支援 40 種以上程式語言的自動縮排
• 客製化的設定使得使用上很有彈性
• 各種強大的Plugin可以加強功能
• 缺點: 不好學,預計練到上手至少要1~2個禮拜
• 不要放棄,學會後受用無窮
類Unix系統上的兩大編輯器
• Vim 和 Emacs
• 兩者都很多人用
• Emacs的小指傷害
• 詳細比較請參考wiki: 編輯器之戰
有誰用Vim?
• Jserv – 第一次自幹作業系統就上手
• Ryan Dahl - Introduction to Node.js
Vim安裝
• Ubuntu
– sudo apt-get install vim
• OS X
– 有內建 Vim 但是版本較舊,會導致一些Plugin
無法使用 ex: Youcompleteme
– 可用 homebrew 安裝
– brew install vim
Vim基本編輯指令
• 跟一般編輯器不一樣,打開亂按是打不出字的
• 首先要了解的: Vim的模式(mode),以下為比較
常用的三種
– Normal(一般模式)
– Insert(輸入模式)
– Visual(可視化模式)
• 打開 Vim 預設會在一般模式,按 i 進入輸入模
式,按Esc回到一般模式 (OS: 幹… 這三
小!@#$%^&*)
Vim基本編輯指令
• 搞那麼多模式幹嘛,為什麼不直接讓我好
好打字就好
• 告訴你一個秘密: 大部分的時間其實都在一
般模式而不是在輸入模式
• 原因: 增加游標的移動速度,在一般模式有
大量的快捷鍵可以使得游標快速跳到你想
要的位置
Vim基本編輯指令
• i -> 進入輸入模式
• Esc -> 回到一般模式
• :w -> 存檔
• :q -> 直接離開(不存檔)
• :wq -> 存檔離開
• :q! -> 不存檔強迫離開
• x -> 刪除當前字元
• dd -> 剪下當前行
• p -> 貼上
• hjkl -> 方向鍵分別為: 左, 下, 上, 右(當然也可以直接
用方向鍵,但是建議不要,有玩過CS都知道為什麼)
讓 Vim 開始有一點意思的指令
• a -> 在游標後面插入
• A -> 跳到行尾插入
• o -> 換行插入
• O -> 在上一行插入
• 0 -> 跳到行頭
• ^ -> 跳到第一個不是空白的行頭
• $ -> 跳到行尾
• g_ -> 跳到最後一個不是空白的行尾
• / -> 做字串搜尋(按n可以一直跳下一個, 按N可以往上跳一個)
• P -> 在上一行做貼上
• yy -> 拷貝這一行
• u -> 回到上一步
• Ctrl + r -> 回到下一步
讓Vim變得好玩的指令
• 數字 + 任何指令 = 這個指令做幾次
• Ex:
– 2dd -> 剪下2行
– 3p -> 貼上3次
• gg –> 跳到第一行
• G –> 跳到最後一行
• 數字gg –> 跳到特定行
• w –> 跳到下一個單字的開頭
• e –> 跳到單字的結尾
• W –> 跳到下一個單字的開頭(用空白分隔)
• E –> 跳到單字結尾(用空白分隔)
• % -> 跳到對應的括號(可適用在 () [] {}, 掛上Match it Plugin之後,連
html tag都能跳 )
• * -> 搜尋所有當前單字,並可以往下搜尋
• # ->搜尋所有當前單字,並可以往上搜尋
讓Vim變得好玩的指令
• v -> 可視化選擇,一定要會
• 可視化選擇 + u -> 把選取的區域變小寫
• 可視化選擇 + U -> 把選取的區域變大寫
• 可視化選擇 還可以結合其他指令達到複製, 剪下, 貼上, 取代等
效果
• f + 字母 -> 將游標跳到當前行的特定字母
• t + 字母 ->將游標跳到當前行的特定字母之前
• F和T與上述功能相同,只是方向相反
• vi + ‘ or “ or ( or [ or { -> 區域內選取
• :split 橫向螢幕切割
• :vsplit 縱向螢幕切割
• = -> 自動縮排
• Ctrl + v -> 區塊可視化選擇
話說最近一直在揪密室逃脫
有關.vimrc
• 在家目錄開一個檔案,檔名取叫 .vimrc ,vim在開啟時會去讀這
個設定檔
• 設定多到講不完…
• 幾個常用的:
• syntax on -> 開啟語法高亮
• set autoindent -> 開啟自動縮排
• set shiftwidth=數字 -> 設定縮排寬度為多少
• set tabstop=數字 -> 設定tab的寬度為多少
• set expandtab -> 將tab一律換成空白
• set number -> 開啟行數
• set ignorecase -> 搜尋忽略大小寫
• set hlsearch -> 高亮搜尋結果
• set incsearch -> 即時顯示搜尋結果
一些好用的Vim Plugin
• Vundle – 讓外掛非常好安裝
• Youcompleteme – 支援關鍵字補齊
• Ctrlp – 對子目錄進行模糊搜尋
• Match it – 可以讓%跳更多對應的符號 如:
html, ruby function
• Vim-powerline – 讓狀態列變漂亮
• Nerdtree – 顯示樹狀目錄(還可以新增檔案 ,
移動檔案等等)
謝謝大家,新年快樂,猴年行大運
(幹…犯太歲)
Q&A

More Related Content

Viewers also liked

Classroom rules
Classroom rules Classroom rules
Classroom rules bwieler
 
Product Portfolio - sample
Product Portfolio - sampleProduct Portfolio - sample
Product Portfolio - samplePeter Slusarczyk
 
Presentation to class
Presentation to classPresentation to class
Presentation to classLeahDixonxxx
 
Distribution and exhibiton reasearch media
Distribution and exhibiton reasearch mediaDistribution and exhibiton reasearch media
Distribution and exhibiton reasearch mediatomcoome
 
Ielts speaking-module
Ielts speaking-moduleIelts speaking-module
Ielts speaking-moduleDinh Thep
 
A3 B VILLAGE R3 R2 and commercial
A3  B  VILLAGE R3 R2 and commercial A3  B  VILLAGE R3 R2 and commercial
A3 B VILLAGE R3 R2 and commercial Phil Anstey
 

Viewers also liked (7)

Classroom rules
Classroom rules Classroom rules
Classroom rules
 
Product Portfolio - sample
Product Portfolio - sampleProduct Portfolio - sample
Product Portfolio - sample
 
Presentation to class
Presentation to classPresentation to class
Presentation to class
 
What Does NAPAC Do Now
What Does NAPAC Do NowWhat Does NAPAC Do Now
What Does NAPAC Do Now
 
Distribution and exhibiton reasearch media
Distribution and exhibiton reasearch mediaDistribution and exhibiton reasearch media
Distribution and exhibiton reasearch media
 
Ielts speaking-module
Ielts speaking-moduleIelts speaking-module
Ielts speaking-module
 
A3 B VILLAGE R3 R2 and commercial
A3  B  VILLAGE R3 R2 and commercial A3  B  VILLAGE R3 R2 and commercial
A3 B VILLAGE R3 R2 and commercial
 

Similar to Introduction to vim

Ch4 vi editor(2013 ncu-nos_nm)
Ch4    vi editor(2013 ncu-nos_nm)Ch4    vi editor(2013 ncu-nos_nm)
Ch4 vi editor(2013 ncu-nos_nm)Kir Chou
 
前端开发工具 - 编辑器篇
前端开发工具 - 编辑器篇前端开发工具 - 编辑器篇
前端开发工具 - 编辑器篇keelii
 
Effective_Vim
Effective_VimEffective_Vim
Effective_VimKing Hom
 
Command line 初級寶典
Command line 初級寶典Command line 初級寶典
Command line 初級寶典Tom Chen
 
VIM入门与进阶
VIM入门与进阶VIM入门与进阶
VIM入门与进阶pan weizeng
 
Automate with Ansible basic (2/e)
Automate with Ansible basic (2/e)Automate with Ansible basic (2/e)
Automate with Ansible basic (2/e)Chu-Siang Lai
 
6, vim
6, vim6, vim
6, vimted-xu
 
Vim hacks
Vim hacksVim hacks
Vim hacksXuYj
 
COSCUP 2016 - LLVM 由淺入淺
COSCUP 2016 - LLVM 由淺入淺COSCUP 2016 - LLVM 由淺入淺
COSCUP 2016 - LLVM 由淺入淺宗凡 楊
 
COSCUP2016 - LLVM框架、由淺入淺
COSCUP2016 - LLVM框架、由淺入淺COSCUP2016 - LLVM框架、由淺入淺
COSCUP2016 - LLVM框架、由淺入淺hydai
 

Similar to Introduction to vim (10)

Ch4 vi editor(2013 ncu-nos_nm)
Ch4    vi editor(2013 ncu-nos_nm)Ch4    vi editor(2013 ncu-nos_nm)
Ch4 vi editor(2013 ncu-nos_nm)
 
前端开发工具 - 编辑器篇
前端开发工具 - 编辑器篇前端开发工具 - 编辑器篇
前端开发工具 - 编辑器篇
 
Effective_Vim
Effective_VimEffective_Vim
Effective_Vim
 
Command line 初級寶典
Command line 初級寶典Command line 初級寶典
Command line 初級寶典
 
VIM入门与进阶
VIM入门与进阶VIM入门与进阶
VIM入门与进阶
 
Automate with Ansible basic (2/e)
Automate with Ansible basic (2/e)Automate with Ansible basic (2/e)
Automate with Ansible basic (2/e)
 
6, vim
6, vim6, vim
6, vim
 
Vim hacks
Vim hacksVim hacks
Vim hacks
 
COSCUP 2016 - LLVM 由淺入淺
COSCUP 2016 - LLVM 由淺入淺COSCUP 2016 - LLVM 由淺入淺
COSCUP 2016 - LLVM 由淺入淺
 
COSCUP2016 - LLVM框架、由淺入淺
COSCUP2016 - LLVM框架、由淺入淺COSCUP2016 - LLVM框架、由淺入淺
COSCUP2016 - LLVM框架、由淺入淺
 

More from 政謙 陳

On sum edge coloring of regular, bipartite and split graphs
On sum edge coloring of regular,  bipartite and split graphsOn sum edge coloring of regular,  bipartite and split graphs
On sum edge coloring of regular, bipartite and split graphs政謙 陳
 
Independent domination in finitely defined classes of graphs polynomial algor...
Independent domination in finitely defined classes of graphs polynomial algor...Independent domination in finitely defined classes of graphs polynomial algor...
Independent domination in finitely defined classes of graphs polynomial algor...政謙 陳
 
Distance domination, guarding and covering of maximal outerplanar graphs
Distance domination, guarding and covering of maximal outerplanar graphsDistance domination, guarding and covering of maximal outerplanar graphs
Distance domination, guarding and covering of maximal outerplanar graphs政謙 陳
 
Approximation algorithms for clique transversals on some graph classes
Approximation algorithms for clique transversals on some graph classesApproximation algorithms for clique transversals on some graph classes
Approximation algorithms for clique transversals on some graph classes政謙 陳
 
A tabu search algorithm for the min max k-chinese postman problem
A tabu search algorithm for the min max k-chinese postman problemA tabu search algorithm for the min max k-chinese postman problem
A tabu search algorithm for the min max k-chinese postman problem政謙 陳
 
A short proof of konigs matching theorem
A short proof of konigs matching theoremA short proof of konigs matching theorem
A short proof of konigs matching theorem政謙 陳
 

More from 政謙 陳 (6)

On sum edge coloring of regular, bipartite and split graphs
On sum edge coloring of regular,  bipartite and split graphsOn sum edge coloring of regular,  bipartite and split graphs
On sum edge coloring of regular, bipartite and split graphs
 
Independent domination in finitely defined classes of graphs polynomial algor...
Independent domination in finitely defined classes of graphs polynomial algor...Independent domination in finitely defined classes of graphs polynomial algor...
Independent domination in finitely defined classes of graphs polynomial algor...
 
Distance domination, guarding and covering of maximal outerplanar graphs
Distance domination, guarding and covering of maximal outerplanar graphsDistance domination, guarding and covering of maximal outerplanar graphs
Distance domination, guarding and covering of maximal outerplanar graphs
 
Approximation algorithms for clique transversals on some graph classes
Approximation algorithms for clique transversals on some graph classesApproximation algorithms for clique transversals on some graph classes
Approximation algorithms for clique transversals on some graph classes
 
A tabu search algorithm for the min max k-chinese postman problem
A tabu search algorithm for the min max k-chinese postman problemA tabu search algorithm for the min max k-chinese postman problem
A tabu search algorithm for the min max k-chinese postman problem
 
A short proof of konigs matching theorem
A short proof of konigs matching theoremA short proof of konigs matching theorem
A short proof of konigs matching theorem
 

Introduction to vim

  • 2. Vim是什麼? 為什麼要學Vim? • 一個文字(程式)編輯器 • 手指完全不用離開鍵盤 • 強大的編輯能力 • 支援 400種以上純文字檔案語法高亮 • 支援 40 種以上程式語言的自動縮排 • 客製化的設定使得使用上很有彈性 • 各種強大的Plugin可以加強功能 • 缺點: 不好學,預計練到上手至少要1~2個禮拜 • 不要放棄,學會後受用無窮
  • 3. 類Unix系統上的兩大編輯器 • Vim 和 Emacs • 兩者都很多人用 • Emacs的小指傷害 • 詳細比較請參考wiki: 編輯器之戰
  • 4. 有誰用Vim? • Jserv – 第一次自幹作業系統就上手 • Ryan Dahl - Introduction to Node.js
  • 5. Vim安裝 • Ubuntu – sudo apt-get install vim • OS X – 有內建 Vim 但是版本較舊,會導致一些Plugin 無法使用 ex: Youcompleteme – 可用 homebrew 安裝 – brew install vim
  • 6. Vim基本編輯指令 • 跟一般編輯器不一樣,打開亂按是打不出字的 • 首先要了解的: Vim的模式(mode),以下為比較 常用的三種 – Normal(一般模式) – Insert(輸入模式) – Visual(可視化模式) • 打開 Vim 預設會在一般模式,按 i 進入輸入模 式,按Esc回到一般模式 (OS: 幹… 這三 小!@#$%^&*)
  • 7. Vim基本編輯指令 • 搞那麼多模式幹嘛,為什麼不直接讓我好 好打字就好 • 告訴你一個秘密: 大部分的時間其實都在一 般模式而不是在輸入模式 • 原因: 增加游標的移動速度,在一般模式有 大量的快捷鍵可以使得游標快速跳到你想 要的位置
  • 8. Vim基本編輯指令 • i -> 進入輸入模式 • Esc -> 回到一般模式 • :w -> 存檔 • :q -> 直接離開(不存檔) • :wq -> 存檔離開 • :q! -> 不存檔強迫離開 • x -> 刪除當前字元 • dd -> 剪下當前行 • p -> 貼上 • hjkl -> 方向鍵分別為: 左, 下, 上, 右(當然也可以直接 用方向鍵,但是建議不要,有玩過CS都知道為什麼)
  • 9. 讓 Vim 開始有一點意思的指令 • a -> 在游標後面插入 • A -> 跳到行尾插入 • o -> 換行插入 • O -> 在上一行插入 • 0 -> 跳到行頭 • ^ -> 跳到第一個不是空白的行頭 • $ -> 跳到行尾 • g_ -> 跳到最後一個不是空白的行尾 • / -> 做字串搜尋(按n可以一直跳下一個, 按N可以往上跳一個) • P -> 在上一行做貼上 • yy -> 拷貝這一行 • u -> 回到上一步 • Ctrl + r -> 回到下一步
  • 10. 讓Vim變得好玩的指令 • 數字 + 任何指令 = 這個指令做幾次 • Ex: – 2dd -> 剪下2行 – 3p -> 貼上3次 • gg –> 跳到第一行 • G –> 跳到最後一行 • 數字gg –> 跳到特定行 • w –> 跳到下一個單字的開頭 • e –> 跳到單字的結尾 • W –> 跳到下一個單字的開頭(用空白分隔) • E –> 跳到單字結尾(用空白分隔) • % -> 跳到對應的括號(可適用在 () [] {}, 掛上Match it Plugin之後,連 html tag都能跳 ) • * -> 搜尋所有當前單字,並可以往下搜尋 • # ->搜尋所有當前單字,並可以往上搜尋
  • 11. 讓Vim變得好玩的指令 • v -> 可視化選擇,一定要會 • 可視化選擇 + u -> 把選取的區域變小寫 • 可視化選擇 + U -> 把選取的區域變大寫 • 可視化選擇 還可以結合其他指令達到複製, 剪下, 貼上, 取代等 效果 • f + 字母 -> 將游標跳到當前行的特定字母 • t + 字母 ->將游標跳到當前行的特定字母之前 • F和T與上述功能相同,只是方向相反 • vi + ‘ or “ or ( or [ or { -> 區域內選取 • :split 橫向螢幕切割 • :vsplit 縱向螢幕切割 • = -> 自動縮排 • Ctrl + v -> 區塊可視化選擇
  • 13. 有關.vimrc • 在家目錄開一個檔案,檔名取叫 .vimrc ,vim在開啟時會去讀這 個設定檔 • 設定多到講不完… • 幾個常用的: • syntax on -> 開啟語法高亮 • set autoindent -> 開啟自動縮排 • set shiftwidth=數字 -> 設定縮排寬度為多少 • set tabstop=數字 -> 設定tab的寬度為多少 • set expandtab -> 將tab一律換成空白 • set number -> 開啟行數 • set ignorecase -> 搜尋忽略大小寫 • set hlsearch -> 高亮搜尋結果 • set incsearch -> 即時顯示搜尋結果
  • 14. 一些好用的Vim Plugin • Vundle – 讓外掛非常好安裝 • Youcompleteme – 支援關鍵字補齊 • Ctrlp – 對子目錄進行模糊搜尋 • Match it – 可以讓%跳更多對應的符號 如: html, ruby function • Vim-powerline – 讓狀態列變漂亮 • Nerdtree – 顯示樹狀目錄(還可以新增檔案 , 移動檔案等等)
  • 16. Q&A