centos6.8 vim+python 开发环境配置(转)

本文详细介绍如何在CentOS 6.8系统下配置vim编辑器以支持Python开发,包括安装必要的软件包、配置vim环境、安装插件及设置代码补全等功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

此操作来自以下链接学来

配置vim+python开发环境

https://realpython.com/blog/python/vim-and-python-a-match-made-in-heaven/

解决上文中py文件格式配置报错

http://stackoverflow.com/questions/11087041/gvim-to-custom-highlight-group-in-vimrc-not-working

 

系统环境

1

2

3

4

[jiel@localhost ~]$ cat /etc/redhat-release 

CentOS release 6.8 (Final)

[jiel@localhost ~]$ uname -a

Linux localhost.jiel 2.6.32-642.el6.x86_64 #1 SMP Tue May 10 17:27:01 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

vim环境

1

[jiel@localhost ~]$ vim --version

输出中一定要有+python 选项

 

开始安装

安装基本环境信息

安装epel仓库

1

[jiel@localhost ~]$ sudo yum install epel-release

安装基本软件

1

[jiel@localhost ~]$ sudo yum install vim python python34 python-devel python34-devel git curl wget

 

 

安装python-pip

1

2

[jiel@localhost ~]$ curl -O https://bootstrap.pypa.io/get-pip.py

[jiel@localhost ~]$ sudo python get-pip.py

 

下载vundle

1

[jiel@localhost ~]$ git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim

创建配置文件

1

2

[jiel@localhost ~]$ touch ~/.vimrc

[jiel@localhost ~]$ vim .vimrc

填入这些基本配置

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

set nocompatible              " required

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 'gmarik/Vundle.vim'

"

" Add all your plugins here (note older versions of Vundle used Bundle

" instead of Plugin)

 

 

" All of your Plugins must be added before the following line

call vundle#end()            " required

filetype plugin indent on    " required

 

进入vim执行

:PluginInstall

 

完成后 基本设置就成功了

 

先开始安装最大的一个插件

这是一个用于代码补全的重要性也是杠杠的链接

1

Bundle 'Valloric/YouCompleteMe'

把这个填入.vimrc里面

wKioL1iPVjjD-BbMAAC49n0dPeA964.png-wh_50

 

再次执行:PluginInstall

wKiom1iPVkzzSXOqAACBcY_-QGo338.png-wh_50

 

进行一些设置避免补全窗口出问题

避免窗口丢失

1

2

3

let g:ycm_python_binary_path = 'python'

let g:ycm_autoclose_preview_window_after_completion=1

map <leader>g  :YcmCompleter GoToDefinitionElseDeclaration<CR>

 

 

设置显示行号

set nu

设置编码

set encoding=utf8

现在设置分屏

 

set splitbelow

set splitright

 

映射分屏快捷键

"split navigations

nnoremap <C-J> <C-W><C-J>

nnoremap <C-K> <C-W><C-K>

nnoremap <C-L> <C-W><C-L>

nnoremap <C-H> <C-W><C-H>

启用折叠

set foldmethod=indent

set foldlevel=99

映射空格键折叠

nnoremap <space> za

自带折叠有时候很头疼安装一个折叠插件

Plugin 'tmhedberg/SimpylFold'

设置显示折叠行字符串

let g:SimpylFold_docstring_preview=1

设置py代码格式PEP8

原文这里后面没有|会报错

au BufNewFile,BufRead *.py

\ set tabstop=4|

\ set softtabstop=4|

\ set shiftwidth=4|

\ set textwidth=79|

\ set expandtab|

\ set autoindent|

\ set fileformat=unix

安装一个自动缩进插件链接

Plugin 'vim-scripts/indentpython.vim'

标记多余的空格

原文这里也是少了一行声明highlight

highlight BadWhitespace ctermbg=red guibg=darkred

au BufRead,BufNewFile *.py,*.pyw,*.c,*.h match BadWhitespace /\s\+$/

设置C-n 打开目录树

map <C-n> :NERDTreeToggle<CR>

 

添加一个语法高亮插件链接

Plugin 'scrooloose/syntastic'

添加一个目录树插件链接

Plugin 'scrooloose/nerdtree'

添加一个C-P搜索插件链接

Plugin 'kien/ctrlp.vim'

添加一个git集成链接

Plugin 'tpope/vim-fugitive'

添加一个状态栏插件链接

Plugin 'Lokaltog/powerline', {'rtp': 'powerline/bindings/vim/'}

 

最后执行安装

:PluginInstall

 

完成后就可以开始痛苦的适应之路了

wKioL1iPXcOzRRWlAAH0P7Ks4Q8460.png-wh_50

 

 

 

$



# git clone https://github.com/Valloric/YouCompleteMe.git
#git submodule update --init --recursive
#yum install python-dev python3-dev

#python3 install.py --clang-completer --system-libclang

wget -qO- https://raw.github.com/ma6174/vim/master/setup.sh | sh -x

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值