VIM 美化配置
![]()
This guide provides a comprehensive .vimrc configuration to enhance Vim’s appearance and functionality, including status line improvements, syntax highlighting, and better navigation.
Installation
Section titled “Installation”-
Backup your existing configuration:
Terminal window mv ~/.vimrc ~/.vimrc.bak -
Apply the configuration:
Copy the following content to your
~/.vimrcfile.
" -- General Settings ----------------------------------------------------------set rulerfiletype offset backspace=2set nuset mouse=a
" -- Bootstrap -----------------------------------------------------------------set encoding=utf-8 " set vim encoding to UTF-8set nocompatible " use vim defaultsset history=1000 " boost historyset undolevels=1000 " boost undo levels
" -- Tmux Integration ----------------------------------------------------------if exists('$TMUX') set term=screen-256colorendif
if exists('$ITERM_PROFILE') if exists('$TMUX') let &t_SI = "\<Esc>[3 q" let &t_EI = "\<Esc>[0 q" else let &t_SI = "\<Esc>]50;CursorShape=1x7" let &t_EI = "\<Esc>]50;CursorShape=0x7" endifendif
" -- Backup and Swap -----------------------------------------------------------set backupset writebackupset swapfile
let s:vimdir=$HOME . "/.vim"let &backupdir=s:vimdir . "/backup"let &directory=s:vimdir . "/tmp"
if exists("*mkdir") if !isdirectory(s:vimdir) call mkdir(s:vimdir, "p") endif if !isdirectory(&backupdir) call mkdir(&backupdir, "p") endif if !isdirectory(&directory) call mkdir(&directory, "p") endifendif
set backupskip+=*.tmp
if has("persistent_undo") let &undodir=&backupdir set undofileendif
let &viminfo=&viminfo . ",n" . s:vimdir . "/.viminfo"
" -- Command Mode --------------------------------------------------------------set wildmenuset wildmode=longest:full,fullset wildignore+=.git,*.DS_Storeif exists ("&wildignorecase") set wildignorecaseendif
" -- Display -------------------------------------------------------------------set titleset lazyredrawset report=0set cursorline
if has("gui_running") set cursorcolumnendif
if exists("+showtabline") set showtabline=1endif
" -- Status Line ---------------------------------------------------------------if has("statusline") function! StatusLineUTF8() try let p = getpos('.') redir => utf8seq sil normal! g8 redir End call setpos('.', p) return substitute(matchstr(utf8seq, '\x\+ .*\x'), '\<\x\x', '0x\U&', 'g') catch return '?' endtry endfunction
function! StatusLineFileEncoding() return has("multi_byte") && strlen(&fenc) ? &fenc : '' endfunction
function! StatusLineUTF8Bomb() return has("multi_byte") && &fenc == 'utf-8' && &bomb?'+bomb' : '' endfunction
function! StatusLineCWD() let l:pwd = exists('$PWD') ? $PWD : getcwd() return substitute(fnamemodify(l:pwd, ':~'), '\(\~\?/[^/]*/\).*\(/.\{20\}\)', '\1...\2', '') endfunction
set laststatus=2 set statusline= set statusline+=%#Number# set statusline+=❐\ %02n set statusline+=\ \|\ set statusline+=%* set statusline+=%#Identifier# set statusline+=%f set statusline+=%* set statusline+=%#Special# set statusline+=%m set statusline+=%#Statement# set statusline+=%r set statusline+=%h set statusline+=%w set statusline+=%#Type# set statusline+=[%{&ff}] set statusline+=[ set statusline+=%{StatusLineFileEncoding()} set statusline+=%#Error# set statusline+=%{StatusLineUTF8Bomb()} set statusline+=%#Type# set statusline+=] set statusline+=%y set statusline+=\ \|\ set statusline+=%* set statusline+=%#Directory# set statusline+=%{StatusLineCWD()} set statusline+=\ set statusline+=%* set statusline+=%= set statusline+=%#Comment# set statusline+=%{v:register} set statusline+=\ set statusline+=%#Statement# set statusline+=[U+\%04B] set statusline+=[%{StatusLineUTF8()}] set statusline+=\ \|\ set statusline+=%#Comment# set statusline+=line\ %5l/%L\ set statusline+=●\ %02p%%,\ set statusline+=col\ %3vendif
set showcmdset cmdheight=1set shortmess=astT
if (&t_Co > 2 || has("gui_running")) && has("syntax") syntax onendif
match ErrorMsg '^\(<\|=\|>\)\{7\}\([^=].\+\)\?$'
if has("termguicolors") let &t_8f = "\<Esc>[38;2;%lu;%lu;%lum" let &t_8b = "\<Esc>[48;2;%lu;%lu;%lum" set termguicolorsendif
" -- Buffers -------------------------------------------------------------------set autoreadset fsync
" -- Navigation ----------------------------------------------------------------nnoremap <C-e> 2<C-e>nnoremap <C-y> 2<C-y>map <C-Up> <C-y>map <C-Down> <C-e>
set startofline
nnoremap j gjnnoremap <Down> gjnnoremap k gknnoremap <Up> gk
set scrolljump=1set scrolloff=4set sidescroll=1set sidescrolloff=4
" -- Editing -------------------------------------------------------------------set showmodeset nowrapset linebreak
if has("multi_byte") set showbreak=↪else set showbreak=>endif
set nojoinspacesset showmatchset matchtime=4set matchpairs+=<:>set virtualedit+=onemoreset smarttab
" -- Searching -----------------------------------------------------------------set wrapscanset incsearchif (&t_Co > 2 || has("gui_running")) set hlsearchendif
set ignorecaseset smartcase
" -- Spell Checking ------------------------------------------------------------set spelllang=enset nospell
" -- Snakemake Syntax Support --------------------------------------------------source $VIMRUNTIME/syntax/python.vimsyn keyword pythonStatement include workdir onsuccess onerrorsyn keyword pythonStatement ruleorder localrules configfilesyn keyword pythonStatement touch protected temp wrappersyn keyword pythonStatement input output params message threads resourcessyn keyword pythonStatement version run shell benchmark snakefile log scriptsyn keyword pythonStatement rule subworkflow nextgroup=pythonFunction skipwhitesyn keyword pythonBuiltin expand config temp protectedsyn match pythonFunction "\%(\%(rule\s\|subworkflow\s\)\s*\)\@<=\h*" containedsyn sync match pythonSync grouphere NONE "^\s*\%(rule\|subworkflow\)\s\+\h\w*\s*"let b:current_syntax = "snakemake"