如何在树莓派上进行python编程_树莓派下为vi配置python开发环境

之前的文章:树莓派(Raspberry PI)上的PyQt 安装,记录了树莓派上安装PyQt库来开发有GUI的python应用程序的过程。但在用默认的vi编写代码时还是蛮痛苦的,没有语法高亮,没有自动补全,现在把这些给加上, 参考网友的文单:Vim 的 Python 编辑器详细配置过程 (Based on Ubuntu 12.04 LTS),是基于ubuntu的,在树莓派上做下来,也是一样的,过程如下:

首先得有vim, Raspbian系统自带有vim, 也可以再装一次,不同版本的vim网上说是“不同的编译选项编译出来的vim而已”,怎么编译,有时间研究一下。

Shell

apt-get install vim

1

apt-getinstallvim

或:

Shell

apt-get install vim-gnome

1

apt-getinstallvim-gnome

实现跳转,安装ctags

Shell

apt-get install ctags

1

apt-getinstallctags

其实ctags不是vim插件,在源码下目录下运行敲:ctags -R 就会在同一目录下生成一个名为tags的文件,然后在vi里按’ctrl-]’为可以跳转到当前光标所在的变量/函数/类/等的定义处。 按‘ctrl-t’返回。

实现左边或右边显示所有tag, 如变量/函数/类/等显示,点击即可跳转到定义处。就是安装一个插件:taglist, 为了实装taglist, 先安装vim-scripts, 它带有vim-addon-manager插件管理器.

Shell

apt-get install vim-scripts

vim-addons install taglist

1

2

apt-getinstallvim-scripts

vim-addonsinstalltaglist

Vim

以下是一些taglist相关的命令与配置:

默认关闭taglist,在.vimrc写入:

let Tlist_Auto_Open=0

在正常编辑区域和tags区域切换命令 :ctrl+w+w。

TlistToggle:开关taglist。

:跳转至tag定义处。

o:在新窗口中显示光标下的tag。

u:更新taglist窗口中的tag。

s:更改排序方式,名字排序或行号排序。

X:taglist窗口放大缩小。

+:打开折叠,等同zo。

-:关闭折叠,等同zc。

*:打开所有折叠,等同zR。

=:将所有tag折叠,等同zM。

[[:跳转至前一个文件。

]]:跳转至后一个文件。

q:关闭taglist窗口。

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

以下是一些taglist相关的命令与配置:

默认关闭taglist,在.vimrc写入:

letTlist_Auto_Open=0

在正常编辑区域和tags区域切换命令:ctrl+w+w。

TlistToggle:开关taglist。

:跳转至tag定义处。

o:在新窗口中显示光标下的tag。

u:更新taglist窗口中的tag。

s:更改排序方式,名字排序或行号排序。

X:taglist窗口放大缩小。

+:打开折叠,等同zo。

-:关闭折叠,等同zc。

*:打开所有折叠,等同zR。

=:将所有tag折叠,等同zM。

[[:跳转至前一个文件。

]]:跳转至后一个文件。

q:关闭taglist窗口。

安装pydiction。 pydiction是用来实现对python文件代码补全和语法提示功能。下载:https://github.com/rkulla/pydiction , 解压后,进入pydiction目录。

PHP

mkdir -pv ~/.vim/after/ftplugin

cp after/ftplugin/python_pydiction.vim ~/.vim/after/ftplugin

cp complete-dict ~/.vim

cp pydiction.py ~/.vim

1

2

3

4

mkdir-pv~/.vim/after/ftplugin

cpafter/ftplugin/python_pydiction.vim~/.vim/after/ftplugin

cpcomplete-dict~/.vim

cppydiction.py~/.vim

这3个文件的功能:

INI

python_pydiction.vim: vim插件文件

complete-dict: 一个基于文本的字典文件, 包含了python的关键字和模块。插件引用的内容就来自于此。

pydiction.py: 一个py脚本,可通过它增加新的模块到complete-dict字典中。

1

2

3

python_pydiction.vim:vim插件文件

complete-dict:一个基于文本的字典文件,包含了python的关键字和模块。插件引用的内容就来自于此。

pydiction.py:一个py脚本,可通过它增加新的模块到complete-dict字典中。

