117

I've been using Vim for quite a long time, but I'm at a level where I use insert mode most of the time, and I still use the arrow keys to move around(!).

I feel like I'm not getting the best out of my lovely editor, particularly regarding navigating (especially code), copy & pasting, and doing other manipulations of existing code. (though I am quite comfortable with complicated search/replace patterns).

  • How should I go about learning more?
  • What resources would people recommend?
James
  • 22,556
  • 11
  • 75
  • 125
  • 8
    What's wrong with using the arrow keys for moving around? That's what they're **for**! – Vilx- Mar 14 '10 at 10:20
  • 40
    @Vilx, you don't move with arrow keys **even in computer action games**! Let alone text editors... – P Shved Mar 14 '10 at 10:23
  • 6
    @Vilx: The arrow keys on a keyboard are in a horribly inconvenient place for any kind navigation. That's why the canon in ViM is to use HJKL, just as you'd use WASD in a first person game. – Will Vousden Mar 14 '10 at 10:34
  • 4
    The WASD is there because it's easier to use it with left hand, since the right one controls the mouse. Left-handed people use the arrows. And HJKL is so counter-intuitive. Which one moves where? – Vilx- Mar 14 '10 at 12:31
  • When you type, both of your hands are on the keyboard and arrows are not inconvenient at all. – Vilx- Mar 14 '10 at 12:32
  • 8
    Well I think it's not about "arrows vs hjkl" as it is "cursor movement vs text objects". – Matteo Riva Mar 14 '10 at 12:36
  • 1
    This question has already been beaten to death, ressurected, shot, ressurected again and hanged. I can't believe it is still here after 3 hours. V for closing. – Rook Mar 14 '10 at 13:51
  • @Autopulated - I think you misunderstood. I wasn't attacking you personally, but all the others who vote for closing questions that have vague resemblance toward other questions, yet, when one like this, whose subject has been covered numerous times, they do nothing. The only thing I resent you, is the fact that you obviously didn't do a simplest of searches before asking, since in here, a subject of learning vim has been covered to no ends. Just putting "vim" in the search box gives me several related topics. – Rook Mar 14 '10 at 16:17
  • @Autopulated - p.s. Love the avatar :-))) – Rook Mar 14 '10 at 16:18
  • Check this out: http://kikuchiyo.org. It's a game that motivates you to learn the other 'jump' and 'teleport' movement keys ( or that's what the game calls them ) Good luck! :) – kikuchiyo Nov 19 '11 at 20:33
  • Do yourslef a favour: upgrade to Ultraedit http://www.ultraedit.com/, IMHO if your code is not worth spending few bucks for an excellent text editor, your code is probably worth nothing. – Marco Demaio Jan 30 '13 at 10:56
  • @Vilx- I'm several years late, but (1) arrow keys are *hugely* inconvenient for a fast (130WPM+) touch typer. Not as bad as moving to a mouse perhaps, but since the entire point of Vim is keyboard efficiency, it makes very little sense to do something which defeats that purpose (such as moving your entire hand to the other end of the keyboard and then having to find your way back again). (2) being counter-intuitive isn't important - that's only a problem in the very brief stage before you commit it to muscle memory. What is important is efficiency (see point 1). – JBentley Feb 23 '21 at 14:43

19 Answers19

79

"Why, oh WHY, do those #?@! nutheads use vi?" is a nice introduction to "the Vim way", especially about text objects which are one of the most defining features of Vim.

Nickolay
  • 28,261
  • 8
  • 94
  • 160
Matteo Riva
  • 23,656
  • 11
  • 69
  • 103
67

Here are some awesome screencasts that should give you an idea of what to learn next. There are also videos for intermediate and advanced topics, but the novice ones are in fact the most important.

Also, when I felt that I was stagnating and not really learning "the Vim way", I chose to disable arrow keys in both normal and insert mode. This forces you to use ESC to get somewhere, and makes you think more Vim-like. Ultimately, I enabled arrow keys again in insert mode, but I hardly ever use them. There is, most often, better ways to get around.

map <up> <nop>
map <down> <nop>
map <left> <nop>
map <right> <nop>

And especially

imap <up> <nop>
imap <down> <nop>
imap <left> <nop>
imap <right> <nop>
DarioP
  • 5,010
  • 1
  • 28
  • 48
