gvim【三】【_vimrc配置】

  • Vim的配置写的不错,每一条命令都加了注释,重点看Vim的配置吧。
  • GVim的配置很久之前弄的,注释也不太详细,可以作为参考。因为用到了一些插件。
  • Vim的配置针对Linux系统,GVim的配置针对Windows系统。但Vim的配置也可用于Windows中,GVim的配置不一定能用在Linux中。

Gvim配置

GVIM可以通过修改vimrc来灵活配置你的编辑器。
这里先给出我的vimrc:

"设置背景主题
"colo Candy

set nocompatible

" Vim with all enhancements
source $VIMRUNTIME/vimrc_example.vim

" Remap a few keys for Windows behavior
source $VIMRUNTIME/mswin.vim

set expandtab
"set tabstop=4
set guifont=Courier_New:h14
"set guifont=DejaVu\ Sans\ Mono\:h14 

"colorscheme	eighties						 "主题设置

" Set window size
winpos 100 100
set lines=25 columns=80

" Use the internal diff if available.
" Otherwise use the special 'diffexpr' for Windows.
if &diffopt !~# 'internal'
  set diffexpr=MyDiff()
endif
function MyDiff()
  let opt = '-a --binary '
  if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
  if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
  let arg1 = v:fname_in
  if arg1 =~ ' ' | let arg1 = '"' . arg1 . '"' | endif
  let arg1 = substitute(arg1, '!', '\!', 'g')
  let arg2 = v:fname_new
  if arg2 =~ ' ' | let arg2 = '"' . arg2 . '"' | endif
  let arg2 = substitute(arg2, '!', '\!', 'g')
  let arg3 = v:fname_out
  if arg3 =~ ' ' | let arg3 = '"' . arg3 . '"' | endif
  let arg3 = substitute(arg3, '!', '\!', 'g')
  if $VIMRUNTIME =~ ' '
    if &sh =~ '\<cmd'
      if empty(&shellxquote)
        let l:shxq_sav = ''
        set shellxquote&
      endif
      let cmd = '"' . $VIMRUNTIME . '\diff"'
    else
      let cmd = substitute($VIMRUNTIME, ' ', '" ', '') . '\diff"'
    endif
  else
    let cmd = $VIMRUNTIME . '\diff'
  endif
  let cmd = substitute(cmd, '!', '\!', 'g')
  silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3
  if exists('l:shxq_sav')
    let &shellxquote=l:shxq_sav
  endif
endfunction

"自动全屏
"autocmd GUIEnter * simalt ~x

"设置编码"
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set encoding=utf-8
source $VIMRUNTIME/delmenu.vim 
source $VIMRUNTIME/menu.vim

"显示行号"
set nu
set number

"突出显示当前行"
"set cursorline
"set cul          "cursorline的缩写形式"

"突出显示当前列"
"set cursorcolumn
"set cuc          "cursorcolumn的缩写形式"

"启用鼠标"
set mouse=a
set selection=exclusive
set selectmode=mouse,key

"显示括号匹配"
set showmatch

"设置缩进"
"设置Tab长度为2空格"
set tabstop=2
"设置自动缩进长度为2空格"
set shiftwidth=2
"继承前一行的缩进方式,适用于多行注释"
set autoindent

"设置粘贴模式"
"显示空格和tab键在Vim中通过鼠标右键粘贴时会在行首多出许多缩进和空格,通过set paste可以在插入模式下粘贴内容时不会有任何格式变形、胡乱缩进等问题。"
set paste

"vimrc显示空格和tab键"
"Vim编辑器中默认不显示文件中的tab和空格符,通过下面的配置可以获得以下的显示效果,方便定位输入错误。"
set listchars=tab:>-,trail:-

"设置当文件被改动时自动载入 
set autoread
 
"quickfix模式
autocmd FileType c,cpp map <buffer> <leader><space> :w<cr>:make<cr>

"代码补全  
set completeopt=preview,menu 

"自动保存
set autowrite

"设置上下文行数
set so=1

" 语法高亮
set syntax=on

"与windows共享剪贴板
set clipboard+=unnamed

"取消自动备份及产生swp文件
set noundofile
set nobackup
set nowb
set noswapfile


"为C程序提供自动缩进
set smartindent

"启动的时候不显示那个援助索马里儿童的提示
set shortmess=atI

"忽略大小写
"set ic(ignorecase 的缩写) 忽略大小写
"set noic(noignorecase 的缩写) 不忽略大小写 

