Skip to content

Commit

Permalink
Merge branch 'master' of gh:fatih/vim-go
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewstuart committed Feb 16, 2015
2 parents bb85de4 + c566260 commit 2bbedd9
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 50 deletions.
34 changes: 18 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,26 +37,28 @@ disabled/enabled easily.

## Install

First of all, do not use it with other Go plugins. If you use pathogen, just
clone it into your bundle directory:
Vim-go follows the standard runtime path structure, so I highly recommend to use
a common and well known plugin manager to install vim-go. Do not use vim-go with
other Go plugins. For Pathogen just clone the repo, for other plugin managers
add the appropriate lines and execute the plugin's install command.

* [Pathogen](https://github.com/tpope/vim-pathogen)
* `git clone https://github.com/fatih/vim-go.git ~/.vim/bundle/vim-go`
* [vim-plug](https://github.com/junegunn/vim-plug)
* `Plug 'fatih/vim-go'`
* [NeoBundle](https://github.com/Shougo/neobundle.vim)
* `NeoBundle 'fatih/vim-go'`
* [Vundle](https://github.com/gmarik/vundle)
* `Plugin 'fatih/vim-go'`
* Manual
* Copy all of the files into your `~/.vim` directory

```bash
$ cd ~/.vim/bundle
$ git clone https://github.com/fatih/vim-go.git
```

For Vundle add this line to your vimrc:

```vimrc
Plugin 'fatih/vim-go'
```
and execute `:PluginInstall` (or `:BundleInstall` for older versions of Vundle)

Please be sure all necessary binaries are installed (such as `gocode`, `godef`,
`goimports`, etc..). You can easily install them with the included
`:GoInstallBinaries` command. Those binaries will be automatically downloaded
and installed to your `$GOBIN` environment (if not set it will use
`$GOPATH/bin`). It requires `git` and `hg` for fetching the individual Go
`:GoInstallBinaries` command. If you invoke it, all necessary binaries will be
automatically downloaded and installed to your `$GOBIN` environment (if not set
it will use `$GOPATH/bin`). It requires `git` for fetching the individual Go
packages.

### Optional
Expand Down
2 changes: 1 addition & 1 deletion autoload/go/fmt.vim
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ function! go#fmt#Format(withGoimport)
" restore 'redo' history because it's getting being destroyed every
" BufWritePre
let tmpundofile=tempname()
exe 'wundo! ' . Tmpundofile
exe 'wundo! ' . tmpundofile
endif

" get the command first so we can test it
Expand Down
79 changes: 46 additions & 33 deletions indent/go.vim
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
" - general line splits (line ends in an operator)

if exists("b:did_indent")
finish
finish
endif
let b:did_indent = 1

Expand All @@ -21,45 +21,58 @@ setlocal indentexpr=GoIndent(v:lnum)
setlocal indentkeys+=<:>,0=},0=)

if exists("*GoIndent")
finish
finish
endif

" use shiftwidth function only if it's available
if exists('*shiftwidth')
func s:sw()
return shiftwidth()
endfunc
else
func s:sw()
return &sw
endfunc
endif

function! GoIndent(lnum)
let prevlnum = prevnonblank(a:lnum-1)
if prevlnum == 0
" top of file
return 0
endif
let prevlnum = prevnonblank(a:lnum-1)
if prevlnum == 0
" top of file
return 0
endif

" grab the previous and current line, stripping comments.
let prevl = substitute(getline(prevlnum), '//.*$', '', '')
let thisl = substitute(getline(a:lnum), '//.*$', '', '')
let previ = indent(prevlnum)
" grab the previous and current line, stripping comments.
let prevl = substitute(getline(prevlnum), '//.*$', '', '')
let thisl = substitute(getline(a:lnum), '//.*$', '', '')
let previ = indent(prevlnum)

let ind = previ
let ind = previ

if prevl =~ '[({]\s*$'
" previous line opened a block
let ind += &sw
endif
if prevl =~# '^\s*\(case .*\|default\):$'
" previous line is part of a switch statement
let ind += &sw
endif
" TODO: handle if the previous line is a label.
if prevl =~ '[({]\s*$'
" previous line opened a block
let ind += s:sw()
endif
if prevl =~# '^\s*\(case .*\|default\):$'
" previous line is part of a switch statement
let ind += s:sw()
endif
" TODO: handle if the previous line is a label.

if thisl =~ '^\s*[)}]'
" this line closed a block
let ind -= &sw
endif
if thisl =~ '^\s*[)}]'
" this line closed a block
let ind -= s:sw()
endif

" Colons are tricky.
" We want to outdent if it's part of a switch ("case foo:" or "default:").
" We ignore trying to deal with jump labels because (a) they're rare, and
" (b) they're hard to disambiguate from a composite literal key.
if thisl =~# '^\s*\(case .*\|default\):$'
let ind -= &sw
endif
" Colons are tricky.
" We want to outdent if it's part of a switch ("case foo:" or "default:").
" We ignore trying to deal with jump labels because (a) they're rare, and
" (b) they're hard to disambiguate from a composite literal key.
if thisl =~# '^\s*\(case .*\|default\):$'
let ind -= s:sw()
endif

return ind
return ind
endfunction

" vim:ts=4:sw=4:et

0 comments on commit 2bbedd9

Please sign in to comment.