86 points · by chdir · 11y ago · 126 comments
Throughout the learning process one thing I observed was that, its just not enough to read about a cool article about Vim and leave it there. I would keep repeating the sequence of actions mentioned in the article atleast ten times every day and would find some usage for it during programming. I would intentionally force myself to use it, until at some point, the action I just learnt magically comes in as a replacement for a dumb action I was about to do. At that point I would know I've mastered it.
One of the most common things I use an IDE for is navigation (between files) and vim is not very good at it compared to IDEs, here's why:
* no tabs
* no project structure
* in my IDE (eclipse based or intellij based) I can ctrl-click a class/object/other to navigate into that object's definition
* in my IDE I can search for classnames, I can press ctrl-T to find who inherits from something, ctrl-alt-H to find who uses something etc...
when I find myself actually writing code, it's usually a line or two in each of several files (because modern programming paradigms tell us we should split code as much as possible), or modifying some copy pasted snippet I found on google - so navigation is extremely important even when editing.
beyond that, there are simply some things that help writing code that a text editor cannot do:
* auto-complete(with annotation to tell you what the function variables are)
* debug inside your IDE
* run code-lint, auto-build on typing to detect errors, etc...
* auto refactor (I.E. extract method, move variable, extract class etc...)
* format all your files according to your pre-specified project guideline.
* sharing you IDE configuration with other contributors
* showing when files are/aren't in version control and integrating version control so that you view history in your IDE.
There are probably projects out there where a full-featured text editor is a real game-changer and is worth the days/weeks it'll take to use it intuitively, but I never worked or know anyone who worked on such a project (even when I started projects from scratch);
I do agree that I'm infinitely more productive in an IDE than I ever would be with any plain text editor (e.g. autocomplete-hints, refactoring support, etc etc). After discovering the JetBrains suite of IDE's some years ago, I can't imagine using anything else for application development.
However, the point of vi/Vim is not so much the editor application itself... but rather its keybindings and modal editing approach in the abstract. Those concepts are decoupled from the actual editor, because every major IDE has plugins which make them available in its environment as well. The "IdeaVim" plugin for JetBrains IDE's is amazing, letting you mix-and-match between Vim commands and normal JetBrains shortcuts in a very intuitive way (or at least intuitive if you're familiar with Vim).
If you're happy with your current working environment, then rock on. But if you're fluent with vi/Vim (and it is a significant learning curve), then you can absolutely have the best of both worlds. To me, arguing about whether to use an IDE or an editor is pretty silly. But the question of whether or not to use modal editing and a suite of standard shortcut commands within an IDE is a much more interesting matter.
I don't think that matters so long as you're methodical in your approach to learning it. It's important to master the basics and then add new tools one at a time.
The amazing thing about vim is that each new command can be composed with your existing knowledge set, so just learning what, say, 's' does gives you a whole lot more power.
Also, while the discoverability might suck, the built in manual is just incredible.
Some are present by default.
> no tabs
It does have tabs, they're just called buffers instead(there is something called "tabs" too, but they're not what you expect tabs to be)
> sharing you IDE configuration with other contributors
Sharing your vim configuration is as simple as sharing your .vimrc
With buffers (unless I'm missing something) you need to type a command to list all your 'tabs' and another command to get to the tab in question. Project structure is similar - it's always visible, and you can always see what other files are close by.
I don't think that can be achieved with plugins, though I never knew there were plugins until now.
Do people who use vim regularly install plugins for it?
A nice configuration for Haskell which I often use to bootstrap new machines is haskell-vim-now(https://github.com/begriffs/haskell-vim-now). That includes almost all the features you mention.
There are many packages on GitHub that will install and configure Vim for you with a variety of useful plugins and keyboard shortcuts out of the box--so after the installation is complete, you'll have a fully fledged Vim IDE ready to use.
One of my favorites is Joe Nelson's setup [0]. It's specific to Haskell development, but even if that's not relevant to your use-case, it's a very sleek demonstration of what Vim can do as an IDE--and a good starting point for customizing your setup (i.e. a very clean .vimrc file for inspiration). I use it basically as-is for my default Vim config and as a full IDE. Check out the keyboard shortcuts for quickly switching buffers, Git integration, and the shortcuts for visualizing project structure & quickly navigating files.
This is somehow controversial to some[1] but it never bothered me.
As far as file navigation though, I just use crtlp[2]
-> multiple vim plugins provide really confortable tabs.
* No project structure.
-> plugin. if you want that kind of tree next to your editor. (i.e. Nerdtree)
* in my IDE (eclipse based or intellij based) I can ctrl-click a class/object/other to navigate into that object's definition
-> tag search plugin. Haven't played with it much though.
* in my IDE I can search for classnames, I can press ctrl-T to find who inherits from something, ctrl-alt-H to find who uses something etc...
-> I believe there are some plugins for but here i haven't seen anything good so far.
* auto-complete(with annotation to tell you what the function variables are)
-> you complete me. plugin.
* debug inside your IDE
-> good point. have to wait for Neovim for this - I believe. Installing current WIP version from neovim is on my todolist. ;)
* run code-lint, auto-build on typing to detect errors, etc...
-> syntastic.
* auto refactor (I.E. extract method, move variable, extract class etc...)
-> good point. don't know any good plugin.
* format all your files according to your pre-specified project guideline.
-> plugin.;)
* sharing you IDE configuration with other contributors
-> here truly most IDEs suck. For vim you find lots of shared vimconfig on github.
* showing when files are/aren't in version control and integrating version control so that you view history in your IDE.
-> if you need to do in the editor... there is plugin for that. However, i found git command line is usually find. and for more serious committing I use GitX (L).
>> -> I believe there are some plugins for but here i haven't seen anything good so far.
Language dependent, Go has "Oracle" for example, for finding callers, etc.
> * debug inside your IDE
>> -> good point. have to wait for Neovim for this - I believe. Installing current WIP version from neovim is on my todolist. ;)
Clewn.
> * auto refactor (I.E. extract method, move variable, extract class etc...)
>> -> good point. don't know any good plugin.
Language specific, Go has multiple and lots of people write small bits of script to do this -- but it is a place IDEs are far ahead of Vim.
> * showing when files are/aren't in version control and integrating version control so that you view history in your IDE.
>> -> if you need to do in the editor... there is plugin for that. However, i found git command line is usually find. and for more serious committing I use GitX (L).
Nerdtree & git-nerdtree.
One of my pains was that Vim-the-program was not ready to go, and that configuring or adding plugins to Vim was a real nuisance, and I think due to terminal limitations, Vim-the-program could never have some of the features other programs had.
-No project structure? Well, there is nerdtree. Or a separate terminal window open to the file system which is usually the way I do it.
-Autocomplete with annotation? Nice plugin for that.
-Debug? I'm running in separate terminal window anyway. I can debug there.
-Auto refactor? No thanks. I'd rather do that myself.
-Format according to guidlines? There is probably a plugin, but for the once or twice that happens third party tools work just fine. Don't need that in the editor.
-Sharing your configuration? Very easy. Just copy your .vim and .vimrc files over.
-Showing files in that aren't in version control? Remember my separate terminal window that's open? I don't want everything in the editor. But there is probably a plugin if you really need it.
____________
Here are the advantages: Cost, Ubiquity, works over SSH the same way. Takes two seconds to move my config files and I'm right back in the environment. Plus I know it and it is fast as heck. There probably some others I'm forgetting.
Honestly, it sounds like you haven't taken the time to get to know Vim. And that's ok... if you have something that work for you then no need. But lots of the things you claim are advantages of your setup really aren't.
Check out http://editorconfig.org/
> * no tabs
There actually are tabs, but they probably don't work the way you expect, they are closer to viewports or workspaces, but they are there. You can also use assorted plugins to improve tabs and/or emulate them.
> * no project structure
Not sure I understand this way -- no enforced structure? Neither to IDEs, no tree viewer -- there are bunches of tree based file viewers.
> * in my IDE (eclipse based or intellij based) I can ctrl-click a class/object/other to navigate into that object's definition
This is supported by the tags system in Vim, which depends on ctags. :tselect, C-], lots more -- this exists out of the box.
> * in my IDE I can search for classnames, I can press ctrl-T to find who inherits from something, ctrl-alt-H to find who uses something etc...
This obviously very specific to some language you have in your head, as many of those things don't make sense in some languages. That said, this is supported in various languages by various plugins (In Go, Oracle for example).
> when I find myself actually writing code, it's usually a line or two in each of several files (because modern programming paradigms tell us we should split code as much as possible), or modifying some copy pasted snippet I found on google - so navigation is extremely important even when editing.
Agreed, which is why Vim has so many ways from jump-to-def to jump-to-file to various smart plugins for rails and C and <X>.
> * auto-complete(with annotation to tell you what the function variables are)
Gobs of plugins do this for Vim -- normally language specific and they tend to work rather great.
> * debug inside your IDE
See Clewn, full gdb support integrated with vim.
> * run code-lint, auto-build on typing to detect errors, etc...
Vim has all of that, syntastic will show errors in the left bar as you type, setting things to autorun is trivial, all major languages already have this.
> * auto refactor (I.E. extract method, move variable, extract class etc...)
Language specific (as is your IDE's features, because to do requires understand the language), but this exists in limited form for Go and C++ -- and I am sure others. The level isn't up to major IDEs. That said, many of these things are easily scriptable in vim.
> * format all your files according to your pre-specified project guideline.
Tons of vim support for this, even supporting standard 3rd party like EditorConfig.
> * sharing you IDE configuration with other contributors
I think you will find far more vimrc files shared in the wild than any IDE.
> * showing when files are/aren't in version control and integrating version control so that you view history in your IDE.
Fugitive has great time travel features for flipping through versions of files and seeing differences. Use git-nerdtree to add git status to nerdtree.
Zealots trying to convert unbelievers is plain obnoxious. Your choice of editor isn't a religion so use what you use and I'll use what I use and you don't have to worry that what I'm using isn't what you are.
The author believes that <Technology X> is superior to the alternatives, and wrote a blog post complaining about people who pressure its users to switch away. That's not exactly Jehovah's Witness knocking on your front door to thrust a magazine in your hand. In fact, the conclusion section starts with, "Do whatever you want. Don't learn it if you feel it's too much effort just for nothing.". The gist of this piece doesn't seem to be "converting" anyone. Ironically, it seems to have been inspired by receiving such pressure from others.
Half of Hacker News consists of discussing why all users of last week's fad should abandon it and jump onto this week's fad (e.g. "MySql -> Postgres -> MongoDB -> back to Postgres"... "Ruby -> Scala -> Node -> Go -> Rust -> Julia", etc). If you're looking for obnoxious zealotry, there are plenty of better threads in which to look.
This argument ("Oh I use <insert console based editor> because I can use it on my laptop or via SSH on the server") is fucking stupid.
If you can learn how to use fucking vim or emacs, you can learn how to use configuration management - either through a "full blown" tool like puppet/chef/ansible/etc or through config packages (if you're on debian) or even through plain old shell scripts.
Except when it's not really your call. And you have to poke around files so far down behind God's back through a shared desktop Enterprise VPN IE-only plugin-fest, that you don't even know which way is 127.0.0.1, then you're happy that you have vim on Dear Client's pointlessly supported RHEL boxes by default.
And othertimes, when you want to debug something that only happens on a live/production server.
Editing files on the server live is - in itself - not right or wrong. Doing it as a regular workflow is what's bad.
Oh, and if you're editing system config files for systems administration tasks? That's on the server. As GP said, if you come from a sysadmin background, you're used to using a keyboard-only editor. And Vim sure beats ed.
I agree calling it better than any other editor is erroneous. There is emacs too, but that's about it.
I'd argue with that.
You need type completion because your brain shouldn't worry about whether the method is called `updateBufferFromStorage` or `updateBufferStorage`, it should be focused on writing the best possible code.
I agree with the statement "use the right tool for the job", but people shouldn't diabolize something without knowing why others swear by it. FYI, in most cases we use Vi(m) because it's the fastest text editor available, not an IDE.
Granted if what you are doing is actually editing text then it makes sense to use Vim or Emacs, but I find that I relatively rarely do that.
Emacs is a good Elisp environment. Evil-mode turns it into a good editor :P
It's like getting your head stuffed into a toilet bowl at a boys' boarding school. Afterwards, you feel like part of the gang.
These two things were worth the other inconveniences of ed, IMO, until I discovered automatic tiling window managers...
For vim itself: I have seen friends trying to learn it. I have seen PhDs and postdocs use it. I have seen coworkers use it. The only people who I could see were editing text as fast as friends/PhDs/coworkers using Sublime were my tech leads. The smartest most proficient and effective programmers I have ever met. Everyone else was slower, at times wrestled with the editor (by this I mean that they executed commands and had to redo them because they didn't do what they wanted). I guess the conclusion is that people can learn to use vim as proficiently as Sublime, but most will fail or it will take them years (and I mean 5 or 10 years).
Actually, two of my tech leads, when I showed them some trick in Sublime were like: I should look into this. Maybe I'll just boldly argue that vim is inferior after all :).
Then people started talking about Sublime 3, Atom, and all that editor hotness. I wanted something stable, something I could learn once and be comfortable with it being around for a long time. I had tried Emacs years ago and found it unpleasant, to say the least.
I looked into Vim. It became very addictive but it does take a bit of time to learn. I love the action followed by motion idea. I found the built in tutorial decent as well as Painless Vim to be a decent starting point: https://leanpub.com/painless_vim
About a year into my Vim conversion, I get around decently and love doing the editing stuff. But I do feel that I need to go over tricks and tips again.
So I'm often quite delighted at learning new things with it, even still! And to be frank, I think this is one of the things I most like about vim - even though I've been using it for years, there are still undiscovered treats yet to be revealed to me, over and over. When I discovered cscope integration, some 10 years ago, it was like getting an OS upgrade .. in my editor! :)
I can imagine it to be a little like holding a speech with a stutter. Sure, most of your time is spent on prep. That doesn't make the pauses less annoying when you're actually talking.
But I don't stutter, so maybe that's ridiculous.
However, often we know that we don't know how to properly design something and we start implementing too early. The end result is sth like: 50% coding, 30% testing and the rest is squeezed into testing, deployment and requirements analysis.
Funilly i realized that very early at university, where i had to perform a code exercice while on holidays, but forgot to take my computer with my me. I did it on paper, then typed it when coming back home, and got the best grade.
vi can be a huge speedup doing text manipulation. Programming is not just manipulating test, but manipulating code. An IDE helps me with syntax, completion, extracting/inlining, modifying signatures, refactoring, etc.
A corollary is: if you're making a tool, make sure it's leaps better than the simplest alternative. I have a friend who gauges lasagna at a restaurant against Stouffer's frozen lasagna. Because Stouffer's is delicious and if I'm going to a restaurant and paying a lot, it has to at least be better than something I can easily heat up at home!
Why are you spending such a vast amount of time on something so simple as data structures?
Seriously. It's pretty much a solved problem these days. You should have read enough of other peoples code to see the common patterns, especially in your industry.
I'm serious that if you spend a lot more time on white boards and paper than programming in this day and age, there's something wrong.
I suppose you're just writing boilerplate code, assembling pre coded components within the boundaries of a framework... That's the kind of boring job i usually try to let interns or beginners do, mostly because it's not economically interesting for customers to have that kind of job performed by senior devs/architect ( it does take more time than brain).
We're way past the decades where you had to sit around "thinking" for ages to come up with a data structure. You still loading the program up on cards or something? You saying it is as preposterous as the guy I met a couple of years back who offered to come and design SQL DBs for me. It's just not done any more. That's not how we work any more, that time has past.
In today's world you can prototype up the basics of any complex system in an hour or two and throw it away if it doesn't work. Tests are cheap, it's easy to mock, there's no compilation to worry about. And if you can't look at a problem and immediately see the effective ways you've solved similar problems before, well, you're not as senior dev/architect as you think you are.
You simply sound dated to me.
In particular, the author emphasises that you leave Insert mode as soon as you've stopped typing. When I first started using Vim, I used to spend too much time in Insert mode while moving around using the arrow keys.
What I learned from the article: If you're not positioned on a parenthesis, the `%` command will “scan character by character to the right, until the first one is found, and then moving to the character matching that one”. Until now, I’d always been using one of the `f`, `;`, `T` family of commands to move to a parenthesis or equivalent character. This will be a real time saver.
I've never grasped vim. It was too slow at the time and the extended command set consumed all the free keys I use to have available to do my own macros (eg: 'q' 'g').
I reckon vim grew to be much more than an editor, it is now an editing plataform, capable of so many things, and contains lots of shortcuts / builtins for common text-editing situations.
The article above contains many vim-only commands. For example 'di>' ("delete inner angle-block") doesn't exist on standard vi, neither the '>aB' ("indent a Block").
I have hopes that neovim will sort some of that out -- it makes a certain amount of sense that vim is slow because of some baggage it carries, but I'll admit they aren't very high hopes: I've been using emacs recently.
How funny is that? That I use emacs because vim is too slow!
Indeed, if you're writing lots of code with hardly any newlines (like k lang), you will probably have performance issues with vim.
> It also has terrible defaults
This can vary from distribution-to-distribution. Certainly the default debian setup comes with annoyingly intrusive defaults, some of them used to have an impact on speed. Three settings you probably want in your $HOME/.vimrc on debian: filetype indent off
filetype plugin off
filetype plugin indent off
[this might be obsolete - that config is more than a decade old]I also really wanted vi bindings for navigation in team chat (isn't it the most obvious thing ever?), so that's how we made it work in Kato (https://kato.im/articles/en/power-users/keyboard-control)
"No, they are not dinosaurs who don't want to catch up with the times - the community of vi users just keeps growing: myself, I only got started 2 years ago"
Using batch to write FORTRAN, the editor was a card punch. On the Deck-writers (teletype) and VT100 terminals, I used to write Pascal, Ed was the only choice. Early Linux use forced your hand, Ed (again? NO) or Vi. This is because Emacs is a 30Mb download and where space was a premium. [0] Try using anything but Vi or Ed with Busybox. [1]
So I stick to Vi(m). I can use any cli editor but with much time and effort in Vi usage why change? I can but why?
[0] esr, "A Tale of Five Editors", http://catb.org/~esr/writings/taoup/html/ch13s02.html
[1] grep "emacs" here ~ http://www.busybox.net/downloads/BusyBox.html
Wouldn't it be more useful to have commands for going to expressions, blocks, scopes and other code level structures?
I see vim people suggesting always leaving blank lines around functions, so you may use paragraph shortcuts to move them around. Why?
But I use sublime or some other graphical editor when I am on my own computer.
Also it's gimped without addons which you very much miss when using someone else's machine.
And if they happened to not have compiled with clipboard support, you're in a world of hurt.
I was fortunate to learn vi by rote, in a series of lectures where there was no computer in the room. Yep, copying the likes of ':wq' from the hand-written blackboard to A4 paper, along with all of the other 'handy' commands, some of which such as 'yank' I do not use to this day. This was a whole different way of learning with the notes referred to rather than things getting 'Googled'. Was this a better way to learn vi?
I don't meet so many 'vi' experts these days, if anything I feel embarrassed to be using 'vi' and associated command line tools like 'grep' when everyone else has some auto-completing high-speed IDE instead. I have to 'psr-fix' my code to make it sufficiently elegant. The problem for me is that I can do most things in 'vi' without having to hunt around for menus etc. Therefore, moving to the new is hard for me. In some ways I am like a secretary knowing 'Wordperfect' 25 years ago and unable to adapt to 'MS Word 2.0c' due to the same UI problem and convenience of known tools (Wordperfect, Vim).
I also do not feel that 'vi' works well in a team, people with Mac-gui-loveliness computers just can't edit things on your computer on an ad-hoc basis, some visual editor has to be found just for them.
If you are a vim person then these funny new-fangled 'gui' editors are really dangerous. It is far to easy for the document to end up with mystery 'j' characters added to the first line, ':wq!' added somewhere at the end, maybe with some randon 'ijk's' in the middle. If you are a vim person then every editor should have an 'insert' and 'normal' mode, not just 'insert'. The rest of the world doesn't see that though.
With people that do use 'vim' I have noticed that everyone does things differently. Some people will regularly use a feature that you never use, to make you wonder why you don't know that trick. Life without the correct, personalised '.vimrc' file is also quite hard, however, I have found some of these that others use to be overly 'souped up', for instance the search, I really do not like the search-as-you-type option, old-school is better, where you need to press enter.
So everyone finds their own dialect of 'vim'. Like car drivers, everyone thinks they are a good 'vim driver' apart from those that haven't learnt to drive. And they shouldn't. Amazing that vim is, it is a relic of former times, there are better tools with better 'UX paradigms'. In my field none of the 'programming gods' use 'vim' as they can't get to their productivity levels with it, so they use modern IDE's for their work, retaining enough 'vim' for any server side config file editing.
Turns that many of these (including IDEs like Visual Studio or Eclipse) have add-ons or built-in modes which emulate a useful subset of vim's behaviour.
> Life without the correct, personalised '.vimrc' file is also quite hard
Is it? For server-side work, I have a "light" vimrc of a few lines with sensible settings (status bar, nohidden, expandtab, this kind of thing). It is trivial to recreate if I don't have a copy. I have a longer vimrc and quite a few add-ons, but it's for more specialized work, not really anything I need for editing a remote configuration file.
> In my field none of the 'programming gods' use 'vim' as they can't get to their productivity levels with it, so they use modern IDE's for their work, retaining enough 'vim' for any server side config file editing.
In a large part, it depends on the language you use. Nobody sensible would work on a mid-size Java project in vim.