How to extract an intention-revealing name using Vim
May 2, 2012 Tagged: vim golf refactoring Comments (View) How to extract an intention-revealing name using Vim This method has a magic number : def wait_time @env[QUEUE_WAIT_HEADER].to_i / 1000 end Let’s extract that to an intention-revealing name . We’ll type: /1000<Enter> # Find the number we want to extract cwmilliseconds_per_second<Esc> # Replace the number with a variable name O<Ctrl+A> = <Esc>p # Assign the replaced number to the variable The result: def wait_time milliseconds_per_second = 1000 @env[QUEUE_WAIT_HEADER].to_i / milliseconds_per_second end Under the covers: <Ctrl+A> inserts the last text you typed in insert mode, so the variable name is available after replacing the number Replacing or deleting text in Vim will place that text in your default buffer, so the number is available to put at the end Assuming your cursor is at the value you want to extract, thi...
Full article:
http://robots.thoughtbot.com/post/22258289125/how-to-extr...