I'd like to add some extras that I sometimes use with
I've found the following to be useful:
Sometimes, you find yourself needing to move to the next
# or the next
, or some specific delimiter. This is especially handy when you need to move across different numbers of words for each cursor.
It provides the functions
iy-go-to-char-backward, which you can bind and use nicely.
This is really useful for similar reason to
iy - when you've got slightly different lines under each cursor, and you maybe want to select the quoted string under the point or similar.
These are things that are just elisp in my config, but I find useful. Probably not written by me.
Prompt for input
I got this one from Magnars in response to a request for putting a different string under each cursor. The code is simple, but binding it to something and using for multiple cursors is a handy way to insert slightly different stuff in each place.
(defun prompt-for-insert ()
(insert (read-string "Insert: ")))
Increment number at point
This either came from SO, or emacswiki. Not sure which.
It's pretty useful on its own, and also when used in combination with
(defun my-increment-number-decimal (&optional arg)
"Increment the number forward from point by 'arg'."
(let (inc-by field-width answer)
(setq inc-by (if arg arg 1))
(when (re-search-forward "[0-9]+" nil t)
(setq field-width (- (match-end 0) (match-beginning 0)))
(setq answer (+ (string-to-number (match-string 0) 10) inc-by))
(when (< answer 0)
(setq answer (+ (expt 10 field-width) answer)))
(replace-match (format (concat "%0" (int-to-string field-width) "d")
This is super powerful, and enables some really useful bits 'n' pieces. It evaluates whatever sexp is behind the cursor, and inserts the result of evaluating it.
Combine it with
multiple-cursors-numbers to e.g. insert powers of two, or a series that goes
0 1 2 0 1 2 0 1 2 across each line or something. (I've done both of these usefully)
Or use it with
s.el to write out those tedious java config with default things. You write out each
CONFIG_VALUE_VARIABLE, then transform that into
CONFIG_VALUE_VARIABLE = "configValueVariable" by running
(defun eval-and-replace ()
(let ((value (eval (preceding-sexp))))
(insert (format "%s" value))))