Sarah
  • 6,374
  • 30
  • 44
  • 5
    I like the idea of disabling the arrow keys, it's a nice way to force yourself to stop using them. – Idan K Mar 14 '10 at 12:37
  • 1
    It worked very well for me, but the first few days were extremely frustrating. Once you get used to it though, and throw the habit of moving around TOO much in insert mode, I recommend reenabling the imaps. – Sarah Mar 14 '10 at 12:42
  • These screencasts were awesome. Thanks for pointing out. – Mert Nuhoglu Jun 14 '10 at 10:35
  • 2
    Disabling arrow keys is AWESOME idea, I'm doing it right now. – gorsky Oct 22 '10 at 18:58
  • Disabling the arrow keys is based on an assumption that arrow keys are more out of the way than hjkl. Better is to get a better keyboard. I use Kinesis Advantage. Even if I was using a standard keyboard, hjkl still makes no sense since I use dvorak. What I mean to say is: the point is not "don't use arrow keys", the point is "Use the most efficient means and don't shirk efficiency gains because of a learning curve." – lmat - Reinstate Monica Jun 04 '18 at 18:29
24
  1. type vimtutor on the command line
  2. go into vim, type :help or <F1>
  3. subscribe to mailing list
  4. official vim docs
ghostdog74
  • 286,686
  • 52
  • 238
  • 332
17

Two more tips:

  • Use Vim for editing everything (email, web forms, code, ...). When something feels slow, there is probably a quicker way to do it. :helpgrep is your friend.

  • Head over to http://vimgolf.com/ and compete. I've learned many tips and tricks that way. [Disclaimer: No responsibility is accepted for the long periods of time that "go missing" while competing at VimGolf].

Johnsyweb
  • 121,480
  • 23
  • 172
  • 229
  • 2
    Neat, I didn't know about vimgolf! – James Jun 05 '11 at 22:46
  • 1
    @Autopulated: Have added disclaimer. – Johnsyweb Jun 05 '11 at 23:04
  • 2
    @Johnsyweb: I really want to be able to use vim for everything-- but how? Getting a proper vim clone inside every web form would be ideal-- because all the browser add-ons I've found usually only implement a small random subset of vim features and re-map keybindings to accomodate for the fact that the browser still needs access to certain keymappings. – Conrad.Dean Nov 05 '11 at 15:33
13

An interesting article by Bram Moolenaar himself: Seven habits of effective text editing.

Paolo Tedesco
  • 49,782
  • 29
  • 130
  • 181
10

This is how I've learned Vim (and a bunch of other things). It's pretty easy.

Browse the help documents and find a command for something you do all the time. Delete a whole word for example. Make it a point to remember this.

Now, the next time you find yourself hitting 'xxxxx' to delete a word, stop, put it back and use the new command. Look it up if you have to. So instead of hitting 'xxxxxx' you go back and hit 'dw'.

Do this over and over, it'll be slow at first but eventually it will stick.

Once you have that command down start at the top. Find another command for an action you do all the time...

You would be surprised how fast you can pick up new commands and techniques this way.

Dennis Hostetler
  • 594
  • 6
  • 10
7

Remapping/disabling the arrow keys as has been suggested is a great way to force yourself not to use them.

Another thing to consider: if hitting Esc on your keyboard is at all uncomfortable you might wish to remap Caps Lock to Esc in your OS. For me this was a hugely helpful step, as Esc is an awkward reach on my KB and that was another obstacle that kept me in Insert mode (as it was hard to get out). Having Esc on Caps Lock makes it a tiny reach and jumping in and out of Insert mode is very fast.

For learning advanced stuff in Vim the best resource is the :help, but for getting the basics down you just need to do it; it's muscle memory more than anything. You say you know search. Consciously use it as a navigation tool. The searches [/, ?] and the inline char based searches [f, F, t, T] are some of the key Vim nav tools. Just use them; comboed with the disabled cursor keys you'll be navigating on muscle memory alone in no time.

Text Objects. Easily one of the best features of the editor. This is the other thing to immediately consciously practice. Things like 'yiw', 'dit', etc. are so powerful and fast; learning and making use of them alone will make you feel like a Vim user.

Once you've got text objects and basic navigation down, then it's time to move on to reading and learning from the :help regularly and scouring the web for awesome plugins. Seriously, you can use Vim for years and have an "ah ha!" moment accidentally stumbling on some obscure tidbit in the :help you'd never known.

numbers1311407
  • 31,870
  • 8
  • 84
  • 88
  • Instead of remapping to Caps Lock I would suggest Ctrl-C. This is easy to type and quite familiar to linux users . – BandGap Jan 13 '12 at 17:08
6

See this thread: What is your most productive shortcut with Vim?

Especially the first answer.

Community
  • 1
  • 1
Konrad Garus
  • 50,165
  • 42
  • 145
  • 220
  • 4
    As the author of the "first" answer I have to say, in all fairness, that it's not necessarily the best guide for generally improving your mastery of the editor. It covers lots of ground about what can be done with vi when you think of it as a language for expressing the ways that you want to manipulate the text, your screen/terminal and the environment of the editor itself. However, lots of the stuff in there is pretty advanced. – Jim Dennis Mar 14 '10 at 11:35
  • 1
    I have learn't so much from reading that answer that I don't think I would ever have learn't by reading documentation! – James Mar 14 '10 at 11:35
