Skip to content

Instantly share code, notes, and snippets.

@lysender
Created November 15, 2023 04:00
Show Gist options
  • Save lysender/962e84f2789be119e8d31620f3eb2757 to your computer and use it in GitHub Desktop.
Save lysender/962e84f2789be119e8d31620f3eb2757 to your computer and use it in GitHub Desktop.
TIL - vim - moving within quotes

Basic key bindings

f" and f' to move to the next double quote or single quote.

F" and F' to move to the previous double quote or single quote.

Used when you want to select or copy text including the quotes.

t" and t' to move to the last character before the next double quote or single quote.

T" and T' to move to the first character after the previous double quote or single quote.

Used when you want to select or copy text inside the quotes.

Application

Copy quoted text including the quotes

  • Position cursor to the quote, ie: "
  • Press yf" to copy the text from the cursor until the next " character
  • Press p somewhere else to paste the text

Copy text inside the quotes

  • Position cursor on the first character inside quote, let's use ' this time
  • Press yt' to copy the text from the cursor until the last character before the '
  • Press p somewhere elase to paste the text

Repeat selection with ;

You can repeat the selection process by just repeating the ; key.

  • First, do the fist motion/selection first, ex: select text within single quotes
  • Position cursor at the first character inside '
  • Press yt' to copy text within the single quote
  • Press p somewhere to paste the text
  • Select another text to copy, but this time, just press y;
  • This will yank/copy text by repeating the previous selection motion, ie: t'
  • Then paste it again
  • You can use ; over and over again, saving keystrokes

Note: Only the t' motion is repeated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment