Custom Vim Refactorings (screencast)
blog.extracheese.org
blog.extracheese.org
Vimcasts gives many insightful manuals for things that I've used on a day-to-day basis.
Here is an emacs function I use, which does the reverse of the refactoring in the screencast. I use it by marking an expression and typing M-x extract-variable, which asks me what I want to call the variable. It then replaces the expression with the variable I named and puts "<varname> = <expression>" into the kill buffer. I navigate to where I want to define the variable and type C-y to yank, which completes the refactoring. It's a useful tool for breaking apart deeply nested code, pulling out constants to make things configurable, and improving the readability of long lines.
(defun extract-variable ()
"Micro-refactoring: replace the region with a variable and save an
assignment statement in the kill ring. After calling this function, find a
good destination for the assignment and yank."
(interactive)
(let ((var-name (read-string "Variable name: ")))
(kill-region (region-beginning) (region-end))
(kill-append " = " t)
(kill-append var-name t)
(unless (eq major-mode 'python-mode)
(kill-append ";" nil))
(insert var-name)))The best tips page [2] has a good set to get started.
[1]: http://vim.wikia.com/wiki/Vim_Tips_Wiki [2]: http://vim.wikia.com/wiki/Best_Vim_Tips
Great screencast.