centos7使用vim打造强大的python IDE

编译升级vim

centos7.3自带的vim是7.4.*版本, YouCompleteMe需要Vim 7.4.1578+
我这里编译安装vim8.0


# 移除旧版本
sudo yum remove vim -y
# 安装必要组件
sudo yum install ncurses-devel python-devel -y
# 下载源码编译安装
git clone https://github.com/vim/vim.git
cd vim/src
# 根据自己实际情况设置编译参数
./configure --with-features=huge --=yes --enable-cscope --enable-fontset --with-python-config-dir=/usr/lib64/python2.7/config –enable-python3interp --with-python-config-dir=/usr/lib/python3.6/config --enable-multibyte --with-features=huge --prefix=/usr/local/vim/
make -j2 && make install

编译参数说明:

  • [ ] –with-features=huge:支持最大特性
  • [ ] –enable-rubyinterp:打开对ruby编写的插件的支持
  • [ ] –enable-pythoninterp:打开对python编写的插件的支持
  • [ ] –enable-python3interp:打开对python3编写的插件的支持
  • [ ] –enable-luainterp:打开对lua编写的插件的支持
  • [ ] –enable-perlinterp:打开对perl编写的插件的支持
  • [ ] –enable-multibyte:打开多字节支持,可以在Vim中输入中文
  • [ ] –enable-cscope:打开对cscope的支持
  • [ ] –with-python-config-dir=/usr/lib64/python2.7/config 指定python 路径
  • [ ] –with-python-config-dir=/usr/lib64/python3.5/config 指定python3路径

注意:必须带上Python编写插件支持,最好带上Python路径,否则使用时会报这个错误:YouCompleteMe unavailable: requires Vim compiled with Python (2.6+ or 3.6+) support

安装完成后,vim就安装在了/usr/local/vim/bin,添加环境变量,把该目录加入到PATH方便terminal全局使用

[[email protected] ~]# cat /etc/profile.d/vim.sh
export PATH=$PATH:/usr/local/vim/bin/

查看版本和支持信息:

[[email protected] ~]# vim --version
VIM - Vi IMproved 8.1 (2018 May 18, compiled Aug 20 2018 03:23:45)
Included patches: 1-299
Compiled by [email protected]
Huge version without GUI.  Features included (+) or not (-):
+acl               +extra_search      +mouse_netterm     +tag_old_static
+arabic            +farsi             +mouse_sgr         -tag_any_white
+autocmd           +file_in_path      -mouse_sysmouse    -tcl
+autochdir         +find_in_path      +mouse_urxvt       +termguicolors
-autoservername    +float             +mouse_xterm       +terminal
-balloon_eval      +folding           +multi_byte        +terminfo
+balloon_eval_term -footer            +multi_lang        +termresponse
-browse            +fork()            -mzscheme          +textobjects
++builtin_terms    +gettext           +netbeans_intg     +timers
+byte_offset       -hangul_input      +num64             +title
+channel           +iconv             +packages          -toolbar
+cindent           +insert_expand     +path_extra        +user_commands
-clientserver      +job               -perl              +vartabs
-clipboard         +jumplist          +persistent_undo   +vertsplit
+cmdline_compl     +keymap            +postscript        +virtualedit
+cmdline_hist      +lambda            +printer           +visual
+cmdline_info      +langmap           +profile           +visualextra
+comments          +libcall           +python            +viminfo
+conceal           +linebreak         -python3           +vreplace
+cryptv            +lispindent        +quickfix          +wildignore
+cscope            +listcmds          +reltime           +wildmenu
+cursorbind        +localmap          +rightleft         +windows
+cursorshape       -lua               -ruby              +writebackup
+dialog_con        +menu              +scrollbind        -X11
+diff              +mksession         +signs             -xfontset
+digraphs          +modify_fname      +smartindent       -xim
-dnd               +mouse             +startuptime       -xpm
-ebcdic            -mouseshape        +statusline        -xsmp
+emacs_tags        +mouse_dec         -sun_workshop      -xterm_clipboard
+eval              -mouse_gpm         +syntax            -xterm_save
+ex_extra          -mouse_jsbterm     +tag_binary
   system vimrc file: "$VIM/vimrc"
     user vimrc file: "$HOME/.vimrc"
 2nd user vimrc file: "~/.vim/vimrc"
      user exrc file: "$HOME/.exrc"
       defaults file: "$VIMRUNTIME/defaults.vim"
  fall-back for $VIM: "/usr/local/vim/share/vim"
Compilation: gcc -std=gnu99 -c -I. -Iproto -DHAVE_CONFIG_H     -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
Linking: gcc -std=gnu99   -L/usr/local/lib -Wl,--as-needed -o vim        -lm -ltinfo -lnsl  -lselinux  -ldl    -L/usr/lib64/python2.7/config -lpython2.7 -lpthread -ldl -lutil -lm -Xlinker -export-dynamic  

安装应用:

pip install pep8 flake8 pyflakes isort yapf autopep8 powerline-status

安装Vundle和YouCompleteMe

Vundle是Vim的插件管理工具,官方文档:https://github.com/VundleVim/Vundle.vim

安装步骤很简单:

git clone https://github.com/VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

添加颜色主题方案

我这里使用monokai 配色方案 :https://github.com/sickill/vim-monokai

下载对应的monokai.vim 文件 放到 ~/.vim/colors/ 即可

mkdir ~/.vim/colors
wget -O ~/.vim/colors/monokai.vim https://raw.githubusercontent.com/sickill/vim-monokai/master/colors/monokai.vim
vim .vimrc

清空后更改为如下内容:

set encoding=utf-8
"去掉vi的一致性"
set nocompatible
"显示行号"
"set number
set nobackup
set nowb
set noswapfile
set noundofile
set showcmd
" 隐藏滚动条"
"set guioptions-=r
"set guioptions-=L
"set guioptions-=b
"隐藏顶部标签栏"
"set showtabline=0
"设置字体"
"set guifont=Monaco:h13
syntax on    "开启语法高亮"
"let g:solarized_termcolors=256    "solarized主题设置在终端下的设置"
set background=dark        "设置背景色"
"colorscheme ron
colorscheme monokai
set nowrap    "设置不折行"
set fileformat=unix    "设置以unix的格式保存文件"
set cindent        "设置C样式的缩进格式"
set tabstop=4    "设置table长度"
set softtabstop=4
set noexpandtab
set shiftwidth=4        "同上"
set showmatch    "显示匹配的括号"
set scrolloff=5        "距离顶部和底部5行"
set laststatus=2    "命令行为两行"
set fenc=utf-8      "文件编码"
set backspace=2
set mouse=c        "启用鼠标"
set selection=exclusive
set selectmode=mouse,key
"set matchtime=5
set ignorecase        "忽略大小写"
"set incsearch
set hlsearch        "高亮搜索项"
"set noexpandtab        "不允许扩展table"
set whichwrap+=<,>,h,l
set autoread
"set cursorline        "突出显示当前行"
"set cursorcolumn        "突出显示当前列"

" C++ part
set exrc
set secure

augroup project
    autocmd!
    autocmd BufRead,BufNewFile *.h,*.c set filetype=c.doxygen
    autocmd BufRead,BufNewFile *.hpp,*.cpp set filetype=cpp.doxygen
augroup END

set makeprg=make\ -C\ -j64
nnoremap <F3> :make!<cr>

"Vundle
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin ‘VundleVim/Vundle.vim‘
Plugin ‘Valloric/YouCompleteMe‘
Plugin ‘Lokaltog/vim-powerline‘
Plugin ‘scrooloose/nerdtree‘
Plugin ‘Yggdroot/indentLine‘
Plugin ‘jiangmiao/auto-pairs‘
Plugin ‘tell-k/vim-autopep8‘
Plugin ‘scrooloose/nerdcommenter‘
Plugin ‘Tagbar‘
Plugin ‘Lokaltog/powerline‘, {‘rtp‘: ‘powerline/bindings/vim/‘}
call vundle#end()
filetype plugin indent on

