Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Alternatively, don't try to hurry enlightenment.

First, learn

    :q!
Next

    h,j,k,l
Then

    i and ESC
Finally

    :w
Now you know vim. Don't let people tell you you're using too many keystrokes. Are you still reaching for the mouse? If not, you're using vim just fine.

Most of the good stuff in vim, you'll learn accidentally, because you're in normal mode when you think you're in insert mode, or because you have caps lock on in normal mode and you don't realize it. Pay attention to the bizarre behavior that results and you'll learn useful tricks. Mode confusion is a feature, not a bug.

For the rest, there are certain topics that reward study and are unlikely to present themselves to you accidentally, but there's no hurry unless you're feeling the pain of not knowing them. I recommend:

1. Visual selection mode

2. Prefixing counts to commands

3. Search and replace with regular expressions

4. Advanced cursor movements

Lastly, if you're using gvim, do

    :set guioptions=
at the beginning of every session. Those GUI elements will tempt you to use the mouse, when that's almost never an appropriate thing to do.

Edit: learning to use x and d early on is probably also a good idea, if like me you're the kind of person who makes mistakes.



Sorry, but I think that's really bad advice.

For one thing, it doesn't give new users any positive experience or reason to learn vim. If all you learn is to do things that are "pointless" (like learning hjkl), then you won't get any value out of vim. And if your way of learning is to do something that screws up your file and try to recreate how that happened, well, let's just say that every time I do something that screws up my file I'm in the middle of working, and the last thing I want is to stop and fix some random problem.

I usually recommend people try to get into vim easily, then learn the GOOD things. I.e. I think it's perfectly fine that people start with arrow keys, much as I love hjkl. But to get value out of vim, you should really learn "f" and "t", and text objects, then how they compose with "c" and "d". That is the reason I started loving vim myself - that's when I saw that it gives me something that other editors didn't give me, adn that encouraged me to explore further.


I have been using Vim for 15 years now and I completely agree with sevensor's comment.

- Vim is not newbie-friendly regardless of whether you remove guioptions or not. One has to spend at least a few hours of study and practice to get comfortable with Vim. If one is forced to invest a few hours to learn an editor, one might as well get rid of guioptions and follow other advice provided in sevensor's comment.

- Learning hjkl is not really pointless. hjkl and other motion commands makes Vim a unique and ergonomically a very superior experience. If one does not want to spend time learning hjkl and other motion keys, then one might as well skip learning Vim and pickup Emacs, Sublime Text or another capable editor.


You might be right. It's true that vim has a learning curve one way or another.

On the other hand, if I want to show someone the "good parts" of vim, I try to show them something they can't do in another editor, rather than something that they can do (arrow keys). Even if I 100% agree that arrow keys are a worse experience, it's just not as convincing as something that can't be done outside of vim.

At least in my experience.


Yeah, but that's a good way to sell vim. Once you've shown someone vim and whet their appetite, it's probably best to show them about 2 or 3 features and let them fill in the blanks while being at least minimally productive.

I've recently taken this approach to emacs and org-mode. I'm a long-time vim user with a super-optimized vimrc, so I know what productivity feels like. I threw in spacemacs to reduce the learning curve, but I still was initially much less productive with org-mode and emacs than with markdown and vim for my TODO lists.

Now, after using org and emacs for three weeks, I'm at the point where several of the amazing features that I had heard about are in my bag of tricks, and it feels awesome! But I've barely tweaked my .spacemacs file, have only learned a bit of org, and am sure that I am nowhere near peak comfort/productivity/flow. But if I had tried to learn all of the things that I know are cool about org-mode, emacs, and spacemacs all at once, I wouldn't have gotten any work done over the past few weeks, and honestly I probably would have given up.

TL;DR: the fancy stuff is the best marketing, but it's best to start slow.


Hmm, I've just decided to start slowly learning vim by adding some vim-like functionality to my browsers.


The best way to impress someone with vim is to do "shift+o" and "o"


