How do I select or edit the content inside backtick-delimited text like Markdown code spans?
Answer
vi`
Explanation
Vim treats backticks as a valid quote delimiter for text objects, just like ' and ". The i`` text object selects the content **inside** a pair of backticks; a`` selects the content and the backticks themselves. This works for Markdown inline code spans, shell command substitutions, JavaScript template literals, and any other backtick-delimited text.
How it works
- `vi`` — enter Visual mode and select inside backticks (the content between them)
va`` — select **a**round backticks (content + surrounding ```` characters)- Works in Normal mode as an operator target:
ci`` changes the content,dideletes it, `yiyanks it - The cursor can be anywhere on the line — Vim searches forward for the nearest backtick pair
Example
Given a Markdown line:
Run `git status` to check your repository.
With the cursor anywhere on the line:
vi`` selectsgit status`ci`` deletesgit status` and puts you in Insert mode to type the replacementda`` deletes the entire ``git status` `` including the backticks
Tips
- Works for all quote-like delimiters:
vi'(single quotes),vi"(double quotes),vi((parentheses),vi{(curly braces),vi[(square brackets) - In Markdown,
ci`is the fastest way to update an inline code snippet without touching the surrounding text - For JavaScript template literals spanning multiple lines,
vi`` may not work as expected — useva{` with the outer object instead :set matchpairsdoes not affect quote text objects; those are always recognized by default