- STANDARD COMMANDS
- PLUGINS
- junegunn/fzf.vim (fuzzy finder)
- terryma/vim-multiple-cursors
- VundleVim/Vundle.vim
- unimpaired.vim
- vim-scripts/tComment
- tpope/vim-surround
- tpope/vim-fugitive (git wrapper)
- tpope/vim-rhubarb
- junegunn/gv.vim
- easymotion/vim-easymotion
- fatih/vim-go
- Mappings
- Snippets
- Move Between Functions (Uses Ctrl-P)
- Guru (editor tool for navigating and understanding Go code)
- Refactor It
- Delve Debugger
- GODEBUG_OUTPUT Window
- Go Test
- Go Coverage
- Go Imports
- vim-go Tutorial
- Add field tags (json snippet)
- Understand It (setup with auto g: commands in .vimrc so don't have to use shortcut to use)
- kien/ctrlp.vim (fuzzy finder)
- scrooloose/nerdtree
- iamcco/markdown-preview.vim
- Valloric/YouCompleteMe (Auto Completion)
- adelarsq/vim-matchit
- simnalamburt/mundo.vim
- tagbar
- tpope/vim-repeat
- jiangmiao/auto-pairs
- suan/vim-instant-markdown
- tmhedberg/SimpylFold
- SirVer/ultisnips
- honza/vim-snippets
- perl-support.vim
- vimwiki/vimwiki
- Look and Feel, Automatic functionality
gq | format paragraph - autowrap text at 80 characters |
(Using unimpaired.vim)
[q, ]q - :cnext, cprevious (mappings from unimpaired.vim)
<leader>a :cclose -> close quickfix window
Location List Navigation
[l, ]l - prev, next location list item
[L, ]L - first, last location list item
Buffer list navigation
[b, ]b - prev, next buffer
[B, ]B - first, last buffer
<C-^> or :b# - previous buffer
:b <name_of_file> -> open <name_of_file>
n, N | repeat next, previous "/" or "?" |
gn, gN | select next, previous match |
-
Use gn / gN when CHANGING/DELETING matches
-
Use n / N when NAVIGATING to matches
- /word - find "word"
- cgnNEW_WORD - change "word" to "NEW_WORD"
- . - repeat change word
Above replaces the following sequence
1. /word
2. visually select the word
3. cNEW_WORD
4. n. n. n. n.
Best option is to use 'terryma/vim-multiple-cursors'
d, c, y -> delete, change, yank (Ex. diw)
iw, aw | inner word, a word |
iW, aW | inner WORD, a WORD |
is, as | inner sentence, a sentence |
ip, ap | inner paragraph, a paragraph |
ib, ab | inner '(' ')' block, a '(' ')' block |
iB, aB | inner '{' '}' block, a '{' '}' block |
]c, [c | next/previous difference |
do | diff obtain |
dp | diff put |
:diffupdate | update diff if updates looks messed up |
d, c, y -> delete, change, yank (Ex. cfn -> change to next 'n')
f{char} - to occurrence of {char} to the right. Cursor is placed on {char} |inclusive|.
F{char} - to occurrence of {char} to the left. Cursor is placed on {char} |exclusive|.
t{char} - Till before occurrence of {char} to the right. Cursor is placed on the character left of {char} |inclusive|.
T{char} - Till after occurrence of {char} to the left. Cursor is placed on the character right of {char} |exclusive|.
; - Repeat latest f, t, F or T .
, - Repeat latest f, t, F or T in opposite direction.
<C-a>, <C-x> - increment/decrement number
zM - close all folds
zR - Open all folds
zA - Open / close fold function ( aliased to <space> )
za - Open / close a fold at cursor
Move cursor.. | H, M, L | Top, Middle, Bottom of Screen |
5k | up 5 rows | |
5j | down 5 rows | |
Scroll current Line to.. | zt,zz,zb | top, middle, bottom of window |
Move screen.. | <C-y> |
up one line |
<C-e> |
down one line | |
Move cursor and screen.. | <C-u> |
up 1/2 page |
<C-d> |
down 1/2 page | |
Split Window Navigation.. | <C-H> |
move to left split window |
<C-J> |
move to lower split window | |
<C-K> |
move to above split window | |
<C-L> |
move to right split window | |
Go Through Jump Locations.. | <C-o> <C-i> |
junegunn/fzf.vim (fuzzy finder)
Mapping | Description |
---|---|
; | :Buffers |
<leader>ag |
search for file under cursor in files |
<leader> <space> |
:Files |
<leader>/ |
search with 'Ag' |
:Commits |
git commits |
:BCommits |
git commits for current buffer |
:Ag |
loads all files and file contents for searching |
:History: |
Command history |
:History/ |
Search history |
:Windows |
list of open windows in vim |
:Commands |
: Commands |
:Maps |
key mappings |
start search with `'` to find exact match
start search with `!` to find exclude match
make visual word selection first then ...
<C-n> - select additional words
c, r, i - to perform operation on selection
<Home> - move to beginning of line
<End> - move to end of line
<Up/Down> - move cursors up/down
:PluginInstall
:PluginList
:PluginClean
:PluginSearch
[b, ]b jump to previous, next buffer
[m, ]m jump to previous, next method
gcc - comment current line
gc - comment visual selected lines
cs"' - change surrounding from " to '
ds" - delete " surrounding
S' - Visual select, surround with '
ysiw] - surround current word with [] (no spaces)
ysiw[ - surround current word with [ ] (with spaces)
tpope/vim-fugitive (git wrapper)
:Gcommit
:Gdiff - diff current file
:Glog
:Gfetch
:Gpull
:Gpush
:Gstatus
:Gwrite
:Gbrowse - open selected lines in browser (works with visual mode)
g? show this help
s - Stage (add) the file or hunk under the cursor
u - Unstage (reset) the file or hunk under the cursor
<C-N> skip to next file or hunk
<C-P> skip to previous file or hunk
<CR> |:Gedit| edit file under cursor
= Toggle inline diff of file under cursor
D, dd |:Gdiff|
ds |:Gsdiff| horizontal split
dv |:Gvdiff| vertical split
a Show alternative format
dp |:Git| add --intent-to-add (untracked files)
q close status
P patch
cc |:Gcommit| Create a commit
ca Amend the last commit and edit the message
ce Amend the last commit without editing the message
gq Close the status buffer.
R Reload the status buffer
Plugin needed for :Gbrowse in vim-fugitive
:GV - Commit browser in Vim :GV! - only list commits that affected the current file
s{char} - search {char} in file
<leader> is '\' key
<leader>s{char} - highlight {char} in file
<leader>j{char} - Line motion - highlight lines below
<leader>k{char} - Line motion - highlight lines above
https://www.diycode.cc/projects/fatih/vim-go
Shortcut | Command | Description | |
---|---|---|---|
quckfix navigations | [q, ]q | :cnext, :cprevious | (mappings from unimpaired.vim) |
function navigation | ]], [[ | jump to next, previous function or method (can be used with d, v prefixes) | |
Go to Definition | gd | :GoDef | jump to definition, locally or globally |
<C-t> | jump back to previous location | ||
\ds | (go-def-split) | ||
\dv | (go-def-vertical) | ||
Go Doc | K, \gd | :GoDoc | Get documentation for function under cursor |
\gv | (go-doc-vertical) | ||
Go Implements (interfaces) | \s | (go-implements) | Show a list of interfaces implemented by the type under your cursor |
Go Rename (refactoring) | \e | (go-rename) | Rename the identifier under the cursor to a new name |
Commands | \b | :GoBuild | |
\r | :GoRun | go run on whole package | |
\R | :GoRun % | go run on current file (map added to .vimrc) | |
\t | :GoTest | run go test on file | |
\c | :GoCoverageToggle | toggle between GoCoverage and GoCoverageToggle | |
:A, :AV, :AS | :GoAlternate | alternate between .go and _test.go | |
Go Declarations | <C-g> | :GoDecls | opens the current file and lists all available function declarations |
\dr | :GoDeclsDir | is the same as :GoDecls, the only difference is it parses all Go files under the current directory | |
Text Objects | dif, cif, vif, yif | detete, change, visual select, yank 'INNER FUNCTION' | |
daf, caf, vaf, yaf | detete, change, visual select, yank 'A FUNCTION' | ||
Struct Split | gS | Split struct expression into multiple lines | |
Struct Join | gJ | Join struct expression into single line |
fn | fmt.Println() |
||
ff | fmt.Printf() |
dynamically copys the variable name into the format string | |
ln | log.Println() |
||
lf | log.Printf() |
dynamically copys the variable name into the format string | |
variables | : | v := value |
(shorthand variable declaration) |
var | (variable declaration) | ||
vars | (variables declaration) | ||
for | for | (for loop) | |
fori | for i := 0; i < N; i++ { } |
(for integer loop) | |
forr | for k, v := range { } |
(for range loop) | |
if, else | if, ife | (if with inline err) | |
else, el | |||
field tags | json | (add json field tag) | |
yaml | (add yaml field tag) | ||
interfaces | in | interface{} |
(interface) |
inf | interface name { /* methods */ } |
(full interface) | |
interface | type Interface interface { /* TODO: add methods */ } |
(interface I) | |
function | fun | func funcName() error { } |
(function) |
fum | func (receiver type) funcName() error { } |
(method) | |
func | func name(params) { } |
||
fumh | func (receiver type) funcName(w http.ResponseWriter, r *http.Request) { } |
(http handler function on receiver) | |
funch | func handler(w http.ResponseWriter, r *http.Request) { } |
(HTTP handler) | |
function as method | meth | func (receiver type) name(params) { } |
(method) |
anonymous function | anon | fn := func() { } |
(anonymous function) |
Errors | err | if err != nil { log.Fatal(err) } |
(Basic error handling) |
errn | if err != nil { return err } |
(Error return) | |
errn, | if err != nil { return nil, err } |
(Error multiple return) | |
errp | if err != nil { panic() } |
(Error panic) | |
errt | if err != nil { t.Fatal(err) } |
(Error test fatal) | |
maps | make | make([]string, 0) |
|
map | map[string]int |
(map[Type]Type) | |
single words | rt | return |
|
br | break |
||
ft | fallthrough |
||
cn | continue |
||
Slices | ap | append(slice, value) |
(append) |
ap= | slice = append(slice, value ) |
(append assignment) | |
Struct | struct | type Struct struct { } |
(struct) |
go routines | go | go funcName() |
(goroutine named function) |
gof | go func() { }() |
(goroutine anonymous function) | |
channels | ch | chan type |
|
select | select { case v1 := <-chan1 } |
select channel | |
switch | sw | switch var { case value1: case value2: default: } |
|
switch | switch var { case value1: } |
||
Testing | test | func TestFunction(t *testing.T) { } |
(test function) |
tt | var tests = []struct { name string expected string given string } { {"", "", "",}, } for _, tt := range tests { tt := tt t.Run(tt.name, func(t *testing.T){ actual := (tt.given) if actual != tt.expected { t.Errorf("(%s): expected %s, actual %s", tt.given, tt.expected, actual) } }) } |
(test table) |
:GoDecls | opens the current file and lists all available function declarations |
:GoDeclsDir | is the same as :GoDecls, the only difference is it parses all Go files under the current directory |
:GoReferrers | find references to the selected identifier, scanning all packages in the workspace. Result is location list |
:GoDescribe | Like :GoInfo, but give more info show methdod set of a type, declarations of a package |
:GoImplements | find the interface a type implements (shows location list) |
:GoCallers | Show "callees" relation for a selected package. A list of possible call targets for the type under the cursor (or selected package) is shown in a location list. |
:GoCallers | Show "callers" relation for a selected function. A list of possible callers for the selected function under the cursor is shown in a location list. |
:GoRename | search all packages under GOPATH and renames all identifiers that depend on the identifier |
:GoFreevars (visual select code) |
result is quickfix list of all variables that are free variables used to determine complexity of a piece of code. See how many variables depend on this code |
Commands | |
---|---|
:GoDebugStart [pkg] [program-args] | (Ex :GoDebugStart ./hello) |
:GoDebugStop | close all windows after stop |
:GoDebugRestart | recompile code |
:GoDebugTest [pkg] [program-args] | (same as :GoDebugStart, but debugs *_test.go file) Use -test.flag to pass flags to go test when debugging a test; for example -test.v or -test.run TestFoo (:GoDebugTest ./app -test.run TestStartServerSuccess) |
:GoDebugPrint {expr} | (Ex. :GoDebugPrint truth == 42) |
:GoDebugStepOut | Run all code in the current function and halt ("step out") |
:GoDebugSet {var} {value} | set the variable to value. Cannot be string. limitation of delve |
Mappings | |
---|---|
<F5> | next breakpoint (:GoDebugContinue) |
<F6> | evaluate the under the cursor (:GoDebugPrint) |
<F9> | add breakpoint (:GoDebugBreakpoint) |
<F10> | next line (:GoDebugNext) Will literally go to the line with active cursor in file! |
<F11> | step into (:GoDebugStep) |
<S-F11> | step out (:GoDebugStepOut) Mapped in .vimrc |
Struct values displayed as {...}
array/slices as [4] -> <CR> on the variable name to expand values
:GoTest | run go test on file |
:GoTestFunc | test only function under cursor |
:GoTestCompile | test compile without problems |
:GoCoverage | go test -coverprofile tempfile |
:GoCoverageClear | clear coverage |
:GoCoverageToggle | toggle between GoCoverage and GoCoverageToggle |
:GoImport | add package to import statement (supports tab completion) |
:GoImportAs | add package with package name (ex. str strings) |
:GoDrop | remove package from imports |
:GoRun % - go run on current file
:GoRun - go run on whole package
:GoBuild - compile file instead of running it
Place cursor at end of Message or ServerName lines.
In insert mode, type json and hit tab.. !
Convert ...
type foo struct {
Message string
Ports []int
ServerName string
}
to ...
type foo struct {
Message string `json:"message"`
Ports []int
ServerName string `json:"server_name"`
}
Identifier Resolution (what is a function accepting or returning)
<leader>i -> :GoInfo
The following shows identifier information whenever move cursor
let g:go_auto_type_info = 1
set updatetime=100 -> set update frequency
Identifier Highlighting
:GoSameIds -> highlight all variables under cursor, across file
:GoSameIdsClear -> clear highlights
let g:go_auto_sameids = 1 -> always highlight when move cursor
Find anything from VIM tutorial
Once CtrlP is open
<F5> - purge cache for current dir to get new files, remove deleted files and apply new ignore
<C-d> - switch to filename search instead of full path
<C-P> - invoke ctrlP
<C-F> <C-B> - switch to next, previous mode in sequence
<C-v> <C-x> - open in Vertical or Horizontal split
<C-j> <C-k> - navigate the result list
<C-n> <C-p> - select next/previous string in prompt history
<C-z> - mark/unmark multiple files. <C-o> to open files
:NERDTree - invoke NERDTree
:MarkdownPreview - open .md file in browser
Also uses ultisnips http://www.alexeyshmalko.com/2014/youcompleteme-ultimate-autocomplete-plugin-for-vim/
start typing. (ife for example)
<C-n> <C-p> to traverse popup menu
<tab> to insert snippet
<C-j> <C-k> to move through fields
Javascript completion
cd .vim/bundle/YouCompleteMe/third_party/ycmd/third_party/tern_runtime
npm install --production
use % to go to matching <tag>
:MundoToggle
traverse branches of file history. allows retreiving any edit
http://vimcasts.org/episodes/undo-branching-and-gundo-vim/
changed from gundo, because gundo no longer supports python3
:TagBarToggle - show program tags
. - repeat command for surround.vim and a few others
snippets for ultisnips
Automatically close HTML tags
color (), [], {} different colors and apply different colors to nested parens
Add open buffers to command line
powerline status bar
theme for info bar at bottom. https://github.com/vim-airline/vim-airline/wiki/Screenshots
tabline extension shows active buffers at top of screen
syntax checker after write of file
:SyntasticInfo to view information about version and enabled checkers on
current file
Debug
:let g:syntastic_debug=3
:SyntasticCheck eslint
run :mes
yarn installed with -- brew install yarn
prettier installed with -- yarn global add prettier
show gutter with git changes
good video - https://www.youtube.com/watch?v=67OZNp9Z0CQ
explanation of rope functions - https://github.com/python-rope/rope/blob/master/docs/overview.rst
\r - run python from within vim
\g - goto definition
K - show documentaion
[[, ]] - Jump to prev, next class or function (normal, visual, operator modes)
[M, ]M - Jump to prev, next class or method (normal, visual, operator modes)
aC Select a class. Ex: vaC, daC, yaC, caC (normal, operator modes)
iC Select inner class. Ex: viC, diC, yiC, ciC (normal, operator modes)
aM Select a function or method. Ex: vaM, daM, yaM, caM (normal, operator modes)
iM Select inner function or method. Ex: viM, diM, yiM, ciM (normal, operator modes)
[l, ]l - Jump to prev, next location of error/warning
Extract method/variable from selected lines.
<C-c>rm - visual select first. Extracts selection and creates new function/method
<C-c>rl - visual select first. Extracts selection and creates new variable
<C-c>ro - organize imports
<C-c>rr - rename method/function/class/variable under cursor
got this working and allow <C-S-e> to run script in vim