The Vim editor is a command-line based tool that’s an enhanced version of the venerable vi editor. Despite the abundance of graphical rich text editors, familiarity with Vim will help every Linux user – from an experienced system administrator to a newbie Raspberry Pi user. VIM Keyboard Shortcuts Cheatsheet By Crystal Crowder / Oct 5, 2020 / The Vim editor is a command-line based tool that’s an enhanced version of the venerable vi editor. Despite the abundance of graphical rich text editors, familiarity with Vim will help every Linux user – from an experienced system administrator to a newbie Raspberry Pi user. XCode cheat sheet of all shortcuts and commands. Mac TIPS (12) Windows TIPS (10) Linux TIPS (3) JETSON NANO TIPS (3) Network TIPS (3) Lightwave (1) Program (1) Cheat Sheet (2) WordPress (1) 趣味や色々 (12) プラモデル (1) 身の回りの文房具 (11) 万年筆や筆記具 (4) 無印万年筆 (3) MMORPG/RPG (15) Baldur's Gate EE (3) SecondLife (7) UltimaOnline (5) オンライン.
Bash/Zsh vi mode
You can use vi mode in your shell by setting the mode. By defaultBash uses emacs mode but you can update your .bashrc or set itmanually. By default, it puts you in insert mode, so it doesn'tfeel very different from emacs mode. You can switch in tocommand mode when you need to manipulate or navigate the line.
- Switch shell modes with
set -o vi
and back withset -o emacs
. - In Zsh, there is a
vi-mode
plugin that can be enabled which allowsthemes to show an indicator if you are in command mode. For example,theavit
theme. - Go through previous/next commands with
j
andk
when in command mode.CTRL-P and CTRL-N may or may not still work since they are emacs binds.Up and down arrows usually still work. - Search history with
/
.CTRL-R
andCTRL-S
might still work. - Press
v
in command mode to pull up the full editor with the commandin the open buffer. When you save and exit, the final output from theeditor is dropped in your shell ready to run. Change the default editorthat is opened when pressingv
by changingEDITOR
environmentvariable. For example,export EDITOR=vim
.
Rebinding CAPS to ESC
I highly recommend remapping the CAPS LOCK
key to ESC
to makeswitching modes easier.
I have instructions on how to do this in Windows, Mac, and Linux in the post: Rebind Caps Lock key to Escape/Control.
Switch between modes
CTRL-[
orESC
to to command mode.i
,a
, ando
to go in to insert mode.I
,A
, andO
to go in to insert mode alternate ways.
Vi Cheat Sheet Machines
Launching vim
- Run
vim
by itself to open an unnamed buffer - Open a single file with
vim filename
- Open multiple buffers (single window)
vim file1 file2 file3
- Open multiple buffers (split windows)
- Horizontally split:
vim -o file1 file2
- Vertically split:
vim -O file1 file2
- Horizontally split:
Managing windows
- Split with current file using
:vsplit
,:split
,CTRL-W S
,CTRL-W V
. - Optionally open new files like
:vsplit filename
. - Switch windows with
CTRL-W W
. - Close a window with
:q
orCTRL-W Q
. - Resize windows with
CTRL-W
to intiate the chord,then follow up with one of:- Shrink and expand vertical with
-
or+
. - Shrink and expand horizontal with
<
and>
. - Maximize vertical with
_
. - Maximize width with
|
. - Split everything equally with
=
.
- Shrink and expand vertical with
- Resize using commands:
- Horizontal resize with
:resize 20
,:res -3
, or:res +3
- Vertical resize with
:vertical resize 20
,:vertical res -3
, or:vertical res +3
- Horizontal resize with
Buffers, reading & opening files
Buffers (open files) are separate from windows.You can have multiple windows all for the same buffer.You can also have one window with multiple buffersopen in the background. Buffers are always in-memory.It is only when you write using a commandthat the changes are saved to disk.
Loading files in to buffers- Open a file for editing with :e filename
- Split window w/ new unnamed buffer using :vnew
or :new
.- Use :enew
to edit new buffer in current window.- Use :tabnew
to open tab w/ new buffer.
- List available buffers with
:ls
. - Create a new unnamed
- Switch current window buffer with
:b2
or:b!2
,:bnext
:bprevious
.
Saving and exiting
- Simple exit with
q
. - Force quit (ignore changes) with
q!
. - Save/write with
:w
- Save and quit with
:wq
or:x
orZZ
.
Moving around
You can multiply any of these commands by pressing a number first.
- General move with
j
,k
,l
,h
- Scroll up and down full/half pages with
CTRL-D
,CTRL-U
,CTRL-B
,CTRL-F
. - Go forward and backward with
w
,b
,W
,B
. - Go to beginning and end of file with
gg
andG
. - Go to specific lines (e.g. 33) with
:33
or33G
. - Go to beginning and end of lines with
$
,^
, and0
.
Cut, paste, delete
- Delete character with
x
. - Make visual selections with
v
orV
. - Copy/yank selection with
y
. - Delete/cut selection with
d
. - Copy/yank line with
yy
. - Delete/cut a line with
dd
. - Paste with
p
orP
.
Undo/Redo
- Just press
u
in command mode. - Type
:u
command and press enter. - Redo a command with
CTRL-R
. - Repeat last command with
.
Editing
Delete and change are similar but change will delete the itemand switch in to insert mode. Delete will only delete.For both, you can work 'inside' an element, or on 'all' of theelement, signified with the keys a
or i
. For example'delete inside )' will delete everything inside the parenthesis.'delete all-of )' will delete the everythign inside AND parenthesis.This works with words, quotation marks, parenthesis, brackets, braces, etc.
- Change inside/all word with
caw
orciw
. - Change inside/all like
ci)
orci'
. - Delete to something like
dt)
ordt'
. - Delete inside something like
di}
ordi]
. - Delete a/all like
daw
,da)
,da'
.
Vi Commands Cheat Sheet Pdf
Search, find, and replace
- Search like
/sometext
. - Re-run last search with just a blank
/
Search backwards with
?sometext
Repeat last search with
n
.Repeat last search but backwards with
N
.:s/old/new/
- Swap text (next occurence on current line):s/old/new/g
- Swap text (globally on current line):%s/old/new/
- Swap text (next occurence in file):%s/old/new/g
- Swap text (globally in file):%s/old/new/gc
- Swap text with confirmation (globally in file)
Running shell commands
- Execute commands like this
:!ls
. - Can also read output in to file with
:r !ls
Macros
- To start and stop a macro recording, press
q
in command mode. - The first letter pressed after hitting
q
is the register wherethe macro is stored. For example,qt
would put the macro in thet
register. - To replay the macro, enter
@<register>
for example@t
. - Repeat a macro with
@@
. - Repeat a macro multiple times w/ a number prefix. E.g.
5@t
.
Misc
- Read file contents and output at cursor with
:r filename
- Open file explorer with
:Explore
![Sheet Sheet](https://cms-assets.tutsplus.com/uploads/users/31/posts/20393/image/overscan.png)
Digraphs
:help digraph
to get more information- Run
:digraph
to see extended ASCII characters.TypeCTRL-V
+ the characters in the digraph. E.g.CTRL-V + 172
.
My ~/.vimrc
- PDF Link: cheatsheet-mac-A4.pdf, Category: tools
- Blog URL: https://cheatsheet.dennyzhang.com/cheatsheet-mac-A4
- Related posts: Shell CheatSheet, CheatSheet: Web Browser, #denny-cheatsheets
File me Issues or star this repo.
1.1 Mac Install Packages
Name | Comment |
---|---|
Mac install dropbox | Link: Download Dropbox |
Mac install all basic packages | code/setupmac.sh |
Mac install iterm2 | brew cask install iterm2 |
Mac install jvm | Link: Download Java for Mac OS X |
Mac install realpath | brew install coreutils |
Mac install lpass | brew install lastpass-cli |
1.2 Summary
Name | Comment |
---|---|
Customize screenshot location | defaults write com.apple.screencapture location ~/Dropbox/Screenshots |
Share files across intranet | System Preferences -> Sharing -> File Sharing , then 192.168.XX.XXX |
Lock the screen | Ctrl + Shift + Power |
Swap Cap and Command key | Link: support.apple.com |
1.3 Fresh Mac Setup
Name | Comment |
---|---|
Install packages and configurations | code/setupmac.sh |
Verify installation | code/verifyinstallation.sh |
1.4 Mac Recommended Applications
Name | Comment |
---|---|
Monosnap | A useful free tool to capture screenshots and videos |
Draw design diagram | draw.io, www.gliffy.com |
1.5 Home Brew Basic
Name | Comment |
---|---|
Get brew version | brew --version |
HomeBrew update | brew update |
Install big binary | brew cask install <package_name> |
List all installed casks | brew cask list , brew cask help |
uninstall big binary | brew cask uninstall <package_name> |
Upgrade all the casks | brew cask upgrade , brew cask upgrade --no-quarantine |
Install openjdk | brew cask install adoptopenjdk |
Install mvn | brew install maven |
Brew install package with given version | brew install python@2 |
Reference | Link: How to Use Homebrew-Cask |
1.6 zsh
Name | Comment |
---|---|
Partially disable zsh’s auto correction | alias vim=’nocorrect vim’ Link: stackoverflow |
1.7 Clean & Release disk
Name | Comment |
---|---|
Xcode | Library/Developer/Xcode/DerivedData |
Trash | ~/.Trash , ~/trash |
1.8 More Resources
![](https://cdn-ak.f.st-hatena.com/images/fotolife/r/ruriatunifoefec/20200910/20200910011350.png)