陈银山 发表于 2017-5-3 08:49:05

Fedora16 安装 vim 以及整合部分插件(for python)

  在Fedora上面使用(更新)vim以及整合部分插件(for python), 笔记如下:


0.提前准备:

0.1 'python-config' tool, Fedora提供该安装包为'python-devel'

su -c 'yum install 'python-devel''
  


这是为了后面准备将vim绑定python的解析器(提供auto-complete功能),

安装成功后将会看到类似的内容:

$ python-config
Usage: /usr/bin/python-config [--prefix|--exec-prefix|--includes|--libs|--cflags|--ldflags|--extension-suffix|--help]

  



可以解决vim编译时绑定解析器可能遇到的问题:


(cached) checking Python's configuration directory... (cached)

can't find it!

compile and link flags for Python are sane... no: PYTHON DISABLED



1.Fedora16默认情况下只提供一个vim-minimal精简版工具,当前下载vim7.3的src



2.解压,cd vim73


3.

./configure --enable-pythoninterp --enable-multibyte
  



说明:2个选项分别是将vim绑定python解析器,以及允许vim正常显示中文

更多对选项可以通过

./configure --help


4.make && sudo make install

安装完成后vim --version,可以查看得到+python +multi_byte


5.由于vim插件默认情况下不会被liunx/unix全部对用户使用,所以自己建立一个文件用于插件配置: ~/.vimrc。

$vim

:echo &runtimepath

将会看到vim运行时加载对配置路径

如果期望加载默认(share)插件配置,可以使用

set runtimepath+=/usr/local/share/vim/vim73


6.整理下当前使用的配置(编辑在~/.vimrc)

" Execute file being edited with <Shift> + e:
map <buffer> <S-e> :w<CR>:!/usr/bin/env python % <CR>
syntax on
filetype indent plugin on
set modeline
set tabstop=4
set expandtab
set softtabstop=4
set shiftwidth=4
set nonumber
nnoremap <F2> :set nonumber!<CR>:set foldcolumn=0<CR>
autocmd FileType python set omnifunc=pythoncomplete#Complete
let Tlist_Ctags_Cmd='/usr/local/bin/ctags'
map <leader>tt :TlistToggle<CR>
set fileencodings=utf-8
set termencoding=utf-8
set encoding=utf-8

  



7.说明:

" Execute file being edited with <Shift> + e:

map <buffer> <S-e> :w<CR>:!/usr/bin/env python % <CR>

扩展编辑python的时候,可以直接通过shift+e来运行代码


syntax on

filetype indent plugin on

set modeline

set tabstop=4

set expandtab

set softtabstop=4

set shiftwidth=4

默认情况下打开vim语法高亮,以及一些插件的支持和tab键的长度


set nonumber

nnoremap <F2> :set nonumber!<CR>:set foldcolumn=0<CR>

默认情况下不显示文本行数,可以直接通过F2来查看


autocmd FileType python set omnifunc=pythoncomplete#Complete
  
python autocomplete插件, 编辑代码的时候,可以使用“ctrl+x ctrl+o”完成代码补全或函数提示(以及docstring),":only" 可以只保留当前的窗口。
  

  


let Tlist_Ctags_Cmd='/usr/local/bin/ctags'

map <leader>tt :TlistToggle<CR>

查看当前代码定义了哪些函数和类

a.下载、安装ctags


b.下载taglist
插件, 将解压后的doc、plugin中的文件放置在~/.vim/doc,~/.vim/plugin

c.修改了下:TlistToggle快捷键为<leader>tt, 默认情况下<leader>键是“\”。


用法:

vim **.py

键入"\tt",将看到另一窗口

可以使用"ctrl+ww"进行切换,在“缩略大纲”(可以通过:q关闭)可以直接通过移动光标到查看目标,然后“enter”即可查看源码。

注:每次大纲里查看到的函数和类是在vim编辑进入时的,并不会随着当前代码的更新而变化,可以在下次进入时看到大纲的更新内容。
  

  


set fileencodings=utf-8

set termencoding=utf-8

set encoding=utf-8

中文编码


9.参考文档:
  
http://wiki.python.org/moin/Vim


http://dancingpenguinsoflight.com/2009/02/python-and-vim-make-your-own-ide/


http://sontek.net/turning-vim-into-a-modern-python-ide



中文编码
http://salogs.com/2010/06/vim%E8%A7%A3%E5%86%B3%E7%BC%96%E8%AF%91%E5%AE%89%E8%A3%85vim7-2%E5%90%8E%E4%B8%AD%E6%96%87%E4%B9%B1%E7%A0%81%E9%97%AE%E9%A2%98/
  http://www.cnblogs.com/hustcat/archive/2010/07/29/1788179.html
  

补充:
  1. 谢谢网络文档的分享!

2. Fedora上面使用vim遇到一些不懂的问题,目前都已经解决了,希望对你有参考帮助,如果有任何错误的理解,请帮忙指正。

3. 短暂试用了下Emacs,目前还是先更熟悉下vim
页: [1]
查看完整版本: Fedora16 安装 vim 以及整合部分插件(for python)