12 ms·
Coming Home to Vim
- mattkirman 14y agoOriginal discussion from a couple of years ago can be found here http://news.ycombinator.com/item?id=1710702 http://news.ycombinator.com/item?id=1710702.
- janogonzalez 14y agothis keeps coming home once a year :P
- fromhet 14y agoIs there anyone on HN not using textmate and sublime no Mac OSX?
- dguaraglia 14y agoI'm a quite happy MacVim user.
- bradleyland 14y agoYes, there are plenty of people using Vim or Emacs as they're primary editor. You don't always hear from them though, because they've already lived through several rounds of editor wars.
- bradleyland 14y agoI'm really embarrassed that "their" ended up "they're". I'm not sure if I typed it out of muscle memory, or if I mistyped it and Lion auto-corrected to "they're". This is why I never stoop to pedantry. I know the difference, I swear!
- spudlyo 14y agoI made my editor choice over 20 years ago, before these things were even a glimmer in their creators eyes. The key sequences I use for editing are cast in stone into my muscle memory, and serve me in nearly every command-line tool I use, as well as every text entry widget in OSX. My editor is part of my hacker DNA.
- mattkirman 14y agoI'm more than happy using a combination of Vim (not MacVim) and tmux on OS X. I was spending more and more time in the terminal (running tests, committing changes, etc.) so it made sense to me to incorporate Vim into the window as well. FYI my transition was Notepad++ > TextMate > Sublime Text 2 > Sublime Text 2 + vintage mode [1] > Vim. [1] http://www.sublimetext.com/docs/2/vintage.html http://www.sublimetext.com/docs/2/vintage.html
- jamiltron 14y agoI use Emacs on OSX, just like I do on every other operating system I have to use.
- zaptheimpaler 14y agoWow, the bit about seeing vim commands as sentences composed of nouns, verbs and adjectives blew my mind. I thought about learning vim, but I didn't know about this, so vim commands seemed like some arcane language that I would have to gradually get proficient at over months.. this might make the transition a lot easier.
- solutionyogi 14y agoYep, that's the zen moment right there with Vim. Once you understand this, you will be able to 'speak' to your editor and bend it at your will. E.g. 't' is a motion command which takes you 'till' a particular character. The same command even works with 'Visual Block Selection'. Most of the other editors have a different work flow for 'Block selection' and they are not friendly at all. And if you are starting out, I would HIGHLY recommend the book 'Practical Vim' http://pragprog.com/book/dnvim/practical-vim http://pragprog.com/book/dnvim/practical-vim . The book teaches the 'The Vim Way' and to be a good Vim user, you have to understand the 'The Vim Way', there is no way around it. Good luck!
- tolos 14y agoMore on vi as a "language:" http://stackoverflow.com/questions/1218390/what-is-your-most-productive-shortcut-with-vim?page=1&tab=votes#tab-top http://stackoverflow.com/questions/1218390/what-is-your-most...
- brown9-2 14y agoThese articles are also helpful: http://blog.carbonfive.com/2011/10/17/vim-text-objects-the-definitive-guide/ http://blog.carbonfive.com/2011/10/17/vim-text-objects-the-d... http://yanpritzker.com/2011/12/16/learn-to-speak-vim-verbs-nouns-and-modifiers/ http://yanpritzker.com/2011/12/16/learn-to-speak-vim-verbs-n...
- bcrescimanno 14y agoLearning to see the commands as a language is helpful; but, it doesn't really reach its full power until you start to see files in terms of the various groupings that Vim affords you (either the out of box things or custom text objects). If you stick with Vim, you'll start seeing things like whether or not you want a word or a WORD, or around (a) or inside (i) an object. Moreover, start to pick up on when you're hitting the same key multiple times or repeating a command. There's almost always a faster way to do something than repeating a command N times. I'll be totally honest, it takes time and a real commitment to using Vim as your only editor. But, over time, you'll start to think in this text objects and, combined with the "commands as a language" concept--that's when Vim will really start to show it's power.
- borplk 14y agoI'm a hardcore nerd and I spend many hours with a text editor during the day. Yet I find vim beyond my nerd level. I just can't be bothered with fiddling with config files and installing little bundles and packages for every functionality. On top of that the whole "language of editing" and combining noun,verb,adjective commands, etc... doesn't really appeal to me because I'm too visual when I'm editing code. I can't stop to think about the right semantics about what I want to do, I just do it visually.
- rauljara 14y ago>>I can't stop to think about the right semantics about what I want to do After the initial learning process, you don't think about the right semantics of what you want to do. Learning vim's normal mode really is very analogous to learning to touch type. In most text editors, when you want to delete a word, you don't really think about hitting backspace a whole bunch of times. Of course, you did think about hitting backspace when you first started. With vim, you don't really think about hitting dw (or cw), you just do it. You did your thinking a while ago, and now it's just how your fingers move. Of course, there are plenty of valid reasons why vim might not be for you, so please don't take my comment as a "No, you really should learn vim" piece of evangelism.
- gms7777 14y agoYeah, I initially learned vim because I didn't really have a choice (it was expected for the class that we would use vim), and I remember it being very painful in the beginning. However, just like any other tool you use on a regular basis, those commands become muscle memory very quickly and you don't even think about it. Now I use vim for work, mostly editing c code. I have a very barebones vimrc and have never installed a little bundle or package. I use it mainly because of its simplicity and terminal integration. I can't say I'm a very visual person though. I get distracted with too many bells and whistles and often times even just switching windows causes me to get distracted by the interwebz (...i'm a bit add), so I like the simplicity of a blank screen. Point being, vim isn't for everyone, but using vim doesn't have to be this big giant complicated endeavor that everyone seems to make it out to be. (Small confession: I also really feel kind of bada$$ when I'm sitting behind a black terminal with green text...)
- tolos 14y agoI'm skeptical that Ack is "far, far better than grep." Different? Ok. Better? Maybe, based on what you're doing. Far, far better? Probably not. Omitting correct results because a file extension isn't white-listed sounds like a pain. http://superuser.com/questions/39384/best-grep-like-tool/342803#342803 http://superuser.com/questions/39384/best-grep-like-tool/342...
- alex-g 14y agoFWIW in ack 2.0 (currently in alpha) this behaviour will be different: it will search all text files by default.
- AngryParsley 14y agoI like Ack more than grep, but I agree: whitelisting file types isn't fun. I wrote a mostly drop-in replacement for Ack in C (https://github.com/ggreer/the_silver_searcher https://github.com/ggreer/the_silver_searcher) and the biggest difference in behavior is the file filtering. Ag searches all text files by default, with the exception of those in .gitignore and .hgignore. You can also add patterns to .agignore files if you want finer-grained control. Oh, and Ag is much faster than Ack. Ack isn't the only thing better than grep. If you're searching in Git repos, you might want to check out git-grep. Another useful tool is Exuberant Ctags: http://ctags.sourceforge.net/ http://ctags.sourceforge.net/
- petdance 14y agoWhere did you see ack as "far, far better than grep". My Ctrl+F finds nada. The reason I took "betterthangrep.com" as a domain name, besides it being catchy, is that I want people to think beyond stock grep as a tool, to know that they have options. The page http://betterthangrep.com/more-tools/ http://betterthangrep.com/more-tools/ is just a listing of other tools that may be better than grep, depending on the use case.
- tolos 14y agoAck If you’re a programmer and you don’t know about Ack, you need to start using it now. It’s far, far better than grep.
- z92 14y ago> nnoremap ; : > I don’t remap : back to ; because it seems to break a bunch of plugins. That sounds like another good trick. But then how do you jump to your next f,F,t? I find myself frequently typeing "f=" to find "=" and then hitting ";" to jump through all the "=" in that line and reach the one I want.
- pyre 14y agoWhen people overwrite things that are basic like that they usually don't have an alternative. They overwrite them, because it doesn't fit their common usage pattern. But, for example, I use ',' as my <Leader>. So that I can still use ',', I also map ',,' back to ',' functionality: let mapleader = "," let maplocalleader = "," nnoremap <leader>, :normal ,<CR>:<CR>
- RegEx 14y agorepmo.vim[0] lets you repeat movements with semicolon as well. I only use two vim plugins, and this is one of them. [0]: http://vim.sourceforge.net/scripts/script.php?script_id=2174 http://vim.sourceforge.net/scripts/script.php?script_id=2174
- pash 14y agoThis blog post recently helped persuade me to switch to Vim (from TextMate). The two things that most helped me learn Vim, beyond the very basics, were Drew Neil's excellent Vimcasts [0] and Steve's own Learn Vimscript the Hard Way [1] (a work in progress). Learn the basic movement commands and text objects, then spend ten minutes every day watching a Vimcast or doing a chapter of LVHW and you'll quickly be past the steep part of the learning curve. 0. http://vimcasts.org/episodes/archive http://vimcasts.org/episodes/archive 1. http://learnvimscriptthehardway.stevelosh.com/ http://learnvimscriptthehardway.stevelosh.com/
- bcrescimanno 14y agoIn addition to the vimcasts, I also found Derek Wyatt's video series very helpful (as well as entertaining). http://ontwik.com/tools/vim-from-novice-to-professional-by-derek-wyatt-p1/ http://ontwik.com/tools/vim-from-novice-to-professional-by-d...
- justauser 14y agoExcellent. I've been a long time user of Vim and never saw this until the blog post.
- losvedir 14y agoSigh, I keep seeing this article, and ones like it, and keep thinking maybe I should go back to vim. I'm happy with Sublime, though I like the idea of vim. I've used vim a great deal in the past and it really is exceptional for editing a given file. The thing that really tipped me to ST2, though, was its management of multiple files in a project. The sidebar and Goto Anything are indispensable. I know vim has command-t, but I just haven't been able to browse a family of related folders as easily. How do others do it? Also, I just can't get used to the line-by-line scrolling of vim and emacs vs. the pixel scrolling of Sublime, or TextMate, or even TextEdit.
- pyre 14y agoI haven't really used it, but there's NERDTree for a Vim sidebar.
- johncoltrane 14y agoCtrlP(1) is a recent alternative to Command-T: you can use it to quickly jump to another buffer, a nearby file, a recently used file… all this with a very consistent interface and a neat feature: you can configure it to look up and up for a .git or .svn or other VCS artefacts and start from there. This makes the whole "open a file in the current project" business an almost seamless experience. Also what's the point of displaying a third of the height of a line? (1) https://github.com/kien/ctrlp.vim/ https://github.com/kien/ctrlp.vim/
- bcrescimanno 14y agoNice tip on the Ctrl-P link; but I'm curious, is there anywhere that sums up why Ctrl-P would be preferred over Command-T? Aside from being written in pure Vimscript, I haven't seen anything touting any specific advantages or disadvantages in a head-to-head.
- nudded 14y agoCommand-T is known to be quite the pain in setting up.
- Craiggybear 14y ago"One of the flaws of Vim is that it takes quite a bit of configuration to make it behave in a decent way. The defaults are backwards-compatible with vi (i.e. older than most college students)" Older, not only, than most students but older than their tutors. This is good. It is good because it is consistent. Vim is all the editor you will ever need. It's pure Zen.
- chimeracoder 14y agoSlightly tangential, but the author mentions remapping Caps_Lock, as I do (I've mapped it to Escape, as Esc used to be where Tab is on modern keyboards anyway). The moment I first did this, I realized how amazing vim really is, and why people always say that you can navigate the entire file without moving your hands from the home row. However, both methods I know for doing this only work inside an X server - does anybody know a good way to remap keys without X?
- spudlyo 14y agoIn linux you want to use loadkeys(1).
- johncoltrane 14y agoI think you have to play with loadkeys and a custom mapping.
- s00pcan 14y agoI used to have it mapped to escape but once I started using tmux I mapped caps lock to control and never looked back. Much more versatile than escape and ctrl+[ will do the same thing (although it's proving hard to break the habit of pressing escape instead).
- spudlyo 14y agoUnmap your escape key, that will force the habit. I did this when I moved my control and meta keys to the left thumb of my kinesis keyboard, and it helped train me not to hit the old keys.
- s00pcan 14y agoI've tried this in the past but it made both escape and ctrl+[ no longer function. What worked for you?
- spudlyo 14y agoUnder OSX I used a tool called KeyRemap4MacBook which adds an item to the control panel that lets you reconfigure keys. I just tested it, you can can disable the escape key, but Ctrl-[ still works like you'd expect.
- patrickod 14y agoDoes anyone know what the author is using to display carriage returns at the end of each line?
- bcrescimanno 14y agoSee: https://github.com/sjl/dotfiles/blob/master/vim/vimrc#L35 https://github.com/sjl/dotfiles/blob/master/vim/vimrc#L35
- Olreich 14y agoin ~/.vimrc : set list set listchars=tab:▸\ ,eol:¬ it's in the getting started section.
- patrickod 14y agoThanks! Don't know how I missed that
- HarrietTubgirl 14y agoI've come and gone with various vim config changes, but this is the one non-standard one I've stuck with: au! BufRead,BufNewFile * lcd %:p:h This makes it so that when you open a buffer, you cd to the current directory (only for that window), so you can quickly open files in that directory. [% is the current file relative to pwd, :p converts to a full path, :h takes off a path component, lcd does a cd but only for the current window] Another tip is that when your internet connection sucks enough for SSH lag (tethered, free wifi, whatever), you can edit a file locally and have vim do the SCP back when you write: :e scp://you@somewhere/path Boom!
- johncoltrane 14y agoset autochdir does what you describe. Thanks for the laggy SSH tip.
- tylerhobbs 14y agoA nice alternative is to do: " Allow easy navigation to relative files cmap %/ %:p:h/ This basically replaces everything before the slash with the directory of the file you're editing. That way, you don't have to necessarily cd, but can easily open files near the one you're currently editing. You can just do ":e %/foo.txt" to open foo.txt in the same directory.
- Lapsa 14y agoOne thing I can't understand - why people remap leader to comma? How they use fFtT without it?
- kisielk 14y ago[fFtT], still works even with comma mapped to leader.
- genbattle 14y agoI took the dive into Vim about a year ago. I was at the stage where I'd become proficient with some command-line tools in Linux, but I didn't yet have an editor I could use fluently from the command line. I tried out both Vim and Emacs, and found Vim to be slightly easier to grok, plus my pinkie got kind of sore from holding down the Ctrl key in Emacs. I changed my default editor at work to be Vim, and started doing all my dev work at home through Vim. I started off just using the arrow keys to move and just using insert mode to edit text the normal way. Each day I tried to add one new command to my repertoire; I learned about how to structure vim commands (c-change i-in w-word, etc.) and move using hjkl and the higher order movement commands like w and b. Now I can maneuver my way around vim quite confidently, and although when I started off I was much slower in Vim than other editors, I now find that Vim is just as fast or faster for most tasks, particularly where I can make use of Macros. At the moment I still have to get my head around markers and a few other concepts, but I've definitely become proficient enough for it to be worth the effort and time invested so far. My tips for anyone learning to use vim for everyday development would be some common tab commands: :tabnew <path> to open a file in a new tab, :tab sball to show all currently open buffers in separate tabs, gt and gT to jump to the next/previous tabs.
- sbochins 14y agoYea, tabs are a very useful feature in vim that many people don't seem to use. I know people that use the panes. This isn't really useful for me though. I use tmux as my window manager for my terminal, so I have not use for panes in vim. I just have a bunch of vim processes running and use tmux for the window management. The great thing about this is my development environment completely mirrors my production environment. I have found that one of the best productivity gains you can get is having one mental model for everything. Unfortunately I'm still coding in PHP (don't think PHP fits into this idea).
- Smudge 14y agoI use tmux too, but I prefer the way vim handles panes. When I'm in mental-vim mode, it's easier for me to not have to jump out to thinking in tmux terms when editing several files.
- Andrew-Dufresne 14y agoAfter using Vim for couple of years, I recently made a switch to Emacs. Sometimes I regret it. I definitely miss Vim modal design and keybindings. Compare Vim's J (join lines) with Emacs go to the lower line and press ^ to join it with the upper one. To copy a line in Vim you just have to press 'yy' but there is no copy line command in Emacs out of the box. What you can do is C-k, C-y, i.e cut a line into clipboard and paste it back to have copy line effect. But trying and learning different tools is obviously useful. Emacs introduced me to ido-mode and org-mode. Now that I know of the possibilities, I can search for and use similar plugins in Vim.
- dedward 14y agoIt goes without saying..... check out vimgolf if you haven't - whether novice or expert, competing or just reading, you learn new stuff. Don't become too plugin dependent too early, but a quick browse through some other's dotfile repositories (yadr is worth looking at, especially if you are on a mac - not necessarily to use, but definitely to see what's possible). Things like EasyMotion really make you think. As do things like persistent undo files. (gundo and other stuff) At some point you should be buildilng up your own set of dotfiles from scratch.... not just relying on someone elses (some day some bug hits you and you have no idea where to start otherwise)
- geoffc 14y agomid eighties till 1992 on Qedit, Emacs till 2002 then VIM to the present, no desire to switch for the next decade of coding :-)
- barbs 14y agoI'm a bit torn. I love the controls in vim, the way you navigate and manipulate text is a brilliant system. It makes it more efficient and more "fun". However, I really don't like the configuration system for vim. Reading the article above, I lost interest when he started talking about his .vimrc file and the plugins he used. It seems arcane to have to have these cryptic settings, whose functions aren't immediately obvious, and write them to a file. I understand that part of the VIM philosophy is that it's almost like a language, or that it's like programming your text, but configuration is just something that you (ideally) set once, and then forget about. Even if I do learn what "nnoremap <leader>ft Vatzf", if I need to set up my environment again, I'll likely forget what it is and why I needed it in the first place. And even if I configure VIM to have the things I want (for example, NERDtree for project navigation), it'll never look or feel as intuitive as having a graphical interface. So it seems when people talk about VIM, it seems that they're really talking about two things: the control scheme (keybindings) and the editor itself (the environment). Being an android developer, I use eclipse. I use the "Vrapper" plugin, which gives me vim keybindings in the eclipse editor. I love it. It gives me the vim navigation that I know and love, but the environment and tools provided by Eclipse. I think this is how it should be - the environment of the editor is best handled separately, and although you can add a ton of plugins and configure the crap out of VIM to turn it into an IDE, it'll never really be a proper IDE. This is why I'm still looking for an ideal lightweight text editor/IDE. My ideal for linux would be Geany, but with Vim keybindings. I discovered Vico yesterday, which looks interesting, but is OSX only at the moment. Might be what I'm looking for, but we'll see.
- sbmassey 14y agoYou can do a lot more in vim without plugins than with most text editors. In fact, I'd say that was one of it's major advantages over the competition. Relying too much on plugins and configuration makes things hard when you're switching machines or using shared logins a lot.
- johncoltrane 14y agoTry Sublime Text 2 for a lightweight editor with Vi keybindings. It's not Vim but it's quite powerful in its own right and is cross-platform. With some experience and the right mindset, Vim's language becomes second nature and a mapping like yours is very easy to understand. The thing is that too many people, me included at the beginning, follow the "learn -> customize" path in the wrong order: "customize -> learn"; often because of articles like this. This lead to a non-productive mix of plugin-addiction and mappings-dependance that's rather obviously counter-productive. The ideal path would be to first learn how to use plain Vim then use this knowledge to customize it. This path leads to a short .vimrc and a lightweight .vim directory while the other leads to a miles-long arcane .vimrc and a bloated .vim directory.
- comatose_kid 14y ago" If switching to a different editor can increase my efficiency by even 10% it would save a good chunk of my time and let me get back to making cool things." Instead of taking us on a long biographical journey of how you found the One True Editor (this week), why not familiarize yourself with Amdahl's Law?
- montecarl 14y agoI'll bite. What do text editing and thinking (both serial tasks) have to do with Amdahl's law?
- comatose_kid 14y agoAmdahl's Law isn't necessarily applied to parallelism.
- stevelosh 14y agoWhere can I get clones of myself willing to concurrently enter text so that Amdahl's law about parallelization performance somehow becomes even the slightest bit relevant to text editing?
- comatose_kid 14y agoOkay, fine - law of diminishing returns, the point still stands (although I deserved that for being a smart-ass).
- teaneedz 14y agoEven though I really enjoy pecking away in BBEdit, I find Vim to be so wickedly fast. Manipulating text in Vim is nicely handled without having to stretch the fingers very far. By the time I go to the trackpad in another IDE, I could have accomplished so much more within Vim.
- Derbasti 14y agoI started off with Textmate, then Emacs, then Vim, then back to Textmate, then Vim (for real that time), then Emacs (for real, that time). I am tempted by Sublime Text and Vim, but can't live without a few Emacs features these day. But sometimes I miss the fluidity of Vim. That said, I found the most important influence on my productivity is fun. I am most productive when I enjoy what I am doing. And this is very directly influenced by the way I do the clickety-clack thing with my keyboard. In fact, I sincerely think that Vim is the most efficient text editor out there. Nothing else comes close. The thing is, me personally, I am having more fun elsewhere, for reasons that have little to do with text editing performance. Mind you, this is not critique against Vim. But I would like to discuss text editing productivity in terms of fun instead of keypress efficiency. Whenever anyone argues about the relative merits of EditorX against EditorY in terms of key presses I feel like he is missing the point. What do you think about this idea/argument?
- irahul 14y ago> In fact, I sincerely think that Vim is the most efficient text editor out there. Nothing else comes close. The thing is, me personally, I am having more fun elsewhere, for reasons that have little to do with text editing performance. > What do you think about this idea/argument? Unless you can tell what is the fun part, and what are the reasons you are having more fun elsewhere, I don't know what do you want to discuss.
- elrzn 14y agoI really like Vim as a concept, but the implementation is somewhat laking and not so easy to extend. At the moment I'm using Emacs with EVIL (Vim layer) and loving it. You should check it out :)
- Derbasti 14y agoI did and I could not cope with it. My brain can either do Emacs or Vim, but not both. Whenever I used Evil, I would fall back entirely into Vim mode and more or less ignore all the Emacs goodies and miss my favorite Vim plugins. Mixing Emacs and Vim did not go well with me. However, maybe I should try it again now that I am comfortable with Emacs.
- jasondavies 14y agoGreat tip for using Perl/Python-compatible regex syntax: nnoremap / /\v vnoremap / /\v This will save me a lot of time. Thanks, Steve!
- norswap 14y ago> "If switching to a different editor can increase my efficiency by even 10% it would save a good chunk of my time and let me get back to making cool things." > "I don’t buy the “you’re thinking 90% of the time and only typing 10% of the time, so your editor doesn’t really matter” argument. Even if the premise is true, the conclusion is wrong." Interestingly to me, people never (or rarely) attempt to improve their thought process, which would probably result in a much higher increase in productivity than editor proficiency.