-
Notifications
You must be signed in to change notification settings - Fork 1
VIM Tips
Line numbers in gutter: set number Show/hide hidden characters: set (no)list Syntax coloring: :syntax on|off
% make sub apply to whole file
/e suppress errors
Need to quote e.g. +, so /\s+/ (Perl) becomes /\s+/ (vim)
Delete all blank lines in the file: :g/^$/d
:help C-w
Split horizontally: C-w s / :sp [file] Split vertically: C-w v / :vsp [file]
Close the active window: C-w q / :q Close all but the active window: C-w o / :only
Click in another window to go to it. Cycle though windows: C-w w Cursor through windows: C-w [hjkl] / C-[hjkl] (I mapped that)
Make window bigger/smaller: C-w +/- / click on bar and drag Equalize windows: C-w = Maximize window horizontally / vertically: C-w /
Rotate windows: C-w r/R Swap adjacent windows: C-w x Move a window directionally: C-w [HJKL] Move current window to new tab: C-w T
Open a new tab: :tabedit [filename]
Convert all tabs to spaces: :retab
List buffers: :ls Next / Prev buffer: :bn :bp adding a ! does it when not saved Go to a specific buffer: C-^ or :b where n is the number in the buffer list. Toggle active / alternate buffer: C-^ or :e #
Auto hide dirty buffers: set hidden
%a active buffer
- buffer has been modified, not saved h hidden -- unsaved changes, with unsaved changes
Revert file: :e
In / de-Indent: >> or << Indent blocks: use visual mode to select a block, then e.g. >> and . to repeat. Autoindent: == (or ==) in visual mode, just =
Indent the entire file: gg=G (go to line 1, then indent{motion}, in this case G Indent block: ={ Indent inside of block: =i} (i selects innner)
Explore: :e
autocmd
setlocal
filetype on to enable detection
Wrap autocmds in if(has(autocomand)
See what kind of file vim thinks you're looking at: :set ft?
Set filetype: :set filetype=
Set a certain filetype for a given extension (in this case, type xml for .rss and .atom files): autocmd BufNewFile,BufRead .rss,.atom setfiletype xml
Show invisibles: :set list Hide invisibles: :set nolist Toggle invisibles: :set list! Keymap it: nmap l :set list! Customize symbols: change listchars Insert unicode char: C-v u25b8 inserts ▸
Search for something (and open the file if needed): :vimgrep Where am I? :pwd CD: :cd Each tab has its own working directory New tab: :tabnew Next tab: :tabn Prev tab: :tabp Open file in new tab: :tabe
Go back to where you were when you left insert mode: g; Move back through the changelist: g; Move forward through the changelist: g, See the changelist: :changes Move back in the jumplist: C-o Move back in the jumplist: C-i View the jumplist: :jumps Follow a hyperlink in help: mouse click link, or C-] Go back a link: (jump back): C-o
Toggle case of the letter you're on: ~ Change case of a region: gU{motion} or gu{motion}
% is the path to the current file, relative to pwd
:p expands to abs path
:h is dirname
To cd to the directory of the curent file: :cd %:p:h
z. move the line the cursor is on to the middle of the screen zt move the line the cursor is on to the top of the screen zb move the line the cursor is on to the bottom of the screen
Append to the end of a word: ea