vi notes
Edit Modes
i– activates text insert mode, inserting text immediately under the current position of the cursorR– Replace / Overwritea– append text, after the cursorA– append text, after end of lineI– insert text, before first non-whitespace charactero– open new line below cursor in Insert ModeO– open new line above cursor in Insert Mode
Movement
l– moves the cursor one character to the righth– moves the cursor one character to the left (2hmoves the cursor two characters to the left)j– moves the cursor one line down (3jmoves the cursor three lines down)k– moves the cursor one line upG– moves the cursor to the last line of text if not preceded by a modifying integernG– moves the cursor to the desired line (5Gmoves the cursor to the fifth line)w– moves to next word$– end of line0– begining of line%– Navigate to matching brace or parenthis>%– indent between selected braces>>– indent line
Deletion
x– deletes the character immediately under the cursorX– deletes a single character to the left of cursorD– removes the text on the current line from the character under the cursor to the end of the linedw– deletes the character immediately under the cursor and the remaining characters to the right of it in the same worddd– deletes the entire line containing the cursor, and the cursor then moves to the next linecw– deletes the character under the cursor and to its right in the same word and allows new characters to be typed in to replace themcc– erases the current line and allows replacement text to be typed incb– deletes the characters to the left of the cursor in the current word and allows replacement characters to be typed in
Search
/string– search?– Search backwardsn– Next forward resultsN– Previous backwards result:%s/pattern/replace/g– Global Search and replace
Sort
Sort lines | Vim Tips Wiki | FANDOM powered by Wikia
:%sort!– Sort in reverse:%sort u– Sort, removing duplicate lines:%!sort -M– Sort using the external Unix sort utility, respecting month-name order (“respecting month-name order” means January < February < … < December):sort n– Numeric sort (this way, 100 doesn’t precede 20 in the sort):g/start/+1,/end/-1 sort n– Sort subsections independently, in this example sort numbers between “start” and “end” markers:296,349sortSort only specific lines using ranges (sort lines 296 to 349, inclusive)
make
Using makefiles can save time when compiling lots of source files into one program. vim can run the makefile without leaving the editing session:
:map <f9> :make – map the F9 key to run make
:set makeprg – change what :make does
:make will compile if you are using a Makefile. Use these to examine the compile errors:
:copen – open a mini-window with make output, hit enter on an error to jump to line
:cclose – closes the mini-window
:cw – toggles the mini-window (if errors exist)
syntax
:set syntax=.... – set value
:set option – set a bool option
:set nooption – disable option
can add ! to the end of a option it toggle
line numbers
:set nonumber – disable line numbers
:set number – enable line numbers
paste mode
- do not auto endent when pasting
:set paste
:set nopaste
invisable characters
:set list – show invisable characters
:set nolist – disable show invisable chars
:set listchars+=space:␣ – Show white space when list enabled
:set listchars=eol:¬,tab:>·,trail:~,extends:>,precedes:<,space:␣ – set other chars in list view
file management
:enew– Create new blank file:q– closes (quits) a file to which no changes have been made:q!– quits without saving any changes:w– writes (i.e., saves) the current file to disk:wq– writes the buffer contents to disk (i.e., saves changes) and quits:r– inserts text into the currently open file from another file (:r lettuce.txtinserts text into the currently open file from the file named “lettuce.txt”):w>>– appends the text from the currently open file into another file (:w>>cabbage appends the text from the currently open file into the file named “cabbage”)ZZ– same as :wq
others
vi Complete Key Binding List
vim tips and tricks: indenting
Summary of Commands in vi
ctl-w w– switch between split painsctl-n– complete text.– repeat last commandxp– transposes two adjacent characters
deep– transposes two adjacent wordsddptransposes two adjacent lines~– changes case of the character under the cursorJ– joins the current line with the next lineu– undo reverses the effects of the most recent command that has changed the bufferU– undoes all changes made to the current line during the current visit to itggVGuchange whole file to lower casegg– goes to first line of textV– turns on Visual selection, in line modeG– goes to end of file (at the moment you have whole text selected)u– lowercase selected area
Plugins
DrawIt
- ASCII diagraming
https://www.vim.org/scripts/script.php?script_id=40```
wget -O DrawIt.vba.gz http://www.vim.org/scripts/download_script.php?src_id=8798
vim DrawIt.vba.gz
:so %
:q \diwill turn on the Drawit! plugin\dswill turn off the Drawit! plugin