找到~/.vimrc文件, 如果没有就添加一个,然后向里面添加如下内容

Vim

let Tlist_Auto_Highlight_Tag=1

let Tlist_Auto_Open=1

let Tlist_Auto_Update=1

let Tlist_Display_Tag_Scope=1

let Tlist_Exit_OnlyWindow=1

let Tlist_Enable_Dold_Column=1

let Tlist_File_Fold_Auto_Close=1

let Tlist_Show_One_File=1

let Tlist_Use_Right_Window=1

let Tlist_Use_SingleClick=1

nnoremap :TlistToggle

filetype plugin on

autocmd FileType python set omnifunc=pythoncomplete#Complete

autocmd FileType javascrīpt set omnifunc=javascriptcomplete#CompleteJS

autocmd FileType html set omnifunc=htmlcomplete#CompleteTags

autocmd FileType css set omnifunc=csscomplete#CompleteCSS

autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags

autocmd FileType php set omnifunc=phpcomplete#CompletePHP

autocmd FileType c set omnifunc=ccomplete#Complete

let g:pydiction_location='~/.vim/after/ftplugin/complete-dict'

set autoindent

set tabstop=4

set shiftwidth=4

set expandtab

set number

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

letTlist_Auto_Highlight_Tag=1

letTlist_Auto_Open=1

letTlist_Auto_Update=1

letTlist_Display_Tag_Scope=1

letTlist_Exit_OnlyWindow=1

letTlist_Enable_Dold_Column=1

letTlist_File_Fold_Auto_Close=1

letTlist_Show_One_File=1

letTlist_Use_Right_Window=1

letTlist_Use_SingleClick=1

nnoremap:TlistToggle

filetypepluginon

autocmdFileTypepythonsetomnifunc=pythoncomplete#Complete

autocmdFileTypejavascrīptsetomnifunc=javascriptcomplete#CompleteJS

autocmdFileTypehtmlsetomnifunc=htmlcomplete#CompleteTags

autocmdFileTypecsssetomnifunc=csscomplete#CompleteCSS

autocmdFileTypexmlsetomnifunc=xmlcomplete#CompleteTags

autocmdFileTypephpsetomnifunc=phpcomplete#CompletePHP

autocmdFileTypecsetomnifunc=ccomplete#Complete

letg:pydiction_location='~/.vim/after/ftplugin/complete-dict'

setautoindent

settabstop=4

setshiftwidth=4

setexpandtab

setnumber

到此已经基本完成python开发环境的搭建。试了一下效果: 2015-11-08-130538_1073x614_scrot.png

————————分割线,下面完善vim本身——————————————-

安装pathogen.vim

Shell

cd ~

git clone https://github.com/tpope/vim-pathogen.git

mkdir -p ~/.vim/autoload ~/.vimbundle

cp vim-pathogen/autoload/pathogen.vim ~/.vim/autoload/

1

2

3

4

cd~

gitclonehttps://github.com/tpope/vim-pathogen.git

mkdir-p~/.vim/autoload~/.vimbundle

cpvim-pathogen/autoload/pathogen.vim~/.vim/autoload/

然后向.vimrc里添加一句:

Vim

execute pathogen#infect()

1

executepathogen#infect()

完成安装pathogen.vim, 以后把vim插件解压到~/.vim/bundle中,它会被自动加到“runtimepath”中。

7 . 折叠代码

简介:将Python代码折叠,Python的class,function,以及在{{{,}}}标记的内容将被折叠。

安装:

将下载的python_fold.vim拷贝到 ~/.vim/plugin 目录下。

关闭开启时默认折叠命令,在.vimrc写入:

Shell

set nofoldenable

1

setnofoldenable

zo: 展开单个折叠区。

zc: 聚合单个折叠区。

zn: 展开全部折叠区。

zN: 聚合全部折叠区。

8. NERDTree目录树

PHP

cd ~/.vim/bundle

git clone https://github.com/scrooloose/nerdtree.git

1

2

cd~/.vim/bundle

gitclonehttps://github.com/scrooloose/nerdtree.git

9. 自动补全

acp.vim

l9.vim

打赏

weixin198crop.png

ico-wechat.jpg微信扫一扫,打赏作者吧~

Post Views:

2,570

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值