Yan Pritzker photographer, entrepreneur, software engineer, musician, skier

Blog :: Git Workflows Book :: Dotfiles :: Photography :: About Me

TwitterCounter for @skwp

Get the news feed
Get updates by email
Follow me on twitter

hello, i'm yan

I am a photographer, entrepreneur, software engineer, guitarist, climber, and telemark skier

This blog is about startups, blogging, Ruby On Rails, virtualization and cloud computing, photography, customer service, marketing, ux and design, git, and lots more.

Enterprise intelligence with prediction markets

Find out what your team, colleagues and partners really know about the future — and leverage their knowledge to improve business decisions.

I'm the founder of Planypus, the place to share your plans!

Archives

Contact

Reach me at yan at pritzker.ws

Convert rspec pending to xit with vim

Posted 3 January 2012 @ 12pm Tagged rspec, vim Comments: Be the first!

RSpec has two ways of disabling tests: pending and xit. Except one of them is truly evil. Pending actually still runs the before block even when it’s disabled. This is bad when you have a test with a very expensive before block. Changing the pending to xit is a great strategy, but tedious. Vimscript to the rescue! The functionality is available as part of my dotfiles repo, but you can just grab the script by itself and type ,rxit to use it on a file.

For more awesomeness, check out my dotfiles repo called YADR (Yet Another Dotfiles Repo), featuring 100% clean vimrc with all custom keymapping done in well factored scripts inside vim/plugin/settings, and a list of plugins perfectly tailored for Rails development, currently in alpha preview.


Learn to speak vim – verbs, nouns, and modifiers!

Posted 16 December 2011 @ 12pm Tagged vim Comments: 20 Comments

Using vim is like talking to your editor in ‘verb modifier object’ sentences, turned into acronyms

  • learn some verbs: v (visual), c (change), d (delete), y (yank/copy). these are the most important. there are others
  • learn some modifiers: i (inside), a (around), t (till..finds a character), f (find..like till except including the char), / (search..find a string/regex)
  • learn some text objects: w (word), s (sentence) p (paragraph) b (block/parentheses), t (tag, works for html/xml) there are others

To move efficiently in vim, don’t try to do anything by pressing keys many times, instead speak to the editor in sentences

  • delete the current word: diw (delete inside word)
  • change current sentence: cis (change inside sentence)
  • change a string inside quotes: ci” (change inside quote)
  • change until next occurrence of ‘foo’: c/foo (change search foo)
  • change everything from here to the letter X: ctX
  • visually select this paragraph: vap (visual around paragraph)

If you understand the verbs and objects you’re dealing with, you will soon realize that adding a new plugin and learning a new verb or noun exponentially increases your productivity, as you can now apply it in all the sentences you already know. It’s just like learning a language.

Let’s add some new text object plugins!

  • install surround.vim: vim-surround- you get a new noun, the ‘surround’ (s or S)
    • visually select a word and surround it with quotes: viwS”
    • change surround from single quote to double quote: cs’”
  • install vim-textobj-rubyblock – you get a new noun, the ‘ruby block’ (r)
    • delete current ruby block: dir (delete inside ruby block)
    • visually select a ruby function: var (visual around ruby block)
    • visually select the innards of a function: vir (visual inside ruby block)
  • install tComment – new verb: “gc” (go comment)
    • comment the current ruby method: gcar (go comment around ruby)

Now go out and learn a new verb or noun every day!

Resources and Further Reading


Vim demystified: ten commands you can start using today

Posted 30 November 2011 @ 10am Tagged productivity, vim Comments: Be the first!

These commands are not only extremely useful but also mnemonic and easy to learn for a huge payoff in keystroke savings. These are the common compound commands I use every day, and I think it’s easier to dive in this way than to try to learn vim key by key.

Read Me First! Save your wrists, stop using ESC in vim
yaw yank around word – copy the current word, no matter where your cursor is inside the word

ci” change inside quote (or any other enclosure). Example: ci( to change something surrounded by parentheses. But what’s really cool is that you can invoke this from anywhere inside a line of code, so even if the string you want to change is far away, typing ci” will put your right inside the string, ready to change it.
ctX change till X (any character); and in general the use of tX where X is any character, to move to that character. You can combine the motion with another command such as dtX (delete till X), ytX (yank till X), or vtX (visually select till X).

gf

go to file – open the file under the cursor (useful for traversing file references inside codebases)

* (Shift-8) Takes you to the next occurrance of the word you’re currently looking at (often the best way to navigate to the definition of a method, if witin the same file)
Ctrl-6 Jumps you back to the previous file you were editing. I use this so often I remapped it to just the capital letter Z:
nnoremap <silent> Z <C-^>
Ctrl-]

Again, immensly useful for traversing codebases, this command relies on exuberant ctags (set up ctags) to take you to method and class definitions. I remap this to simply leader capital F:

nnoremap <silent> F <C-]>

I believe all highly used commands should be a single letter, as close as possible to home row.

mX
‘X

You can bookmark a file very quickly by using m plus any capital letter. Then to go back to the file at any time, hit and the same letter again.

The commands in this section are based on custom aliases. Please check that the alias doesn’t overload a key you’re used to.
K For super fast code navigation, nothing beats the git grep plugin combined with an alias to grep the Kurrent word under the cursor:

nnoremap <silent> K :GitGrep <cword><CR>

vv
ss
Splitting windows is a common and every day task, so you shouldn’t spend extra time typing to do so. Just double tap vv or ss:
nnoremap <silent> vv <C-w>v
nnoremap <silent> ss <C-w>s
Window navigation using J,K,I,M Bonus: A very common task for which the default key bindings involve way too many keystrokes. Use directional style keys to move between windows:
nnoremap <silent> H <C-w>h
nnoremap <silent> L <C-w>l
nnoremap <silent> I <C-w>k
nnoremap <silent> M <C-w>j

If you liked this post, you might want to watch my dotfiles repo on github. My dotfiles follow a keystroke minimizing principle where all common tools are only a few characters long, and are in the process of being cleaned up in order to release as a product targeting keystroke saving enthusiasts (this is especially important for those concerned with RSI prevention).


← Before After →