Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Custom Vim Refactorings (screencast) (extracheese.org)
29 points by moe on Dec 28, 2010 | hide | past | favorite | 7 comments


For people who enjoy stuff like this, I'd recommend http://vimcasts.org/ — probably has been mentioned on HN at least a few times, but there seem to be people on this thread still amazed by what this guy was doing in the screen cast.

Vimcasts gives many insightful manuals for things that I've used on a day-to-day basis.


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.

    (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


"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.


Really wish the video wasn't so small and wasn't private on the vimeo site. Fullscreen buttons never play nicely with my tiling window manager.


What WM are you using? Fullscreen flash works on XMonad (you have to customize the manage-hook, but that's in the FAQ.)


A small glimpse into the power of vim.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: