Emacs: Select Text Between Quotes šŸ“œ

By Xah Lee. Date: . Last updated: .

Select Text between Quotes/Brackets

Select text inside quotes is one of the most frequently needed operation in programing languages code.

put this in your Emacs Init File:

(defun xah-select-text-in-quote ()
  "Select text between the nearest left and right delimiters.
Delimiters here includes QUOTATION MARK, GRAVE ACCENT, and most commonly used Unicode matching brackets.
Does not include APOSTROPHE.
This command ignores nesting. For example, if text is
怌(a(b)cā–®)怍
the selected char is 怌c怍, not 怌a(b)c怍.

URL `http://xahlee.info/emacs/emacs/emacs_select_quote_text.html'
Created: 2020-11-24
Version: 2026-07-09"
  (interactive)
  (let ((xskipChars "^`\"ā€œā€()[]{}<>ļ¼œļ¼žļ¼ˆļ¼‰ļ¼»ļ¼½ļ½›ļ½ā¦…ā¦†ć€šć€›ā¦ƒā¦„ā€¹ā€ŗĀ«Ā»ć€Œć€ć€ˆć€‰ć€Šć€‹ć€ć€‘ć€”ć€•ā¦—ā¦˜ć€Žć€ć€–ć€—ć€˜ć€™ļ½¢ļ½£āŸ¦āŸ§āŸØāŸ©āŸŖāŸ«āŸ®āŸÆāŸ¬āŸ­āŒˆāŒ‰āŒŠāŒ‹ā¦‡ā¦ˆā¦‰ā¦Šā›āœāāžāØā©āŖā«ā“āµā¬ā­ā®āÆā°ā±"))
    (skip-chars-backward xskipChars)
    (push-mark (point) t t)
    (skip-chars-forward xskipChars)))
(defun xah-cut-text-in-quote ()
  "Cut text between the nearest left and right delimiters.
See `xah-select-text-in-quote'

URL `http://xahlee.info/emacs/emacs/emacs_select_quote_text.html'
Created: 2023-07-23
Version: 2026-07-09"
  (interactive)
  (let ((xskipChars "^`\"ā€œā€()[]{}<>ļ¼œļ¼žļ¼ˆļ¼‰ļ¼»ļ¼½ļ½›ļ½ā¦…ā¦†ć€šć€›ā¦ƒā¦„ā€¹ā€ŗĀ«Ā»ć€Œć€ć€ˆć€‰ć€Šć€‹ć€ć€‘ć€”ć€•ā¦—ā¦˜ć€Žć€ć€–ć€—ć€˜ć€™ļ½¢ļ½£āŸ¦āŸ§āŸØāŸ©āŸŖāŸ«āŸ®āŸÆāŸ¬āŸ­āŒˆāŒ‰āŒŠāŒ‹ā¦‡ā¦ˆā¦‰ā¦Šā›āœāāžāØā©āŖā«ā“āµā¬ā­ā®āÆā°ā±")
        xbeg xend)
    (skip-chars-backward xskipChars)
    (setq xbeg (point))
    (skip-chars-forward xskipChars)
    (setq xend (point))
    (kill-region xbeg xend)))

Emacs, Work with Brackets