Vim
Vim and vim-mode in other tools. Should probably be broken up into different pages.
Tips
cit
Change Inside Tag. Can be used anywhere in the line and will find the nearest tag to change inside of.- Vim Surround #
dst
Delete Surrounding Tag.
- Replace with Register #
gr
replace with unnamed registergrr
replace line with unnamed register"xgr
replace with registerx
Workflows
- Run
vim index.html
to 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
,l
ArrowsbB
To beginning of word/WORDeE
To end of current word/WORDwW
To start of next word/WORDge
To end of previous word$
To end of the line0
To start of line
Repeating
3w
Move cursor 3 words forward. Equivalent to pressingw
three time.30i- Esc
Insert a dash 30 times
Finding
f
,F
Find next, previous characterfo
Find next "o"3fq
Find third "q"*
,#
Find next, previous word under cursor/
Search forward?
Search backwardn
,N
Find next, previous resultCtrl+g
show status line
Jumping
%
jump to matching parens0
start of line$
end of linegg
beginning of fileG
end of file20G
line 20Ctrl-o
Back (history)Ctrl-I
Forward (history)
Inserting
i
Insert before cursor (before the character under the cursor)I
Insert at beginning of linea
Append After cursor (after the character under the cursor)A
Append After line (at end of line)o
Open line belowO
Open line above
Editing
r
Replace characterrx
E.g., replace with "x"R
Replace multiple characters (overwrite). This is actually a different mode, called "REPLACE (paste)"c
Change (goes into Insert mode)ce
Change to end of worddw
Delete to next wordd2w
Delete two wordsde
Delete to end of wordd$
Delete to end of linedd
Delete current line2dd
Delete two linesdf
Delete until find result (inclusive)df.
E.g., delete until .u
UndoU
Undo whole line, restore line to its original state.
Redo?s/old/new/g
Substitute "new" for "old"./g
means globally (for the current line)#,#s/old/new/g
Substitute within lines in range #,#%s/old/new/g
Replace across entire file%s/old/new/gc
Replace across entire file but ask for confirmation each time
Selection and Registers
- Things deleted with
d
get stored in a register p
Put command, put from the register. Put below/afterv
Visual selectiony
Yank selection, or with operatoryw
E.g., yank one word
Files
w
Save filew
With selection - save subset of filer
Read filer !
Read output of commandr !ls
E.g., read output ofls
Commands
:!
Run external commands:!ls
E.g., runls
Window Management
Ctrl+W h,j,k,l
Move between windows in directionCtrl+ww
Switch 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