13 ms·
Vim, you complete me
- solutionyogi 14y agoI have been using Vim for over 3 years and I didn't know about the whole line completion. I think the best thing about Vim is that it will always keep surprising you. If only we could find a life partner like that, there won't be any divorces.
- leftnode 14y agoOr maybe that's why there are so many divorces!
- calinet6 14y agoThis is a little out of left field, but... > If only we could find a life partner like that, there won't be any divorces. Personally, I find that if you stop relying on your life partner to be the person you expect them to be or want them to be, then there won't be any divorces. This idea that you have to just find the right person and everything will be fine is pretty flawed and won't take you far. Sure, people are different, and you should find a good person you can get along with, but that's only the start. Any person will stop surprising you after a while, and you have to be prepared to start from there and still build something together. In other words, don't give up just because your partner is an emacs user.
- jes5199 14y agoI've been using Vim for over 14 years and never used whole line completion. It seems vaguely familiar like I might have seen it in the docs, but I've never thought "hey, I'm gonna look up the keystroke for whole line completion!"
- johncoltrane 14y agoWhole line completion is very useful when you write very repetitive languages. In CSS, <C-x><C-l> is a gift of the gods.
- Rudism 14y agoIt all started out innocently enough. You experimented with it once or twice in your first year of college, but Nano and Pico were easier—closer to what you had already been using during high school on the Windows machines and Macs. But as time went on and you got more experience under your belt in the college-level computer science courses, you started to notice something: All of the really great programmers—the kind who churned out 4 line solutions for an assignment that took you 10 pages of code to complete; the kind who produced ridiculously over-featured class projects in a day while you struggled with just the basics for weeks—none of them used Nano or Pico. Staying late one night to finish an assignment that was due at midnight, you happened to catch a glimpse over one of the quiet uber-programmer's shoulders. Your eyes twinkled from the glow of rows upon rows of monitors in the darkened computer lab as you witnessed in awe the impossible patterns of code and text manipulation that flashed across the screen. "How did you do that?" you asked, incredulous. The pithy, monosyllabic answer uttered in response changed your life forever: "Vim." At first you were frustrated a lot, and far less productive. Your browser history was essentially a full index to the online Vim documentation; your Nano and Pico-using friends thought you were insane; your Emacs using friends begged you to change your mind; you paid actual money for a laminated copy of a Vim cheat sheet for easy reference. Even after weeks of training, you still kept reaching for your mouse out of habit, then stopped with the realization that you'll have to hit the web yet again to learn the proper way to perform some mundane task that you never even had to think about before. But as time went on, you struggled less and less. You aren't sure when it happened, but Vim stopped being a hindrance. Instead, it become something greater than you had anticipated. It wasn't a mere text editor with keyboard shortcuts anymore—it had become an extension of your body. Nay, an extension of your very essence as a programmer. Editing source code alone now seemed an insufficient usage of Vim. You installed it on all of your machines at home and used it to write everything from emails to English papers. You installed a portable version along with a fine-tuned personalized .vimrc file onto a flash drive so that you could have Vim with you everywhere you went, keeping you company, comforting you, making you feel like you had a little piece of home in your pocket no matter where you were. Vim entered every part of your online life. Unhappy with the meager offerings of ViewSourceWith, you quickly graduated to Vimperator, and then again to Pentadactyl. You used to just surf the web. Now you are the web. When you decided to write an iPhone application, the first thing you did was change XCode's default editor to MacVim. When you got a job working with .NET code, you immediately purchased a copy of ViEmu for Visual Studio (not satisfied with the offerings of its free cousin, VsVim). Late one night, as you slaved away over your keyboard at your cubicle, working diligently to complete a project that was due the next morning, you laughed to yourself because you knew no ordinary programmer could complete the task at hand before the deadline. You recorded macros, you moved entire blocks of code with the flick of a finger, you filled dozens of registers, and you rewrote and refactored entire components without even glancing at your mouse. That's when you noticed the reflection in your monitor. A wide-eyed coworker looking over your shoulder. You paused briefly, to let him know that you were aware of his presence. "How did you do that?" he asked, his voice filled with awe. You smile, and prepare to utter the single word that changed your life. The word that, should your colleague choose to pursue it, will lead him down the same rabbit hole to a universe filled with infinite combinations of infinite possibilities to produce a form of hyper-efficiency previously attainable only in his wildest of dreams. He reminds you of yourself, standing in that darkened computer lab all those years ago, and you feel a tinge of excitement for him as you form the word. "Vim." :wq
- mun2mun 14y agoAlso checkout neocomplcache, https://github.com/Shougo/neocomplcache https://github.com/Shougo/neocomplcache
- riannucci 14y agoAlso, SuperTab is all of the win: https://github.com/ervandew/supertab/ https://github.com/ervandew/supertab/ It'll let you use <Tab> for all the completion types, and you can tell it the fallback order for various thing (i.e. try omni, then <C-N>, etc.). It's even slightly context aware, so it can guess a good first completion method for you. All with <Tab> :)
- pdeuchler 14y agoThis may just be me, but I feel that a lot of the productivity that Vim supposedly creates is a result of programmers spending lots of time learning one tool very well, as opposed to something inherent within Vim that automatically makes you more productive. That's not to say Vim doesn't have an excellent ecosystem, and has tried and true ergonomic benefits, however I feel that if someone spent the same amount of time learning, say TextMate (just an example, may not be the best), they would be just as productive.
- heretohelp 14y agoIf you want something that is inherently superior and has a lot of effort invested in it, you use Emacs ;)
- gfodor 14y agoYou might feel that way, but you're probably wrong :) Vim basically is the logical result of taking the idea of "how can I manipulate a text buffer efficiently using my keyboard" to its conclusion. Once you've burned in the muscle memory using arrow keys and a traditional buffer with the mouse is like having your hands chopped off.
- calinet6 14y agoI find SublimeText (and TM to a much lesser degree) have certain features that really help with efficiency, like multi-line editing and good key shortcuts for in-file search and replace and regexp replace. Vim is like this but without having to take your hands off the keyboard, so you get a little extra. But using the mouse and having a very visual hand-eye-coordinated text editing representation is really intuitive, so it's definitely a tradeoff. Vim takes a long time to get used to, is not intuitive, and gives an extra boost in speed by its very nature; pretty much comes down to that. Sort of like a car: it takes a long time and investment to learn how to drive and get used to the completely new world of streets and driving rules, but once you're there you can get places way faster. All that said, I still use SublimeText, because I don't necessarily need Vim to program efficiently (I admit, my main obstacle is my mind, not my editing speed), and the experience of SublimeText is very efficient and matches my intuitive mental model of text. So the moral is, use what works for you.
- calinet6 14y agoI understand Vim. Really, I do. I even know how to use it for the most part. But I guess I just don't get it. It's too obtuse. I don't feel connected to my editing while using it, I feel... connected to Vim. Which, I think, might explain why others feel so connected to Vim too. They get attached to it because it's an investment, and as we know from various psych studies, we get attached to things we invest in. This isn't a bad thing, just wanted to throw my 2¢ out there. Vim's a cool language for text editing, but it's not the only one.
- solutionyogi 14y agoI completely understand where you are coming from. For me and others, we actually feel connected to our text instead of Vim. Let me give you an example, let's say I have following sentence. "Why, oh WHY, do those #?@! nutheads use vi?" my cursor is on the letter 'h' of 'nutheads'. Let's say I decide to change the whole word to 'crazy people'. Here's how you would do it in conventional editor (using EditPlus as an example). Ctrl + <- (to jump to n) Ctrl + Shift + -> (to select the whole world) Shift + <- (to remove the space which was selected. ) Type in "crazy people" Here's how you would do it in Vim. ciw - (change inner word), it gets rid of the whole 'nutheads' word and puts me in INSERT mode. type in "crazy people" As you can see, EditPlus forces to you to navigate the text using conventional method. It doesn't have a concept of a 'word'. Compare this to Vim. I told Vim what I exactly wanted to do ('change inner word') and it let me achieve that without any fuss. As I wrote in my other comment, Vim lets me 'talk' and 'interact' with my text at a semantic level. Vim is like a translator which completely disappears when I am working with my text. The example sentence was borrowed from another excellent article on Vim: http://www.viemu.com/a-why-vi-vim.html http://www.viemu.com/a-why-vi-vim.html
- deleted 14y ago[deleted]
- calinet6 14y agoExcellent comparison, thanks. It's important to note that many modern text editors do have concepts of "words" and "lines" and such that can be used in similar ways. Granted, not near the extent of Vim, but they're still useful. In sublime for example, I can Ctrl+Shift arrow to select words before and after. This even works with multiple selection (multiple caret positions). It's pretty cool. Again, I understand that Vim is more of a language to describe editing text and is very efficient, I'm just saying you can get close with modern editors, and personally I find their visual language to work better for me.
- jes5199 14y agoThere's something weird about the ^P/^N menu - I always have trouble telling which possible completion is selected in the list, and I often end up picking the wrong one.
- solutionyogi 14y agoMay be it is your colorscheme. I took snapshot from my current editing session: Selecting the last item: http://i.imgur.com/dEkws.png http://i.imgur.com/dEkws.png Selecting the second last item: http://i.imgur.com/D6Icl.png http://i.imgur.com/D6Icl.png My vimrc is here: https://github.com/SolutionYogi/VimSetup https://github.com/SolutionYogi/VimSetup
- jes5199 14y agoyeah, I should tweak it somehow. This is what the (otherwise amazing) inkpot theme looks like: http://imgur.com/TaUym http://imgur.com/TaUym - can you tell that the dark, bold entry is selected?
- solutionyogi 14y agoI don't know which entry is selected (because I don't know the color scheme) but those two items have very distinct colors and I would definitely be able to differentiate between them. I think you should experiment with some other color scheme or try to tweak your existing scheme.
- cletus 14y agoVim reminds me of an example from Bret Victor's excellent talk Inventing on Principle [1] (which you should watch from beginning to end if you've somehow been hiding under a rock and have missed it). Bret mentions Larry Tesla (starting at about 38:10) who made it his personal mission to eliminate modes from software. This is the problem I've always had with Vim and I suspect I'm not alone in this. I find the concepts of modes jarring, even antiquated. Everyone who has used vi(m) has copied and pasted text in while in command mode and done who knows what. Emacs is better in this regard but I find Emacs's need to consecutive key presses (or a key press followed by a command) to be longwinded. The advantage of either is they're easy to use over ssh+screen (or tmux) for resuming sessions. That all being said, give me a functional IDE any day. IDEs understand the language syntax. Vim can do a reasonable job of this. Emacs (with elisp) seems to do a better job (or so it appears; I'm no expert) but IDEs (my personal favourite being IntelliJ) just make everything easier. Things as simple as left-clicking on a method and going to its definition. For statically typed languages (eg Java/C#), IDEs (quite rightly) rule supreme. Static code analysis, auto-completion, etc are just so much better than text-based editors. Dynamic languages are more of a mixed bag and its certainly the norm for, say, Python and Ruby programmers to use one of these. Still, give me an IDE any day. One objection seems to be that people don't like using the mouse. I tend to think the speed differences over not using the mouse are largely illusory. Anyway, I can use vim but I've never felt comfortable in it and I don't think I ever will and modes are the primary reason. EDIT: I realize there are plugins and workarounds for many of these things but that's kinda the point: I don't want to spend hours/days/weeks/years messing with my config to get it "just right". Also, instead of archaic commands to, say, find matching opening/closing braces (which tend to involve an imperfect understanding of the language), IntelliJ just highlights matching braces/parentheses, where a variable is used and so on. [1[: http://www.youtube.com/watch?v=PUv66718DII http://www.youtube.com/watch?v=PUv66718DII
- jes5199 14y agoThe way that most Vim users use modes is like using "StickyKeys" on your Shift/Control/Option keys. You smack "i" or "a" to go into insert mode just for the duration that you need it, and then you smack Escape the moment that you stop typing, even if it's just pausing to think. Also, if you use a GUI version of Vim, then it knows about "paste" and doesn't make the mistake of interpreting your paste buffer as keystrokes.
- JangoSteve 14y ago> For example, in HTML vim should know that you can’t nest a div inside an a... In HTML5, you can. See http://html5doctor.com/block-level-links-in-html-5/ http://html5doctor.com/block-level-links-in-html-5/
- johncoltrane 14y agoThat. And isn't it the job of the programmer to know those things?
- sirdavidoff 14y agoMoving to vim from TextMate, I found that I missed TextMate's autocompletion. In Vim you have to specify whether the word you're looking for is above or below the cusror (using C-P or C-N). IIRC, TextMate just looks for the closest matching word, no matter where it is. I wrote a little plugin to do make it exactly that: https://github.com/sirdavidoff/vim-nearest-complete https://github.com/sirdavidoff/vim-nearest-complete Disclaimer: totally rough and not (yet) very customisable
- gubatron 14y ago"Fuck VIM" -Richard Stallman
- va_coder 14y agoI didn't know this one: ^X ^L
- pbiggar 14y agoI used vim for about 10 years before I finally gave up, and it was completion that did it for me. It was just so ludicrously hard to customize vim (writing vimscript - although the python integration wasn't much better) that it hurt. I was held back by not being able to customize it, and the fact that I couldn't get any better completion than ctags was insane. My startup Circle is written in Clojure, so I was pretty much forced to learn Emacs, and the world is such a nicer place. I really wish I had learned Emacs 5 years ago - with the time I spent mastering and then trying to customize vim, I could have mastered and learned to properly customize emacs.
- johnchristopher 14y agoUsing the article completion method it turns out that I can no longer use <tab> to insert a <tab> since it displays a list of word to be completed. It might be due to my vim configuration but I doubt it (though I am not a vim script expert by any means). Here is a function I found on the web a long time ago and that seems to prevent that problem: inoremap <Tab> <C-R>=MyTabOrComplete()<CR> function MyTabOrComplete() let col = col('.')-1 if !col || getline('.')[col-1] !~ '\k' return "\<tab>" else return "\<C-N>" endif endfunction No idea how it really works, I never investigated. Credits/source: http://www.slideshare.net/andreizm/vim-for-php-programmers-pdf http://www.slideshare.net/andreizm/vim-for-php-programmers-p... slide 44 edit: formating and credits
- ChuckMcM 14y agoWe never saw poetry written about TECO.
- baggers 14y agoThough this doesn't help with the holy wars, I do find it just fantastic that there are two editors that so many find, with an acceptable amount of playing, can be the near perfect tool for their craft. I played with vim first but never quite got a flow going...oddly enough I hit it off almost immediately with emacs, it was still damn confusing but I made much more progress much faster. I'm almost disappointed I didn't fall for Vim as it is always on any server I have to use and emacs muscle memory has only compounded my problem with Vim shortcuts! For those not fancying diving into vim or emacs are there any more traditional IDE's with a way to script new behaviours and have them feel native?
- exDM69 14y agoNice overview of vim's completion features, but... This article is very incomplete, there are various completion modes. I also don't recommend mapping complete to tab (or even using SuperTab or other completion plugins). Vim has a total of 13 different completion modes (see :help ins-completion), all of which are useful. There's complete on local and global keywords, complete for complete lines or filenames. In particular, this article calls Vim 7's omni complete (^X^O) "syntax aware complete" which it is not. It's a language specific completion, which can complete stuff like members of structs or functions. You need your language specific plugins to be installed. Vim ships with a decent plugin for C and C-like languages, which works if you have a ctags database generated (:help 'tags'). If you want syntax completion, you can map it to user-defined completion (^X^U) like this: set completefunc=syntaxcomplete#Complete It's not particularly useful as such, because syntax complete completes keywords like "for" and "while" which we all have in muscle memory.
- wiradikusuma 14y agoi'm a java IDE user (eclipse, then intellj). in intellij, you can ctrl+w to select word, ctrl+w again to select statement, ctrl+w again to select function, etc. you can also refactor replace all, shown if foo.gif actually exist in img src, ctrl+click to css, shown if a variable (in code/js/css) is unused, hinted if a line can be simplified, etc. can vim do that? if it can not, what's the compelling reason for people like me to use it? (i honestly interested, but wondering if it's worth the effort)
- ohhmaagawd 14y agoI use Intellij (and the derivative editors RubyMine and AppCode) as well. IMO the main advantage of vim is it's instant. No waiting for the IDE to load. IJ takes quite a while to load and you have to have your project set up. Another major advantage of vim is it's available everywhere. SSH to your production server and edit just like you do your code. But I have to say: I much prefer coding in the Jetbrains editors. They offer a UX that can't be matched by vim. They are just smarter, esp for statically typed language. But even dynamic - they are damn good. And you can use VIM key bindings if you like.