Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Linux 環境開發必備:Vim 編輯器核心操作與設定速查表

編輯:Linux 教學

基本流程

# vim hello.c      # 新建/開啟檔案
# 按 i 進入插入模式(左下顯示 -- INSERT --)
# 編輯完成按 Esc 回一般模式
# :wq  存檔離開
# :q!  不存檔強制離開

游標移動與編輯指令(一般模式)

動作指令
換行Enter(插入模式)
刪除游標字元x
刪除整行dd
復原上一步u
重做Ctrl+R
複製 2 個單字y2w
複製整行yy
貼上p
跳至第 5 行:5 <Enter>
搜尋關鍵字/keyword

縮排與 Tab 設定

:set cindent shiftwidth=4   # 程式碼自動縮排 4 空格
:set tabstop=2              # Tab 顯示 2 空格
:set number                 # 顯示行號

永久生效:~/.vimrc 範例

set nocompatible
set number
set tabstop=4
set shiftwidth=4
set expandtab
set autoindent
set cindent
syntax on

跨平台換行符轉換

Windows (CRLF) → Linux (LF):

dos2unix filename

或在 Vim 內::set fileformat=unix 後存檔。

Copyright © Windows教程網 All Rights Reserved