Skip to content

Instantly share code, notes, and snippets.

@gricard
Last active November 27, 2019 20:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gricard/c94ccda5f591a6ad269a3b45a8db7afd to your computer and use it in GitHub Desktop.
Save gricard/c94ccda5f591a6ad269a3b45a8db7afd to your computer and use it in GitHub Desktop.
VIM
:q quit
:q! quit without saving
:w save changes
:wq save and exit
:x save and exit
:cq exit with error code
MISC
. repeat last command
:source file reload config file (:source ~/.ideavimrc)
Ctrl-o in insert mode, break out and run any command (e.g., `ctrl-o, "+p` to paste system clipboard while in insert mode)
NAVIGATION
h move left
j move down
k move up
l move right
w go to start of next word
b go to start of prev word
e go to end of word
( start of sentence / go to prev empty line before code
) end of sentence /go to next empty line before code
{ start of paragraph/code block
} end of paragraph/code block
C-f page down
C-b page up
^ go to beginning of text in current line
0 go to beginning of line
$ go to end of line
* go to next instance of word at cursor
# go to prev instance of word at cursor
% go to matching bracket
#| go to column #
'. go to last edited line
`. go to last edited column in last edited line
ctrl-o go to previously edited file (repeatable)
GO
# enter line # and hit enter
#G go to line #
gg top of file
G end of file
gd go to definition
SCREEN MOVEMENT
z. center screen on cursor
zt move line with cursor to top of screen
zb move line with cursor to bottom of screen
H top of screen
M middle of screen
L bottom of screen
EDITING
i insert
a append
A append at end of line
D delete to end of line
C change to end of line
r replace a charater
x delete character
O insert line above
o insert line below
c change / delete & insert
c$ change to end of line
ci'' change content inside next occurrence of '' characters
d delete
dd delete line
dw delete word
diw delete current word cursor is inside of
di'' delete content inside next occurrence of '' characters
u undo last command
uu undo last block of commands
C-r redo
xp swap two characters
REPEATING TEXT
3i-ESC insert "-" 3 times
SELECTING
v select by letter
V select by line
viw select word under cursor
CASE
U make selected text upper case (in visual selection)
u make selected text lower case (in visual selection)
~ reverse case of selected text
COMMENT SELECTED LINES
Ctrl-V
Up/Down to select lines
shift-I to insert text ("//" or "#" etc)
Esc to finish and prepend all lines
COPY/PASTE
yy copy (yank) a line
yw copy word
y$ copy to end of line
Vjjy select next two lines and copy
p paste after
P paste before
"+y copy selection to system clipboard
"+p paste from system clipboard
REGISTERS
"k___ ___ = command done on register k
"kyy copy current line into register k
"kp paste contents of register p after cursor
:reg list registers
"+ OS clipboard
"/ last search command
": last command
"_ black hole register (/dev/null basically)
INDENT
> shift right
< shift left
SEARCH
/text find text (fwd)
?text find text (rev)
n go to next match
N go to prev match
fX find next character "X"
FX find prev character "X"
Ctrl-R 0 paste contents of register 0 into search input
SEARCH & REPLACE
:%s/[pattern]/[replacement]/g replace without confirmation
:%s/[pattern]/[replacement]/gc replace with confirmation
:.,+5s/foo/bar/g replace all "foo" with "bar" from current line (.) to 5 lines down (+5)
:5,10s/foo/bar/g replace all "foo" with "bar" on lines 5 - 10
TABS
gt go to next tab
gT go to prev tab
:tabs list tabs
:tabedit file open file in tab
:tabclose
BUFFERS
:ls list buffers
:bp prev buffer
:bn next buffer
:bd close buffer
:new new window & buffer
:e filename edit file
SPLITS
:sp split window
:vsp vertically split window
C-w j go to split above
C-w k go to split below
C-w h go to split left
C-w l go to split right
:q close split
FOLDING
zo open fold
zc close fold
SETTINGS
:set number turn on line numbers
CUSTOM COMMANDS (in ~/.ideavimrc)
nmap g] :action GotoImplementation<CR> go to definition of label under cursor
vmap \c :s!^!//!<CR> type \c to comment selected lines
vmap \u :s!^//!!<CR> type \u to uncomment selected lines
nnoremap <F5> "=strftime("%F%T")<CR>P type F5 to enter current date/time (formatted for gatsby frontmatter)
KEY NOTATION
http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-_Tutorial_%28Part_2%29
https://stackoverflow.com/questions/1764263/what-is-the-leader-in-a-vimrc-file
KEY MAPS
http://michael.peopleofhonoronly.com/vim/vim_cheat_sheet_for_programmers_print.png
https://external-preview.redd.it/iigrixvxp5aYN9ox7Gr1dfI_rhLRotWlLsCafjJqjEQ.png?auto=webp&s=1594ddc17408cb9186a73c2a6d1a1bf1e00769dd
LINKS
http://vim.wikia.com/wiki/Buffers
http://vim.wikia.com/wiki/Folding
http://vim.wikia.com/wiki/Shifting_blocks_visually
https://www.keycdn.com/blog/vim-commands
https://medium.com/@danidiaz/configuring-ideavimrc-de16a4da0715
https://stackoverflow.com/questions/1764263/what-is-the-leader-in-a-vimrc-file
https://guide.freecodecamp.org/vim/useful-commands/
https://www.fprintf.net/vimCheatSheet.html
https://www.openvim.com/
REACT DEV
https://drivy.engineering/setting-up-vim-for-react/
https://github.com/tpope/vim-vinegar
https://github.com/mjackson/dotfiles/blob/master/vimrc
https://engagor.github.io/blog/2017/02/15/vim-ide-exploring-code/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment