查看vim是否支持clipboard:
vim --version
如果不支持(即-clipboard),则要安装vim-gnome:
-
sudo apt install vim-gnome
- 如果方法1安装失败,则尝试手动下载vim-gnome的deb安装包并安装
安装vundle插件:
git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim
badwolf颜色主题:
从GitHub下载好badwolf.vim并放到/usr/share/vim/vimxx/colors文件夹下(xx为对应vim版本,如vim8.2就是/usr/share/vim/vim82/colors)。
Debian系统vim的~/.vimrc文件配置:
" 基本配置
"
"
" 设置行号
set number
" 语法高亮。自动识别代码,使用多种颜色表示
syntax enable
" 选择颜色主题(已经下载好并放到/usr/share/vim/vim82/colors文件夹下)
colorscheme badwolf
" 支持使用鼠标
set mouse=a
" 按下回车键后,下一行的缩进会自动跟上一行的缩进保持一致
set autoindent
" 按下Tab键后,vim显示的空格数
set tabstop=4
" normal模式下,>>增加一级缩进、<<取消一级缩进、==取消全部缩进时,每一级缩进的空格数
set shiftwidth=4
" 自动将Tab转为空格(防止Tab键在不同编辑器缩进不一致导致问题)
set expandtab
" Tab转为多少个空格
set softtabstop=4
" 光标所在行高亮
set cursorline
" 关闭自动折行
set nowrap
" 垂直滚动时,光标距离顶部/底部的距离(单位:行)
set scrolloff=5
" 水平滚动时,光标距离行首或行尾的距离(单位:字符)
set sidescrolloff=30
" 设置行宽,即一行显示多少字符
set textwidth=1000
" 是否显示状态栏:0表示不显示,1表示只在多窗口显示,2表示显示
set laststatus=2
" 设置状态条显示的信息:文件名、光标所在字符的ASCII码、光标所在字符的ASCII码的十六进制、光标所在的位置、光标所在行之上的内容占整个文件的百分比、文件总行数
set statusline=\ %F%m%r%h%w\ \ \ \ ASCII=\%03.3b\ \ \ \ HEX=\%02.2B\ \ \ \ POS=%04l,%04v\ \ \ \ %p%%\ \ \ \ NumOfLine=%L
" 显示行尾的空格
highlight WhitespaceEOL ctermbg=red guibg=red
match WhitespaceEOL /\s\+$/
" 光标遇到括号时,自动高亮对应的另一半括号
set showmatch
" 命令行模式下,在底部显示当前键入的指令。例如键入dd删除一行时,键入第一个d,底部右侧显示d,完全键入dd时,操作完成,底部显示消失
set showcmd
" 搜索时,高亮显示搜索结果
set hlsearch
" 搜索时,每输入一个字符,自动跳到第一个匹配的结果
set incsearch
" 搜索时忽略大小写
set ignorecase
" 不创建交换文件
set noswapfile
" 保留 撤销 操作历史
set undofile
" 设置操作历史文件的保存位置
set undodir=~/.vim/.undo//
" vim需要记住多少次历史操作
set history=1000
" 命令模式下,底部操作指令按下 Tab 键自动补全。第一次按下 Tab,会显示所有匹配的操作指令的清单;第二次按下 Tab,会依次选择各个指令
set wildmenu
set wildmode=longest:list,full
" F5一键编译运行
map <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
exec "w"
if &filetype == 'c'
exec '!g++ % -o %<'
exec '!time ./%<'
elseif &filetype == 'cpp'
exec '!g++ % -o %<'
exec '!time ./%<'
elseif &filetype == 'python'
exec '!python %'
" 如果显示时间,将上面一句换为exec '!time python %'
elseif &filetype == 'sh'
:!time bash %
endif
endfunc
" 定义F1快捷键为切换vim窗口
map <F1> <C-w>w
" Vundle配置
set nocompatible " 设置vim和vi不兼容。在兼容模式下运行时,Vim 大部分增强及改善的功能就不可用了,vundle要求必须有
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
" Keep Plugin commands between vundle#begin/end.
" 在vim中使用git命令
Plugin 'tpope/vim-fugitive'
" 在vim行号旁显示git diff的差异标记
Plugin 'airblade/vim-gitgutter'
" 插入和删除成对的符号(surrounding),如括号,引号
Plugin 'jiangmiao/auto-pairs'
" 给现有代码插入、删除或修改成对的符号(surrounding)
Plugin 'tpope/vim-surround'
" 一键注释单行或多行代码
Plugin 'scrooloose/nerdcommenter'
" nerdtree
Plugin 'scrooloose/nerdtree'
" 在nerdtree目录中显示git状态,用法暂不明了,之后使用git时再继续学习
Plugin 'Xuyuanp/nerdtree-git-plugin'
" code formatter
Plugin 'rhysd/vim-clang-format'
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList - lists configured plugins
" :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line
" 各种插件的配置
"
"
" NERD Commenter配置
" 将leader从"\"改为","
let mapleader = ","
" 在注释符后面自动添加空格
let g:NERDSpaceDelims = 1
" Use compact syntax for prettified multi-line comments:使用紧凑语法美化多行注释
let g:NERDCompactSexyComs = 1
" Align line-wise comment delimiters flush left instead of following code indentation:靠左对齐注释符,而不是 跟随代码缩进
let g:NERDDefaultAlign = 'left'
" Allow commenting and inverting empty lines (useful when commenting a region):允许注释和反注释空行 (在注释多行代 码时很有用)
let g:NERDCommentEmptyLines = 1
" Enable trimming of trailing whitespace when uncommenting:取消注释的同时删除当前行末尾的空格
let g:NERDTrimTrailingWhitespace = 1
" Enable NERDCommenterToggle to check all selected lines is commented or not:暂时不知道什么意思,作 什么用途
let g:NERDToggleCheckAllLines = 1
"
"
" NERDTree配置
" 将F2设置为开关NERDTree的快捷键
map <F2> :NERDTreeToggle<cr>
" 修改树的显示图标
" let g:NERDTreeDirArrowExpandable = '+'
" let g:NERDTreeDirArrowCollapsible = '-'
" 打开vim时如果没有文件自动打开NERDTree
autocmd vimenter * if !argc()|NERDTree|endif
" 当NERDTree为剩下的唯一窗口时自动关闭
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
"
"
" nerdtree-git-plugin配置
let g:NERDTreeGitStatusIndicatorMapCustom = {
\ "Modified" : "✹",
\ "Staged" : "✚",
\ "Untracked" : "✭",
\ "Renamed" : "➜",
\ "Unmerged" : "═",
\ "Deleted" : "✖",
\ "Dirty" : "✗",
\ "Clean" : "✔︎",
\ 'Ignored' : '☒',
\ "Unknown" : "?"
\ }
"
"
" vim-clang-format
let g:clang_format#code_style = "chromium"
let g:clang_format#auto_format = 1
let g:clang_format#style_options = {
\ "PointerAlignment" : "Right"
\ }
最后在vim的normal模式下执行:PluginInstall。
其中,vim-clang-format要提前安装:
sudo apt-get install clang-format
/root/.vimrc文件配置(共用普通用户的plugin):
" 基本配置
"
"
" 设置行号
set number
" 语法高亮。自动识别代码,使用多种颜色表示
syntax enable
" 选择颜色主题(已经下载好并放到/usr/share/vim/vim82/colors文件夹下)
colorscheme badwolf
" 支持使用鼠标
set mouse=a
" 按下回车键后,下一行的缩进会自动跟上一行的缩进保持一致
set autoindent
" 按下Tab键后,vim显示的空格数
set tabstop=4
" normal模式下,>>增加一级缩进、<<取消一级缩进、==取消全部缩进时,每一级缩进的空格数
set shiftwidth=4
" 自动将Tab转为空格(防止Tab键在不同编辑器缩进不一致导致问题)
set expandtab
" Tab转为多少个空格
set softtabstop=4
" 光标所在行高亮
set cursorline
" 关闭自动折行
set nowrap
" 垂直滚动时,光标距离顶部/底部的距离(单位:行)
set scrolloff=5
" 水平滚动时,光标距离行首或行尾的距离(单位:字符)
set sidescrolloff=30
" 设置行宽,即一行显示多少字符
set textwidth=1000
" 是否显示状态栏:0表示不显示,1表示只在多窗口显示,2表示显示
set laststatus=2
" 设置状态条显示的信息:文件名、光标所在字符的ASCII码、光标所在字符的ASCII码的十六进制、光标所在的位置、光标所在行之上的内容占整个文件的百分比、文件总行数
set statusline=\ %F%m%r%h%w\ \ \ \ ASCII=\%03.3b\ \ \ \ HEX=\%02.2B\ \ \ \ POS=%04l,%04v\ \ \ \ %p%%\ \ \ \ NumOfLine=%L
" 显示行尾的空格
highlight WhitespaceEOL ctermbg=red guibg=red
match WhitespaceEOL /\s\+$/
" 光标遇到括号时,自动高亮对应的另一半括号
set showmatch
" 命令行模式下,在底部显示当前键入的指令。例如键入dd删除一行时,键入第一个d,底部右侧显示d,完全键入dd时,操作完成,底部显示消失
set showcmd
" 搜索时,高亮显示搜索结果
set hlsearch
" 搜索时,每输入一个字符,自动跳到第一个匹配的结果
set incsearch
" 搜索时忽略大小写
set ignorecase
" 不创建交换文件
set noswapfile
" 保留 撤销 操作历史
set undofile
" 设置操作历史文件的保存位置
set undodir=~/.vim/.undo//
" vim需要记住多少次历史操作
set history=1000
" 命令模式下,底部操作指令按下 Tab 键自动补全。第一次按下 Tab,会显示所有匹配的操作指令的清单;第二次按下 Tab,会依次选择各个指令
set wildmenu
set wildmode=longest:list,full
" F5一键编译运行
map <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
exec "w"
if &filetype == 'c'
exec '!g++ % -o %<'
exec '!time ./%<'
elseif &filetype == 'cpp'
exec '!g++ % -o %<'
exec '!time ./%<'
elseif &filetype == 'python'
exec '!python %'
" 如果显示时间,将上面一句换为exec '!time python %'
elseif &filetype == 'sh'
:!time bash %
endif
endfunc
" 定义F1快捷键为切换vim窗口
map <F1> <C-w>w
" Vundle配置
set nocompatible " 设置vim和vi不兼容。在兼容模式下运行时,Vim 大部分增强及改善的功能就不可用了,vundle要求必须有
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=/home/username/.vim/bundle/Vundle.vim "username为对应普通用户用户名
call vundle#begin('/home/username/.vim/bundle') "username为对应普通用户用户名
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
" Keep Plugin commands between vundle#begin/end.
" 在vim中使用git命令
Plugin 'tpope/vim-fugitive'
" 在vim行号旁显示git diff的差异标记
Plugin 'airblade/vim-gitgutter'
" 插入和删除成对的符号(surrounding),如括号,引号
Plugin 'jiangmiao/auto-pairs'
" 给现有代码插入、删除或修改成对的符号(surrounding)
Plugin 'tpope/vim-surround'
" 一键注释单行或多行代码
Plugin 'scrooloose/nerdcommenter'
" nerdtree
Plugin 'scrooloose/nerdtree'
" 在nerdtree目录中显示git状态,用法暂不明了,之后使用git时再继续学习
Plugin 'Xuyuanp/nerdtree-git-plugin'
" code formatter
Plugin 'rhysd/vim-clang-format'
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
" To ignore plugin indent changes, instead use:
"filetype plugin on
"
" Brief help
" :PluginList - lists configured plugins
" :PluginInstall - installs plugins; append `!` to update or just :PluginUpdate
" :PluginSearch foo - searches for foo; append `!` to refresh local cache
" :PluginClean - confirms removal of unused plugins; append `!` to auto-approve removal
"
" see :h vundle for more details or wiki for FAQ
" Put your non-Plugin stuff after this line
" 各种插件的配置
"
"
" NERD Commenter配置
" 将leader从"\"改为","
let mapleader = ","
" 在注释符后面自动添加空格
let g:NERDSpaceDelims = 1
" Use compact syntax for prettified multi-line comments:使用紧凑语法美化多行注释
let g:NERDCompactSexyComs = 1
" Align line-wise comment delimiters flush left instead of following code indentation:靠左对齐注释符,而不是 跟随代码缩进
let g:NERDDefaultAlign = 'left'
" Allow commenting and inverting empty lines (useful when commenting a region):允许注释和反注释空行 (在注释多行代 码时很有用)
let g:NERDCommentEmptyLines = 1
" Enable trimming of trailing whitespace when uncommenting:取消注释的同时删除当前行末尾的空格
let g:NERDTrimTrailingWhitespace = 1
" Enable NERDCommenterToggle to check all selected lines is commented or not:暂时不知道什么意思,作 什么用途
let g:NERDToggleCheckAllLines = 1
"
"
" NERDTree配置
" 将F2设置为开关NERDTree的快捷键
map <F2> :NERDTreeToggle<cr>
" 修改树的显示图标
" let g:NERDTreeDirArrowExpandable = '+'
" let g:NERDTreeDirArrowCollapsible = '-'
" 打开vim时如果没有文件自动打开NERDTree
autocmd vimenter * if !argc()|NERDTree|endif
" 当NERDTree为剩下的唯一窗口时自动关闭
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
"
"
" nerdtree-git-plugin配置
let g:NERDTreeGitStatusIndicatorMapCustom = {
\ "Modified" : "✹",
\ "Staged" : "✚",
\ "Untracked" : "✭",
\ "Renamed" : "➜",
\ "Unmerged" : "═",
\ "Deleted" : "✖",
\ "Dirty" : "✗",
\ "Clean" : "✔︎",
\ 'Ignored' : '☒',
\ "Unknown" : "?"
\ }
"
"
" vim-clang-format
let g:clang_format#code_style = "chromium"
let g:clang_format#auto_format = 1
let g:clang_format#style_options = {
\ "PointerAlignment" : "Right"
\ }
注意,如果与普通用户共用plugin,则不要用root用户执行:PluginInstall命令。