"按F5运行python"
map <F5> :Autopep8<CR> :w<CR> :call RunPython()<CR>
function RunPython()
  let mp = &makeprg
  let ef = &errorformat
  let exeFile = expand("%:t")
  setlocal makeprg=python\ -u
  set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
  silent make %
  copen
  let &makeprg = mp
  let &errorformat = ef
endfunction

" 设置tagbar的窗口宽度
let g:tagbar_width=30
" 映射Tagbar的快捷键,按F6自动打开
map <F6> :TagbarToggle<CR>

"按F9运行python调试"
map <F9> :Autopep8<CR> :w<CR> :call RunPythonDebug()<CR>
function RunPythonDebug()
  let mp = &makeprg
  let ef = &errorformat
  let exeFile = expand("%:t")
  setlocal makeprg=python\ -m\ pdb
  set efm=%C\ %.%#,%A\ \ File\ \"%f\"\\,\ line\ %l%.%#,%Z%[%^\ ]%\\@=%m
  silent make %
  copen
  let &makeprg = mp
  let &errorformat = ef
endfunction

"YouCompleteMe
"默认配置文件路径"
let g:ycm_global_ycm_extra_conf = ‘~/.vim/bundle/YouCompleteMe/third_party/ycmd/examples/.ycm_extra_conf.py‘
"打开vim时不再询问是否加载ycm_extra_conf.py配置"
let g:ycm_confirm_extra_conf=0
set completeopt=longest,menu
"python解释器路径"
let g:ycm_path_to_python_interpreter=‘/usr/bin/python‘
"是否开启语义补全"
let g:ycm_seed_identifiers_with_syntax=1
"是否在注释中也开启补全"
let g:ycm_complete_in_comments=1
let g:ycm_collect_identifiers_from_comments_and_strings = 0
"开始补全的字符数"
let g:ycm_min_num_of_chars_for_completion=2
"补全后自动关机预览窗口"
let g:ycm_autoclose_preview_window_after_completion=1
" 禁止缓存匹配项,每次都重新生成匹配项"
let g:ycm_cache_omnifunc=0
"字符串中也开启补全"
let g:ycm_complete_in_strings = 1
"离开插入模式后自动关闭预览窗口"
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>‘
"YouCompleteMe clang settings
let g:clang_format#style_options = {
             \ "AccessModifierOffset" : -4,
             \ "AllowShortIfStatementsOnASingleLine" : "true",
             \ "AlwaysBreakTemplateDeclarations" : "true",
             \ "Standard" : "C++11"}
let g:clang_format#auto_format=1

"Nerd tree
"F2开启和关闭树"
map <F2> :NERDTreeToggle<CR>
let NERDTreeChDirMode=1
"显示书签"
let NERDTreeShowBookmarks=1
"设置忽略文件类型"
let NERDTreeIgnore=[‘\~$‘, ‘\.pyc$‘, ‘\.swp$‘]
"窗口大小"
let NERDTreeWinSize=25

"缩进指示线"
let g:indentLine_char=‘┆‘
let g:indentLine_enabled = 1
"autopep8设置"
let g:autopep8_disable_show_diff=1
autocmd Filetype python noremap <buffer> <F8> :call Autopep8()<CR>

map <F4> <leader>ci <CR>

安装插件

打开任意一vim编辑窗口,使用命令模式键入以下命令即可实现对应功能

:PluginList - 列出所有已配置的插件
:PluginInstall - 安装插件,追加 `!` 用以更新或使用
:PluginUpdate:PluginSearch foo - 搜索 foo ; 追加 `!` 清除本地缓存
:PluginClean - 清除未使用插件,需要确认; 追加 `!` 自动批准移除未使用插件
:h vundle 获取更多细节和wiki以及FAQ

或者通过以下快速安装:

 vim +PluginInstall +qall

附加

增加clang:添加C语言家族语法补全功能

sudo yum install cmake -y
cd ~/.vim/plugin/YouCompleteMe
./install.py --clang-completer

效果如图:

原文地址:http://blog.51cto.com/m51cto/2162161

时间: 2024-10-07 22:36:36

centos7使用vim打造强大的python IDE的相关文章

PTVS+VS2013 Shell实现免费轻巧强大的Python IDE

