" 设置文件编码
set encoding=utf-8
set fileencodings=utf-8,gbk,ucs-bom,cp936,latin1
set termencoding=utf-8
set fileformats=unix
" 启用行号和相对行号
set number
set relativenumber
" 启用鼠标
set mouse=a
" 启用搜索时高亮显示
set hlsearch
" 智能缩进
set smartindent
set tabstop=4
set shiftwidth=4
set expandtab
" 启用语法高亮
syntax enable
" 启用文件类型检测
filetype on
filetype plugin on
filetype indent on
" 启用自动补全
set completeopt=menuone,noselect
set shortmess+=c
" 启用插件管理器(使用 vim-plug)
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs \
https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
" 插件列表(示例,你可以根据需求添加更多)
call plug#begin('~/.vim/plugged')
Plug 'junegunn/fzf.vim'
Plug 'tpope/vim-surround'
Plug 'scrooloose/nerdtree'
Plug 'itchyny/lightline.vim'
" 添加其他插件...
call plug#end()
" 设置颜色主题(示例)
colorscheme desert
" 设置状态栏
set laststatus=2
let g:lightline = {
\ 'colorscheme': 'wombat',
\ 'active': {
\ 'left': [ [ 'mode', 'paste' ],
\ [ 'fugitive', 'readonly', 'filename', 'modified' ] ]
\ },
\ 'component_function': {
\ 'fugitive': 'FugitiveStatusline'
\ },
\ 'component': {
\ 'readonly': '',
\ },
\ 'tabline': {
\ 'left': [ [ 'tabs', 'buffers' ] ],
\ 'right': [ [ 'close' ] ]
\ },
\ }
Vim 的配置是非常个性化的,下面是一个基本的 Vim 配置,包括一些非常有用的插件。你可以将配置添加到你的 ~/.vimrc
文件中