<<
Home , Vi

VI/ Essential Reference By Donald Raymond https://github.com/hbc/NGS_Data_Analysis_Course/blob/master/VI_CommandReference.pdf and Mary Piper

Basic Controls & Commands Editing and Saving Files

Esc - Basic command (Default mode) :e filename - Edit a new (add to buffer) i - Insert mode (for inserting text) :enew - New empty file gg/G - Move to /bottom of file :read !command - Insert command output 0/$ - Move to begin/end of line :x or ZZ - Save and quit if file was changed /b - Move to next/previous word :w >> file2 - Append contents of file tofile2 dw/ - Delete word/line . - Repeat last command u/Ctrl + r - Undo/Redo V/v - Visual mode for selecting lines/char :set number/set nonumber - add/remove line #s :%s/search/replace/gc - Search and replace :w file - file :f newname - Change file name to newname :wq - Write and quit (:wq! to enforce) i/a - Insert text before/after char :q! - Quit without saving I/A - Insert text start/end of line Navigation and Searching O/o - Insert new line above/below cursor r - Replace char :n - Move cursor to line n cw/cc - Replace word/line Ctrl + u/d - Move down/up half page R - Replace text (typeover) Ctrl + f/b - Move down/up a full page s/S - Delete char/line and insert text e - Move to end of word ~/g~~ - Reverse case of char/line h/j/k/l - Move cursor left/down/up/right H/M/L - Jump to top/middle/bottom of page Deleting and Copying Text :n - Move cursor to line n x/X - Delete current/previous char fn - Search forward for next n nd - Delete line #n /pattern ?pattern - Search pattern forward/back D or d$ - Delete rest of line n/N - Next/previous occurrence of search pattern d0 - Delete from here to beginning of line # - Search for word under cursor Y or yy - Copy to register : topic - Show documentation for topic y0/y$ - Copy to beginning/end of line Buffers & Windows p/P - register after/before cursor : or :files - Display list of opened files Other Useful Commands :b n - Open file n in current window view file - Open file in read-only mode :bdn - Delete file n# from buffer :sh - open shell ( to re-enter vi) :next/previous - Move to next/previous file : !command - Run system command in VI :first/last - Switch to first/last file :e . - Browse a directory and display file explorer :e! - Reload current file :command - Execute command in vi Ctrl + wn or :new - New empty window : path/to/dir - Change directory Ctrl + ws or :sp - window horizontally :noh - Disable search highlighting Ctrl + wv or :vsp - Split window vertically :Sex - Split window and show file explorer (Hor) Ctrl + or :close - Close window :Sex! - Split window and show file explorer (Ver) Ctrl + wo or :only - Close all but current window vimdiff file1 file2 - Compare two files Ctrl + ww - Jump to next window n| - Move cursor to column n Ctrl + w[hjkl] - Move window focus * - Go to next occurrence of word under cursor Ctrl + w[HJKL] - Move window nG - Go to line n :resize/vertical resize +n - Resize window (Hor/ver)