萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 作業系統 >  >> Linux 教學

SecureCRT 設定 Linux Vim 彩色語法高亮:終端模擬與 .vimrc 完整配置

在 SecureCRT 中讓 Vim 顯示完整語法高亮,需同時配置終端機模擬設定與 Vim 運行配置。

1. SecureCRT 終端機色彩設定

選單:Options → Session Options → Terminal → Emulation
• Terminal 選 ANSI、Linux 或 xterm
• 勾選 ANSI Colour

2. ~/.vimrc 核心配置

" 基礎設定
set nocompatible
set ruler
set number
set autoindent
set smartindent
set shiftwidth=4
set tabstop=4
set noexpandtab
set wrap
set hlsearch

" 語法高亮與折疊
syntax on
set foldmethod=syntax

" GUI/終端機差異化配色
if has("gui_running")
  set nowrap
  set guioptions+=b
  colorscheme inkpot
else
  set wrap
  colorscheme ron
  " 終端機 256 色支援 (SecureCRT 需)
  set t_Co=256
  set t_Sf=^[[3%p1%dm
  set t_Sb=^[[4%p1%dm
endif

" Leader 鍵設為逗號
let mapleader = ","

關鍵說明:

  • ^[[ 為 Ctrl+V 後按 Esc 輸入的實際轉義字元
  • t_Co=256 啟用 256 色模式,配合 t_Sf/t_Sb 讓 Vim 正確發送 ANSI 色碼
  • 非 GUI 環境下此設定確保 SecureCRT 正確渲染 Vim 色彩

套用後重新開啟 Vim 即可看到完整語法高亮與代碼折疊效果。

copyright © 萬盛學電腦網 all rights reserved