Vim折腾笔记(六) | CentOS7中配置Python环境的Vim8

Ricsy · · 710 次点击 · · 开始浏览    
这是一个创建于 的文章,其中的信息可能已经有所发展或是发生改变。



说明

  • 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 "开发工具" -yyum 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
"===========================================================
call plug#begin()

" 目录结构展示插件
Plug 'scrooloose/nerdtree'
Plug 'Xuyuanp/nerdtree-git-plugin'

" 代码自动补全
Plug 'ycm-core/YouCompleteMe'

" 括号自动补全
Plug 'jiangmiao/auto-pairs'

" 你所有的插件必需在这一行之前添加
call plug#end()            "required

" --------------------------------------------------------------

" 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"   : "?"
    \ }
" }}}
" --------------------------------------------------------------

let g:ycm_python_binary_path = 'python3'
let g:ycm_autoclose_preview_window_after_completion = 1

" 对指定源文件,输入两个字母后即触发语义补全
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,
            \ }
"===========================================================
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 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> 
  • 安装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

参阅:


更新中......



有疑问加站长微信联系(非本文作者)

本文来自:简书

感谢作者:Ricsy

查看原文:Vim折腾笔记(六) | CentOS7中配置Python环境的Vim8

入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889

710 次点击  
加入收藏 微博
暂无回复
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传