Is there a way to copy the entire line up to the stop character in Emacs?

Today I saw a neat copy function in VI, in which you could copy the entire line up to the stop character.

eg. if( copy == this );

With VI, he could copy everything in parentheses. I wonder if you can do this with emacs? (Without using ctrl + space and manually noting that I want to kill)

+5
source share
5 answers

Try

M-z CHAR

What kills the text through the next occurrence CHAR. Aka M-x zap-to-char. The documentation for Other Destruction Teams may be interesting .

Edited to add: on request here zap-to-before-char, which just took the source code for zap-to-charand deleted the comment (and the updated doc line):

(defun zap-to-before-char (arg char)
  "Kill up to and ARGth occurrence of CHAR.
Case is ignored if `case-fold-search' is non-nil in the current buffer.
Goes backward if ARG is negative; error if CHAR not found."
  (interactive "p\ncZap to char: ")
  ;; Avoid "obsolete" warnings for translation-table-for-input.
  (with-no-warnings
    (if (char-table-p translation-table-for-input)
        (setq char (or (aref translation-table-for-input char) char))))
  (kill-region (point) (progn
                         (search-forward (char-to-string char) nil nil arg)
                         (goto-char (if (> arg 0) (1- (point)) (1+ (point))))
                         (point))))
+12

, , ( ), C-M-u C-M-SPC M-w (backward-up-list, mark-sexp, kill-ring-save). , C-M-u C-M-k (backward-up-sexp, kill-sexp). sexp ; : C-M-b (backward-sexp) C-M-f (forward-sexp) ( C-M-).

+2

, . , c-x (. , :

c-s (
c-space
c-s )
M-w

c-x ). c-x e.

- ... , . , , .

(, ):

http://www.emacswiki.org/emacs/KeyboardMacros

0

Emacs , elisp, , :

(defun mark-inside-delimiters ()
"Mark all chars inside the balanced expression point is in"
  (interactive)
  (let (p start pairs stop)
    (skip-chars-backward "^<({[\"'")
    (setq p (point))
    (setq start (char-to-string (preceding-char)))
    (setq pairs '(("<" . ">")("(" . ")")("{" . "}")
                  ("[" . "]")("\"" . "\"")("'" . "'")))
    (setq stop (cdr (assoc start pairs)))
    (skip-chars-forward (concat"^" stop))
    (set-mark p)))

(global-set-key (kbd "C-c m") 'mark-inside-delimiters)

, , , .

0

Emacs gazillion, , .

, , ( ctrl-space), (ctrl-s) , ( -, , Pascal "end My_Procedure_Name;" ). , , . ctrl-k .

:

ctrl-space
ctrl-s
) return
ctrl-k

( a ctrl-_, , ).

// .. emacs , .

-1

All Articles