Live data from Hacker News

Ask HN: Power of VIM?

news.ycombinator.com

11–20 of 21 posts

Re: Ask HN: Power of VIM?

#11
It's easy to tell you why: powerful and precise text manipulation through concise commands. It's difficult to make you value that until you've tried it.

Vim will increase your productivity by allowing you to manipulate large or small pieces of text at will, in ways you've probably not thought of, while your hands rarely leave their position of hovering over the home row. The arrow keys work, but you'll rarely use them. You'll be fast, not from fast typing but from less typing.

Once you've become reasonably proficient with vim, the difference between arrow key-based editors and vim begins to feel like the difference between chisels on stone and telekinesis.

It's easy to become minimally proficient. After you've installed gvim, run it and run these two commands:

[ESC]:help

[ESC]:help tutor

You should know about the first command, but the second is more important for you right now. It shows you how to start the interactive vim tutorial on your system, which will teach you just enough to use vim better than you can use Notepad++. Follow the tutorial, it won't take long and you don't have to do it all at once.

Now use vim whenever you edit a text file. You'll be a little slower than Notepad at first (but not much). You'll quickly gain speed.

The vim screencasts mentioned elsewhere in the comments are good for people learning vim, but I don't think they're a great advertisement for vim. The best thing for you is to run the tutorial.

Note: everything said here goes for emacs as well. It's a personal choice, and most people are either a vim person or an emacs person. I've never liked the chord-like commands of emacs, but emacs has more integration with the world outside of text editing and compiling than vim. Whichever type of person you turn out to be, you should be using one of these instead of Notepad.

Note note: I like vim so much that I've installed a firefox addon that lets me quickly edit web page text fields (like this one) with vim. https://addons.mozilla.org/en-US/firefox/addon/4125

Re: Ask HN: Power of VIM?

#12
For me, one of the reasons of getting into basic vim usage was that it was the only editor I could count on always being available on the machines I was administrating. I learned just enough to be able to edit files with vi when necessary and did the heavy lifting in emacs.

Just a week or so ago, I decided to try to see if I could switch over to vi for all my editing needs. I know people who really know vi are wicked fast at doing stuff in it, none of the additional functionality in emacs is really something that I'm using, and none of the GUI-based editors I've used have really done anything to convince me they're worth the extra hassle. Plus, I know it's available on all platforms I could conceivably need that sort of text editing, so I know my skills will be usable wherever the file might be.

Re: Ask HN: Power of VIM?

#15
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 `/\* 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.

Re: Ask HN: Power of VIM?

#17

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 `/\ * You have `my_dict['ab|cd']` and want `my_dict['efg']`. You type `ci'efg`. That's replace (…

I loved your my_dict tip: ci' - new to me. Thanks.

Here's my favorite: http://rayninfo.co.uk/vimtips.html

Re: Ask HN: Power of VIM?

#18
I wish vim would provide a kill-ring like emacs. I was recently writing an editor for an app of mine on the terminal. To enhance the keyboard usability - I read up on and implemented (among others) the kill-ring, it was easy to do, and really makes work easier than having to use registers. (kill-ring is for copying and yanking, multiple yanks go into the ring, and the values can be cycled through).

Re: Ask HN: Power of VIM?

#19
If You are coming from the Windows world and use Notepad++ you are definitely on the right track to find a good text editor. I know since I have make that same path long time ago.

Now on all my systems that are mostly Linux (Ubuntu) and Windows I use Vim (vim & GVim).

I like to have powerful editor in all situations on all machines that I work and vim is that first.

The greatest feature is that hands are on keyboard all the time and as You learn the vim features You get amazed all the time and get more productive in every iteration.

The learning curve is easy and the most surprising at first is switching vim modes. That is adopted very fast and all that follows is fun and enjoinment.

Naturally all depends on Your affinity and if You spend lot of time in text editor dealing with different formats of text (HTML, xml, CSS, js, C#, Ruby, Php, C++, java, ...) You should invest some time learn to have real power on Your fingertips.

Re: Ask HN: Power of VIM?

#20
post #8
post #3

Someone steal this idea: A site with screencasts of people writing software in the editor of their choice. Let people browse videos by editor, programming language, whatever else.

There is a great collection of Vim screencasts at: http://vimcasts.org/ Peeepcode has a "Meet Emacs" screencast available for about $9 as well here: https://peepcode.com/products/meet-emacs It's not quite the site you describe, but I've learned quite a bit watching Vimcasts.

I'll second the support for vimcasts.org.

Also, PeepCode released "Smash Into VIM" yesterday: http://peepcode.com/products/smash-into-vim-i

Post reply on HN