Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學

Vim 核心命令速查與最小化配置入門

編輯:Linux 系統常見問題解答

三大模式切換

  • Normal 模式:啟動默認,輸入命令。Esc 從任意模式返回。
  • Insert 模式:i(光標前)、a(光標後)、o(下行)、O(上行)、I(行首)、A(行尾) 進入。
  • Command-line 模式:: 進入,執行保存、退出、替換、搜索等 Ex 命令。

Normal 模式核心操作

操作鍵位備註
光標移動h/j/k/l (左/下/上/右)數字前綴加速,如 10j
單詞跳轉w(下一詞首) b(上一詞首) e(詞尾)
行首/尾0 / $
文件首/尾gg / G
翻頁Ctrl+f / Ctrl+b
刪除字符x (光標下) X (光標前)
刪除單詞/行dw / ddD = d$
復制/粘貼yy / p(後) P(前)Y = yy
撤銷/重做u / Ctrl+r
搜索/pattern (向下) ?pattern (向上)n/N 下一個/上一個
可視模式v(字符) V(行) Ctrl+v(塊)配合 d/y/c 操作選區

Command-line 必知命令

:w          保存:w file     另存為:q          退出 (無修改):q!         強制退出:wq / :x    保存並退出:set nu      顯示行號:set nonu    隱藏行號:%s/old/new/g  全文替換:!cmd       執行 Shell 命令

最小化 ~/.vimrc 推薦

set nocompatible    " 關閉 vi 兼容模式set number          " 顯示行號set relativenumber  " 相對行號 (配合 dj/k 快速移動)set cursorline      " 高亮當前行set wrap            " 自動換行set tabstop=4 shiftwidth=4 expandtab  " 縮進 4 空格set autoindent      " 自動縮進set hlsearch        " 高亮搜索set incsearch       " 增量搜索set ignorecase smartcase  " 智能大小寫set mouse=a         " 啟用鼠標支持syntax on           " 語法高亮filetype plugin indent on  " 文件類型插件

進階插件管理:vim-plug,安裝 Plug 'preservim/nerdtree'、Plug 'vim-airline/vim-airline' 等。

Copyright © Windows教程網 All Rights Reserved