vim 教學 安裝 一般 wsl(windows subsystem linux)已經有安裝了,可以打 vim 直接使用
Downloading Vim 可以挑選自己的平台版本
vim/vim-win32-installer 可以直接下載 windows 版本
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
CLI 安裝 依據提示把安裝路經新增到 PATH 的環境變數中
再輸入 nvim 就能直接啟動
也可以裝在 VSCode 上(參考 VSCode 必裝套件 的 vim 套件)
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
這邊有 VSCodeVim 介紹影片:
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
離開 vim :q 離開
:w 存檔
:wq 存檔離開
模式切換
i
鍵 insert 可以輸入打字,按 esc ( Ctrl+[
)離開 insert 模式
a
鍵 append 目前位置前面插入字串
o
鍵 new line 目前位置換到下一行
移動游標 h
左
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
j
下
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
k
上
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
l
右
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
w
往右
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
移動一個字(英文) 大寫 W
跳過逗點
b
往左
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
移動一個字(英文) 大寫 B
跳過逗點 {
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
與 }
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
跳左右一個段落 大寫 G
到文件底端
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
gg
到文件首頁
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
單行 0
行首
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
$
行尾
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
同區塊(文字過長自動換行)下一行 jg
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
上一行 gk
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
搜尋文字 – NORMAL – 模式下,打 /
/
會出現在左下
再打你要搜尋的文字(例如:sit)
畫面上符合的文字會反白(例如:sit)
按下 enter 後,游標就會跑到第一個 sit 上
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
如果沒有反白可以在 – NORMAL – 模式下,輸入 :set hlsearch
按下小寫 n
可以往下切換每個搜尋字串(例如:sit)
跳到最後一個會回到第一個
一直循環這個動作
按下大寫 N
可以往上切換每個搜尋字串(例如:sit)
跳到最頂個會回到最後一個
一直循環這個動作
?
同 /
只是按下 n
會反過來往上搜尋
在字串上按下 *
會自動反白游標上的字串為搜尋字串
在字串上按下 #
會自動反白游標上的字串為搜尋字串
按下小寫 n
會相反按下 *
搜尋的反方向
在 – NORMAL – 模式下,輸入 :set nohlsearch
可以關閉反白選取
按下小寫 f
後面再按 a 會往後跳到目前這行的 a 字串
按下大寫 F
後面再按 a 會往前跳到目前這行的 a 字串
游標移到某一行後,輸入 zz
選中的那行會置中在畫面上
同上按下 zb
選中的那行會在畫面下方
同上按下 zt
選中的那行會在畫面上方
選取、複製、貼上 按下小寫 v
進入 – VISUAL – 模式
此時游標移動到那裡
進入 – VISUAL – 模式的起點到目前的游標位置
都會被選取
複習一下上面的 移動游標
可以快速選取整塊的區域
按下大寫 V
會選取一整行且左下角會進入 – VISUAL LINE – 模式
每次選取都是一整行
反白指定字串後
按下 y
( =yank
)就能複製字串了
這邊按下 y
會複製到 register (暫存器)
不是複製到剪貼簿(只有一個會覆蓋剛剛的內容)
register 共有 48 個,其中 26 個可以自由使用(a-z)
按下 "ay
就是複製到 a 暫存器裡面(a-z)
:reg
可以檢視所有暫存器內容
按下 p
就能貼上字串了
按下 "ap
就是貼上到 a 暫存器裡面(a-z)內容到游標處
等同於有 26 個剪貼簿可以用
Image Not Showing
Possible Reasons
The image file may be corrupted The server hosting the image is unavailable The image path is incorrect The image format is not supported
Learn More →
但是複製到剪貼簿的內容
不會存在 vim 的暫存器中
不相通的
除非輸入設定 :set clipboard=unnamed
注意一下貼上的位置
假設游標在 ab 字串上的 a
貼上 123
會變成 a 123
b
複製一整行時,按下小寫 p
會貼在下一行
複製一整行時,按下大寫 P
會貼在上一行
貼錯位置可以按下 u
回到上一步
按下 ctrl + r 會 redo
按下 5p
就能連續貼上5次字串
要注意的是
不是在 – INSERT – 模式
才能貼上字串
按下 yy
複製目前游標那一整行
連選都不用選
按下 2yy
複製目前游標那兩行
按下 y$
複製目前游標到最後一個字串(參考上面的 移動游標
)
按下 yG
複製目前游標到文件底端最後一個字串(參考上面的 移動游標
)
要注意的是,在 – INSERT – 模式下,打字就好,不要移動
在 – NORMAL – 模式下,移動
在 – VISUAL – 模式下,選取
參考資料 Windows下Vim的安装与插件管理
高見龍 | 即將失傳的古老技藝 Vim
擁抱 Vim 讓你的時間不浪費在編輯上
在VSCode里面配置Vim正确姿势(细节解析)
vim、gvim 在 windows 下中文亂碼解決方案
set encoding=utf-8
set fileencodings=utf-8,chinese,latin-1
if has("win32" )
set fileencoding=chinese
else
set fileencoding=utf-8
endif
"解決選單亂碼
source $VIMRUNTIME /delmenu.vim
source $VIMRUNTIME /menu.vim
" 解決consle輸出亂碼
language messages zh_CN.utf-8