You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
start search with ' to find exact match, not fuzzy find
Windows
<c-w> z
close preview window
Standard Commands
gq
format paragraph - autowrap text at 80 characters
vimdiff Commands
]c, [c
next/previous difference
do
diff obtain
dp
diff put
:diffupdate
update diff if updates looks messed up
Word Search / Modification
n, N
repeat next, previous "/" or "?"
gn, gN
select next, previous match
How to edit word repeatedly through file
Use gn / gN when CHANGING/DELETING matches
Use n / N when NAVIGATING to matches
1. /word - find "word"
2. cgnNEW_WORD - change "word" to "NEW_WORD"
3. . - 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'
Text Objects
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
Quickfix and Location Windows
(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
Buffers
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>
'find' and 'till'
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.
Edit in place
<C-a>, <C-x> - increment/decrement number
folding
zM - close all folds
zR - Open all folds
za - Open / close fold at cursor ( aliased to <space> )
make visual word selection
<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
[b, ]b jump to previous, next buffer
[m, ]m jump to previous, next method
vim-scripts/tComment
gcc - comment current line
gc - comment visual selected lines
tpope/vim-surround
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)
MAPPINGS - These mappings are available in the :Gstatus buffere and the
Fugitive object buffers
g? show this help
Staging and resetting mappings
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
Commit Mappings
cc |:Gcommit| Create a commit
ca Amend the last commit and edit the message
ce Amend the last commit without editing the message
Miscellaneous mappings
gq Close the status buffer.
R Reload the status buffer
easymotion/vim-easymotion
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
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
Javascript completion
cd .vim/bundle/YouCompleteMe/third_party/ycmd/third_party/tern_runtime
npm install --production
python-mode/python-mode
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
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)
Move Between Functions (Uses Ctrl-P)
: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
Guru (editor tool for navigating and understanding Go code)
: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.
Refactor It
: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
Delve Debugger
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
GODEBUG_OUTPUT Window
Struct values displayed as {...}
array/slices as [4] -> <CR> on the variable name to expand values
Go Test
:GoTest
run go test on file
:GoTestFunc
test only function under cursor
:GoTestCompile
test compile without problems
Go Coverage
:GoCoverage
go test -coverprofile tempfile
:GoCoverageClear
clear coverage
:GoCoverageToggle
toggle between GoCoverage and GoCoverageToggle
Go Imports
:GoImport
add package to import statement (supports tab completion)
:GoRun % - go run on current file
:GoRun - go run on whole package
:GoBuild - compile file instead of running it
Add field tags (json snippet)
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"`
}
Understand It (setup with auto g: commands in .vimrc so don't have to use shortcut to use)
Identifier Resolution (what is a function accepting or returning)
<leader>i -> :GoInfo
The following shows identifier informatino 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
adelarsq/vim-matchit
use % to go to matching <tag>
simnalamburt/mundo.vim
: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
tagbar
:TagBarToggle - show program tags
tpope/vim-repeat
. - repeat command for surround.vim and a few others
jiangmiao/auto-pairs
suan/vim-instant-markdown
tmhedberg/SimpylFold
SirVer/ultisnips
honza/vim-snippets
snippets for ultisnips
perl-support.vim
vimwiki/vimwiki
Look and Feel, Automatic functionality
alvan/vim-closetag.vim
Automatically close HTML tags
kien/rainbow_parentheses.vim
color (), [], {} different colors and apply different colors to nested parens
bling/vim-bufferline
Add open buffers to command line
vim-airline/vim-airline
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
liuchengxu/space-vim-dark
vim-syntastic/syntastic
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
Plugin 'prettier/vim-prettier'
yarn installed with -- brew install yarn
prettier installed with -- yarn global add prettier
https://www.digitalocean.com/community/tutorials/how-to-install-python-3-and-set-up-a-local-programming-environment-on-macos
This is how to run a specific version fo python
source Environments/my_env/bin/activate
now python has is linked to python from my_env (which is python3)
"(my_env) python --version"
"Python 3.6.5"
SETUP ALIASES
From https://github.com/robbyrussell/oh-my-zsh/blob/master/plugins/common-aliases/common-aliases.plugin.zsh
placed in ~/.zshrc