I agree. I didn't really learn vim (and subsequently learn to love it) until I disabled the arrow keys in my .vimrc file, which forced me to learn hjkl.


I think we just don't agree about what the good parts of vim are. I find f and t to be a minute improvement over forward search. I think hjkl is strictly better than arrow keys, because you don't have to move your fingers from the home row to navigate a file, and I think the basic editing commands I outlined are sufficient for a superior editing experience within a day of learning them, no deep study required.


Forward search is probably my most used vim feature. /LOCATION<enter>c/NEXT_LOCATION<enter> and you can be in insert mode changing the content. The only thing you need to think about is the content you want to change. You don't think about how to get there, you don't think about how many times you need to hit arrow while holding down shift-alt, or the fact that it will always jump one too far and you'll need to shift-leftarrow back one.


Let me clarify, I absolutely love hjkl, and couldn't live without it (seriously - I built scripts just so the computer will always have hjkl as arrow keys, and many other vim goodies).

I just feel like it's a thing that people don't realize will help until they internalize it. Whereas almost everyone I show the text objects to immediately realizes their utility. I'm only looking at this from a pedagogical perspective.


i'm sure it becomes intuitive with lots of use, bit i find it awkward with having to move my finger off the home keys to move left. somehow for me, its even more confusing that way. where as my arrow keys are completely intuitive, one finger for the left and right keys and the middle finger handles up down. to me its not a big deal to remove my fingers from the home row if i already have to move from the home keys.


So I've been thinking about this and your other responses in this thread, and I think I've figured out where our viewpoints differ, fundamentally. I think many people, yourself included, want to do more with an editor. That's your motivation for using vim, and so you pursue customization, advanced features, and relentlessly minimize keystrokes. (That's a plural you, by the way. I'm speaking to everyone advocating a bells-and-whistles approach to learning vim.) I want to emphasize that there's nothing wrong with this -- it's a perfectly valid frame of mind, but it's just not my frame of mind. In contrast, I want to think less about my editor. That is, I want editing text to be as automatic as touch-typing. I want for there to be as little friction between my mind and the screen as possible, so I don't want to learn new things about my editor any faster than I can incorporate them into the set of things I can do without thinking about them. As a result, I'm sure there are people who've been using vim for two weeks who know more features than I do after 20 years.

Anyhow, I'd be really interested to know if you agree with this characterization of your outlook.


A lot of people learn vi out of necessity. Eventually, they have to SSH into a server and have to make minor changes to files where it's quicker to do it right there rather than use FTP or VCS. If that's the case, all you really need to know are the basics that the OP mentioned. After that, it's up to the person's personality to decide if there is value in learning further and more complicated commands.


> Sorry, but I think that's really bad advice [...] If all you learn is to do things that are "pointless" (like learning hjkl),

I agree. For navigation I rather use f, w, e, {,}, ctrl-l, ctrl-u, /, o. I think hjkl are overrated.


hjkl are the minimum keys needed to be able to move anywhere in vi[m], they're certainly not pointless.


Vim supports the cursor keys, even in insert mode.

Assuming the new Vim user already knows how those work, telling them that they instead need to go `Esc -> hjkl -> i` and ending things there... that's going to leave them worse off in Vim than saying nothing.


I always recommend 'Your problem with Vim is that you don't grok vi.' to new users starting out in vim [0]. You can never learn about the language of vim too early.

[0] https://stackoverflow.com/a/1220118/2131903


That's a very informative link -- I can see how that might be helpful context for a new user. It's hard for me to get into that mental frame, since my first text editor was edlin for DOS. I'll stick by my recommendation to type first and study later, however. Experience is a powerful teacher.


Thank you for that link. I appreciate that he chose to intersperse the history of commands (such as grep!) within his explanation.


That was enlightening. Thanks for sharing!


`vimtutor` is where most people should start. It's bundled with every vim installation. Vimtutor teaches the absolute basics in an interactive manner so you'll remember the lessons.


