600字范文,内容丰富有趣,生活中的好帮手!
600字范文 > linux vim go语言 CentOS7系统基于Vim8搭建Go语言开发环境

linux vim go语言 CentOS7系统基于Vim8搭建Go语言开发环境

时间:2022-12-20 02:55:18

相关推荐

linux vim go语言 CentOS7系统基于Vim8搭建Go语言开发环境

主要是在vim中通过vundle来安装vim-go插件、gocode插件,支持代码高亮、代码提示以及语法检查等功能

安装Golang 1.11.2

curl -Lo golang.tar.gz /go/go1.11.2.linux-amd64.tar.gz

tar zxf golang.tar.gz -C /opt

mkdir -p /home/golang/{go,other}

在/etc/profile尾部添加

export GOROOT=/opt/go

export GOPATH=/home/golang/go:/home/golang/other #多个工作目录用:分隔

export PATH=$PATH:$GOROOT/bin:${GOPATH//://bin:}/bin

source /etc/profile

安装Vim 8.1

卸载旧版本的vim

yum remove vim vim-common vim-minimal #注意卸载vim-minimal会卸载sudo

# 安装vim 8

curl -Lo vim8.tar.gz /vim/vim/archive/v8.1.0513.tar.gz

tar zxf vim8.tar.gz

cd vim-8.1.0513

yum install gcc ncurses ncurses-devel

./configure \

--with-features=huge \

--enable-pythoninterp=yes \

--enable-cscope \

--enable-fontset \

--with-python-config-dir=/usr/lib64/python2.7/config

说明:

–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/lib64/python2.7/config 指定python 路径

–with-python-config-dir=/usr/lib64/python3.5/config 指定python3路径

vim --version | grep python #查看vim是否包含对python的支持

make

make install #会安装到/usr/local/bin/vim

安装vim插件管理工具vundle

yum install git

git clone /VundleVim/Vundle.vim.git ~/.vim/bundle/Vundle.vim

编辑~/.vimrc 进行配置

syntax on

"set nu

set nocompatible

filetype off

set rtp+=~/.vim/bundle/Vundle.vim

call vundle#begin()

Plugin 'VundleVim/Vundle.vim'

call vundle#end()

filetype plugin indent on

打开vim 输入:PluginInstall 将自动安装插件

之后的安装插件安装,仅需添加Plugin 'xxx'语句到~/.vimrc文件中

安装Go语言代码检查和高亮插件vim-go

在~/.vimrc中添加 Plugin 'fatih/vim-go'

打开vim 输入:PluginInstall

默认代码并不会高亮显示,需要配置,编辑~/.vimrc文件

syntax on

"set nu

set nocompatible

filetype off

set rtp+=~/.vim/bundle/Vundle.vim

call vundle#begin()

Plugin 'VundleVim/Vundle.vim'

Plugin 'fatih/vim-go'

call vundle#end()

filetype plugin indent on

let g:go_version_warning = 1

let g:go_highlight_types = 1

let g:go_highlight_fields = 1

let g:go_highlight_functions = 1

let g:go_highlight_function_calls = 1

let g:go_highlight_operators = 1

let g:go_highlight_extra_types = 1

安装代码补全工具YouCompleteMe

在~/.vimrc中添加 Plugin 'Valloric/YouCompleteMe'

打开vim 输入:PluginInstall

# 这个过程比较慢 会下载大约225MB文件

YMC安装完成后,需要编译才能使用,编译时要选择支持的语言,这里选择Golang

cd ~/.vim/bundle/YouCompleteMe/

yum install cmake python-devel gcc-c++

./install.sh --go-completer

设置tab键为4个空格

在~/.vimrc中添加

#解决退格键问题

set nocompatible

set backspace=indent,eol,start

#设置tab为四个空格

set ts=4

set expandtab

安装目录结构展示插件nerdtree

在~/.vimrc中添加 Plugin 'scrooloose/nerdtree'

打开vim 输入:PluginInstall

自动启用

在.vimrc中添加 autocmd vimenter * NERDTree

安装代码结构展示插件Tagbar

go get -u /jstemmer/gotags

yum install ctags

在~/.vimrc中添加 Plugin 'Tagbar'

打开vim 输入:PluginInstall

使用时,输入 :Tagbar

最终效果:

.vimrc文件:

Vim

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

setnocompatible

setts=4

setexpandtab

setbackspace=indent,eol,start

syntaxon

"set nu

filetypeoff

setrtp+=~/.vim/bundle/Vundle.vim

callvundle#begin()

Plugin'VundleVim/Vundle.vim'

Plugin'fatih/vim-go'

Plugin'Valloric/YouCompleteMe'

Plugin'scrooloose/nerdtree'

Plugin'Tagbar'

callvundle#end()

filetypepluginindenton

letg:go_version_warning=1

letg:go_highlight_types=1

letg:go_highlight_fields=1

letg:go_highlight_functions=1

letg:go_highlight_function_calls=1

letg:go_highlight_operators=1

letg:go_highlight_extra_types=1

autocmdvimenter*NERDTree

参考:

Vim

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

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

"==========================================

"通用

"==========================================

"history存储长度

sethistory=1000

"检测文件类型

filetypeon

"针对不同的文件类型采用不同的缩进格式

filetypeindenton

"允许插件

filetypepluginon

"启动自动补全

filetypepluginindenton

"兼容vi模式。去掉讨厌的有关vi一致性模式,避免以前版本的一些bug和局限

setnocompatible

"文件修改之后自动载入

setautoread

"启动时不显示那个援助索马里儿童的提示

setshortmess=atI

"取消备份

setnobackup

setnowb

setnoswapfile

"粘贴时保持格式

setpaste

"- 则点击光标不会换,用于复制

setmouse-=a" 在所有的模式下面打开鼠标

setselection=exclusive

setselectmode=mouse,key

"去掉输入错误的提示声音

setnoerrorbells

setnovisualbell

sett_vb=

settm=500

"==========================================

" 显示和格式

"==========================================

"显示行号

setnumber

"取消换行

setnowrap

"为方便复制,用开启/关闭行号显示

nnoremap:setnonumber!:setfoldcolumn=0

"括号配对情况

setshowmatch

"How many tenths of a second to blink when matching brackets

setmat=2

"高亮search命中的文本。

sethlsearch

"搜索时忽略大小写

setignorecase

"随着键入即时搜索

setincsearch

"有一个或以上大写字母时仍大小写敏感

setsmartcase

"代码折叠

setfoldenable

"折叠方法

" manual 手工折叠

" indent 使用缩进表示折叠

" expr 使用表达式定义折叠

" syntax 使用语法定义折叠

" diff 对没有更改的文本进行折叠

" marker 使用标记进行折叠, 默认标记是 {{{ 和 }}}

setfoldmethod=syntax

"设置Tab键的宽度 [等同的空格个数]

setfoldcolumn=4

settabstop=4

setshiftwidth=4

setexpandtab" 将Tab自动转化成空格 [需要输入真正的Tab键时,使用 Ctrl+V + Tab]

"按退格键时可以一次删掉 4 个空格

setsofttabstop=4

setai"Auto indent

setsi"Smart indent

"==========================================

"状态

"==========================================

"显示当前的行号列号

setruler

"在状态栏显示正在输入的命令

setshowcmd

"Set 7 lines to the cursor - when moving vertically using j/k 上下滚动,始终在中间

setso=7

"突出显示当前行

setcursorline

喜欢 (0)or分享 (0)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。