[TOC]
This repo stores my most used bundles and tricks.
Scripts
install.sh
handlesvim
,tmux
,terraformrc
andbash_profile
. It will installHomebrew
,vim
andjq
by default.set-golang.sh
handles all dependencies of vim plugin and environment setup. Since Go would setGOPATH
to$HOME/go
from version 1.8 hence we just putbin/
into our environment variable setup.set-php.sh
is deprecated.
Take jq tutorial from here.
Bundle: Vim-go
As title, for golang.
:GoUpdateBinaries
Action | Sub actions | KeyMap | Commands | NOTE! |
---|---|---|---|---|
Next error in quickfix | ||||
Previous error in quick fix | ||||
Close quick fix | a | |||
Build | b | (build_go_files) | run :GoBuild or :GoTestCompile based on the file we currently have |
|
Test | t | :GoTest |
||
:GoTestFunc |
||||
Coverage | c | :GoCoverageToggle |
||
C | :GOCoverageBrowser |
|||
Go Import | :GoImport strings :GoImportAs str strings |
|||
Go Drop | :GoDrop strings |
|||
Range, Inside the function | if | vif | ||
Range, All the function | at | vaf, includes comment | ||
GoAlternate | Jump between go and go test file | :GoAlternate :A :AV :AS :AT |
:AV vSplit :AS Split :AT Tab |
|
Go To Definition | d | :GoDef | ||
in Tab | gt | |||
Previous Tab | gT | |||
Navigation | Jump to previous position | |||
Jump to previous location | ||||
Open GoDef history | :GoDefStack |
|||
Clear GoDef history | :GoDefStackClear |
|||
Jump to previous function | [[ | v[[ | ||
Jump to next function | ]] | 3[[ | ||
Looking for declaration | :GoDecls :GoDeclsDir :GoDeclsClear |
Required ctrlp |
||
Looking for documentation | K | :GoDoc |
||
Show identifier | i | :GoInfo |
auto_type_info | |
List package dependency files | :GoFiles |
|||
List all dependency files | :GoDeps |
|||
Find reference | :GoReferrers |
|||
Show identifier advanced | :GoDescribe |
|||
List interfaces the type is implementing | :GoImplements |
|||
List possible error value of the type | :GoWhicherrs |
|||
Describe channels | :GoChannelPeers |
|||
Who been called as the function? | :GoCallees |
|||
Who call the function? | :GoCallers |
|||
List call stack from root | :GoCallstack |
|||
Change guru scope | :GoGuruScope |
:GoGuruScope ... |
||
Refactory name | :GoRename |
Change struct field | ||
Detect Free Vars | :GoFreevars |
Select a range... | ||
AutoGen - Implement | a | :GoImpl |
Put your cursor on top of T :GoImpl io.ReadWriteCloser :GoImpl b *B fmt.Stringer |
let g:go_guru_scope = ["github.com/fatih/vim-go-tutorial"]
let g:go_guru_scope = ["..."]
let g:go_guru_scope = ["github.com/...", "golang.org/x/tools"]
let g:go_guru_scope = ["encoding/...", "-encoding/xml"]
package main
type Foo struct {
Name string
Ports []int
Enabled bool
}
func main() {
foo := Foo{Name: "gopher", Ports: []int{80, 443}, Enabled: true}
}
gS
: Move your cursor atfoo
in #10, spit it into multiple line.gJ
: Move your cursor atfoo
, join it into oneline.
type foo struct {
Message string .
^ put your cursor here
Ports []int
ServerName string
}
In insert
mode, type json
and hit tab. You'll see that it'll be automatically expanded to valid field tag.
Matching the counterpart when you're typing.
Help folks to align text, equals, declarations, tables, etc.
Usage:
<leader>t=
Align assignments.<leader>t,
Align on commas.<leader>tsp
Align on whitespace.<leader>acom
Align comments.<leader>Htd
Align HTML tables.
Makes commenting out your code with ease!
Usage:
gcc
Comments/uncomments one line<Range>gc
Comments/uncomments a visual range
Command:
:g/TODO/Commentary
:7,17Commentary
Delete/change/add parentheses/quotes/XML-tags/much more with ease.
Usage:
- Normal mode:
cs<$1><$2>
Replace(c) surrounding(s) from $1 to $2.cs'"
Replace single quotes with double quotes.cs'<q>
Replace single quotes withtags.
cst"
Replace tags with double quotes.ds<$1>
Delete(d) $1 surrounding.ds"
Delete surrounding double quotes.yss<$1>
Wrap entire line with $1.
- Visual mode:
S<$1>
Wrap with $1.S<p class="foo">
You have to step into Tmux and start vim before you can run/test golang code in Tmux panel.
Usage:
ra
:GolangTestCurrentPackagerw
:GolangTestFocused
The zf
operator not only creates a fold but also folds the text. To unfold, it press zo
, and then zc
closes the fold again. Mnemonics of this is also quite smart (:help usr_28
). z
looks like a folded piece of paper, and then o
stands for "open", and c
for "close".
There is also zM
and zR
to close / open all the folds in the file, no matter how deep. That's super useful with big files when you need to get an overview of the whole file.
And of course, let's not forget about za
, which works like a toggle. When the cursor is on an open fold, it will close it and the other way around. I'm using it so often that I have it mapped to Space:
nnoremap <space> za
Vim-go has the functionality to go over the reference by using :GoReferrer
but it just works for go language. There is another option we can use for the other languages, most are ruby and javascript.
https://github.com/eapache/starscope
The tool box for creating vim plugins.