I like the "Learn Vim Progressively" guide. It starts with just a few commands, and introduces new ones in small batches when you feel comfortable with the ones you're using.

http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressiv...

I'd add windows to your list of things to take a look at once you feel comfortable with the editor. You can split your workspace with ctrl+w followed by 'v' (vertical) or 's' (split). Then you can switch between those panes by pressing ctrl+w twice, or ctrl+w followed by hjkl or an arrow key. You can also resize the windows and stuff, it's great for things like viewing a header and source file at the same time.


I feel like window management is a good way to introduce vimscript as well. Lets you tweak some of the features like having the windows open on the right instead of left or getting rid of the w so it's just ctrl+{hjkl}.


I learned vi 20 years ago now, and vim a year or three later. In all that time, I've never seen the point to vimscript. If you want a heavily customized, scriptable editor, why just not use emacs? Vi works the way it works.


I missed my chance of learning vim properly and I never internalized h I j k. After trying a few episodes of forcing myself to use h I j k miserably, I question that wisdom. The fact is I never find arrow keys a hindrance, probably when I navigate with arrow keys, I am always unclear of my editing goals and I can use some slowdown thinking anyway


I'd argue that text objects are by far the biggest advantage vim has over other editing models. From my experience they are pretty easy to learn for programmers.


> i and ESC

I think i and Ctrl+[ is better? It's more in line with the idea of keeping your hands near home row.


It's a fair point. I learned ESC long years before ^[ and it's stuck in my muscle memory. But a new user might benefit from using ^[ instead. Some keyboards put F1 where ESC belongs, and my habit has been to remap F1 to NOP because help is so annoying, but maybe I should remap ESC to help. That would get me to switch over in short order.


I've remapped capslock to ESC. I can't remember ever wanting to use capslock mode since I first learned to touch type. Much easier to have Esc there. Or Backspace, Home, End, or delete are also good options.


Like sibling, I also mapped capslock to control. I use ^[ instead of ESC and there are other control-<whatever> shortcuts that are extremely useful, so it gets more utility than ESC would.

Of course, then I bought a kinesis advantage2 keyboard and now suddenly every key is easy to press, even the cursor keys.


I mapped capslock to Control and use Control-c instead of escape. It's much easier on my pinky.


>learning to use x and d early on is probably also a good idea, if like me you're the kind of person who makes mistakes

Same with using 's'. Super handy when you accidentally type the wrong character.


I work at a company where we pair on everything. The feature that generally converts people is keyboard macros, after I use them to automatically perform some tedious code transformation.


I came to the comments after a bit of the tutorial to write something along the same lines but less eloquently. I absolutely agree, too much too fast.

My hackles were raised when it starts with "ESC" to enter normal mode and "i" for insert mode. Rather than "i" for insert mode and "ESC" to get out of insert mode. Also, I used the arrow keys to move around in vim for ages before I disabled them.


totally agreed. the best way to learn vim is slowly. teach your self one thing a day and use it all day. if you keep using it great, if not move on to the next thing. otherwise you get brain overload and someone is trying to teach you how THEY use vim and you don't create your own style.


If you are relying on accidentally f'ing things up then u and ctrl-r are essential too.

u is my favourite!


If you mess up the whole undo/redo sequence by typing inbetween, :earlier and :later are nice to know about too.


Oh wow. Thanks for those. I completely forgot those were things.


As a heavy vim user for 15~ years I don't find h,j,k,l useful and for new users that may be one of the most confusing / alien changes.


I still find them useful, but they're just another navigation tool as opposed to the main navigational commands a newcomer might use them as. There are frequently situations where I can easily move next to the character I want to operate on and adjust the position with h or l.


Agreed, though arguably you need to tell newbs that in order to quit, they must type <Esc>:q!, not just :q!


"Mode confusion is a feature, not a bug." Just one reason why vim is the most overrated POS of all time.


> Mode confusion is a feature, not a bug.

Then you realize that insert mode is the least useful mode there is.




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

Search: