查看原文
其他

工欲善其事必先利其器--开发者利器vim更新篇

biocoder BT开发者 2022-09-20


1. Vim更新前言

Vim是一款高度可配置的文本编辑器,支持非常多的文件格式。我平时工作中常常需要写python , R , Rmarkdown 等脚本,或者开发相关软件包。但我太懒,不想学IDE 工具,恰好Vim 中有个叫YouCompleteMe 的插件。只要装好这个插件,那不管是python , R , 还是C++ ,Vim 基本都支持自动补全等IDE 常见的功能。但有一个问题就是,如果是使用Centos 系统的同学,会发现自带的Vim版本比较低,安装好YouCompleteMe 后会发现,系统自带的Vim 不能支持,那就只能更新Vim 了。

2. Vim下载

下载有很多方式,git 就是其中一种,当然也可以直接到官网网页https://ftp.nluug.nl/pub/vim/unix/vim-8.2.tar.bz2 直接下载。

2.1 通过git 下载

terminal 下操作

cd ~/softwares/sourceTmp/
git clone https://github.com/vim/vim.git
cd vim

2.2 通过网页下载

将在下载好的vim-8.2.tar.bz2 放到目标路径下

#也可以通过wget下载
#wget https://ftp.nluug.nl/pub/vim/unix/vim-8.2.tar.bz2
mv vim-8.2.tar.bz2 ~/softwares/sourceTmp
cd ~/softwares/sourceTmp
tar -jxf vim-8.2.tar.bz2
cd vim82

3. Vim安装

进入到Vim 的文件夹下

cd ~/softwares/sourceTmp/vim
# 或 cd ~/softwares/sourceTmp/vim82
mkdir -p /opt/devtools/vim-8.2/
configure --with-features=huge --prefix=/opt/devtools/vim-8.2/ --enable-python3interp --enable-perlinterp --enable-tclinterp --enable-rubyinterp --enable-pythoninterp
#可以通过`configure -h | less`稍微看下使用
make && make install

这里的--prefix 类似于windows 下自定义安装软件时指定的安装路径,这里我安装在/opt/devtools/vim-8.2 下,这样的好处是,如果你不想用了这个版本了,那就可以用rm -rf /opt/devtools/vim-8.2 干掉它。因为系统中原来的vim 没有被删掉, 所以你还能继续使用系统自带的。--enable-pythoninterp 是对python编写的支持。相应的还有--enable-perlinterp 对perl ,--enable-python3interp 对python3 。

4. 环境文件配置

4.1 Centos下的调用

#打开~/.bashrc文件
vi ~/.bashrc
#添加路径
export PATH=$PATH:/opt/devtools/vim-8.2/bin
#保存退出
source ~/.bashrc

4.2 Ubuntu下的调用

#打开~/.bashrc文件
vi ~/.bashrc
#添加alias
alias vim='/opt/devtools/vim-8.2/bin/vim'
alias vi='/opt/devtools/vim-8.2/bin/vim'
#保存退出
source ~/.bashrc

5. 测试

vim --version
## VIM - Vi IMproved 8.0 (2016 Sep 12, compiled Aug 17 2018 15:22:29)
## Included patches: 1-503, 505-680, 682-1283
## Compiled by root@apple.com
## Normal version without GUI. Features included (+) or not (-):
## +acl +file_in_path -mouse_sgr +tag_old_static
## -arabic +find_in_path -mouse_sysmouse -tag_any_white
## +autocmd +float -mouse_urxvt -tcl
## -balloon_eval +folding +mouse_xterm -termguicolors
## -browse -footer +multi_byte -terminal
## +builtin_terms +fork() +multi_lang +terminfo
## +byte_offset -gettext -mzscheme +termresponse
## +channel -hangul_input +netbeans_intg +textobjects
## +cindent +iconv +num64 +timers
## -clientserver +insert_expand +packages +title
## -clipboard +job +path_extra -toolbar
## +cmdline_compl +jumplist -perl +user_commands
## +cmdline_hist -keymap +persistent_undo +vertsplit
## +cmdline_info +lambda +postscript +virtualedit
## +comments -langmap +printer +visual
## -conceal +libcall -profile +visualextra
## +cryptv +linebreak +python/dyn +viminfo
## +cscope +lispindent -python3 +vreplace
## +cursorbind +listcmds +quickfix +wildignore
## +cursorshape +localmap +reltime +wildmenu
## +dialog_con -lua -rightleft +windows
## +diff +menu +ruby/dyn +writebackup
## +digraphs +mksession +scrollbind -X11
## -dnd +modify_fname +signs -xfontset
## -ebcdic +mouse +smartindent -xim
## -emacs_tags -mouseshape +startuptime -xpm
## +eval -mouse_dec +statusline -xsmp
## +ex_extra -mouse_gpm -sun_workshop -xterm_clipboard
## +extra_search -mouse_jsbterm +syntax -xterm_save
## -farsi -mouse_netterm +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/share/vim"
## Compilation: gcc -c -I. -Iproto -DHAVE_CONFIG_H -DMACOS_X_UNIX -g -O2 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=1
## Linking: gcc -L/usr/local/lib -o vim -lm -lncurses -liconv -framework Cocoa

更新好后就可以安装YouCompleteMe 了。


您可能也对以下帖子感兴趣

文章有问题?点此查看未经处理的缓存