5 ms·
I used to get stuck in vim when logging in to linux servers. The key things to know for any newbie... :q i ESC :w After I learned those, I've really come t
by sudonim 16y ago
I used to get stuck in vim when logging in to linux servers. The key things to know for any newbie...
:q
i
ESC
:w
After I learned those, I've really come to love Vim. I imagine I'd need to learn about 50 more commands before I could be really well versed. What are some other important things to know?
- bradleyland 16y agoLearning to exit, insert, and save the file is about as minimal a text editor skill set I can imagine. You should definitely start out by running through vimtutor a few times. The vim help is also really good. The author also provides a good list of links at the bottom of the article.
- Dobbs 16y agohjkl for moving around. I and A insert beginning/end of line. 0 and $ go to the beginning/end of line without entering insert mode. :%!command -- Runs the entire document through the command. If you use visual mode and then press ':!command' and it will run the selection through the command specified. Super useful for sorting a list. Also ctrl+[ is equivalent to esc. If you rebind caps to ctrl you can easily hit escape and other commands like ^d, ^u (page down and up).
- dhimes 16y ago0 and $ go to the beginning/end of line without entering insert mode You might find ^ more useful than 0 for indented code as it takes you to the beginning of the text on the line (like the regexp).
- dfischer 16y agoGreat tip! I will be using this one.
- burgerbrain 16y agoIf your aim is to indent/de-indent text, try the > and < commands (in normal mode). I also find that selecting large blocks of text then using the = command to autoindent everything is exceedingly useful.
- dhimes 16y agodo you know how to highlight a block then double-indent? I can't make that work. With a block highlighted, I only know how to indent one ts at a time (then re-hightlight, etc.).
- pyre 16y ago> Super useful for sorting a list. Unless you have some special script/filter for specific sorting of lists, then why not just use ':sort' instead of ':!sort' (i.e. the Vim sort command, rather than piping it to /usr/bin/sort)?
- silentbicycle 16y agoWhy should vim have :sort built-in, when /usr/bin/sort already does it so well? If you really want to get on a roll with vi, think of all the other cases where you wish it could do something, then make it work with :%!command_written_in_any_language_you_want . You can also apply it to ranges. "%1,5!rev" reverses lines 1-5, etc.
- bsergean 16y ago:sort will work on Windows too.
- pyre 16y agoI never said that '%!command' was a bad thing. I was just pointing out that that particular use-case was already built into the editor. We could make pedantic arguments about Unix all day long (e.g. "Each command should do something specific and do it well, Vim doesn't need the :sort built-in" vs "Why should I incur the cost of starting up another process and having it eat up my precious memory space?") but it's relatively useless. Being able to pipe through commands is a powerful tool, but using an example where the external command already has a built-in equivalent seems possibly confusing to the (novice Vim'er) reader (please don't rattle me off the laundry list of options that /usr/bin/sort has that :sort doesn't because you'd be missing the point). That said... On the topic of ranges, never give :bd! a range unless you know what you're doing. I ran :bd! once while I had a number of lines selected in visual mode because I though that the selected lines wouldn't affect :bd. Bad idea. The '<,>' part of the range apparently is converted to line numbers (e.g. '3,6') and then :bd reads that range as the buffers to delete. So when you select lines 1-8 and then hit :bd! it goes something like this: :<,>bd! -> :1,8bd! -> delete buffers 1-8 without prompting for unsaved changes Oops!
- gurraman 16y agoI started writing the basic commands in a comment, but it got kind of long. You'd best look at a reference. http://tnerual.eriogerg.free.fr/vimqrc.html http://tnerual.eriogerg.free.fr/vimqrc.html http://www.pixelbeat.org/vim.tips.html http://www.pixelbeat.org/vim.tips.html http://www.rayninfo.co.uk/vimtips.html http://www.rayninfo.co.uk/vimtips.html I'd start with looking at commands that allow you to quickly move around in buffers first (/, f, t, w, e, b etc). Then start combining those with actions (ct", dw etc). Then "timesavers" such as macros and built-in conveniences (q, gqq, marks etc). The rest will come to you.
- wyclif 16y agoPython and vim: Two great tastes that go together (slides): http://www.tummy.com/Community/Presentations/vimpython-20070225/vim.html http://www.tummy.com/Community/Presentations/vimpython-20070...
- sudonim 16y agoThanks. Learning keyboard controls can be daunting. Your advice on where to start is much appreciated.
- hiteshiitk 16y agoJust print this http://www.viemu.com/vi-vim-cheat-sheet.gif http://www.viemu.com/vi-vim-cheat-sheet.gif out and stick it to your side board.
- 5teev 16y agoOne thing I do all the time is making macros on the fly for repetitive edits with :map. E.g., switch the current and next line :map * ddp Then type * in command mode to execute the steps. And if you mangle your file beyond hope with out of control macros, there's always u to undo and :q! to quit without saving.
- crazydiamond 16y agoAre you not aware that '*' (asterisk) searches for the next occurrence of the word under the cursor. That's one key i just can't live without. '#' (hash) does the reverse. Why not do a 'qq' to record your macro as 'q' and @q to replay it.
- 5teev 16y agoIt was an arbitrary choice for an example. Obviously one would choose a key not being used for anything else. (This choice can also vary from session to session, depending on the task at hand.)
- eeperson 16y agoProbably the most useful commands that aren't mentioned in most tutorials are: ctrl-[ can be used in place of ESC . repeats the last edit
- rbonvall 16y agoWhen you are experimenting, u (undo) and Ctrl+R (redo) are invaluable.