35

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

 4 years ago
source link: https://www.tuicool.com/articles/BzQBBnY
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
RZFBV3B.png!web

说明

  • 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
ja6V327.png!web
  • 在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

mYv2MjQ.png!web

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:
6NFBVv7.png!web
  • 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

更新中......


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK