There have been multiple accounts created with the sole purpose of posting advertisement posts or replies containing unsolicited advertising.

Accounts which solely post advertisements, or persistently post them may be terminated.

fhein ,

I guess a few hours until I had memorised basic stuff like moving around, copy-paste, etc. Then maybe a week or two before I really felt comfortable with it. There’s some point where you actually understand vim and start using it more like a programming language and less like a traditional text editor. For example I love the “repeat last command” (default bound to . key), but to use it effectively you need to create a command that will be usable everywhere you want it to, and there are many different commands that do the same thing.

Here’s a random example:

Let’s say you have the following text in a document you’re editing with vim, and you want to delete the word “dance”. Vim is currently in normal mode, and with the cursor placed on the highlighted “c”:

Monkey dance party

If your brain is still in Notepad.exe mode, you might achieve this by pressing “i” to go into insert mode and using a combination of backspace and delete to edit the line.

A vim beginner might know that “x” and “X” in normal mode works like delete and backspace, without going to insert mode, so “XXXxx” does the same.

Someone who has learned basic movement could instead solve this by combining two commands, first “b” to move the cursor back to the beginning of the word, followed by “dw” (delete to next word).

But there’s also a single command that deletes the current word, regardless of where the cursor is in it, which is “daw”. And since this is a single command, you can repeat it with the “.” key to delete a different word.

Now here comes the vim magic: If you instead want to replace the word “dance” with “pool” you just modify the above commands by replacing “d” (delete) with “c” (change). So in our example you could type “caw” in normal mode, which deletes the word under the cursor and places you in insert mode. There you write “pool” and press Escape to go back to normal mode. Now you have a single command that replaces any word under the cursor with the word pool, which you can repeat anywhere you like.

And if it’s not just the current word you want to change, then replace the “w” in the command with something else, for example “ca)” will change a pair of parenthesis and everything inside them, which is very useful when programming C/C++/etc… And if you have nested parentheses and want do something with two levels at the same time, the command becomes “c2a)” which might look complicated, but it’s basically just simple rules that you string together.

vim-adventures.com might be a fun way to get started, then look up some nice vim cheat sheet and keep that nearby. I would also recommend looking up some example vim configs, because the editor is very bare bones with the defaults. I like relative line numbers for easy jumping between lines, so give that a try.

When you’ve mastered (?) vim you’ll also see less (the program) keyboard shortcuts make a lot more sense. You can also change your shell to vi mode for faster editing of commands.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • [email protected]
  • random
  • lifeLocal
  • goranko
  • All magazines