1.前言 Halo!现在开始写第一篇Blog,有点小激动呢,以后请大家多多指教! PTVS (Python Tools for Visual Studio) 是一个开源项目,采用Apache 2.0许可发布,主要功能呢就是可以在Visual Studio上码Python及IronPython等,可以实现高级编辑功能.智能感知(Intellisense),代码浏览等功能.网上的资料挺多的,我这里就不说其他废话了.但我从网上找到的大多是在VS上安装插件的形式来使用PTVS的方法,我之前也是以插件的形

使用vim打造自己的python编辑器

基础配置 vim的配置是在用户主目录下的 ~/.vimrc 文件中完成的,如果没有的话,需要自己新建一下: 1 2 cd ~ touch .vimrc 首先做些简单的配置: 1 2 3 4 5 6 7 8 9 10 set nocompatible "关闭与vi的兼容模式 set number "显示行号 set nowrap    "不自动折行 set showmatch    "显示匹配的括号 set scrolloff=3        "距离顶部和

vim as python IDE

参照Martin Brochhaus大神的视频,今天我也尝试了一下配置vim python IDE以后使用过程中只需要https://github.com/wyj1239630590/vim-as-a-python-ide, 然后将.vimrc复制到家目录下,安装包管理器与需要的插件即可(.vimrc的注释文件中有). 目前支持的功能: , + m or n : 前后切换tabctrl + > or < : 给选中的行增加或者减少缩进f and F : 对python中的函数进行折叠或者去折叠

使用VIM打造IDE(针对C语言)

=============================== 话不多说,先来看看效果 =============================== ================================ 使用vim打造IDE, 针对C语言开发者 建议使用gvim ================================ # 安装ruby, command-t插件会用到 sudo apt install ruby ruby-dev # 安装vim, vim-gtk sudo

vim打造IDE

1.首先安装插件管理器 Pathogen Install to ~/.vim/autoload/pathogen.vim mkdir -p ~/.vim/autoload ~/.vim/bundle && curl -LSso ~/.vim/autoload/pathogen.vim https://tpo.pe/pathogen.vim 在Centos家目录中新建.vimrc文件,添加: execute pathogen#infect() syntax on filetype plugi

Use Vim as a Python IDE

Use Vim as a Python IDE I love vim and often use it to write Python code. Here are some useful plugins and tools for building a delightful vim python environment, escpecially for Vim8: 我喜欢vim,经常用它来编写Python代码.以下是一些有用的插件和工具,用于构建令人愉快的vim-python环境,尤其是vim

Ubuntu16.04下使用sublime text3搭建Python IDE

本来是想用pycharm,但你看它的内存要求,我的虚拟机一共也就1G Vim太别扭了,就算有代码颜色,不能自动对齐,不能规范格式,跳转到函数定义,显示文档,要配置起来太费劲,所以就尝试着用sublime text3 来搭建Python IDE 安装sublime text3 目前最简单的方法是通过ppa安装,打开终端,输入以下命令: sudo add-apt-repository ppa:webupd8team/sublime-text-3 sudo apt-get update sudo ap

转载八个最佳Python IDE

八个最佳Python IDE 作者:chszs,转载需注明.博客主页:http://blog.csdn.net/chszs Python是一种功能强大.语言简洁的编程语言.本文向大家推荐8个适合Python开发的IDE. 1. Eclipse with PyDev http://pydev.org/ Eclipse+PyDev插件,很适合开发Python Web应用,其特征包括自动代码完成.语法高亮.代码分析.调试器.以及内置的交互浏览器. 2. Komodo Edit http://komod

八个最佳Python IDE

八个最佳Python IDE 作者:chszs,转载需注明.博客主页:http://blog.csdn.net/chszs Python是一种功能强大.语言简洁的编程语言.本文向大家推荐8个适合Python开发的IDE. 1. Eclipse with PyDev http://pydev.org/ Eclipse+PyDev插件,很适合开发Python Web应用,其特征包括自动代码完成.语法高亮.代码分析.调试器.以及内置的交互浏览器. 2. Komodo Edit http://komod