4 ms·
A few specific examples (| is cursor position): * You have a function call: `|foo("blah", blah)` and want `bar()`. You type `c%bar()`. The `c` command means 'r
by grayrest 16y ago
A few specific examples (| is cursor position):
* You have a function call: `|foo("blah", blah)` and want `bar()`. You type `c%bar()`. The `c` command means 'replace' while `%` searches forward for a matching character and jumps to the closing.
* You realize (after the fact) that you have a few more calls to foo. You type `/\<foo` and enter to jump to the next word in the file starting with foo and hit `.` to repeat the last edit. Then `n` to search for the next match and `.` again to repeat, etc. Since the vim command syntax is really expressive, repeat becomes a very powerful tool if you're doing it right.
* You have `my_dict['ab|cd']` and want `my_dict['efg']`. You type `ci'efg`. That's replace (c) inner (i) single-quoted string (') with efg. If you then wanted to change the single quotes to double quotes and had the surround.vim plugin, you type `cs'"`, which is replace (c) surrounding (s) single-quotes (') with double-quotes (").
* You have `fooTransformer(blah)` and want `barTransformer(blah)`, you type `ctTbar`, which is replace (c) 'till character (t) T with bar.
I've been deliberately using the replace command for these examples, but what makes the vim command syntax neat is that the command and the motion parts are orthogonal. So you could replace the `c` in any of the above examples with `d` to delete or with `y` to copy (yank) or with g% to rot13 or whatever.
It may seem like relatively small gains, but the most important thing is that I stay in the flow of the code. If I think "replace call" I type `c%`, which is only slightly slower and far faster than trying to ctrl+shift+arrow my way through the codebase.
The downside of Vim is that the learning curve is very, very long and is initially steep. Unless you're coding for a couple hours a day, it's honestly not worth it.
One tip that everybody eventually learns but is almost never metioned in beginner tutorials: Whenever you stop typing, go back to normal mode (use ctrl-[ or remap insert mode ctrl-j to Esc for more efficiency). This will eventually become automatic and will help you to avoid mode errors where you think you're in normal mode but you're actually in insert/replace mode.
- crazydiamond 16y agoI loved your my_dict tip: ci' - new to me. Thanks. Here's my favorite: http://rayninfo.co.uk/vimtips.html http://rayninfo.co.uk/vimtips.html