Vim
Vim and vim-mode in other tools. Should probably be broken up into different pages.
Tips
citChange Inside Tag. Can be used anywhere in the line and will find the nearest tag to change inside of.- Vim Surround #
dstDelete Surrounding Tag.
- Replace with Register #
grreplace with unnamed registergrrreplace line with unnamed register"xgrreplace with registerx
Workflows
- Run
vim index.htmlto create a new HTML file from scratch. Have good defaults like shorter tabs etc. - Working with files in a project. Find files, create new.
- Create a new directory when creating a new file (Create file in non-existing directory)
- Easily add support for a new workflow, for e.g. editing Liquid templates with Jekyll
- Built-in terminal
- Toggle, hide
- Scrollback
Working with the terminal
When Zsh is also configured to use Vim mode, what commands get interpreted by which Vim?
:term to open a terminal in a new window (will split the screen)
Ctrl-d to close the window (will remove the split)
Ctrl-W N for Normal mode (special "terminal-normal" mode, :h Terminal-mode)
Ctrl-W : command mode (Ex command)
Working with buffers and windows
Key Concepts
word vs WORD
A word consists of a sequence of letters, digits and underscores, or a sequence of other non-blank characters, separated with white space (spaces, tabs, <EOL>). This can be changed with the 'iskeyword' option. An empty line is also considered to be a word. A WORD consists of a sequence of non-blank characters, separated with white space. An empty line is also considered to be a WORD.
Usage
operator [number] motion
operator - is what to do, such as d for delete
[number] - is an optional count to repeat the motion
motion - moves over the text to operate on, such as w, $
Motions
h,j,k,lArrowsbBTo beginning of word/WORDeETo end of current word/WORDwWTo start of next word/WORDgeTo end of previous word$To end of the line0To start of line
Repeating
3wMove cursor 3 words forward. Equivalent to pressingwthree time.30i- EscInsert a dash 30 times
Finding
f,FFind next, previous characterfoFind next "o"3fqFind third "q"*,#Find next, previous word under cursor/Search forward?Search backwardn,NFind next, previous resultCtrl+gshow status line
Jumping
%jump to matching parens0start of line$end of lineggbeginning of fileGend of file20Gline 20Ctrl-oBack (history)Ctrl-IForward (history)
Inserting
iInsert before cursor (before the character under the cursor)IInsert at beginning of lineaAppend After cursor (after the character under the cursor)AAppend After line (at end of line)oOpen line belowOOpen line above
Editing
rReplace characterrxE.g., replace with "x"RReplace multiple characters (overwrite). This is actually a different mode, called "REPLACE (paste)"cChange (goes into Insert mode)ceChange to end of worddwDelete to next wordd2wDelete two wordsdeDelete to end of wordd$Delete to end of lineddDelete current line2ddDelete two linesdfDelete until find result (inclusive)df.E.g., delete until .uUndoUUndo whole line, restore line to its original state.Redo?s/old/new/gSubstitute "new" for "old"./gmeans globally (for the current line)#,#s/old/new/gSubstitute within lines in range #,#%s/old/new/gReplace across entire file%s/old/new/gcReplace across entire file but ask for confirmation each time
Selection and Registers
- Things deleted with
dget stored in a register pPut command, put from the register. Put below/aftervVisual selectionyYank selection, or with operatorywE.g., yank one word
Files
wSave filewWith selection - save subset of filerRead filer !Read output of commandr !lsE.g., read output ofls
Commands
:!Run external commands:!lsE.g., runls
Window Management
Ctrl+W h,j,k,lMove between windows in directionCtrl+wwSwitch windows
Tips
For learning vim
- Disable Insert mode features, don't allow backing beyond the initial insertion point, don't allow arrow keys
- Relative line numbers
- (from Improving Vim Speed - YouTube)
Articles
Vim: Seven habits of effective text editing
Your problem with Vim is that you don't grok vi. · GitHub
vimrctips - best practices - reddit/vim
Copy, cut and paste | Vim Tips Wiki | Fandom
Links
- Vim Awesome - Plugins
- Newest - Vim Colors
- r/Vim porn
- vim wallpaper