说明
- VM15虚拟机中的CentOS7
- Xshell连接
安装最新版vim
- 增加最新版vim源
curl -L https://copr.fedorainfracloud.org/coprs/lantw44/vim-latest/repo/epel-7/lantw44-vim-latest-epel-7.repo -o /etc/yum.repos.d/vim-latest.repo
- 更新vim
yum update -y
- 验证vim
vim
- 在vim中输入命令
:echo $VIMRUNTIME
来查看Vim的运行目录
配置最新版vim
- 创建用户的.vim文件夹
mkdir ~/.vim
- 创建用户的.vimrc文件
touch ~/.vimrc
- 创建vim的主题文件夹
mkdir -p ~/.vim/colors
配色方案
- 安装gruvbox配色方案
curl -fLo ~/.vim/colors/gruvbox.vim --create-dirs https://raw.githubusercontent.com/morhetz/gruvbox/master/colors/gruvbox.vim
- 配置用户的vim
vim ~/.vimrc
" gruvbox配色方案
colorscheme gruvbox
参阅:
插件管理
- 安装开发工具
yum grouplist
yum groupinstall "开发工具" -y
或yum groupinstall Development tools -y
- 安装部分依赖
yum install cmake python-devel clang kernel-devel ncurses-devel yum-utils epel-release https://centos7.iuscommunity.org/ius-release.rpm -y
- 安装python3和pip3
yum search python3 | grep devel
yum install python36u python36u-devel python36u-pip -y
- 创建python3连接符
ln -s /usr/bin/python3.6 /usr/bin/python3
- 创建pip3链接符
ln -s /usr/bin/pip3.6 /usr/bin/pip3
- 配置pip3
mkdir ~/.pip && cd ~/.pip
vim pip.conf
[global]
index-url = http://pypi.douban.com/simple
[install]
trusted-host = pypi.douban.com
- 版本查看
python -V
python3 -V
pip3 -V
- 升级pip3
pip3 install --upgrade pip
- 安装vim_runtime配置方案
git clone --depth=1 https://github.com/amix/vimrc.git ~/.vim_runtime
sh ~/.vim_runtime/install_awesome_vimrc.sh
- 下载plug.vim(vim插件管理器)
curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
- 配置用户的vim
vim ~/.vimrc
" F11快捷键激活/取消paste模式
set pastetoggle=<F11>
- 配置用户的vim
vim ~/.vimrc
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""" 一、Vim-plug插件配置 """
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
call plug#begin()
" 目录结构展示插件
Plug 'scrooloose/nerdtree'
Plug 'Xuyuanp/nerdtree-git-plugin'
" 代码自动补全
Plug 'ycm-core/YouCompleteMe'
" 括号自动补全
Plug 'jiangmiao/auto-pairs'
Plug 'vim-airline/vim-airline'
Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'
Plug 'junegunn/vim-easy-align'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
call plug#end()
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""" 二、NerdTree配置 """
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" vim 启动的时候默认开启 NERDTree
autocmd VimEnter * NERDTree
" 默认光标在右侧文件编辑区
wincmd w
autocmd VimEnter * wincmd w
" 文件树设置 {{{
" NERDTree开关
map <silent> <F3> :NERDTreeToggle<CR>
""当NERDTree为剩下的唯一窗口时自动关闭
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTree") && b:NERDTree.isTabTree()) | q | endif
"" 修改树的显示图标
let g:NERDTreeDirArrowExpandable = '►'
let g:NERDTreeDirArrowCollapsible = '▼'
let NERDTreeAutoCenter=1
" 指定鼠标模式(1.双击打开;2.单目录双文件;3.单击打开)
let NERDTreeMouseMode=2
" 将 NERDTree 的窗口设置在 vim 窗口的左侧
let NERDTreeWinPos="left"
" 显示行号
let NERDTreeShowLineNumbers=1
" 是否显示隐藏文件
let NERDTreeShowHidden=1
" 设置宽度
let NERDTreeWinSize=25
" 在终端启动vim时,共享NERDTree
let g:nerdtree_tabs_open_on_console_startup=1
" 忽略一下文件的显示
let NERDTreeIgnore=['\.pyc','\~$','\.swp']
let g:NERDTreeIndicatorMapCustom = {
\ "Modified" : "✹",
\ "Staged" : "✚",
\ "Untracked" : "✭",
\ "Renamed" : "➜",
\ "Unmerged" : "═",
\ "Deleted" : "✖",
\ "Dirty" : "✗",
\ "Clean" : "✔︎",
\ 'Ignored' : '☒',
\ "Unknown" : "?"
\ }
" }}}
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""" 三、YCM配置 """
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let g:ycm_global_ycm_extra_conf='~/.ycm_extra_conf.py'
" 打开vim时不再询问是否加载ycm_extra_conf.py配置
let g:ycm_confirm_extra_conf=0
autocmd InsertLeave * if pumvisible() == 0|pclose|endif "离开插入模式后自动关闭预览窗口
inoremap <expr> <CR> pumvisible() ? "\<C-y>" : "\<CR>" "回车即选中当前项
"上下左右键的行为 会显示其他信息
inoremap <expr> <Down> pumvisible() ? "\<C-n>" : "\<Down>"
inoremap <expr> <Up> pumvisible() ? "\<C-p>" : "\<Up>"
inoremap <expr> <PageDown> pumvisible() ? "\<PageDown>\<C-p>\<C-n>" : "\<PageDown>"
inoremap <expr> <PageUp> pumvisible() ? "\<PageUp>\<C-p>\<C-n>" : "\<PageUp>"
let g:ycm_python_binary_path = 'python3'
let g:ycm_autoclose_preview_window_after_completion = 1
" 在注释输入中也能补全
let g:ycm_complete_in_comments = 1
" 在字符串输入中也能补全
let g:ycm_complete_in_strings = 1
" 开启 YCM 基于标签引擎
let g:ycm_collect_identifiers_from_tags_files=1
" 注释和字符串中的文字也会被收入补全
let g:ycm_collect_identifiers_from_comments_and_strings = 1
" 禁止缓存匹配项,每次都重新生成匹配项
let g:ycm_cache_omnifunc=0
" 语言关键字补全, 不过python关键字都很短,所以,需要的自己打开
let g:ycm_seed_identifiers_with_syntax=1
let g:ycm_collect_identifiers_from_tags_files = 1
" 从第2个键入字符就开始罗列匹配项
let g:ycm_min_num_of_chars_for_completion=2
"mapping
nmap <leader>gd :YcmDiags<CR>
" 跳转到申明处
nnoremap <leader>gl :YcmCompleter GoToDeclaration<CR>
" 跳转到定义处
nnoremap <leader>gf :YcmCompleter GoToDefinition<CR>
nnoremap <leader>gg :YcmCompleter GoToDefinitionElseDeclaration<CR>
" 对指定源文件,输入两个字母后即触发语义补全
let g:ycm_semantic_triggers = {
\ 'c,cpp,python,java,go,erlang,perl': ['re!\w{2}'],
\ 'cs,lua,javascript': ['re!\w{2}'],
\ }
let g:ycm_filetype_whitelist = {
\ "c":1,
\ "cpp":1,
\ "go":1,
\ "python":1,
\ "sh":1,
\ "zsh":1,
\ }
" 黑名单,不启用
let g:ycm_filetype_blacklist = {
\ 'tagbar' : 1,
\ 'gitcommit' : 1,
\ }
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""" 1. 基本配置 """
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"set shortmess=atI " 启动的时候不显示那个援助乌干达儿童的提示
set autoindent " Indent according to previous line.
set expandtab " Use spaces instead of tabs.
set softtabstop =4 " Tab key indents by 4 spaces.
set shiftwidth =4 " >> indents by 4 spaces.
set shiftround " >> indents to next multiple of 'shiftwidth'.
set smartindent " 为C程序提供自动缩进
set noeb " 去掉输入错误的提示声音
set confirm " 在处理未保存或只读文件的时候,弹出确认
set iskeyword+=_,$,@,%,#,- " 带有如下符号的单词不要被换行分割
set smarttab " 在行和段开始处使用制表符
set completeopt=preview,menu " 代码补全
filetype plugin indent on
" 打开文件类型检测, 加了这句才可以用智能补全
set completeopt=longest,menu
" 可以在buffer的任何地方使用鼠标(类似office中在工作区双击鼠标定位)
set mouse=a
" 通过使用: commands命令,告诉我们文件的哪一行被改变过
set report=0
set hidden " Switch between buffers without having to save first.
set display =lastline " Show as much as possible of the last line.
set ttyfast " Faster redrawing.
set lazyredraw " Only redraw when necessary.
set splitbelow " Open new windows below the current window.
set splitright " Open new windows right of the current window.
set cursorline " Find the current line quickly.
set wrapscan " Searches wrap around end-of-file.
set report =0 " Always report changed lines.
set synmaxcol =120 " Only highlight the first 200 columns.
set list " Show non-printable characters.
if has('multi_byte') && &encoding ==# 'utf-8'
let &listchars = 'tab:▸ ,extends:❯,precedes:❮,nbsp:±'
else
let &listchars = 'tab:> ,extends:>,precedes:<,nbsp:.'
endif
" Put all temporary files under the same directory.
let s:vim_backup = expand("$HOME/.vim/files/backup/")
if !isdirectory(s:vim_backup)
silent! call mkdir(s:vim_backup, 'p')
endif
let s:vim_swap = expand("$HOME/.vim/files/swap/")
if !isdirectory(s:vim_swap)
silent! call mkdir(s:vim_swap, 'p')
endif
let s:vim_undo = expand("$HOME/.vim/files/undo/")
if !isdirectory(s:vim_undo)
silent! call mkdir(s:vim_undo, 'p')
endif
let s:vim_info = expand("$HOME/.vim/files/info/")
if !isdirectory(s:vim_info)
silent! call mkdir(s:vim_info, 'p')
endif
set backup
set backupdir =$HOME/.vim/files/backup/
set backupext =-vimbackup
set backupskip =
set directory =$HOME/.vim/files/swap/
set updatecount =100
set undofile
set undodir =$HOME/.vim/files/undo/
set viminfo ='100,n$HOME/.vim/files/info/viminfo
" 显示行号
set number
" 取消换行
set nowrap
" 为方便复制,用<F6>开启/关闭行号显示
nnoremap <F6> :set nonumber!<CR>:set foldcolumn=0<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""" 2. C/C++运行与调试 """
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"C、C++ 的运行
map <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
exec "w"
if &filetype == 'c'
exec "!gcc % -o %<"
exec "! ./%<"
elseif &filetype == 'cpp'
exec "!g++ % -o %<"
exec "! ./%<"
elseif &filetype == 'java'
exec "!javac %"
exec "!java %<"
elseif &filetype == 'sh'
:!./%
endif
endfunc
" C、C++的调试
map <F8> :call Rungdb()<CR>
func! Rungdb()
exec "w"
exec "!g++ % -g -o %<"
exec "!gdb ./%<"
endfunc
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""" 3. 新文件标题 """
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 新建.c,.h,.sh,.java文件,自动插入文件头
autocmd BufNewFile *.cpp,*.[ch],*.sh,*.java exec ":call SetTitle()"
"" 定义函数SetTitle,自动插入文件头
func SetTitle()
"如果文件类型为.sh文件
if &filetype == 'sh'
call setline(1,"\#########################################################################")
call append(line("."), "\# @File Name: ".expand("%"))
call append(line(".")+1, "\# @Author: Ricsy")
call append(line(".")+2, "\# @Email: Ricsy45@163.com")
call append(line(".")+3, "\# @Created Time: ".strftime("%c"))
call append(line(".")+4, "\#########################################################################")
call append(line(".")+5, "\#!/bin/bash")
call append(line(".")+6, "")
else
call setline(1, "/*************************************************************************")
call append(line("."), " > @File Name: ".expand("%"))
call append(line(".")+1, " > @Author: Ricsy")
call append(line(".")+2, " > @Email: Ricsy45@163.com")
call append(line(".")+3, " > @Created Time: ".strftime("%c"))
call append(line(".")+4, " ************************************************************************/")
call append(line(".")+5, "")
endif
if &filetype == 'cpp'
call append(line(".")+6, "#include <iostream>")
call append(line(".")+7, "using namespace std;")
call append(line(".")+8, "")
endif
if &filetype == 'c'
call append(line(".")+6, "#include <stdio.h>")
call append(line(".")+7, "#include <stdlib.h>")
call append(line(".")+8, "")
endif
" if &filetype == 'java'
" call append(line(".")+6,"public class ".expand("%"))
" call append(line(".")+7,"")
" endif
"新建文件后,自动定位到文件末尾
autocmd BufNewFile * normal G
endfunc
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""" 4. CTags的设定 """
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let Tlist_Sort_Type = "name" " 按照名称排序
let Tlist_Use_Right_Window = 1 " 在右侧显示窗口
let Tlist_Compart_Format = 1 " 压缩方式
let Tlist_Exist_OnlyWindow = 1 " 如果只有一个buffer,kill窗口也kill掉buffer
let Tlist_File_Fold_Auto_Close = 0 " 不要关闭其他文件的tags
let Tlist_Enable_Fold_Column = 0 " 不要显示折叠树
autocmd FileType java set tags+=D:\tools\java\tags
"autocmd FileType h,cpp,cc,c set tags+=D:\tools\cpp\tags
"不同时显示多个文件的tag,只显示当前文件的
"let Tlist_Show_One_File=1
"设置tags
set tags=tags
"set autochdir
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
- 安装YouCompleteMe插件
vim
:PlugInstall
提示:
- Q1:
- A1:
mkdir -p ~/.vim_runtime/sources_non_forked/ack.vim/plugged/YouCompleteMe/third_party/go/src/golang.org/x
cd ~/.vim_runtime/sources_non_forked/ack.vim/plugged/YouCompleteMe/third_party/go/src/golang.org/x
git clone https://github.com/golang/tools.git
cd ~/.vim_runtime/sources_non_forked/ack.vim/plugged/YouCompleteMe/third_party/ycmd/third_party/go/src/golang.org/x
git clone https://github.com/golang/tools.git
cd ~/.vim_runtime/sources_non_forked/ack.vim/plugged/YouCompleteMe
git submodule update --init --recursive
- 安装虚拟环境
pip3 install virtualenv
cd ~/.vim_runtime/sources_non_forked/ack.vim/plugged/YouCompleteMe
virtualenv venv
source venv/bin/activate
提示:
- 退出venv
deactivate
- 安装
./install.py --clang-completer
- 新建项目文件夹
cd ~ && mkdir mydata
cd mydata
virtualenv venv
source venv/bin/activate
vim test.py
import os
os.
提示:
pip3 install requests
参阅:
- github——junegunn
推荐
- github——amix/vimrc
推荐
- github——rust-lang/rust
推荐
- 强大的vim配置文件,让编程更随意
- Vim中nerdtree配置
- vim 常用 NERDTree 快捷键
更新中......