8 ms·
Use Vim Like A Pro
- crazydiamond 16y agoIf you program, please try SnipMate.vim. There are plenty more very helpful plugins, but this one is great and is programmable. And don't forget pathogen.vim. Yankring, command-T or fuzzyfinder, surround, repeat, align, ack and fugitive are others i recommend.
- symkat 16y agoPet peeve: Vim should be spelled "Vim," not "VIM."(1) Consistency in case would also make it easier to read in my opinion, Vim/VIM seem to be used interchangeably throughout the article.(2) Other than that, this is a good crash course. =) 1 See spelling in use at http://www.vim.org/about.php http://www.vim.org/about.php 2 "Vim has a small footprint in RAM and on the CPU. A given system can support a great many VIM users at once."
- mahmud 16y agoI don't think executable size makes a huge difference for this type of application. All static sections of a given binary is shared among all users; code, globals, and shared libraries. Even the non-static parts are copied on write.
- rexyo 16y agoThats exactly what I like about Vim.. Small footprint is really great on an multi user environment or when editing or viewing large files like logfiles. I was used to editing files over ssh with Vi, but after they improved;) I was hooked on Vim forever. Vim really is an absolute a must-have skill in your toolbox.
- thomie 16y agoHow do I contact the other of this piece? "Yank from the current character to the end of the line into register y" should be: "yy$ instead of "y$
- telemachos 16y agoThe author is Tim Ottinger. You can find him on Twitter[1] for example, pretty easily. [1] http://twitter.com/#!/tottinge http://twitter.com/#!/tottinge
- pyre 16y agoI always remap 'Y' to 'yank to end of line.' I mean, 'D' is 'Delete/cut to end of line,' why not have to same thing for yank?
- brianto2010 16y agoAwesome! I learned about zt, zb, zz, ^x ^f, and ^x ^i today. They'll definitely come in handy.
- Nervetattoo 16y agoIts amazing that after having read probably hundreds of Vim tutorials / guides every user is able to learn something completely new from every one of them. It sure scales. This one brought ^T and ^D for indenting in insert mode to me, and starting with -o/O as argument for opening multiple files in splits.
- zmmz 16y agoOne of the best resources for learning more about vim is the various .vimrc files on github A simple http://github.com/search?&q=vimrc http://github.com/search?&q=vimrc is a goldmine for mastery.
- limedaring 16y agoI learned cw, and it blew my mind.
- wonderzombie 16y agoYou should give ci' or ci( or ci[ or ci" a try. (You could also use ci) or ci] if you prefer.) Do it on a line where there is a pair of quotes, parens, brackets, etc.
- telemachos 16y agoAlso cit/cat in HTML.
- throw_away 16y agoalso, ciw which I use far more often than cw (don't need to be on beginning of word to change the whole thing). I like how all the ci commands always elicit a "whoa, what did you just do?" from people watching me edit.
- ivanzhao 16y agoVim is ancient yet its idea can be quite advanced: we have 10 fingers so why not use as many of them as possible? It's like a puppet master wiring her fingers to fully express herself through the puppet. In the case of programming, Vim is the wire and the puppet is the code.
- yuvadm 16y agospectacular. now where's 'use emacs like a pro'?
- symkat 16y agoemacs has a text editor too? I always just used it as an irc client... (http://delysid.org/emacs/erc.html http://delysid.org/emacs/erc.html) http://www.emacswiki.org/emacs/EmacsCrashCourse http://www.emacswiki.org/emacs/EmacsCrashCourse is fairly good for a quick introduction to similar ways of doing things in emacs. =)
- SkyMarshal 16y agoAn IRC client? Funny, I thought it was personal organizer.
- jrockway 16y agoEmacs is self-documenting, so you only need two things to use Emacs like a pro -- Emacs, and your brain. The first thing a new Emacs user should do is to peruse the Emacs manual. You won't remember every detail, of course, but you should at least have a basic idea of what sorts of operations are available. Then, start editing text. When you do something that seems tedious, you're doing it wrong. Try to remember back to the section of the manual that has something to do with what you were doing. Then read that section. Now try to redo the operation, but "the Emacs way" instead of the tedious way you invented yourself. Do this several times a day. Now you're an expert.
- wonderzombie 16y agoI might've found this out through HN, in which case this'll be redundant. Still, I'll risk it: http://vimcasts.org/ http://vimcasts.org/ is a good resource. This fellow puts up bite-sized, five minute screencasts of various Vim-related features. Some of the 'casts are more advanced, and some of them are pretty basic.
- klochner 16y agoI recently switched to vim (macvim), and one thing bugs me that maybe someone knows a fix for . . . The padding between the left edge of the window (or the right edge of the line numbers) and the interior text it ~0. I'd like just a little padding. anyone?
- gurraman 16y ago:help numberwidth
- gurraman 16y agoAh, I was too quick to reply. Sorry. I do not know if it's possible to do what you want. I find that a slight variation in background color (:highlight LineNr) helps in distinguishing the numbers from the content.
- klochner 16y agoIt may be macvim specific, vim doesn't look as bad. I can distinguish text from line numbers, but it bugs me that they touch. I posted to superuser with an image to give you an idea of what I'm talking about: http://superuser.com/questions/205553/how-can-i-add-some-padding-to-the-macvim-text-area http://superuser.com/questions/205553/how-can-i-add-some-pad...
- hesitz 16y agoYou can make use of the foldcolumn. The fold column is an optionally visible column that can be put between line numbers and text. It is generally used to show markers to indicate level of folding, if any. If you want to use it to create separation between line numbers and text, but don't want to see the folding markers, just set the foreground color of the fold column to be same as the background color. So something like this: :set foldcolumn=3 (or 4 or 5 or what4ever. . . ) :hi FoldColumn guifg=black guibg=black That should do it.
- davnola 16y agoIf you enjoyed this, you should definitely check out http://http://vimcasts.org http://http://vimcasts.org. I caught Drew's talk at Arrrrcamp on Friday and he is a fantastic explicator. His Vim book for PragProg should be excellent.
- hippich 16y agohttp://vimcasts.org http://vimcasts.org And thanx for great site!
- gfodor 16y agoAnother important vim tip for me that wasn't in there and might be one for the author himself: you can use ctrl-C or ctrl-[ instead of ESC to exit insert mode. This, combined with re-mapping capslock to control, is a big, big win.
- rue 16y agoI have mapped hh (jj on a QWERTY) to ESC.
- atuladhar 16y agoThank you!
- viraptor 16y agoYou can remap ESC to whatever you need. I prefer CTRL+s == ESC: inoremap <C-s> <ESC> vnoremap <C-s> <ESC>
- klochner 16y agoIt's also common to remap ii to exit insert mode, that way "i" puts you in, "ii" takes you out. Personally, I remapped caps lock to esc, because I don't like the way the editor lags when typing an "i" after "ii" has been remapped, but Caps-->Ctrl has the additional benefit of making other Ctrl-Foo sequences easy.
- pyre 16y ago> Personally, I remapped caps lock to esc, because I don't like the > way the editor lags when typing an "i" after "ii" That's the problem with mapping non-Ctrl/Alt sequences in Insert mode. Even thing like bindings that automatically insert a closing } (with auto-indent) when you type the opening { are really annoying because they are commonly bound to the sequence "{<Enter>". So when you type { without <Enter> there is a delay while it waits to see if you're going to hit <Enter>.
- stuhacking 16y agoHow would one insert the string 'ascii'?
- adimitrov 16y agoThere's a myriad of vim-tutorials around the Net, but I find that people usually tend to forget that vim has a built-in tutorial. Of all the ones I've found, this is really one of the best. Most importantly, it's interactive, and I'm a 'learning-by-doing' person. Just type `vimtutor` at the command prompt (also `gvimtutor`.) Not to diminish on the author's efforts. The tutorial he wrote taught me about vim's capabilities in directory mode — I would usually just quit every time I accidentally ended up in it.
- lmx 16y agoAnother Vim tip: plugins can be amazingly useful. The NERD Tree plugin gives you a directory tree that lets you easily move between files and do filesystem operations. http://www.vim.org/scripts/script.php?script_id=1658 http://www.vim.org/scripts/script.php?script_id=1658
- micaelwidell 16y agoTextMate is getting older and older. I would like to try something else, but I haven't yet found another editor with a sane file/folder sidebar, which is a must for me. Any tips? The sidebars I've seen for emacs and vim either look lika crap or use too big a font for them to be practical.
- klochner 16y agoNerdTree
- SkyMarshal 16y agoCheck out Command-T also. Good discussion here: http://news.ycombinator.com/item?id=1688500 http://news.ycombinator.com/item?id=1688500
- ed 16y agoIf you're learning Vim, I highly recommend installing Vimium for Chrome. It's an amazing plugin that brings Vim-like keyboard mappings to the browser, making it significantly easier to build muscle memory. http://vimium.github.com/ http://vimium.github.com/
- kgroll 16y agoOr for Firefox - vimperator. http://vimperator.org/vimperator http://vimperator.org/vimperator
- scottjackson 16y agoSafari - vim. http://github.com/mutle/vim.safariextension http://github.com/mutle/vim.safariextension Only a few keybindings, but I only really use it for the j/k page navigation. (Note: it does get overwritten by pages with their own keyboard navigation (flickr, tumblr's dashboard, ffffound, etc.))
- room606 16y agoOr Pentadactyl - an improved fork of vimperator by it's most active developers. Probably the only thing keeping me from using Chrome as my main browser http://dactyl.sourceforge.net/pentadactyl/ http://dactyl.sourceforge.net/pentadactyl/
- ElbertF 16y agoOr Pentadactyl, a Vimperator fork: http://dactyl.sourceforge.net/pentadactyl/ http://dactyl.sourceforge.net/pentadactyl/
- jordinl 16y agoI'm trying it but I don't find the way to enter insert mode... :i, doesn't work, am I missing something?
- brianobush 16y agoI use emacs daily, but enjoy vi(m) on the side occasionally. Nice tips!
- clvv 16y agoAlso, :x is the short version of :wq(also available in vi). And some people put their rc files up on github, here is my vimrc file: http://github.com/wei23/dotfiles/blob/master/.vimrc http://github.com/wei23/dotfiles/blob/master/.vimrc I cherry-picked a lot of useful features from different vimrc files on github and dotfiles.org
- tectonic 16y agoWhat's the best way to jump to the implementation of a symbol in vim?
- whimsy 16y ago/symbol Oh, it's a metacharacter? /\meta \ escapes metacharacters
- silentbicycle 16y agoTag searching. I don't remember what key combination, though - my fingers remember for me. It's in the docs. Essential.
- jberryman 16y agoLook into ctags as others mentioned. Also, while over a word you can press * to jump to the next occurrence of that word. Press n for the next, etc.
- gfodor 16y agoctags + fuzzyfinder plugin gives you TextMate like symbol lookup. (there's another textmate-like plugin whose name escapes me that's a bit more faithful to the TextMate lookup.)
- melling 16y agoI'm in the Emacs camp. However, vi has a certain minimalistic efficiency to it for development. Let me add that a pro might want to quit with :x instead of :wq.
- pyre 16y agoIt's probably best to learn a bit of both, but specialize in one. Especially since common tools like `less` use vim bindings. Examples: * `less +23 file.txt` opens the file in less at line 23 * Searching in less works just like vim: / -- starts a forward search ? -- starts a backward search n -- cycle through matches forward N -- cycle through matches backwards * Some movement keys are shared: gg -- go to the top of the file G -- to go the bottom of the file ... etc ...
- DennisP 16y agoWow that's cool...what other tools do that sort of thing?
- louisYuHoo 16y agoI've always remapped WW to save without quitting. I'm not sure why ZZ is standard but not something like WW.
- expeditious 16y agoLooks like a great tutorial. Covers a lot of ground that others don't (such as the star command, windowing commands, ctags use, etc.). Vim certainly has a lot of ninja editing moves (however, I don't think my development speed is particularly limited by my raw text editing speed).
- crazydiamond 16y agohttp://stevelosh.com/blog/2010/09/coming-home-to-vim/ http://stevelosh.com/blog/2010/09/coming-home-to-vim/ Doesn't look like anyone's posted this link as yet.
- pyre 16y agoThis was on HN a while back (assuming posted == 'posted this article' and != 'posted this in the comments').
- hbt 16y agoThere is also http://jvi.sourceforge.net/ http://jvi.sourceforge.net/ a netbeans module with vim like behavior. Surprisingly, it has a lot of stuff.
- sagarun 16y agoTip: 'vim -x filename.txt' asks for password and encrypts the file :-)
- dchest 16y agoset cryptmethod=blowfish in 7.3 to really encrypt it.
- shimonamit 16y agoI remapped 'hjkl' to 'jkl;' and never looked back.
- lelele 16y agoThe ultimate Vim tip? Use GNU Emacs. Seriously. Vim is a great editor, it just lacks a decent implementation; GNU Emacs is a great OS, it just lacks a great editor. GNU Emacs + Viper + Vimpulse is what you should learn and use for maximum effectiveness.