What are the most-used vim commands/keypresses?

前端 未结 10 933
长发绾君心
长发绾君心 2020-12-22 14:22

I\'m a Ruby programming trying to switch from Textmate to MacVim, and I\'m having trouble wading through the gargantuan lists of things you can do in VIM and all of the keyp

10条回答
  •  囚心锁ツ
    2020-12-22 14:54

    tuxfiles.org holds a pretty good cheat sheet. I think there are a couple of points to learning the commands:

    • Read the cheat sheet regularly. Don't worry about using all of them, or remembering all the keys, just know that the command exists. Look up the command and use it when you find yourself doing something repetitive.
    • If you find yourself doing something regularly (like deleting an entire line after a particular character d$), go a quick google search to see if you can find a command for it.
    • Write down commands you think you'll find useful and keep that list where you can see it while you're writing your code. I would argue against printing something out and instead encourage you to use post it notes for just a few commands at a time.
    • If possible, watch other programmers use vim, and ask them what commands they are using as you see them do something interesting.

    Besides these tips, there are some basic concepts you should understand.

    • vim will use the same character to represent the same function. For example, to delete a line after a character use d$. To highlight a line after a particular character use v$. So notice that $ indicates you will be doing something to the end of the line from where your cursor currently is.
    • u is undo, and ctrl+r is redo.
    • putting a number in front of a command will execute it repeatedly. 3dd will delete the line your cursor is on and the two lines that follow, similarly 3yy will copy the line your cursor is on and the two lines that follow.
    • understand how to navigate through the buffers use :ls to list the buffers, and :bn, :bp to cycle through them.
    • read through the tutorial found in :help This is probably the best way to 'learn the ropes', and the rest of the commands you will learn through usage.

提交回复
热议问题