Vi Cheat Sheet Mac



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 with set -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,the avit theme.
  • Go through previous/next commands with j and k 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 and CTRL-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 pressing v by changing EDITOR 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-[ or ESC to to command mode.
  • i, a, and o to go in to insert mode.
  • I, A, and O 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

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 or CTRL-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 =.
  • 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

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 or ZZ.

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 and G.
  • Go to specific lines (e.g. 33) with :33 or 33G.
  • Go to beginning and end of lines with $, ^, and 0.

Cut, paste, delete

  • Delete character with x.
  • Make visual selections with v or V.
  • Copy/yank selection with y.
  • Delete/cut selection with d.
  • Copy/yank line with yy.
  • Delete/cut a line with dd.
  • Paste with p or P.

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 or ciw.
  • Change inside/all like ci) or ci'.
  • Delete to something like dt) or dt'.
  • Delete inside something like di} or di].
  • 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 the tregister.
  • 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

Digraphs

  • :help digraph to get more information
  • Run :digraph to see extended ASCII characters.Type CTRL-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

NameComment
Mac install dropboxLink: Download Dropbox
Mac install all basic packagescode/setupmac.sh
Mac install iterm2brew cask install iterm2
Mac install jvmLink: Download Java for Mac OS X
Mac install realpathbrew install coreutils
Mac install lpassbrew install lastpass-cli

1.2 Summary

NameComment
Customize screenshot locationdefaults write com.apple.screencapture location ~/Dropbox/Screenshots
Share files across intranetSystem Preferences -> Sharing -> File Sharing, then 192.168.XX.XXX
Lock the screenCtrl + Shift + Power
Swap Cap and Command keyLink: support.apple.com

1.3 Fresh Mac Setup

NameComment
Install packages and configurationscode/setupmac.sh
Verify installationcode/verifyinstallation.sh

1.4 Mac Recommended Applications

NameComment
MonosnapA useful free tool to capture screenshots and videos
Draw design diagramdraw.io, www.gliffy.com

1.5 Home Brew Basic

NameComment
Get brew versionbrew --version
HomeBrew updatebrew update
Install big binarybrew cask install <package_name>
List all installed casksbrew cask list, brew cask help
uninstall big binarybrew cask uninstall <package_name>
Upgrade all the casksbrew cask upgrade, brew cask upgrade --no-quarantine
Install openjdkbrew cask install adoptopenjdk
Install mvnbrew install maven
Brew install package with given versionbrew install python@2
ReferenceLink: How to Use Homebrew-Cask

1.6 zsh

NameComment
Partially disable zsh’s auto correctionalias vim=’nocorrect vim’ Link: stackoverflow

1.7 Clean & Release disk

NameComment
XcodeLibrary/Developer/Xcode/DerivedData
Trash~/.Trash, ~/trash

1.8 More Resources