Last active
September 7, 2022 19:53
-
-
Save chris-ramon/3f9e580548d2dcab27a9 to your computer and use it in GitHub Desktop.
vim notes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# show number all tabs | |
:tabdo windo set number | |
# copy to clipboard fix | |
sudo apt-get install vim-gtk | |
# editorconfig | |
https://github.com/editorconfig/editorconfig-vim | |
# autocomplete | |
cd ~/.vim/bundle/YouCompleteMe | |
git submodule update --init --recursive | |
brew install cmake | |
python3 install.py --go-completer | |
# enable jenkinsfile syntax highlighting | |
au BufNewFile,BufRead Jenkinsfile setf groovy | |
au BufNewFile,BufRead Jenkinsfile.dev setf groovy | |
# enable indent lines | |
:IndentLinesEnable | |
# send command to pane 1 and redraw vim to avoid press enter message | |
exe "silent !tmux send -t 1 '(cd ~/ && pwd)' Enter" | redraw! | |
# send commands to tmux pane | |
exe "!tmux send -t 1 'echo cool' Enter" | |
# count selected words | |
# select words | |
g | |
ctrl + g | |
# eg: Selected 1 of 999 Lines; 4 of 2089 Words; 28 of 25511 Bytes | |
# create new file in current dir | |
:e %:h/filename | |
:w | |
# restore syntax highlighting | |
:e | |
# full-screen | |
ctrl + w _ | |
# undo full-screen | |
ctrl + w = | |
# undo | |
:earlier 1f | |
# count lines | |
# select lines | |
ctrl + v | |
# g - ctrl + g | |
# set tab to 2-spaces | |
set tabstop=2 | |
# screen resize | |
# vertical | |
:resize -v 40 | |
:resize -h 50 | |
# screen resize | |
# left | |
ctrl-w + 45 < | |
# right | |
ctrl-w + 45 > | |
# bottom | |
ctrl-w + 10 - | |
# up | |
ctrl-w + 10 + | |
# resize | |
:10winc - | |
# search, count pattern within file | |
:g/pattern/p | |
# visual selection tags | |
v | |
# outer | |
at | |
# inner | |
it | |
# visual selection | |
# place cursor on curly or paren then | |
# within curly brances | |
viB | |
# within parenthesis | |
vib | |
# within double quotes | |
vi" | |
# inclusive selection | |
va{ | |
# find only in visual selection | |
# select a block using ctr-v and arrows | |
# ESC | |
/\%Vpattern | |
# close all execept active one | |
:only | |
# new file current tab | |
:e | |
# jump to column | |
10| | |
# redo | |
ctrl + r | |
# show explorer | |
:Ex | |
# jump to changes | |
g; | |
g, | |
# turnoff autoident when pasting text | |
:set paste | |
# turnon autoindent when pasting text | |
:set nopaste | |
# select current cursor's word | |
viw | |
# show numbers | |
:set number | |
:set nonumber | |
# pass current path file to a command | |
:!mycommand %:p | |
# spell off | |
:set spell! | |
# spell checking | |
:setlocal spell | |
:setlocal spell spelllang=en_us | |
# sync/unsync tabs if opened same files | |
:set scrollbind | |
:set noscrollbind | |
# re-open closed tabs | |
:ls " get the buffer number | |
:tabnew +Nbuf " where N is the buffer number | |
# jump to byte offset | |
:100go | |
# bookmarks -> https://github.com/MattesGroeger/vim-bookmarks | |
# add/remove | |
mm | |
# all | |
# open a file withing cwd | |
ma | |
# softtabstop -> tab's width. | |
# shiftwidth -> shifth's width. | |
# tabstop -> width of tabs to be shown like. | |
# noexpandtab -> to use tab-base indent | |
# autoindent -> copy indentation from prev. line | |
# format json file | |
:%!python -m json.tool | |
# count match pattern | |
:'<,'>s/pattern//gn | |
# shows stash content | |
git stash show -p stash@{1} | |
# next/prev '{' '}' | |
#backwards | |
[msr | |
#forwards | |
m] | |
# jump to previous } of func definition | |
[] | |
# readonly option set | |
:w !sudo tee % | |
# previous location | |
ctrl + o | |
# details(word, byte info ...) of current cursor word. | |
g + ctrl - g | |
# sort selected lines alphabetically | |
# select lines -> v + arrows to select lines | |
:{select lines}!sort | |
# spelling suggestion | |
1z= | |
# close other tabs, except active one | |
# and buffers | |
ctrl-w o | |
# jump next/previous | |
# changed lines - git | |
]c | |
[c | |
# go back, after going to def | |
ctrl + o | |
# list all buffers | |
:ls | |
# go to one specific buffer | |
:b4 | |
# open errors tab | |
:Errors | |
# indent guides | |
:IndentGuidesEnable | |
# toggle shortcut | |
<Leader>ig | |
# https://github.com/tpope/vim-surround | |
# wrap current line within a tag | |
yss | |
<p> | |
# enter | |
# convert vertical split to horizontal split | |
Ctrl-w t - Ctrl-w K | |
# horizontal to vertical | |
Ctrl-w t Ctrl-w H | |
# fold/unfold | |
# for go: | |
# set foldmethod=syntax | |
# set nofoldenable | |
`za` - toggles | |
`zc` - closes | |
`zo` - opens | |
`zR` - open all | |
`zM` - close all | |
# convert to: snakecase/camelcase | |
# should be use alogn https://github.com/tpope/vim-pathogen to work | |
github.com/tpope/vim-abolish | |
crs | |
crm | |
# uppercase/lowercase, highlight the word then: | |
gU | |
gu | |
# quite recording vim | |
q | |
# set config per language, eg for html files: | |
# file: ~/.vim/ftplugin/html.vim | |
set shiftwidth=2 | |
set softtabstop=2 | |
# create files directories with NERDTree | |
# open nerdtree, place cursor where you want | |
# to create the file or dir | |
m | |
# then 'a' then the name of dir/file, for | |
# directories make sure | |
# too write '/' at the end. | |
# move current line to middle of screen | |
zz | |
# move current line to top of screen | |
zt | |
# move current line to bottom of screen | |
zb | |
# search match exactly | |
/person\C | |
# keyarrows stop working | |
:!reset | |
# diplay current file name | |
ctrl + g | |
# install plugin using Vunble | |
clone git repo within ~/.vim/bundle | |
then add plugin in ~/.vimrc.local | |
Plugin 'abc/efg.vim' | |
# select matching words of the current cursor | |
shift + 3 | |
# having multiple tabs open, you want to fullwidth one temporary with: | |
:tab split | |
# to close | |
:tabc | |
# ^^^ to add a short cut | |
:noremap tt :tab split<CR> | |
# to close, as always | |
:wq | |
# match exact | |
/\<word\> | |
# square selection | |
ctrl + v | |
# some files does not highlight syntax, remove dir: | |
~/.vimviews | |
# make windows same size | |
:winc = | |
# increase size of tab | |
ctrl w + < | |
ctrl w + > | |
# open new file in vertical new tab | |
:vert new filename.extension | |
# eleminate line, move line top, paste | |
ddkP | |
# eleminate line, move line bottom, paste | |
ddjP | |
# replace word under cursor | |
ciw | |
# list buffer | |
:ls | |
# go next/prev file | |
:bn | |
:bp | |
# search for text | |
:vimgrep "PublishableKey" **/* | |
# search and replace | |
:%s/search-word/replace-word | |
# go to next/prev matching | |
:cn | |
:cp | |
# jump to def | |
:gd | |
# split vertically | |
:vs | |
# horizontal (straight) split | |
:sp | |
# stop highlighting what u searched for | |
:noh | |
" size of a hard tabstop *** to new line | |
set tabstop=4 | |
" size of an "indent" | |
set shiftwidth=4 | |
" a combination of spaces and tabs are used to simulate tab stops at a width | |
" other than the (hard)tabstop *** tab indent | |
set softtabstop=4 | |
# delete current line | |
dd | |
# copy current line | |
yy | |
# comment block with nerdcommenter | |
,c<space> | |
# copy/paste block selected on visual mode | |
v <enter> (use arrows to selec block) | |
# to copy | |
y | |
# to paste | |
p | |
# reveal file in nerdtree | |
:NERDTreeFind | |
# go to matching { ( | |
% | |
Cursor movement | |
h - move left | |
j - move down | |
k - move up | |
l - move right | |
w - jump by start of words (punctuation considered words) | |
W - jump by words (spaces separate words) | |
e - jump to end of words (punctuation considered words) | |
E - jump to end of words (no punctuation) | |
b - jump backward by words (punctuation considered words) | |
B - jump backward by words (no punctuation) | |
0 - (zero) start of line | |
^ - first non-blank character of line | |
$ - end of line | |
G - Go To command (prefix with number - 5G goes to line 5) | |
Note: Prefix a cursor movement command with a number to repeat it. For example, 4j moves down 4 lines. | |
Insert Mode - Inserting/Appending text | |
i - start insert mode at cursor | |
I - insert at the beginning of the line | |
a - append after the cursor | |
A - append at the end of the line | |
o - open (append) blank line below current line (no need to press return) | |
O - open blank line above current line | |
ea - append at end of word | |
Esc - exit insert mode | |
Editing | |
r - replace a single character (does not use insert mode) | |
J - join line below to the current one | |
cc - change (replace) an entire line | |
cw - change (replace) to the end of word | |
c$ - change (replace) to the end of line | |
s - delete character at cursor and subsitute text | |
S - delete line at cursor and substitute text (same as cc) | |
xp - transpose two letters (delete and paste, technically) | |
u - undo | |
. - repeat last command | |
Marking text (visual mode) | |
v - start visual mode, mark lines, then do command (such as y-yank) | |
V - start Linewise visual mode | |
o - move to other end of marked area | |
Ctrl+v - start visual block mode | |
O - move to Other corner of block | |
aw - mark a word | |
ab - a () block (with braces) | |
aB - a {} block (with brackets) | |
ib - inner () block | |
iB - inner {} block | |
Esc - exit visual mode | |
Visual commands | |
> - shift right | |
< - shift left | |
y - yank (copy) marked text | |
d - delete marked text | |
~ - switch case | |
Cut and Paste | |
yy - yank (copy) a line | |
2yy - yank 2 lines | |
yw - yank word | |
y$ - yank to end of line | |
p - put (paste) the clipboard after cursor | |
P - put (paste) before cursor | |
dd - delete (cut) a line | |
dw - delete (cut) the current word | |
x - delete (cut) current character | |
Exiting | |
:w - write (save) the file, but don't exit | |
:wq - write (save) and quit | |
:q - quit (fails if anything has changed) | |
:q! - quit and throw away changes | |
Search/Replace | |
/pattern - search for pattern | |
?pattern - search backward for pattern | |
n - repeat search in same direction | |
N - repeat search in opposite direction | |
:%s/old/new/g - replace all old with new throughout file | |
:%s/old/new/gc - replace all old with new throughout file with confirmations | |
Working with multiple files | |
:e filename - Edit a file in a new buffer | |
:bnext (or :bn) - go to next buffer | |
:bprev (of :bp) - go to previous buffer | |
:bd - delete a buffer (close a file) | |
:sp filename - Open a file in a new buffer and split window | |
ctrl+ws - Split windows | |
ctrl+ww - switch between windows | |
ctrl+wq - Quit a window |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment