Various vim tricks I learn through the years
vim cheatsheet - https://vim.rtorr.com/
f"
orf'
- jumps to the next quoteF"
orF'
- jumps to the previous quotet"
ort'
- jumps before the next occurrence of quoteT"
orT'
- jumps after the previous occurence of quote
To combine with other commands, we can do the following:
df"
- deletes all chars from cursor until the next quote, including the quote itselfdt"
- deletes all chars from cursor until the next quote, not including the quote
When used repeatedly, you can do the following shortcut:
d;
- repeats the previoust
orT
orf
orF
motions, ie:t"
ort'
, then execute the delete command
To highlight contents within {}
or ()
or []
or ""
while inside:
vi}
vi)
vi]
vi"
vi'
viw
- highlight a wordviW
- highlight a word (can contain punctuation)
Note: You can also use the opening bracket or parenthesis.
With nvim-surround
plugin installed, we can do the following where; *
is the cursor position:
Old text Command New text
--------------------------------------------------------------------------------
surr*ound_words ysiw) (surround_words)
*make strings ys$" "make strings"
[delete ar*ound me!] ds] delete around me!
remove <b>HTML t*ags</b> dst remove HTML tags
'change quot*es' cs'" "change quotes"
<b>or tag* types</b> csth1<CR> <h1>or tag types</h1>