3

How should I go about learning more?

Read vim manual completely (type :h; you can browse from there). This is how you get to know all of the movements and commands. That's most useful if you already know the basics and want to improve.

What resources would people recommend?

vim.org, look through the most popular vim scripts. Check sources of them if you find something of interest. Or just install them and enjoy. That site comprises a lot of links to scripts that help browsing source code in different languages; and it is relatively easy to find them there.

StackOverflow.com also might be of help.

Community
  • 1
  • 1
P Shved
  • 87,005
  • 15
  • 114
  • 161
3

I made this game to help my nephew learn, but it only works on Firefox and Chrome >.< http://kikuchiyo.org

For now, it just deals with movement and entering insert mode. Beta version allows you to attack enemies with light-saber, 'i' to the left, and 'a' to the right :P

Keep trying to learn Vim, it's worth the effort!

:)

kikuchiyo
  • 3,231
  • 3
  • 21
  • 28
2

Learning the vi and vim editors.

Alex Budovski
  • 16,568
  • 6
  • 48
  • 57
2

I still use the arrow keys to move around(!).

I don't see a problem with this.

Frankly, what's the probability that you'll have to use vim and a keyboard that lacks arrow keys?

You know, most people use vim because it does the job (oh well, because they mastered it to a level when it does the job for them), not for being elitists (like not using the arrow keys).

A couple of advices for improving your vim knowledge:

  • periodically open the vim help at a random place and read about a random distinct feature. It will take you a couple of minutes. It's possible that you won't use this feature during next X years. But if you are lucky, you'll be in a situation when you'll see that you can apply your knowledge about that feature to achieve a certain task. You'll open the help again to refresh your memory. After using the feature in practice for a couple of times, it'll stick. At this point your vim knowledge will be improved.
  • use :helpgrep to dig into random places of documentation. If you need to do something and you find the place that explains it in the docs, don't stop there. Read the doc snippet one more time. Find the keywords. For each keyword, use :helpgrep keyword to discover the logical links with other parts of the vim documentation.
Alex_coder
  • 1,980
  • 2
  • 16
  • 15
  • I guess the problem I have with just reading documentation is that I find I don't learn things very effectively without actually *doing* them. – James Mar 14 '10 at 11:39
  • 1
    Using cursor keys to move your cursor for short distances can be just as efficient as using the [h], [j], [k], [l] keys ... if your fingers happen to be near them for some other reason. Using any linear cursor movements is horrid for more than a few columns or lines of movement. Usually it's best to think about what you're looking for and express that directly in vi using the / or ? commands and regular expressions. Last bit of text near foo? G?foo[Enter] (six keystrokes). First line with "bar ... something .. bang in it? 1G/bar.*bang[Enter] (about a dozen keystrokes) ... and so on. – Jim Dennis Mar 14 '10 at 11:40
  • Though arrow-keys are probably more efficient than reaching for the mouse, if you type by using the home-row keys to regroup your hands after typing in a sequence of characters, then there is no movement required to enter one of the basic movement keys of 'j', 'k', 'l', and a slight leftward 'twitch' to get the the 'h' key. If you do things the Vim way your hands should always be be closer to the home-row keys than to the arrow-keys. Keep practicing and you'll get it. :) – kikuchiyo Nov 19 '11 at 20:56
2

I take a look at this list of Best of VIM Tips every now and then and I still pick up new tricks on a regular basis.

Brian Rasmussen
  • 109,816
  • 33
  • 208
  • 305
2

the way I stopped using the arrow keys was not disabling them (I still use them in Insert mode) but if you think about it if you want to go right use your pinky finger which is the l key, go left Index finger the h key, & ring finger up ("ring up") the k key & "pick down" the j key.

So first of the four digits on your hand (forget about the thumb) the Index one is leftmost & the Pinky is rightmost. Use the expression "ring up" as in telephone call for up with your ring finger & the middle finger has nowhere else to go but down.

It also helps a lot I found to forget about what the keys are named (h, j, k, l). There isn't a good mnemonic for remembering them that way that I've found & there's not too many mappings using those keys either.

phildobbin
  • 774
  • 7
  • 9
1

I think videos are very helpful in learning.

  1. Derek Wyatt's on vimeo
  2. vimcasts
Rob W
  • 315,396
  • 71
  • 752
  • 644
SergioAraujo
  • 8,735
  • 1
  • 46
  • 37
0

1- read this

2- if you use a rss reader subscribe to these pages

page 1

page 2

aliva
  • 4,364
  • 1
  • 28
  • 43
0

http://www.vi-improved.org/tutorial.php <-- you should read and flowing this chat, it's very useful for beginner. Happy vimmer

James
  • 11
  • 1