|
Which configurations are essential and are there any good sources for getting started with Vim? |
|
I would recommend learning a useful but minimal subset of commands: Opening/saving/exiting, undoing/redoing, basic movement and insert mode. I was going to recommend the tutorial I once read, but it is my impression that this tutorial is even better. My impression is that the strength of using Vim in particular is the structure of its commands in Normal mode. Vim has a large number of states it can be in: Normal mode (useful for navigating, manipulating and deleting text), Insert mode (useful for inserting), Command mode (useful for controlling things like windows and files) and Visual mode (useful for copying and deleting). It also has some other modes. (Sometimes, Normal mode and Command mode are confused. Command mode is the one with the colon.) In Normal mode, a command consists of a range and some action. The action could be deletion, and the range determines what needs to be deleted. Ranges can be specified in several ways: By a count, by a starting and an ending line number, or by a movement command. So the best way to learn to use Vim is to accept that one must not simply learn many commands, but instead combinators that can be put together. Examples: "dd" deletes the current line, "d2d" deletes the current line and the next line, "dG" deletes until the end of file, "dgg" deletes until the start of file, "d$" deletes until the end of line, "d2w" deletes the next two words. By learning the basic way to combine commands and learning a few new commands every day or week, it is not shameful to forget the ones that are rarely used. Vim has so many commands it is impossible to remember all of them, and so every Vim user will remember their own subset of commands. Once the basics are there, I recommend delving into the following topics: Searching/replacing by regular expressions (Vim's regexes are a little special, and not really in a good way), useful ways of going into Insert mode (e.g. by replacing: S, c), macros, and extensions. An example of what I might do inside Vim instead of using Perl or AWK: Transform the list
into
The command would be
This reveals that Vim regular expressions deviate from PCRE/Perl/what-you'd-expect in the following ways: Parentheses are escaped, the + quantifier is escaped, but the * quantifier isn't. Scarily, this may vary depending on the embarassingly named "magic" variable. In comment to the regexes, you can enable very magic mode, by including a As Simon says, start with the basics. They are confusing enough as it is. But remember always to learn, there is loads and loads of features. When you have mastered search and replace, moving on to more efficient moving around in your document is a good place to go for instance. |
|
You need to learn how to "speak vim" or even "program vim", and understand that when you use vim it's almost like a programming language. As Simon Shine mentions you combine "more powerful " commands from a bunch of basic ones. "Learn to speak vim – verbs, nouns, and modifiers!" - is a nice blog post that might help you with understanding this way of thinking of vim as a language. "Vim Text Objects: The Definitive Guide" goes a bit more deeper into understanding how vim treats text as objects and how you quickly can manipulate characters, words, sentences, paragraphs etc. When you have read through those blog, be sure to run through the vimtutor at least once to get a hang of the most basic commands. A basic vim installation is all nice and dandy, but it's a shame not to take advantage of some of the fantastic addons that exist for vim. vim-scripts.org is a great place to start. Using a addon manager of some sorts is recommended. I use vim-addon-manager because it offers a automatic download and installation of addons (from all sorts of revision control systems). If you seek inspiration on which addons to install check out Vimcasts for some nice videos showing off some addons and nice ways of configuring your vim. And last but not least the almighty cheatsheet for vim (set it as you wallpaper or something so you can refer to it quickly). (Ps. I'm really glad you've asked this question! I've been wanting to write a more thorough guide to using vim and configuring it into acting exactly as you want to - so stay tuned! I will update this space with more goodies soon!) |