[ Prev ] [ Index ] [ Next ]

vim mapping

Created Saturday 07 January 2017


Vim editor works a bit different than other editors (I've used at least).
Vim works in a concept of modes - and you will not be able to type directly once you run it.
This is because Vim opens in its normal mode - not insert mode.
The normal mode allows you to push a key, and what-ever action bound to that key will be run.


Command Mode

# Commands can be entered by hitting : (colon) from Normal Mode


Save and/or Exit

# To save (write) :w
# Save to specific file :w file_name
# Save and Exit :x
# Exit (quit) :q
# (Save) Forgot to open document as sudo? Use :w!! (double exclamation)


Find and Replace

# Below examples will replace instances of original with replacement
# Search and replace the first instance :%s/original/replacement
# Search and replace all instances :%s/original/replacement/g
# All instances, but confirm before replacing :%s/original/replacement/gc


Change Color every 10sec

# Use this little snippet :while 1|sleep 10|call NextColor(1)|endwhile
# Stop it with Ctrl+c



Normal mode

# You can reach normal mode by hitting Esc at any time
# In Normal Mode you just hit the key - or key combo - to activate the action attached
# <leader> = , (comma)


Nerd Tree (file manager)

# Open (plugin) file manager with Ctrl+n
# To show Hidden files in NerdTree, hit I


Insert Mode (edit content)

# Insert mode (before cursor) i
# Insert mode (before line) I
# New line below, and enter Insert mode o
# New line above, and enter Insert mode O
# After Cursor a
# End of line A
# Replace 1 character r
# Replace many characters R


Deleting Text

# Delete character at cursor x
# Delete a word dw
# Delete from cursor to end of line D
# Delete line dd
# Delete 3 lines (ex) 3dd


Undo Tree

# A Git-like undo tree with F5


Searching

# Search forward /
# Search backwards ?
# Next result n
# Previous result N
# Clear Search (command) :noh # Modified to <leader>Space


Searching for words under cursor

# You can place your cursor at a word and hit * (star) to find next instance of that word.
# To search backwards use #


Matching parenthesis

# You can navigate to a parenthesis and hit % to jump to the opening/closing parenthesis.


Navigating Lines

# You can specify the number of lines to jump by entering a numeric value before moving
# Etc. type 40 then press arrow-down, tell Vim to jump down 40 lines.


Navigation

# Navigate to the beginning of the document gg
# Navigate to the end of the document G
# Move to the end of a line $
# Move to the beginning of a line 0
# Move to the next word w
# Move to the beginning of a word b
# Move to the end of a word e
# Move a sentence back (
# Move a sentence forward )


Folds

# You can engulf code in {} to make it fold-able
# Navigate to a fold and hit Space to open/close toggle
# Open all folds zR
# Close all folds zM
# Quickly create a set of fold markers zf Space


Color Theme

# Next Color Theme with F8
# Random Color Theme with Alt+F8



Visual Mode

# Visual Mode is used for selecting text
# Visual Mode for single characters v
# Visual Mode for lines V
# You can also hold down Shift and navigate left/right to start marking
# Once in Visual Mode, navigate around to select text
# Below is a few options, that seems logic for selected text


# Copy (yank) y # (modified to Ctrl+c )
# Switch case ~
# Indent right >
# Indent left <



Vimdiff

# Open and differentiate between two files
$ vimdiff /path/to/file1 /path/to/file2


Commands

# Re-scan the files for differences :diffupdate


Navigate the two files

# Jump between the two files with Ctrl+w Ctrl+w (double)


Search Differences

# Next Difference with ]c
# Previous Difference [c


Bring changes to their counterpart file

# diff-obtain (do) brings changes from the other file, to the current file do
# diff-put (dp) sends changes from the current file, to the other file dp


Fold & Unfold

# Unfold text with zo
# Refold it with zc
# Unfold both files completely zr
# Fold both files completely zm