Development Tip

VIM에 대한 GoLang 구문 강조 표시 추가

yourdevel 2021. 1. 9. 11:02
반응형

VIM에 대한 GoLang 구문 강조 표시 추가


http://go-lang.cat-v.org/text-editors/vim/ 여기에 제공된 리소스와 방향을 사용하여 우분투의 VIM에 Go 언어 구문 강조 표시를 추가하려고합니다 .

Go는 go.vimVIM에 대한 구문 설정이 포함 파일 과 함께 제공되며 위 페이지에서는 다음 지침을 제공합니다.

$ GOROOT / misc / vim / syntax / go.vim을 ~ / .vim / syntax /에 넣고 다음을 ~ / .vim / ftdetect / go.vim에 넣습니다.

au BufRead,BufNewFile *.go set filetype=go 

이것은 사용자 정의 정력 구문 나는 다른 곳에서 (본 적이을위한 절차의 더 많거나 적은 같은 맥락이다 'ftplugin'디렉토리의 어느 곳이 없습니다 우분투 12.10에 빔 7.3https://github.com/jnwhiteh/vim-golang/blob /master/readme.txt )

그래서 디렉토리를 만들 때 옳은 일을하고 있다고 생각합니다 :
~ / .vim
~ / .vim / syntax
~ / .vim / ftdetect

추가하여 위의 지침을 따르십시오.

go.vim을 ~ / .vim / syntax /로 만들고 ~ / .vim / ftdetect /에 파일 go.vim을 만듭니다.

au BufRead,BufNewFile *.go set filetype=go

그러나 구문 강조가 발생하지 않는 것 같습니다. VIM이 이러한 새 설정 파일을 보도록 강제하기 위해해야 ​​할 일이 있습니까?


다음 줄을 추가 할 수 있습니다 ~/.vimrc.

set rtp+=$GOROOT/misc/vim
filetype plugin indent on
syntax on

편집 이것은 filetype plugin indent off이러한 줄 (즉, .vimrc파일의 시작) 이전에 가정 하고 그렇지 않은 경우 문제를 일으킬 수 있습니다. 더 안전한 버전은 아래 @peterSO의 답변을 참조하십시오.


최신 정보:

Go 1.4 릴리스 정보

잡록

편집기 및 IDE (플러그인, 초기화 스크립트 등)에 대한 Go 지원을 포함하는 데 사용되는 표준 저장소의 최상위 기타 디렉토리입니다. 목록에있는 편집자 중 상당수가 핵심 팀의 구성원이 사용하지 않았기 때문에이를 유지하는 데 시간이 많이 걸리고 외부 도움이 필요했습니다. 또한 우리가 사용하지 않는 편집자에게도 주어진 편집자에게 어떤 플러그인이 가장 적합한 지 결정해야했습니다. 일반적으로 Go 커뮤니티는이 정보를 관리하는 데 훨씬 더 적합합니다. 따라서 Go 1.4에서는이 지원이 저장소에서 제거되었습니다. 대신 위키 페이지 에서 사용할 수있는 정보에 대한 선별 된 정보 목록이 있습니다 .


표준 Go 배포에는 Vim 용 Go 파일이 go/misc/vim/. 이 디렉토리에는 readme.txt설치 지침 이 포함 된 파일이 있습니다.

readme.txt

Go 용 Vim 플러그인 ( http://golang.org)

모든 Vim 플러그인을 사용하려면 다음 줄을 $HOME/.vimrc.

" Some Linux distributions set filetype in /etc/vimrc.
" Clear filetype flags before changing runtimepath to force Vim to reload them.
filetype off
filetype plugin indent off
set runtimepath+=$GOROOT/misc/vim
filetype plugin indent on
syntax on

더 적은 수의 플러그인을 선택하려면이 파일의 나머지 부분에있는 지침을 따르십시오.

<< .. SNIP .. >>


데비안에서는 우분투에서도 동일하다고 가정합니다.

sudo apt-get install vim-gocomplete gocode vim-syntax-go
vim-addon-manager install go-syntax
vim-addon-manager install gocode

최고의 구문 강조를 위해 https://github.com/fatih/vim-go를 시도 하십시오.

많은 vim 플러그인을 통합하고 많은 기능을 추가하는 새로운 프로젝트입니다. Readme에서 :

  • 함수, 연산자, 메서드와 같은 향상된 구문 강조 표시 ..
  • gocode를 통한 자동 완성 지원
  • 저장시 더 나은 gofmt, 커서 위치 유지 및 실행 취소 기록을 깨지 않음
  • godef로 기호 / 선언으로 이동
  • goimports를 통해 자동으로 패키지 가져 오기
  • 패키지를 컴파일하고 빌드하고 go install로 설치하십시오.
  • 현재 파일 / 파일을 빠르게 실행하십시오.
  • Run go test and see any errors in quickfix window
  • Lint your code with golint
  • Run your code trough go vet to catch static errors.
  • Advanced source analysis tool with oracle
  • List all source files and dependencies
  • Checking with errcheck for unchecked errors.
  • Integrated and improved snippets. Supports ultisnips or neosnippet
  • Share your current code to play.golang.org

on 25/Jan/2015

Please see https://github.com/golang/go/wiki/IDEsAndTextEditorPlugins as now all editor & shell support in Go repo is removed (https://codereview.appspot.com/105470043)


For whatever reason outside of my own decision making, we got Golang installed on our dev VMs by Debian packages. This particular distribution of vim doesn't come with any of the goodies for vim as far as I was able to tell from a search around for it. Anyways, I decided to go the vundle route in order to rapidly deploy the goodies to all these dev VMs. You could probably work this method into puppet or something if you'd like, we didn't do that though. Anyways, here's what I did:

Step 1: Install vundle: https://github.com/gmarik/vundle

Step 2: put this line in your .vimrc (It's from here, of course: https://github.com/jnwhiteh/vim-golang ), and then run vim from the command line like vim +BundleInstall +qall or from within vim with :BundleInstall

Bundle 'jnwhiteh/vim-golang'

Step 3: Save this little bash script I whipped up as govim.sh or whatever, chmod +x govim.sh, and run it like ./govim.sh

Script as follows:

#!/bin/bash
mkdir $HOME/.vim/ftdetect
mkdir $HOME/.vim/syntax
mkdir $HOME/.vim/autoload
mkdir $HOME/.vim/autoload/go
mkdir $HOME/.vim/ftplugin
mkdir $HOME/.vim/ftplugin/go
mkdir $HOME/.vim/indent
mkdir $HOME/.vim/compiler
mkdir $HOME/.vim/plugin
mkdir $HOME/.vim/plugin/godoc
ln -s $HOME/.vim/bundle/vim-golang/ftdetect/gofiletype.vim $HOME/.vim/ftdetect
ln -s $HOME/.vim/bundle/vim-golang/syntax/go.vim $HOME/.vim/syntax/
ln -s $HOME/.vim/bundle/vim-golang/autoload/go/complete.vim $HOME/.vim/autoload/go/
ln -s $HOME/.vim/bundle/vim-golang/ftplugin/go.vim $HOME/.vim/ftplugin/
ln -s $HOME/.vim/bundle/vim-golang/ftplugin/go/*.vim $HOME/.vim/ftplugin/go/
ln -s $HOME/.vim/bundle/vim-golang/indent/go.vim $HOME/.vim/indent/
ln -s $HOME/.vim/bundle/vim-golang/compiler/go.vim $HOME/.vim/compiler/
ln -s $HOME/.vim/bundle/vim-golang/plugin/godoc/godoc.vim $HOME/.vim/plugin/godoc/
ln -s $HOME/.vim/bundle/vim-golang/syntax/godoc.vim $HOME/.vim/syntax/

Kaching! You now have all the goodies installed, and someone correct me if I'm wrong on this but perhaps more than what comes with the official Golang distribution. I don't know about this either having not tried it yet, but I think that the runtimepath/rtp gets clobbered if you use Vundle with the other answers here anyways.


This page says that:

Place $GOROOT/misc/vim/syntax/go.vim in ~/.vim/syntax/ 
and put the following in ~/.vim/ftdetect/go.vim:

au BufRead,BufNewFile *.go set filetype=go

It worked for me, only i did not find the /misc/vim/go.vim directory at first. So i copied the files from another computer that had installed go on /usr/local/go/...


It should be easy as 1, 2, 3 :

  1. Download the file vim.go and place in in ~/.vim/syntax under the name go.vim (create the directory syntax if you don't already have it).

  2. If you don't already have the file ~/.vim/ftdetect/go.vim, create it (and the folder if necessary).

  3. In .vim/ftdetect/go.vim, add the following line : au BufRead,BufNewFile *.go set filetype=go


I did not find instructions on turning on vim syntax highlighting for CentOS 7. Have tested the ensuing instructions to work on CentOS 7.3.1611. First, create the following directory in your home directory:

$ mkdir ~/.vim/ftdetect/

Then, create a file named, go.vim inside the above directory with the contents:

au BufRead,BufNewFile *.go set filetype=go

Download the syntax definition file for Go: vim.go. Transfer it to the right system-wide directory so that multiple users can share:

$ sudo mv -i go.vim /usr/share/vim/vim74/syntax/

Turns out the directions above were slightly ambiguous.

~/.vim/syntax/go.vim should have the same contents as ~/.vim/ftdetect/go.vim

only ~/.vim/ftdetect/go.vim must be appended with au BufRead,BufNewFile *.go set filetype=go.

If taken literally, the directions tell you to create a file ~/.vim/ftdetect/go.vim containing only

         au BufRead,BufNewFile *.go set filetype=go

I suppose that's where contextual knowledge should kick in. Only I'd never done this before and had no such context. Thanks all!

ReferenceURL : https://stackoverflow.com/questions/15579822/add-golang-syntax-highlighting-for-vim

반응형