Custom Vim Refactorings (screencast)(blog.extracheese.org)
blog.extracheese.org
Custom Vim Refactorings (screencast)
http://blog.extracheese.org/2010/11/screencast-custom-vim-refactorings.html
6 comments
I doubt I'll ever be a heavy vim user because it just doesn't fit my brain well, but this video is an example of why I have great respect for people who have truly mastered vim and can use it quickly and effectively. The rapid click-clack of the keyboard--as he pounds out commands as fast as he can think them up--is the same familiar sound I remember from vim experts I've known in the past.
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.
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)))Another great resource for learning about vim is the Vim Tips Wiki [1]. The have a LOT of content on there, most of which will be useful at some point.
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
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
"zdd and ^Rz are awesome. I didn't know that before. I always thought that there must be something like that, but never actually searched about it.
Great screencast.
Great screencast.
A small glimpse into the power of vim.
Vimcasts gives many insightful manuals for things that I've used on a day-to-day basis.