How to mark the text between the parentheses in Emacs?

后端 未结 4 784
眼角桃花
眼角桃花 2021-02-01 19:31

Any such function or elisp script? I want the equivalent function as vi\" sequence in vim.

相关标签:
4条回答
  • 2021-02-01 20:05

    Xah Lee has an emacs-lisp function which achieves this called xah-select-text-in-quote. It is available from his website:

    Select text between the nearest left and right delimiters. Delimiters here includes the following chars: \"<>(){}[]“”‘’‹›«»「」『』【】〖〗《》〈〉〔〕(). This command does not properly deal with nested brackets.

    0 讨论(0)
  • 2021-02-01 20:08

    With Emacs keybinding M-m v works great.

    0 讨论(0)
  • 2021-02-01 20:12

    expand-region (which is bound to C-=) works great.

    0 讨论(0)
  • 2021-02-01 20:25

    Try the key sequence C-M-u C-M-SPC (i.e., while holding the Control and Meta keys, press u and Space in sequence), which executes the commands backward-up-sexp and mark-sexp.

    Edit:

    I made a mistake: backward-up-sexp doesn't exist in standard Emacs. I wrote it exactly because of the problem mentioned in lkahtz's comment, that the existing function backward-up-list won't work when point is between double quotes.

    (defun backward-up-sexp (arg)
      (interactive "p")
      (let ((ppss (syntax-ppss)))
        (cond ((elt ppss 3)
               (goto-char (elt ppss 8))
               (backward-up-sexp (1- arg)))
              ((backward-up-list arg)))))
    
    (global-set-key [remap backward-up-list] 'backward-up-sexp)
    
    0 讨论(0)
提交回复
热议问题