11 ms·
Coming Home to Vim
- grayrest 16y agoCouple tricks: " this splits a netrw window in the directory of the current file, :Vexplore for vsplit. nnoremap - :Sexplore<CR> " I use surround.vim all the time. The default mapping for s is terrible. nmap s ysi nmap S ysa
- samdk 16y agoOne of the things I love about Vim is that every time I read though a post like this or look at someone's .vimrc I learn something new about what it can do or get another insight about how its features can make my life easier. My (semi-commented) .vimrc is on GitHub if anyone wants another example: http://github.com/samdk/vimconf/blob/master/dotvimrc http://github.com/samdk/vimconf/blob/master/dotvimrc I've also found StackOverflow's list of most-voted questions tagged vim to be a very useful source of little tidbits: http://stackoverflow.com/questions/tagged/vim?sort=votes&pagesize=15 http://stackoverflow.com/questions/tagged/vim?sort=votes&... And there've been several HN .vimrc posts that I also found very useful. This is one of the best: http://news.ycombinator.com/item?id=856051 http://news.ycombinator.com/item?id=856051 This is another excellently commented and extensive .vimrc that (I think) is mentioned in one of the above links, but deserves its own specific mention here: http://www.vi-improved.org/vimrc.php http://www.vi-improved.org/vimrc.php And this is another I found completely by accident a while ago that includes some excellent examples of vimscript macros: http://fingelrest.silent-blade.org/uploads/Main/vimrc.html http://fingelrest.silent-blade.org/uploads/Main/vimrc.html
- stevelosh 16y agoExactly. Case in point: I just found out about ending the backupdir with two slashes to include the full path in the filename by reading your .vimrc. Thanks!
- sigzero 16y agosyntax on filetype on filetype plugin on filetype indent on You do not want "filetype off" Also, check out snipMate as it gives you easy to use TextMate type snippets. In Vim: :h filetype
- telemachos 16y agoYou do not want "filetype off" A minor quibble: you might want "filetype off" temporarily, if you use Pathogen (which the poster does). Pathogen needs to run before the filetype plugin is turned on, and due to the way some distros work (Debian and its children, primarily, I think), this requires you to start your .vimrc this way[1]: filetype off call pathogen#runtime_append_all_bundles() call pathogen#helptags() " Later... filetype plugin indent on Since I work both with Debian and OSX, I just use that as a shared .vimrc set-up. As a general rule, though, you are right that you want it turned on normally. [1] http://www.vim.org/scripts/script.php?script_id=2332 http://www.vim.org/scripts/script.php?script_id=2332
- graywh 16y agoThis has been changed in Debian (the system vimrc no longer turns syntax or filetype on), but persists in Ubuntu.
- telemachos 16y agoI wasn't aware of the change. Thanks for letting me know.
- stevelosh 16y agoReplying to myself because I can't seem to reply to sigzero: Yeah, I definitely need to get around to reading :h filetype. I mentioned Snipmate in the article, so I know about it :)
- icey 16y ago
- mrud 16y agoAnother good vimrc is the vimrc from grml http://git.grml.org/?p=grml-etc-core.git;a=blob_plain;f=etc/vim/vimrc http://git.grml.org/?p=grml-etc-core.git;a=blob_plain;f=etc/... It is a good start to a simple but yet powerful vim configuration, especially integration with screen, pastetoggle, etc.
- Seth_Kriticos 16y agoNice, I got a feeling what your main line of programming is from the source. That's somehow fun. Anyway, might as well join in too, here is my vimrc: http://gist.github.com/144742#file_gistfile1.vim http://gist.github.com/144742#file_gistfile1.vim
- lelele 16y agoThat's exactly what I hate about both Emacs and Vim: yes, they are customizable, however many useful customization are scattered around user scripts. EDIT: A flag here and there does not make a structured environment. That's why many people are running to other editors: they find that what they are more likely to need is already there in a designed way, not in a thrown-together one.
- adorton 16y agoThis is an excellent vim tutorial. Unlike others I've read, it makes me want to be vim power user by clearly spelling out the benefits of various tricks and commands.
- ollysb 16y agoEntirely agree on the aesthetics, one of the things holding me back from switching is that I love vibrant ink in textmate. I just can't seem to find a theme that is quite as bright (vividchalk was pretty close). Any suggestions?
- davidmathers 16y agoConvert your textmate theme to vim: http://coloration.sickill.net/ http://coloration.sickill.net/
- ollysb 16y agoThanks! macvim here I come :) edit: Many of the most popular textmate schemes have already been converted and can be found at http://github.com/squil/vim_colors http://github.com/squil/vim_colors
- nagnatron 16y agoSome are even "improved". I love molokai http://winterdom.com/2008/08/molokaiforvim http://winterdom.com/2008/08/molokaiforvim .
- calloc 16y agoThe issue I had with Molokai (and it may be my screen) is that the comments were barely readable. The colours were just too close to the background. My favourite is earendel (http://www.vim.org/scripts/script.php?script_id=2188 http://www.vim.org/scripts/script.php?script_id=2188)
- kevincolyar 16y agoIf you're a vim user on a mac, try ViKing. It lets you use vi-like navigation throughout OSX. It's still in beta and I would love some feedback. http://vikingapp.com http://vikingapp.com @vikingapp
- SkyMarshal 16y agoThis is what I love most about Vim, it's becoming a universal, mouseless interface to just about everything you use a computer for, except maybe games. So far there's a Vim plugin or mod for: Emacs, Firefox, Chrome/Chromium, Opera, Eclipse, and now even OS X. What others are there?
- stevelosh 16y agoI've given you feedback before, but will repost it here for other HN readers. The main reason I don't use ViKing is that the hotkeys all end up shadowing something useful or being very awkward. If I choose Ctrl I shadow Ctrl+H. If I choose Cmd I shadow lots of stuff, like Cmd+L in a browser. If I choose Alt (ViKing doesn't do that right now, but I'll assume it could be added) it's quite awkward (unless I remap capslock to Alt, but I've already got capslock-as-Ctrl in my fingers). I don't have a solution to this, but would desperately love to find one.
- kevincolyar 16y agoSorry I haven't fixed this yet. I've been swamped with other projects. I was thinking about it tonight... what do you think of some kind of double-tap combo that would enable/disable ViKing functionality, like ctrl-ctrl?
- steve19 16y agoThe kevincolyar account does nothing but spam HN with links to his application. I am sick of seeing him post spam each time a VIM article hits the homepage.
- stevelosh 16y agoI'm the author and submitter of the post and for what it's worth I don't mind his comment at all. It's relevant because OS X Vim users would probably like to use Vim movement everywhere. I know I would. It's certainly more relevant than the "use emacs lol" comments that inevitably show up.
- wccrawford 16y agoI disagree with everything that he starts with 'I almost never do X so I...' But other than that, I think this is a great list of addons and I already use a few of them myself.
- njharman 16y agoyeah i rely on replacing first pattern all the time!
- kaffiene 16y agoI feel the same way about Emacs. I use IDEs for specific development tasks (I don't generally code Java in Emacs, for example, since Netbeans, Eclipse, Idea are all much better in that context) but where content is all over the place as it often is with net development, I use Emacs.
- mhansen 16y agoFor a free, cross-platform (and excellent) alternative to PeepOpen, try Command-T I used to use FuzzyFinder_TextMate, but that's stopped development, and the creator recommends you use Command-T instead. https://wincent.com/products/command-t https://wincent.com/products/command-t
- pyre 16y agoLustyExplorer is good. One feature that I really like is that I can start exploring from the current directory or the directory of the current file. This way I can keep vim's current directory at the root of my source tree, and not have to deal with turning on 'acd' and all of the incompatibilities that can arise.
- cosmok 16y ago+1 for LustyExplorer. Use that every day at work and at home.
- stevelosh 16y agoI've added a link to this to the post, thanks!
- swannodette 16y agoOn a side note, the Gundo feature (http://stevelosh.com/blog/2010/09/coming-home-to-vim/#gundo http://stevelosh.com/blog/2010/09/coming-home-to-vim/#gundo) is available for Emacs (http://briancarper.net/blog/568/emacs-undo-trees http://briancarper.net/blog/568/emacs-undo-trees).
- boskone 16y agoDon't lose another four years before blogging about how you finally switched to emacs from vim and bite the bullet now. Emacs is to vim as vim is to textmate IF you are a hard core software developer. Vim is best for sysadmins, simple, quick non-complex editing. I know, I know... But when you were newly in "love" with textmate I'm sure if I said you need to switch to vim you'd say no way. Skip vim and go right to the best there is, Emacs.
- swah 16y agoAgreed, but is it painful. (And yes, I swapped Control with Caps on day one)
- silentbicycle 16y ago...and once your fingers are raw, bloody stumps from typing with three modifier keys held down, then you can write about coming home to vim again! Bonus! Seriously, can we not start yet another Emacs vs. vi argument? Neither is perfect, they both have ardent fans, pick either, get really proficient with it, and don't look back. (Emacs user who loves Emacs's extensibility and multi-buffer design but prefers vi's modal keyboard ui. And yes, I know about viper, etc.)
- oddthink 16y agoHave you noticed that all of the recent press seems to be for vim? It seems like every month there's a new "I switched to vim!" post, but never a similar emacs version, or even a mention of emacs in the switch article. Note: I am not attempting to argue emacs vs. vim.
- silentbicycle 16y agoIf I'm not mistaken, they're usually switching to vim specifically from textmate. The Mac + Ruby community seems to be disproportionately well-represented in blogs, probably due to a high concentration of web developers. Some high-profile Ruby people (e.g. Yehuda Katz) wrote about switching to vim about two months ago (http://yehudakatz.com/2010/07/29/everyone-who-tried-to-convince-me-to-use-vim-was-wrong/ http://yehudakatz.com/2010/07/29/everyone-who-tried-to-convi...), and it probably set off a chain reaction.
- picklestime 16y agoInteresting article. I found it a bit strange that he didn't link to or reference this: http://weblog.jamisbuck.org/2008/10/10/coming-home-to-vim http://weblog.jamisbuck.org/2008/10/10/coming-home-to-vim which shares the exact same title.
- stevelosh 16y agoYeah, I didn't realize that post had the same title, even though I read it and it's a fantastic post. I'll add a link to it now.
- astrofinch 16y agoAfter a few months of vim use, I did part of the vim tutorial using both vim and a click-and-type editor (gedit) and timed myself. Gedit was significantly faster. Can't say I understand you vim fanatics.
- stevelosh 16y agoIf you say why Gedit was faster perhaps us vim fanatics can help you understand us.
- astrofinch 16y agoLet's say I need to change a word. With Gedit, I double-click the word and retype it the right way. With Vim, I press j until I'm on the line where the word is, then I press w until I'm at the beginning of the word, then I press cw to change the word, retype it the right way, and press escape to go back to command mode. Triple-clicking in Gedit highlights a line. Triple-clicking and dragging highlights a contiguous group of lines. In Vim, I'd need to move to the line I want to begin my selection on ([number]G or jjj), then press V, then press jjj until everything is selected. And I don't have to deal with the fact that the default way of deleting things overwrites the default clipboard either. I do use Vim when I need to process lines in a text document (with macros), when I'm editing files on a server, or when I'm writing a git commit message. I suppose I could use Vim in much the same way as Gedit through its mouse capability, but I dislike the lack of interface between my system clipboard and Vim's, and the fact that when I paste code in to a Vim document, the indentation gets all screwed up.
- Symmetry 16y agoGenerally, if you know where you're going its a lot faster to just start typing a search until you get to the word you want than to mess around with j and w (why incremental search isn't default eludes me). I won't claim that will always be faster than a mouse, but it should narrow the difference a lot. I totally agree with you about the clipboard issues though.
- stevelosh 16y ago
- nagnatron 16y agoI was getting a bit tired of seeing/reading a blog post by a random convert to vim/emacs every week but this one is very good.
- julianz 16y agoGreat read. Among other things it made me dig deep into the heart of my Vista machine and find whatever font was making your site (and others) utterly unreadable. The answer is shitty Palatino fonts installed by HP, presumably as part of a printer driver. So there you go, if Steve's site makes your eyes bleed then go and kill the HP Palatino fonts on your machine.
- stevelosh 16y agoHmm, perhaps I should change the font stack. Is your shitty HP font named "Palatino" or "Palatino Linotype"? If it's "Palatino" I'll need to insert a Windows-only font at the front of the list. If it's "Palatino Linotype" I'll need to insert a Windows-only font as the second element in the list.
- julianz 16y agoHi Steve - it's "Palatino". I also have "Palatino Linotype" and it looks fine now that I've knocked off Palatino. It's a problem I've come across previously on Windows, I think Sun's Java was also installing some horrible version of Palatino a while back. Pity, as it's a wonderful typeface and looks nice on your site.
- tommynazareth 16y agoTextMate doesn't have split windows?!
- compay 16y agoNope. It's one of the biggest complaints about Textmate, and one of the things that led me to (mostly) switch to vim. A lot of people are pretty upset with the author because rather than choosing to release an incremental update that adds smaller features like this, he decided on a total rewrite and got bogged down with no release in sight. That said, Textmate still feels remarkably current despite the fact that its last major update was more than 4 years ago.
- ptn 16y agoA little off-topic: I love how in the side panel of the page the sub-title fades in and out as you scroll.
- cracki 16y agothat's proportional to how much of the actual headline is still visible. scroll slowly and you'll notice.
- stevelosh 16y agoHere's a bit more about them: http://stevelosh.com/blog/2010/09/making-my-site-sing/#showing-context-with-scrolly-headers http://stevelosh.com/blog/2010/09/making-my-site-sing/#showi...
- CGamesPlay 16y ago>Some people use a mapping that turns search highlighting off and on, but I don’t like that solution. It means I have to remember to turn it back on later once I’ve probably already forgotten about the original search. :nohlsearch removes highlighting, doesn't modify search history, and also doesn't disable highlighted search. It will still highlight matches for the next search. > nnoremap <leader>S ?{<CR>jV/^\s*\}?$<CR>k:sort<CR>:let @/=''<CR> I'm curious why not just use `ViB:sort`? > When I press return, create a new line at the same indentation level as the current one. Don’t try to be clever and adjust the indent of new line in any fashion. set autoindent nosmartindent nocindent Wrap it in a filetype line if you like.
- stevelosh 16y ago> I'm curious why not just use `ViB:sort`? Because we use LessCSS[1] which lets you nest selectors: body { color: #151515; background-color: white; a { color: red; } } When I sort the "body" properties I don't want it to break up the stuff nested under it. I'll give the indent settings a try, thanks! [1]: http://lesscss.org/ http://lesscss.org/
- sunny36 16y agoA litte off topic. Much that I like vim I haven't found any plugin than can indent Javascript properly. To be honest whenever I write Javascript I just open up emacs. Is there something close to js-mode in vim?
- sharkbrainguy 16y ago(ITYM js2-mode) No. I use this to indent my JS: http://www.vim.org/scripts/script.php?script_id=1936 http://www.vim.org/scripts/script.php?script_id=1936 You could use JSLint plugin to get more of the features, but I've never gotten it to feel like js2-mode.
- njharman 16y agoI dont see the appeal of nerdtree and the like. For me they are clumsy and too much information. I'm very adept at unix cmd line, find, ack, locate, CDPATH, cmd history, and friends. I spend 10-20% of my editing time at the bash prompt. So much so i aliased :e to vim Having never got the "gui" file managemnet tools i cant say for certain but i wonder if power and productivity gains one sees from truly learning vim can be reproduced by truly learning cmd line.
- lenni 16y agoCould you please share how exactly you do the "jump to file foo.bar" functionality? That is the only part of vim I still find a bit laborious, probably because I haven't found a good workflow for it.
- jb55 16y ago:b has smart tab completion. You can type any part of the filename and you can tab through the results. This is generally what I find myself doing when I have a lot of buffers open. Otherwise I just use minibufexpl with buffer next/prev keybinds.
- lenni 16y agoBut what about files that you haven't already opened?
- xenomachina 16y ago:e also has tab completion. I also use ctags. Usually I want to look things up by symbol name, not filename, though it's trivially easy to make a script that generates a tags file of just filenames too. (And :tag also supports tab completion.)
- njharman 16y ago:e f<tab>.b<tab><return> or similar from command line often using history. After using a code base for a few hours/days I pretty much know where everything is and exactly how many chars I need to type before tab autocompletes. After I open a file once it is in my vim and or bash history which means opening it again is only a couple keystrokes. I use <ctrl>6 and multiple (3-4) non-overlapping terminals (with text mode vim) in various directories. So "jump to file foo.bar" is often look at the vim/terminal to the upper right or <ctrl>6 or :e<space>f<up><enter> Don't remember what this does excactly but it's in my vimrc and might have something to do with it. "freakin awesome file completion set wildmode=list:longest I also use this form of "history" bind '"\e[A"':history-search-backward bind '"\e[B"':history-search-forward
- merijnv 16y agoWhat annoys me about a lot of tech blog posts like this one is that they're essentially voodoo. People like the author write instructions about what you should do without even understanding the instructions themselves. "I’m not entirely sure what the filetype lines do. I’ve read that they’re necessary and so far I haven’t had problems." His example .vimrc has filetype listed twice, which is redundant. This in itself isn't a big deal, but the problem these lines illustrate is. Sentences like these are the reason for billions of blog posts about setting up an OpenSSL certificate authority all repeating the same example which the documentation explicitly mentions is the wrong way of doing things. In fact I find that these voodoo instructions often crowd out any actual proper tech guides in the search results, all for the sake of drawing traffic to some blog... Don't write tech guides if you can't be bothered to do the research and explain to your readers why they should do what you do and what exactly they're doing!
- loewenskind 16y agoI wish this post were closer to the top. Now that knowledge can finally become instantly available, it's biggest enemy is large amounts of misinformation. This is a much more effective strategy than censorship.
- andymorris 16y agoI'm not a vim guru by any stretch of the imagination, but I still don't take what he says at face value. I don't trust ANYTHING I see on the internet just because it's there! Your criticism seems to be due to the belief that, in a world where the only information on the internet could be treated as gospel, that would allow the experts opinion to come through easily. Unfortunately, that sets up the circumstance where the experts get granted much more exposure and trust than they necessarily deserve, and it inevitably gets subverted and abused. I personally prefer the current system - treat all information as suspect until you can verify it. It leaves MUCH less room for exploitation than all of our other "trust by default" mediums. -- Ayjay on Fedang
- merijnv 16y agoOh, I agree that not trusting information on the internet is the sensible default. However, there are plenty of people who will be copying his examples directly without any investigation. Some will probably post the exact same stuff on their own blogs or link to this post. Before you know it this example will drown out any serious search results for "vim filetype", effectively stopping new people from learning how to do things properly. Now obviously this post is a bit hyperbole in this instance. But these things do happen because people can't be arsed to treat the things they write/publish with the care it deserves.
- barfoomoo 16y agoA bit off the topic but a couple of doubts regarding pathogen. I installed pathogen and am a bit confused regarding the organisation of the plugins within pathogen. Say I have plugin called foo.vim, inside the bundles folder do I directly drop it or do I create a folder called foo and then drop foo.vim within it? Also say a plugin has syntax files and an ftplugin folder then do I just drop the plugin in pathogen and it is supposed to work? Is there any good doc out there explaining how to configure with pathogen?
- mattikus 16y ago"Say I have plugin called foo.vim, inside the bundles folder do I directly drop it or do I create a folder called foo and then drop foo.vim within it? You need to create the folder foo with a folder called plugin and then foo.vim inside it -> foo/plugin/foo.vim " Also say a plugin has syntax files and an ftplugin folder then do I just drop the plugin in pathogen and it is supposed to work? Yep. Normally vim plugins are shipped in zip files that contain the structure and are meant to be installed on top of your .vim directory. All you do is instead install them into .bundles/pluginName instead. Also, since a lot of vim plugins are kept in source control anyways, a lot on github, you can simply use git submodules to version your plugins as well making updating them a cinch.
- barfoomoo 16y agoThank you.
- SpookyET 16y agoI am quite proud of my vimrc. It took me a while to build it. By default, it's just a text editor without settings required for development. Use dev to enable devmode and nodev to go back to normal text editing mode. http://github.com/SpookyET/dotfiles/blob/master/vimrc http://github.com/SpookyET/dotfiles/blob/master/vimrc
- dschobel 16y agoI have nothing constructive to add beyond-- thank you Steve, what a fantastically informative post. It clearly took a lot of time and effort to put together and it is very much appreciated.
- sabalaba 16y agoIf anybody is curious, or just wanted to steal his .vimrc (like myself), here it is [I'm surprised he didn't provide it at the end of the article...] http://paste.pocoo.org/show/265338/ http://paste.pocoo.org/show/265338/
- stevelosh 16y agoHere's the BitBucket link, which will stay current as I push more updates in the future: http://bitbucket.org/sjl/dotfiles/src/tip/vim/.vimrc http://bitbucket.org/sjl/dotfiles/src/tip/vim/.vimrc I did link it in the "Important .vimrc Lines" section, but perhaps I should add it at the bottom as well.
- irahul 16y agoSince the blog isn't taking comments, posting it here. > doesn't work very well with is Python, because it preserves whitespace when it moves the code over the REPL. If that's the only issue, it's easy to fix it. All you need to do is to replace multiple new lines with single new line. let s:foo_text = substitute(a:text, '\n\s*\n\+', '\n', 'g') . "\n" Here is my slightly modified slime.vim: http://gist.github.com/589934 http://gist.github.com/589934 I have been using it on Ubuntu with vim and IPython and it seems to work fine. When I started using slime.vim for Python, I ran into whitespace issue and Jonathan(slime.vim developer) resolved it when I asked him on his blog. http://technotales.wordpress.com/2007/10/03/like-slime-for-vim/ http://technotales.wordpress.com/2007/10/03/like-slime-for-v... You can search for Rahul in the comments.
- njharman 16y ago"Many people like to remove any extra whitespace from the " ends of lines. Here is one way to do it automatically " when saving file. fun! <SID>StripTrailingWhitespaces() let l = line(".") let c = col(".") %s/\s\+$//e call cursor(l, c) endfun autocmd BufWritePre * :call <SID>StripTrailingWhitespaces() " When editing a file, always jump to the last known cursor position. au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal g'\"" | endif " This function determines, wether we are on the start of the line text (then tab indents) " or if we want to try autocompletion function InsertTabWrapper() let col = col('.') - 1 if !col || getline('.')[col - 1] !~ '\k' return "\<tab>" else return "\<c-p>" endif endfunction " Remap the tab key to select action with InsertTabWrapper inoremap <tab> <c-r>=InsertTabWrapper()<cr>
- BoppreH 16y agoI can't get snipMate to work. Downloaded a brand-new gVim (windows 64, btw) dropped a pathogen.vim file straight from github into my vimfiles/autoload folder and copied the snipMate's files to vimfiles/bundle/snipMate.vim I'm using the article's _vimrc. :scriptnames lists the "plugin/snipMate.vim" files from both the "snipmate.vim/" and "snipmate.vim/after" But when I type some snippet (like a "for" in a *.c file) and press tab, a single space (not a tab) is inserted. Pressing tabs on non-snippets inserts a tab like expected. Am I missing something here?