"状态行显示的内容
"set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")}  
set statusline=\ [POS=%l,%v][%p%%]\ %{strftime(\"20%y/%m/%d\ -\ %H:%M\")}  
"打开文件类型检测, 加了这句才可以用智能补全
set completeopt=longest,menu


"插件"
set nocompatible               "去除VIM一致性,必须"
filetype off                   "必须"

"设置包括vundle和初始化相关的运行时路径"
set rtp+=$VIM/vimfiles/bundle/Vundle.vim/
call vundle#begin('$VIM/vimfiles/bundle/')

"启用vundle管理插件,必须"
Plugin 'VundleVim/Vundle.vim' 

"在此增加其他插件,安装的插件需要放在vundle#begin和vundle#end之间"
"安装github上的插件格式为 Plugin '用户名/插件仓库名'"

"括号颜色对齐
Plugin 'kien/rainbow_parentheses.vim'
Plugin 'https://github.com/schmich/vim-guifont'

"目录
Plugin 'preservim/nerdtree'
Plugin 'preservim/nerdcommenter'

call vundle#end()              
filetype plugin indent on      "加载vim自带和插件相应的语法和文件类型相关脚本,必须"

autocmd VimEnter * RainbowParenthesesToggle

""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""

"自动加载NERDTree
"autocmd VimEnter * NERDTree
" 设置NerdTree
map <F3> :NERDTreeMirror<CR>
map <F3> :NERDTreeToggle<CR>

基本每种命令都添加了注释,大家结合注释来看就好,有些命令我不需要注释掉了,大家也可以取消注释看看是什么功能。

"插件"开始是添加了两个GVIM插件,GVIM插件的功能非常齐全,大家可以根据需要来安装不同的插件。我这里安装了两个:NERDTree和rainbow_parentheses。NERDTree是文件目录,rainbow_parentheses是括号颜色对齐。如下所示:

在这里插入图片描述
安装方法:
Gvim 树形目录插件 NERDTree 安装方法
vim插件——rainbow
vim插件: rainbow_parentheses[括号高亮]

博客中的文件从我的github上进行下载。

Vim配置英文版

可以直接copy到服务器:

" Set font
set guifont=Courier\ New\ 14
" Set window size at startup
set lines=50 columns=130
" Set window position at startup
winpos 70 50
" Enable syntax highlighting
syntax on
syntax enable

" Set shortcuts
" Set F11 as a shortcut for full-screen mode
nnoremap <F11> :set lines=9999 columns=9999<Bar>winpos 0 0<CR>
" Set F12 as a shortcut for a small window
nnoremap <F12> :set lines=50 columns=130<Bar>winpos 70 50<CR>
" Set F9 as an editing shortcut; some files may be afraid of being modified ('modifiable' is off), use this shortcut to quickly set them as modifiable
nnoremap <F9> :set ma<CR>

" Window settings
" Set text width (textwidth), which specifies the maximum number of characters per line in the text
set tw=10000
" Enable ruler, a status line at the bottom of the Vim window that typically displays information such as the current cursor position, line number, and column number
set ruler
" Enable displaying current command in the status line
set showcmd
" Enable displaying current editing mode in the status line
set showmode

" Set temporary files
set noswapfile
set nobackup
set nowritebackup
set noundofile

" Display relative line numbers
set rnu 
" Display line numbers
set nu
" Enable highlight search feature
set hlsearch
" Set highlight for the current line and column
set cuc
set cul

" Indentation
" Configure the Tab key behavior
" autocmd FileType make set noexpandtab
" Configure the Tab key behavior
" set expandtab
" Enable smart indent
set smartindent
" Enable automatic indent, making Vim automatically match the indentation level of the previous line in a new line
set autoindent
" Set the width of soft tabs to 4 spaces, controlling the number of spaces inserted when using the Tab key in editing
set softtabstop=4
" Set the width of tabs to 4 spaces, controlling the number of spaces inserted when using the Tab key in editing
set tabstop=4
" Set the number of spaces used for indentation to 4 spaces, affecting the code's indentation level
set shiftwidth=4

" Enable Vim's file type detection, plugin support, and automatic indent features
filetype plugin indent on
" Switch to the color theme named "desert"
colorscheme desert 
" Disable compatibility mode
set nocompatible
" Configure the behavior of the backspace key in Vim
set backspace=indent,eol,start

" Enable line break feature in Vim, breaking lines at word boundaries for better readability
set linebreak
" Enable text auto-wrap feature, automatically wrapping lines when they are too long
set wrap
" Enable matching character highlighting
set showmatch
" Add "kspell" completion option, indicating that Vim will use spell check functionality for word completion
set complete+=kspell
" Enable folding feature, allowing you to fold code blocks or text paragraphs for easier browsing and editing of large files
set foldenable
" Set top and bottom margins for vertical scrolling to 4 lines
set scrolloff=4
" Set the display level of the status line to 2, showing the status line at the bottom with file name, file type, etc.
set laststatus=2
" Enable incremental search feature
set incsearch
" Set the maximum number of lines for Vim command history to 1000 lines
set history=1000
" Enable auto-read feature, meaning if a file is externally modified while editing (e.g., modified by another program), Vim will automatically reread the file to update the content in the editor, preventing conflicts
set autoread
" Enable smart menu feature, displaying a menu below the command line when using wildcards (e.g., :e *.txt) to help you select files
set wildmenu

" Map Ctrl+C to insert a commented line
map ^C i//------------------------------------------------------------------------------------------------------------------^M//^M<ESC>0Di//------------------------------------------------------------------------------------------------------------------<ESC>ka

" Automatically set file type to Verilog based on file extension
au BufNewFile,BufRead *.v,*.vh set filetype=verilog
" Automatically set file type to python based on file extension
au BufNewFile,BufRead *.py set filetype=python
" Automatically set file type to logtalk based on file extension
au BufNewFile,BufRead *.txt,*.log,README set filetype=logtalk

" Use <M-i> (Alt+i) to perform corresponding actions
" Mapping defines the operation when Alt+i is pressed in normal mode, i.e., insert a comment
nnoremap <M-i> :normal! I//<Esc>
" Mapping defines the operation when Alt+i is pressed in visual mode, i.e., insert a comment
vnoremap <M-i> :s/^/\/\//<CR>
" Use <M-o> (Alt+o) to perform corresponding actions
" Mapping defines the operation when Alt+o is pressed in normal mode, i.e., uncomment
nnoremap <M-o> :normal! ^xx<Esc>
" Mapping defines the operation when Alt+o is pressed in visual mode, i.e., uncomment
vnoremap <M-o> :s/^\/\///<CR>
" Mapping defines the operation when Alt+i is pressed in insert mode, i.e., insert a comment
inoremap <M-i> :<Esc>I//<Esc>
" Mapping defines the operation when Alt+o is pressed in insert mode, i.e., uncomment
inoremap <M-o> :<Esc>^xx<Esc>

" In insert mode, automatically insert a right parenthesis ) after typing a left parenthesis ( and move the cursor to the middle of the parentheses
inoremap ( ()<Left>
" In insert mode, automatically insert a right square bracket ] after typing a left square bracket [ and move the cursor to the middle of the square brackets
inoremap [ []<Left>
" In insert mode, automatically insert a right curly brace } after typing a left curly brace { and move the cursor to the middle of the curly braces
inoremap { {}<Left>
" In insert mode, automatically insert a right double quote " after typing a left double quote " and move the cursor to the middle of the quotes
inoremap " ""<Left>

" After entering bg in insert mode, automatically replace it with begin and insert end on the next line
inoremap bg begin<Enter>end<Esc>k$a

Vim配置

这个是上面英文版的翻译,帮助你理解的:

" 设置字体
set guifont=Courier\ New\ 14
" 设置启动时窗口大小
set lines=50 columns=130
" 设置启动时窗口位置
winpos 70 50
" 设置语法高亮
syntax on
syntax enable

" 设置快捷键
" 设置F11为全屏快捷键
nnoremap <F11> :set lines=9999 columns=9999<Bar>winpos 0 0<CR>
" 设置F12为小窗口快捷键
nnoremap <F12> :set lines=50 columns=130<Bar>winpos 70 50<CR>
" 设置F9为编辑快捷键,有些文件可能怕被修改:'modifiable' is off,可以通过这个快捷键快速设置为可修改
nnoremap <F9> :set ma<CR>

" 窗口设置
" 设置文本宽度(textwidth),文本宽度指定了文本中每行的最大字符数
set tw=10000
" 启用标尺(ruler),标尺是一个位于 Vim 窗口底部的状态行,它通常用于显示当前光标位置、行号和列号等信息
set ruler
" 启用状态栏(status line)中显示当前命令
set showcmd
" 启用状态栏中显示当前编辑模式
set showmode

" 设置临时文件
set noswapfile
set nobackup
set nowritebackup
set noundofile

" 显示相对行号
set rnu 
" 显示行号
set nu
" 启用高亮搜索功能
set hlsearch
" 设置高亮当前行和列
set cuc
set cul

" 缩进
" 配置 Tab 键的缩进行为
" autocmd FileType make set noexpandtab
" 配置 Tab 键的缩进行为
" set expandtab
" 启用智能缩进
set smartindent
" 启用自动缩进功能,使 Vim 在新行中自动匹配上一行的缩进级别
set autoindent
" 设置软制表符的宽度为 4 个空格,用于控制在编辑中使用 Tab 键时插入的空格数量
set softtabstop=4
" 设置制表符(Tab)的宽度为 4 个空格,控制在编辑中使用 Tab 键时插入的空格数量
set tabstop=4
" 设置缩进时使用的空格数为 4 个空格,影响代码的缩进级别
set shiftwidth=4

" 启用 Vim 的文件类型检测、插件支持和自动缩进功能
filetype plugin indent on
" 切换到名为 "desert" 的颜色主题
colorscheme desert 
" 禁用兼容模式
set nocompatible
" 配置 Vim 中的回退(backspace)键行为
set backspace=indent,eol,start

" 启用 Vim 中的换行(line break)功能,当你启用这个选项时,Vim 将根据单词边界来换行,而不会在单词中断的地方进行换行,这有助于提高文本的可读性
set linebreak
" 启用文本自动换行功能,当文本行过长时,它将自动折行显示。
set wrap
" 启用匹配字符高亮显示
set showmatch
" 添加 "kspell" 补全选项,这表示 Vim 在进行单词补全时将使用拼写检查功能
set complete+=kspell
" 启用折叠(folding)功能,折叠允许你折叠代码块或文本段落,以便更轻松地浏览和编辑大型文件
set foldenable
" 设置垂直滚动时的上下边距为 4 行
set scrolloff=4
" 设置状态栏的显示级别为 2
set laststatus=2,这将在底部显示状态栏,其中包括文件名、文件类型等信息
" 启用增量搜索功能
set incsearch
" 设置 Vim 命令历史记录的最大行数为 1000 行
set history=1000
" 启用自动读取功能,这意味着如果在编辑一个文件时,该文件在外部被修改了(比如被其他程序修改了),Vim 会自动重新读取文件以更新编辑器中的内容,以防止冲突
set autoread
" 启用智能菜单功能,当你在命令行中使用通配符(如 :e *.txt)时,Vim 会在命令行下方显示一个菜单,列出匹配的文件名,以帮助你选择文件
set wildmenu

" 将crtl+C按键映射为插入注释行
map ^C i//------------------------------------------------------------------------------------------------------------------^M//^M<ESC>0Di//------------------------------------------------------------------------------------------------------------------<ESC>ka

" 根据文件扩展名自动设置文件类型为 Verilog
au BufNewFile,BufRead *.v,*.vh set filetype=verilog
" 根据文件扩展名自动设置文件类型为 python
au BufNewFile,BufRead *.py set filetype=python
" 根据文件扩展名自动设置文件类型为 logtalk
au BufNewFile,BufRead *.txt,*.log,README set filetype=logtalk

" 使用了 <M-i> 键(Alt+i)来执行相应的操作
" 映射定义了在普通模式下按下 Alt+i 时的操作,即插入注释
nnoremap <M-i> :normal! I//<Esc>
" 映射定义了在可视模式下按下 Alt+i 时的操作,即插入注释
vnoremap <M-i> :s/^/\/\//<CR>
" 使用了 <M-o> 键(Alt+o)来执行相应的操作
" 映射定义了在普通模式下按下 Alt+o 时的操作 ,即取消注释
nnoremap <M-o> :normal! ^xx<Esc>
" 映射定义了在可视模式下按下 Alt+o 时的操作 ,即取消注释
vnoremap <M-o> :s/^\/\///<CR>
" 映射定义了在插入模式下按下 Alt+i 时的操作,即插入注释
inoremap <M-i> :<Esc>I//<Esc>
" 映射定义了在插入模式下按下 Alt+o 时的操作 ,即取消注释
inoremap <M-o> :<Esc>^xx<Esc>

" 在插入模式下输入一个左括号 ( 后,自动插入右括号 ) 并将光标移到括号中间
inoremap ( ()<Left>
" 在插入模式下输入一个左方括号 [ 后,自动插入右方括号 ] 并将光标移到方括号中间
inoremap [ []<Left>
" 在插入模式下输入一个左大括号 { 后,自动插入右大括号 } 并将光标移到大括号中间
inoremap { {}<Left>
" 在插入模式下输入一个左引号 " 后,自动插入右引号 " 并将光标移到引号中间
inoremap " ""<Left>

" 在输入 bg 后,自动将其替换为 begin,并在下一行插入 end
inoremap bg begin<Enter>end<Esc>k$a


本系列其他博客

  1. gvim【一】【安装和基本使用】
  2. gvim【二】【ab命令快速制作verilog模板】
  3. gvim【三】【_vimrc配置】
  • 3
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值