安装步骤
1. 安装支持python3的vim
首先是卸载raspbian自带的vim,这个是必要,因为树莓派自带的vim和 sudo apt install vim 命令安装的vim都是默认不支持python2/3的,这点通过 vim --version 即可看见python和python3前面都有“-”标志,意思是不支持python。必须解决的原因是之后安装的一个重要插件“YouCompleteMe”必须依赖于vim支持python3才能使用。
安装思路很简单,卸载和vim有关的所有软件包后手动下载源码编译安装即可:
sudo apt-get remove vim vim-tiny vim-common vim-runtime #卸载raspbian一般自带的vim相关软件包
dpkg -l | grep vim #看看还有哪些vim的版本没卸载,优先使用“sudo apt purge 软件包名”来卸载
#如果发现无法卸载的情况,可以通过“whereis 软件包名”来查看文件所在位置并手动删除
#如果还出现无法删除的情况可以通过“sudo -i”切换到root帐户下删除
安装依赖包以防之后安装失败
sudo apt-get install python-dev
sudo apt-get install python3-dev
sudo apt-get install libncurses5-dev
安装vim
git clone https://github.com/vim/vim.git #下载vim源码包,本文写出时是vim8
#如果下载提示失败,可以适当调整下git的参数以实现正常下载:
git config --global http.postBuffer 20000000
cd vim
./configure --with-features=huge --enable-multibyte --enable-rubyinterp=yes --enable-python3interp=yes --with-python3-config-dir=/usr/lib/python3.5/config-3.5m-arm-linux-gnueabihf --enable-perlinterp=yes --enable-luainterp=yes --enable-gui=gtk2 --enable-cscope --prefix=/usr
#在写本文的时候只有此configure参数可以实现vim支持python3且安装过程不会出错
sudo make &&sudo make install
对于configure有关数据做个简单介绍:
--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/lib/python2.7/config-x86_64-linux-gnu/ 指定python 路径
--with-python-config-dir=/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu/ 指定python3路径,但根据测试,本文需要的vim必须支持python3而不是python2,而一旦配置2,3的配置就无效了
--prefix=/usr/local/vim:指定将要安装到的路径(自行创建,但建议不知道vim默认安装路径的时候最多/usr就可以了)
此时再通过命令vim --version即可查看到安装的vim支持python3了。至此,vim安装完成。
2. 安装专为C/C++定制的vim插件一键脚本vimplus和添加一键编译运行C/C++程序快捷键
因为vimplus并不支持一键编译安装功能,加上每次修改过程序要运行就得输入两句命令挺麻烦
gcc 文件名.c
./文件名.out
或者
gcc 文件名.c -o 制定文件名(无需后缀)
./定制文件名
作者对于实现方法的介绍的搬运
Use the following mapping code in your .vimrc file for compiling and running a c programming file.
map : !gcc % && ./a.out
F8 key is for run the mapping. "%" is to take the current file name.
Or, if you want to save the current file before compiling it, use
map :w :!gcc % && ./a.out
Or more ideally, if you want to use the file basename not the default 'a.out' as the executable file name, use the following:
map :w :!gcc % -o %< && ./%<
In the above command, " foo), so "%
You can find this and similar infos in cmdline.txt. Command in vim:help: cmdline.txt. You can also find specific details about the use of "%" by using :help filename-modifiersin vim.
CTRL+SHIF+T调出的终端中输入vim
按下组合键 ,和e (英文字母逗号和小写字母e)打开/home/pi/.vimrc,在行末添加一下一行并保存
map : !gcc % && ./a.out #vimplus默认F5,F7-10都有功能分配,我就选择将编译运行按键设置为F4