SlideShare una empresa de Scribd logo
1 de 42
Descargar para leer sin conexión
由淺入淺
hydai@htcg 2015/11/8
哈秋 <3
hachu.cat
hydai
我叫海帶,可以吃的那種
你可以透過下⾯面的⽅方式找到我
hydai@gapp.nthu.edu.tw
@hydai on GitHub
本投影⽚片採⽤用以下授權
簡單介紹⼀一下來歷
傳說中的編輯器之神
▸ ⽂文字編輯器
▸ 基本上不需要滑⿏鼠就可以操作
▸ ⾼高度客製化,想怎麼改就怎麼改
▸ ⼀一堆神奇的 Plugin 更加強化功能
▸ 多數的⼯工作站上有機會遇⾒見他
▸ 學習曲線,頗陡
$ vim # 開啟 vim
$ vim file # 開啟 file
介紹 vim mode
Normal mode
Start
i,I,a,A,o,O
Insert mode
<ESC>
Bottom-line
mode
: <ENTER>
⼀一進⼊入是 normal mode
按下 i 進⼊入 insert mode
按下 <ESC> 回到 normal mode
按下 : 進⼊入 bottom-line mode
在 normal mode 移動游標
C-f Page up
C-b Page down
C-u Half page up
C-d Half page down
gg 移到檔案開頭
G 移到檔案結尾
zz 將游標所在該⾏行
移動到螢幕中間
numG 移到第 num ⾏行
在 normal mode ⽂文字處理
x delete
X backspace
dd 刪除或剪下游標在的那⼀一⾏行
yy 複製游標在的那⼀一⾏行
p 貼上前⼀一個剪下或複製的值
u undo
C-r redo
存檔離開
:w 存檔
:q 離開
:wq 存檔並離開
:q! 強⾏行離開,會遺失為儲存的資料
搜尋字串
/string 往後搜尋字串
?string 往前搜尋字串
n 前往下⼀一個結果
N 前往上⼀一個結果
分割視窗
:split ⽔水平分割
:split file 將開啟檔案放到⽔水平分割視窗中
:vsplit 垂直分割
:vsplit 將開啟檔案放到垂直分割視窗中
C-w hjkl 移動游標到哪個分割視窗中
看起來很醜難⽤用呀?
真的是編輯器之神?
你可能會這樣想
你沒裝插件、沒客制化
當然不夠好⽤用囉~
不可質疑 Vim ⼤大神
撰寫你⾃自⼰己的 vimrc 吧!
vimrc 通常會放在你的家⺫⽬目錄
好⽐比說 /home/hydai/.vimrc
vim 有許多的功能選項
可以直接從 bottom-line mode
那邊進⾏行輸⼊入
寫⼊入 vimrc 則為⼀一啟動就載⼊入這些設定
General 設定
" 這是註解
filetype plugin indent on "偵測檔案格式
syntax on "syntax highlight
scriptencoding utf8 "設定編碼 utf8
set mouse=a "開啟滑⿏鼠模式
set background=dark "以深⾊色為底
Vim UI 設定
set number "顯⽰示⾏行號
set showmode "顯⽰示⺫⽬目前模式
set cursorline "在當前⾏行下顯⽰示標記
" 以下兩⾏行會更加 highlight 當前⾏行
highlight clear SignColumn
highlight clear LineNr
Vim UI 設定 - con't
set showcmd "顯⽰示輸⼊入的指令
set showmatch "對應的括弧
set hlsearch "highlight search
set smartcase "同下
set ignorecase "忽略⼤大⼩小寫搜尋
Vim Formatting 設定
set autoindent "⾃自動縮排
set smartindent "智慧縮排
set shiftwidth=4 "讓縮排是四格空⽩白
set tabstop=4 "內縮是四個欄位
set softtabstop=4 "backspace可刪除tab
Vim Formatting 設定
set expandtab "⽤用空⽩白取代 tab
autocmd FileType make setlocal noexpandtab
"上⾯面這⾏行是為了編輯 makefile 時保持使⽤用 tab
Key binding 設定 (leader)
let mapleader = ',' " 讓 , 作為指令的開頭
" Toggle highlight search
nmap <leader>/ :set hlsearch! hlsearch?<CR>
" Toggle paste mode
nmap <leader>p :set invpaste paste?<CR>
Key binding 設定 (indent)
" Visual shifting
vnoremap < <gv
vnoremap > >gv
⽅方便的設定
" 開啟檔案可以回到上次離開的游標位置
autocmd BufReadPost * if line("'"") > 1 &&
line("'"") <= line("$") | exe "normal! g`"" | endif
" 能標記出怪怪的空⽩白位置
set list
set listchars=tab:› ,trail:•,extends:#,nbsp:.
看了這麼多可怕的東⻄西
還沒加上插件喔( ̄▽ ̄)
覺得疲憊了嗎?
使⽤用 Vundle 來做套件管理吧!
很久很久以前,
裝套件是直接把插件的檔案放進去某個特定位置
要控管、要升級都算是⼀一個⼩小⼩小的惡夢
於是有⼈人做出了裝備介⾯面,讓⼤大家可以輕鬆處理
在這麼多套套件管理的⼯工具,我選擇 Vundle
他使⽤用上算是直覺的⼯工具
起⼿手式 - 安裝 Vundle
$ git clone https://github.com/VundleVim/
Vundle.vim.git ~/.vim/bundle/Vundle.vim
接著要進去你的 vimrc 中把設定檔案放好喔!
替 Vundle 設定 vimrc
set nocompatible " required
filetype off " required
set rtp+=~/.vim/bundle/Vundle.vim " Vundle 路徑
call vundle#begin() " 以下放你想裝的 Plugin
Plugin 'VundleVim/Vundle.vim' " Vundle 控管⾃自⼰己
Plugin 'L9' " Vim script library
call vundle#end() " 以上放你想裝的 Plugin
安裝 Plugin 吧!
把剛才的 vimrc 存檔以後,再重新開啟
打上 :PluginInstall
他就會開始幫你裝囉
NERDTree
nmap <leader>t :NERDTreeToggle<CR> " 快速開啟
NERDCommenter
註解該⾏行 <leader>cc
解除註解該⾏行 <leader>cu
直接 DEMO
syntastic
幫你做語法檢查,要加上下⾯面的設定,直接 DEMO
ctrlp - 快速開檔案
可惜 c-p 太常⽤用,我會改⽤用nnoremap <c-> :CtrlP<CR>
airline - 下⾯面那條 status bar
airline - 下⾯面那條 status bar
solarized - 好看的color schema
要設定成 256 ⾊色,不然會醜醜的QQ
下⾯面的順序要放對,不然看起來會怪怪的
Code snippet
幫你補完各種常⽤用的 code block
需要裝下⾯面三個插件
超強⼤大⾃自動補完
裝下⾯面這三個套件,還需要加上些設定
資源推薦
▸ 強⼤大插件整理區 Vim awesome
▸ http://vimawesome.com/
▸ Vim 內建的教學
▸ :help
▸ 超絕懶⼈人包
▸ https://github.com/spf13/spf13-vim
▸ vgod 的 Vim ⼊入⾨門圖解
▸ http://blog.vgod.tw/2009/12/08/vim-cheat-sheet-for-
programmers/

Más contenido relacionado

La actualidad más candente

Bash shell script 教學
Bash shell script 教學Bash shell script 教學
Bash shell script 教學Ming-Sian Lin
 
在開始工作以前,我以為我會寫扣。
在開始工作以前,我以為我會寫扣。在開始工作以前,我以為我會寫扣。
在開始工作以前,我以為我會寫扣。Chih-Hsuan Kuo
 
Command line 初級寶典
Command line 初級寶典Command line 初級寶典
Command line 初級寶典Tom Chen
 
常用Mac/Linux命令分享
常用Mac/Linux命令分享常用Mac/Linux命令分享
常用Mac/Linux命令分享Yihua Huang
 
VIM入门与进阶
VIM入门与进阶VIM入门与进阶
VIM入门与进阶pan weizeng
 
Node.js开发体验
Node.js开发体验Node.js开发体验
Node.js开发体验QLeelulu
 
Introduction to FreeBSD commands
Introduction to FreeBSD commandsIntroduction to FreeBSD commands
Introduction to FreeBSD commands郁凱 黃
 
Open Street Map安裝指引 (Ubuntu 12.04)
Open Street Map安裝指引 (Ubuntu 12.04)Open Street Map安裝指引 (Ubuntu 12.04)
Open Street Map安裝指引 (Ubuntu 12.04)Marc Huang
 

La actualidad más candente (8)

Bash shell script 教學
Bash shell script 教學Bash shell script 教學
Bash shell script 教學
 
在開始工作以前,我以為我會寫扣。
在開始工作以前,我以為我會寫扣。在開始工作以前,我以為我會寫扣。
在開始工作以前,我以為我會寫扣。
 
Command line 初級寶典
Command line 初級寶典Command line 初級寶典
Command line 初級寶典
 
常用Mac/Linux命令分享
常用Mac/Linux命令分享常用Mac/Linux命令分享
常用Mac/Linux命令分享
 
VIM入门与进阶
VIM入门与进阶VIM入门与进阶
VIM入门与进阶
 
Node.js开发体验
Node.js开发体验Node.js开发体验
Node.js开发体验
 
Introduction to FreeBSD commands
Introduction to FreeBSD commandsIntroduction to FreeBSD commands
Introduction to FreeBSD commands
 
Open Street Map安裝指引 (Ubuntu 12.04)
Open Street Map安裝指引 (Ubuntu 12.04)Open Street Map安裝指引 (Ubuntu 12.04)
Open Street Map安裝指引 (Ubuntu 12.04)
 

Similar a Vim 由淺入淺

use Nagios on openSUSE 11.4
use Nagios on openSUSE 11.4use Nagios on openSUSE 11.4
use Nagios on openSUSE 11.4welong
 
Vim hacks
Vim hacksVim hacks
Vim hacksXuYj
 
Effective linux.1.(commandline)
Effective linux.1.(commandline)Effective linux.1.(commandline)
Effective linux.1.(commandline)wang hongjiang
 
Visual Studio Code 快速上手指南
Visual Studio Code 快速上手指南Visual Studio Code 快速上手指南
Visual Studio Code 快速上手指南Shengyou Fan
 
Vim get start_1.0
Vim get start_1.0Vim get start_1.0
Vim get start_1.0longhao
 
Developer Student Clubs NUK - Web Fundamentals
Developer Student Clubs NUK - Web FundamentalsDeveloper Student Clubs NUK - Web Fundamentals
Developer Student Clubs NUK - Web FundamentalsJiaxuan Lin
 
現代 IT 人一定要知道的 Ansible 自動化組態技巧
現代 IT 人一定要知道的 Ansible 自動化組態技巧現代 IT 人一定要知道的 Ansible 自動化組態技巧
現代 IT 人一定要知道的 Ansible 自動化組態技巧Chu-Siang Lai
 
手把手教你把Vim改装成一个IDE编程环境(图文)
手把手教你把Vim改装成一个IDE编程环境(图文)手把手教你把Vim改装成一个IDE编程环境(图文)
手把手教你把Vim改装成一个IDE编程环境(图文)King Hom
 
深入剖析浏览器
深入剖析浏览器深入剖析浏览器
深入剖析浏览器jay li
 
版本控制 使用Git & git hub
版本控制   使用Git & git hub版本控制   使用Git & git hub
版本控制 使用Git & git hub維佋 唐
 
大家應該都要會的工具 Git 從放棄到會用1-基礎篇
大家應該都要會的工具 Git   從放棄到會用1-基礎篇大家應該都要會的工具 Git   從放棄到會用1-基礎篇
大家應該都要會的工具 Git 從放棄到會用1-基礎篇Alan Tsai
 

Similar a Vim 由淺入淺 (12)

use Nagios on openSUSE 11.4
use Nagios on openSUSE 11.4use Nagios on openSUSE 11.4
use Nagios on openSUSE 11.4
 
Vim hacks
Vim hacksVim hacks
Vim hacks
 
Effective linux.1.(commandline)
Effective linux.1.(commandline)Effective linux.1.(commandline)
Effective linux.1.(commandline)
 
Visual Studio Code 快速上手指南
Visual Studio Code 快速上手指南Visual Studio Code 快速上手指南
Visual Studio Code 快速上手指南
 
Vim get start_1.0
Vim get start_1.0Vim get start_1.0
Vim get start_1.0
 
Developer Student Clubs NUK - Web Fundamentals
Developer Student Clubs NUK - Web FundamentalsDeveloper Student Clubs NUK - Web Fundamentals
Developer Student Clubs NUK - Web Fundamentals
 
現代 IT 人一定要知道的 Ansible 自動化組態技巧
現代 IT 人一定要知道的 Ansible 自動化組態技巧現代 IT 人一定要知道的 Ansible 自動化組態技巧
現代 IT 人一定要知道的 Ansible 自動化組態技巧
 
手把手教你把Vim改装成一个IDE编程环境(图文)
手把手教你把Vim改装成一个IDE编程环境(图文)手把手教你把Vim改装成一个IDE编程环境(图文)
手把手教你把Vim改装成一个IDE编程环境(图文)
 
深入剖析浏览器
深入剖析浏览器深入剖析浏览器
深入剖析浏览器
 
Work with Vim
Work with VimWork with Vim
Work with Vim
 
版本控制 使用Git & git hub
版本控制   使用Git & git hub版本控制   使用Git & git hub
版本控制 使用Git & git hub
 
大家應該都要會的工具 Git 從放棄到會用1-基礎篇
大家應該都要會的工具 Git   從放棄到會用1-基礎篇大家應該都要會的工具 Git   從放棄到會用1-基礎篇
大家應該都要會的工具 Git 從放棄到會用1-基礎篇
 

Más de hydai

Introduction to Ewasm - crosslink taipei 2019
Introduction to Ewasm - crosslink taipei 2019Introduction to Ewasm - crosslink taipei 2019
Introduction to Ewasm - crosslink taipei 2019hydai
 
Introduction to ewasm
Introduction to ewasmIntroduction to ewasm
Introduction to ewasmhydai
 
Lity - 讓你更安全的 Smart Contract Language
Lity - 讓你更安全的 Smart Contract LanguageLity - 讓你更安全的 Smart Contract Language
Lity - 讓你更安全的 Smart Contract Languagehydai
 
COSCUP2016 - LLVM框架、由淺入淺
COSCUP2016 - LLVM框架、由淺入淺COSCUP2016 - LLVM框架、由淺入淺
COSCUP2016 - LLVM框架、由淺入淺hydai
 
連哈秋都懂的Git教學
連哈秋都懂的Git教學連哈秋都懂的Git教學
連哈秋都懂的Git教學hydai
 
Slack&typora
Slack&typoraSlack&typora
Slack&typorahydai
 

Más de hydai (6)

Introduction to Ewasm - crosslink taipei 2019
Introduction to Ewasm - crosslink taipei 2019Introduction to Ewasm - crosslink taipei 2019
Introduction to Ewasm - crosslink taipei 2019
 
Introduction to ewasm
Introduction to ewasmIntroduction to ewasm
Introduction to ewasm
 
Lity - 讓你更安全的 Smart Contract Language
Lity - 讓你更安全的 Smart Contract LanguageLity - 讓你更安全的 Smart Contract Language
Lity - 讓你更安全的 Smart Contract Language
 
COSCUP2016 - LLVM框架、由淺入淺
COSCUP2016 - LLVM框架、由淺入淺COSCUP2016 - LLVM框架、由淺入淺
COSCUP2016 - LLVM框架、由淺入淺
 
連哈秋都懂的Git教學
連哈秋都懂的Git教學連哈秋都懂的Git教學
連哈秋都懂的Git教學
 
Slack&typora
Slack&typoraSlack&typora
Slack&typora
 

Vim 由淺入淺