Settings

Theme

Why Vi Rocks

why-vi.rocks

56 points by 15DCFA8F 7 years ago · 79 comments

Reader

cwbrandsma 7 years ago

I’ve learned some vi, and emacs, Visual Studio, VS Code, XCode, IntelliJ, and Android Studio.

All the examples listed are pretty uncommon or trivial in any of the other IDEs (aside from the regex part, which is cool, but I never want to be in a place where I have to regex my code...ever). 90% of the time I’m doing simple code maintenance, with an occasional refactoring. And I know devs that swear by vi...they are developing any faster than I am, and I touch my mouse about as much as they do (hardly ever).

My favorite is still Visual Studio with Resharper, worst is XCode.

  • billfruit 7 years ago

    I am writing this from emacs experience (some if not all these features are in vi as well), there are features from emacs that make a real difference in writing programs especially:

    * Unlimited yanking from kill rings: ie pasting text from history of the clipboard.(This is one thing I have most difficulty with when switching from emacs to modern editors)

    * Macro recording and playback : recording an arbitrary set of edit operations and then replaying them any number of times.

    * two or more code frames/windows side by side, even displaying the same file Surprisingly modern IDE guis seems not designed for it, eclipse can do it but clumsily.

    * Remote file editing: use the IDE tools to edit file residing on another computer.

    * Column edits or rectangle edits. Selecting a vertical column or rectangle of text and copying, moving it to another place.

    • max76 7 years ago

      > some if not all these features are in vi as well

      I'm not sure exactly which vim features are also in vi. Vim has been a daily use tool for me since about 2007.

      Vim has really good Macro recording. Vim + Tmux is great for side by side code frames, and there are plugins for showing multiple buffers in one Vim instance. Remote file editing is good with SSH + Vim. Vim has multiple registries for yanking/putting. Vim has column editing functionality.

      Almost anything Emacs does out of the box Vim can do with either a plugin or with an external program pairing. I prefer Vim's keybindings because there are less "chords" (Ctrl-C and Ctrl-V are copy and paste chords, they requiring pressing two buttons at the same time). Too many chords causing my pinky fingers to become tired. Vimscript is a surprisingly powerful language for dealing with text data, but it's cryptic the first decade you are exposed to it.

      EDIT: I'm more interesting in the code people write than the way people write it, but I wanted to share some of my vim knowledge and point of view.

      • nitemice 7 years ago

        Unless I've misunderstood, you can use splits to show multiple buffers in Vim without any plugins.

        • billfruit 7 years ago

          What about manipulating of splits, like converting vertical split to a horizontal split, enabling/disabling synchronized scrolling, etc..

          • logram 7 years ago

            You can do both of those things in vim. I don't mean to be nitpicky, I'm just mentioning in case someone reading this didn't know and uses vim. You can set scrollbind and convert splits (off the top of my head I think it's Cw Ch and Cw Ct).

      • billfruit 7 years ago

        Remote editing, I mean using the local computer's emacs to edit file on the remote computer, where emacs does all the work of fetching and syncing the file (using ftp, ssh etc) back to remote. I think vim can do something similar too.

    • bch 7 years ago

      Friendly reply -

      > Unlimited yanking from kill rings

      vi has named buffers, which aren’t the same thing you’re talking about, but definitely more than a single clipboard

      > Macro recording and playback

      vi can “execute a buffer” which are arbitrary commands, and at least nvi can do automatic substitutions as well in a “dumb macro” sort of way

      > Two or more code frames...

      Same for vi. In nvi it’s :E for vertically stacked or :vsplit for side-by-side. Like emacs, you can even run an interactive shell in a buffer (frame) and cut/copy/paste with another.

      > Remote file editing

      I presume you’re talking Tramp. Not out of the box with nvi, but it interacts with the Unix shell fantastically if you’re lucky enough to be developing in such an env. I’d be surprised if vim doesn’t have a decent Tramp-like feature.

      I think vim does columnar edits, but I’m not a vim user; nvi is out of luck there, unless again one finds a solution punting to the shell - which isn’t the end of the world. But this case I think would disappoint you the most from your feature list (speaking for nvi).

    • cmroanirgo 7 years ago

      All of these features are also in "graphical" editors, despite the claims. M$ had been doing it for decades.

      I remember a friend of mine showing how easy it was to block select in vim. I waited 30 secs or so. I showed him the same in visual c++ (circa 2000s). We then had a "vim-off". eg. Find/replace/regex across a range of things -- using only the keyboard. The best I conceded was how the highlighting of results was probably superior... (sublime text, and vs code are as good as that now)

      I know a lot of people here love vi (and Emacs), but personally, the only command I'm happy to learn is :q (and I presume negative karma for this comment will result) :D

      I always install le for my terminal connections, and fall back to nano where needed. I've been meaning to write a console editor of my own that matches ye-o olde vc++ and visual studio...

      I think there's something in the vi evangelism that I haven't quite grasped... otherwise I'm sure I'd have been using it for decades.

      edit: not sure about the yank/ clipboard history... but that's part of the os in gui world.

    • flukus 7 years ago

      > two or more code frames/windows side by side, even displaying the same file Surprisingly modern IDE guis seems not designed for it, eclipse can do it but clumsily.

      It's embarrassing how much better emacs/vim/tmux/others are at windowing compared to supposedly advanced IDE's built on advanced windowing systems.

  • org3432 7 years ago

    > And I know devs that swear by vi...they are developing any faster than I am

    I hear about this from time to time, but have never seen it people do it successfully first hand, what I do see is silly mistakes in their checkins; incomplete variable renames, formatting is off, syntax errors, switching between browsers and their code while looking at manuals, or other obvious mistakes that can be caught inline by IDEs while you type.

    • foob 7 years ago

      I think this says more about those developers than it does about Vim. In my experience, people who are highly effective at programming in Vim typically have it configured in such a way that it offers language-specific functionality comparable to any IDE. You don't get that out of the box (unless you use a Vim distro), but you are able to personalize it to your workflow more exactly than you can with an IDE. A junior developer probably isn't going to be more effective in Vim than an IDE, but a very senior developer easily could be. And somebody who is committing code with lots of obvious errors is almost by definition not a senior developer in my book, regardless of whether they're programming in nano, Vim, or an IDE.

    • nouveaux 7 years ago

      I see the same thing from people using vscode. Its safe to say that those who know their tools well will be more productive than those who do not.

      • org3432 7 years ago

        I think VS Code has the same issues I see it with that too, I haven't noticed it as much with VisualStudio and JetBrains' IDEs. Agree completely on knowing how to use your tools, it's like a carpenter showing up for work with a rusty hand saw and thinking they're going to make a house with it.

    • colordrops 7 years ago

      Hmm, I've got syntax/compile checking, linting, automatic code formatting and generation, and code completion based on context in vim right now. I don't see how any of the problems you mention are vim specific.

      • org3432 7 years ago

        What packages are you using and what language out of curiosity?

        • colordrops 7 years ago

          C++ and JavaScript. I've got about 60 plugins installed and a highly configured vimrc. Some of the important ones:

          w0rp/ale

          junegun/fzf

          junegun/fzf.vim

          majutsushi/tagbar

          scrooloose/nerdtree

          jistr/vim-nerdtree-tabs

          erahhal/nerdtree-ack

          tpope/vim-commentary

          joegesualdo/jsdoc.vim

          Raimondi/delimitMate

          tpope/vim-surround

          vim-scripts/AutoComplPop

          Shougo/deoplete.nvim

          carlitux/deoplete-ternjs

          marijnh/tern_for_vim

          Rip-Rip/clang_complete

          SirVer/ultisnips

          tpope/vim-fugitive

          mhinz/vim-signify

          vim-scripts/DirDiff.vim

          sheerun/vim-polyglot

          pangloss/vim-javascript

          vim-utils/vim-man

          • org3432 7 years ago

            That's a useful list, thanks for sharing. What would be useful is if there was just a distribution of Vim that just had everything included for a specific language. Or at least a base and then a way to discover and add more from within Vim.

            • colordrops 7 years ago

              There are definitely distributions, for instance SpaceVim. I've got my own configs shared in GitHub but I'd prefer not to reveal my identity. I'm sure there are plenty to be found.

            • JetSpiegel 7 years ago

              There are plugins made for a language, but they are usually bloated, it's cleaner to compose smaller plugins to achieve the same outcome.

              Usually vim configs are like toothbrushes, everyone uses a special one. Here's mine that includes dozens of plugins, some of them repeated from colordrops' list:

              https://gitlab.com/somini/dotnvim

    • scruple 7 years ago

      Most of the things you're describing as editor issues would be caught by formatters and linters and a test suite, so I have a hard time understanding where you're coming from with this.

      edit/ A word.

      • org3432 7 years ago

        This is a good point actually, the sooner you catch the mistake the quicker you can correct it. So once it gets down the line, even in a pre-commit, you're just wasting your own time on getting the feedback. It's not always possible to get it sooner of course.

        • scruple 7 years ago

          Yep. I have formatters and linters run on save in vim (of course, any editor or IDE can handle this) and the linters render their results in vim, as well. I also use vim-dispatch [0] to handle running builds and test suites asynchronously, but I don't run any auto commands for that, instead preferring to kick those tasks off with a keystroke.

          My workflow is crafted in a way to give me, what I have found to be, the tightest feedback loop that I can possibly get with the languages and frameworks and tooling that I use at work. I find that vim, out of every other editor or IDE that I've ever used, is set apart in it's ability to deliver on that requirement.

          [0]: https://github.com/tpope/vim-dispatch

  • brandonmenc 7 years ago

    At any rate, it's a good thing that literally every single IDE can do search and replace with regexes.

  • thethirdone 7 years ago

    > but I never want to be in a place where I have to regex my code...ever).

    I use regex search and replace fairly often; why are you so opposed to it?

    If I need to change $t1 into t1 in a group of 6 lines (something I did today), its pretty easy to just make that replacement automatically. Doing it by hand would just take longer.

    > ... with an occasional refactoring

    That's exactly what I use the feature for.

    • mypalmike 7 years ago

      In a refactoring IDE, you never risk overmatching or under-scoping. You just rename the syntactic object and it's renamed exactly where it needs to be, including possibly on the filesystem and in git.

      • thethirdone 7 years ago

        Importantly, you don't get that safety in comments or strings.

        The nice thing about replacing via vim is that you can restrict it to a selected block which also gives you a type of safety.

        Particularly for the situation I used replacement today, an IDE couldn't make it better and doing it only on a range was helpful.

        • mypalmike 7 years ago

          Fair enough. An IDE will generally present you with matching strings on a project level and let you select which ones to change. But if you know where to look, replace within selection seems useful. Apparently IntelliJ supports that, but I've never thought to use it.

  • byte1918 7 years ago

    If you're still working with VS & Resharper and your projects allow you to, have a look at Rider from JetBrains. It supports the same color scheme & hotkeys as VS + Resharper out of the box so the transition is very smooth, you'll be productive in minutes after installing it. Also, if you were using VsVim, you can use IdeaVim for Rider and in addition you can install KJump plugin (it's what easy-motion is for vim). Since setting this up, rider & webstorm have become my favorite developer tools I have ever worked with and I feel they are superior to VS & VSCode (the things I was using before).

  • tacomplain 7 years ago

    First, I also had trouble with XCode. About the regex in vi: there is a technique of writing/maintaining code based on substitutions instead of inserting/deleting. It can be very powerful but you have to "write" your code thinking about the patterns and maintaining some kind of structure. I am not saying that it is good or recommended. It's interesting. I coded for like 5 years like that. I was maintaining a codebase completely solo. When working with a not very synchronized team or having tools like resharp or omnisharp etc avaliable, I don't think it would pay off.

  • depressed 7 years ago

    Searching with regexes is more likely to be useful when trolling through log or data files than code.

    Even then, the most common cases for me are searching for a string only at the beginning or ending of a line, or only searching for instances that are not part of a larger word.

    • joevandyk 7 years ago

      I search for /def.*partial_name/ frequently when I can’t quite remember what a method is called in Ruby.

adrianrocamora 7 years ago

I've been using Neovim consistently for the last few months and it's a game-changer. Terminals within Neovim that I can paste into/from my Vimwiki files or source files is amazing. It's not very different from a Vim setup and using it with the Qt GUI on Windows gets rid if the issue of having everything close when eventually having to call <C-w>. Meanwhile, in my linux environment it runs like a charm on a terminal.

omaranto 7 years ago

Half of it is "Why standard unix utilities rock".

rococode 7 years ago

IntelliJ with the IdeaVim plugin is my goto editor nowadays. As others have said, I honestly don't find myself using the really fancy features of vim that often. What I do use frequently are basic motions together with yanking, deletions, word movement (w/e/b), marks, indents, centering (zz), page scrolls (ctrl+u/d), and using searches (f and /) to jump around in code quickly.

For those purposes, IdeaVim works just fine, and gives me all the little speed boosts of vim with the added bonus of (in my opinion) a much more robust coding environment. It even makes some functions better; for example, `gd` works super well and nearly instantly in IntelliJ since the definitions are supplied by the IDE's 'Go To Declaration' rather than some hacky vim plugin. Other editors have similarly sufficient vim plugins, e.g. VSCodeVim.

  • foob 7 years ago

    Have they fixed the issues with where the cursor ends up after certain operations? It's been a couple of years since I've used it, so I can't give an explicit example, but there were multiple common operations where the cursor would end up in a different location afterwards than it does in vim. This was really difficult for me because I still used vim a lot for other things, and it felt like it was actively eroding my muscle memory to use two conflicting implementations.

    • lukecameron 7 years ago

      I use IdeaVim at my day job and can confirm it's gotten better. There are still some rough edges, especially around handling movements like L, M, and H which don't always go where you expect them to. And some operations like undo don't play well with the vim commands such as undo.

      And yes, I completely agree about switching between vim and ideavim for different languages, the experience is very different and the sight differences are very noticeable.

    • rococode 7 years ago

      For the most part it does what I want it to do. As the other responder said, undo/redo can occasionally have some issues if you mix them with the IDE's version of those. I also have problems with the tag stack and jumplist (like ctrl+i/o) having serious latency problems so I stick to marks and `` as much as I can. The last thing I have problems with is when the IDE changes your code for you during an action - for example an auto-import when you type out a new class. The repeat action tends to mess up in those cases, trying to redo both your own typing and whatever the IDE did.

      Again, I'm not a power user so to me these are the main issues and they're tolerable. For cursor movements I don't do anything too tricky, and all the movements I'm aware of do what I expect them to do.

umvi 7 years ago

Vim is like Dvorak. The cognitive burden for remembering which key maps to what is high unless you use it 24/7.

  • griffinheart 7 years ago

    Your problem with Vim is that you don't grok vi. [0]

    I agree with you that if you don't use a specialist tool 24/7 you'll be slow, but that is expected vi optimizes for expert users not for novice users.

    In the same way that if I don't use Photoshop and then just want to do something simple in it, it's going to take me a lot of time and am probably going to forget how to do it because I don't use it enough.

    0 - https://stackoverflow.com/questions/1218390/what-is-your-mos...

  • civility 7 years ago

    I have a friend who used to use Vi(m) with his Dvorak keyboard at home, and Emacs with his qwerty keyboard at work. He considered it an exercise for keeping his brain sharp. I don't think he still does it, but maybe.

    Vim on Dvorak is insane, imho.

    • rohansingh 7 years ago

      Why do you feel that Vim on Dvorak is insane?

      • civility 7 years ago

        Motion in Vi is based on treating the home row of the keyboard as arrow keys. H, J, K, and L are left, down, up, and right. They aren't mnemonics, and so scrambling them around (Dvorak) is just doubly confusing.

        • rohansingh 7 years ago

          Oh, huh, never considered that a real issue. I've used Vim on Dvorak for years, and use hljk for motion.

          It's nice that jk are adjacent on Dvorak, and hl are conveniently placed as well.

          • beatgammit 7 years ago

            Can confirm, I use Dvorak and vim without issues. I find myself not using hjkl very often though, since I can usually use another movement to get where I want to go, so it's really not an issue.

  • joevandyk 7 years ago

    Using it 3/2 is probably enough...

  • base698 7 years ago

    It's actually not that hard:

    The formula: number(Optional) action movement

    Examples:

    2 dl - delete two characters right

    dw - delete a word

    yb - copy back a word

    y/foo - copy to the search foo

    4cw - change the next four words

    actions: yank(copy, delete, change)

    movements: /(search), t(til character), f(to character), many many others (l, h, j, k, *, #, T, F)

    Combine as you see fit.

    • nitemice 7 years ago

      `action [number] movement` also works, and makes more sense to my brain.

  • anotherevan 7 years ago

    Does anyone use Vim on a Dvorak keyboard?

    • rgoulter 7 years ago

      I used dvorak for a bit. I didn't remap HJKL, since JK were still beside each other, and H was to the left of L (albeit, not on the same row).

      In terms of transferring Vim 'motor memory' from a qwerty layout to a dvorak layout, IMO it meant focussing more on an added indirection of "which letters" rather than "which fingers where".

    • civility 7 years ago

      Funny you ask. While you were writing, I posted about a friend of mine who did that in a sibling message.

    • phlyingpenguin 7 years ago

      Yeah. It's really not too bad. It's certainly a little bit better if you take the ~4-10 lines to reconfigure a couple of keys. I map dhtn to hjkl and move d to j, n to l. It's pretty natural after that.

    • beatgammit 7 years ago

      I do, and it works well. I tend to use movements other than hjkl for moving around, so that doesn't bother me too much. I don't remap anything, and my config is pretty bare.

    • bjoli 7 years ago

      I did for a long time and I found the switch to be painless. I then replaced most of my daily used software with Emacs.

    • geowwy 7 years ago

      I use vim with colemak.

  • dilyevsky 7 years ago

    I use it 4-8/5. Works out OK

asciimov 7 years ago

Why do I use vi(m)?

* Eclipse - Forced to use this in University in the early aughts. I would say that crashing and clobbering systems was its best feature. You moved your mouse it crashed; thought about saving crash; need an update, now you need to format and clean install windows; want to print, printing works! want to compile, your gonna need to try again after restarting windows...

* SSH - In University we had some awesome terminal servers that were a joy to work with. I could access all my work from anywhere, regardless of how limited my local machine was. Vim was always there, chugging right along.

amanzi 7 years ago

"vi is the de facto standard Unix editor, you find it in every *NIX derived OS"

I was going mention a recent article I heard about that vi was going to be removed from upcoming Ubuntu distributions, but it appears that was an April Fools joke... <insert curmudgeon grumbling here>

veryworried 7 years ago

No mention of vim or neovim?

bgorman 7 years ago

The few times I have encountered nvi, it was just off enough from vim to give me a headache. Somehow it is worse than busybox vi, where I at least know to stick to primitive operations.

ChuckMcM 7 years ago

Since I "grew up" with vi I mostly use vi when using vim, but I do appreciate syntax coloring. I find it easier to scan comments that way and pick out constants.

andrewfromx 7 years ago

i see people struggling, fighting with Intelli-J every day. I wish I could give them vim as a gift. All the extra stuff you think you can't possibly give up you don't need. I'm a professional text file editor. Vim is like playing the piano. I guess what I'm saying is learn to play the piano for real, and don't spend your life in a piano-player-helper IDE thing.

  • greysonp 7 years ago

    Vim is a fantastic text editor, but it is not an IDE replacement. Here's just a few IntelliJ features I use daily that Vim doesn't have: Go to declaration, find usages, rename method/class, change method signature, auto-import, shortcut to override method, easy-to-configure style rules, really good code completion, quick access to javadoc.

    I could keep going. Again, not hating on Vim. I use Vim keybindings in IntelliJ! I just don't think it's the best tool for working in large codebases.

    • perryao 7 years ago

      I think the future on this front is looking pretty bright. I use the awesome vim-go plugin which has support for the features you mentioned. And it's getting better as gopls (the language server) gets finalized. As the Language Server Protocol and the Build Server Protocol develop, I think we'll start to see Vim more closely resemble an IDE for many languages.

      I use Vim because I love the history behind it and love knowing that investing my time in learning it is unlikely ever to go to waste. It's a solid editor and also helps keep me as close to understanding the ins and outs of my system and build tools. And for better or worse I just enjoy figuring out the best way to configure things exactly how I want them.

    • 6keZbCECT2uB 7 years ago

      I imagine there are probably IDEs out there with low-friction searching, highlighting, diffing, replacing, block operations, and convenient macros, but I never ran into those features in the IDEs that I've used. I also expect there are probably IDEs out there that don't crash on code bases larger than a GB and code bases which can't be compiled locally, but I haven't used those ones.

      >> Here's just a few IntelliJ features I use daily that Vim doesn't have: vim is intended to work with an operating system. The following assumes C or C++ since that's what I use. Maybe someone will find this list of equivalents useful? 1. Go to declaration: I use ctags which is built into vim. clangd can do better, but I've never bothered. 2. find usages: ctags also has support for this I think. 3. rename method/class: I haven't needed to rename something that wasn't exclusively in one file yet, but I expect clang-rename works well. 4. change method signature: not sure what this does. If it's just changing the declaration of the function, that seems pretty easy. ci( 5. auto-import: This one seems harder to get, but I never noticed it wasn't there. For in-project stuff, I just jump to definition. For standard library stuff, it's standard library. 6. shortcut to override method: I don't do much inheritance, so I never really noticed. This seems pretty easy to do a hack job with a macro and jump to definition. 7. easy-to-configure style rules: clang-format 8. really good code completion: basic autocomplete is built into vim. clangd is probably pretty good, but I don't usually need autocomplete. 9. quick access to javadoc: cppman is pretty good. https://stackoverflow.com/questions/2272759/looking-up-c-doc...

      Maybe the state of tooling for Java isn't as openly accessible outside of an IDE and isn't as good for vim as C++? If using an IDE works well for you, great. I like using vim because it's lightweight, has good support for different file endings and large files, scales to any size code base I've encountered, and it gets out of my way. I feel like it's optimized enough that my brain is the limiter.

    • chimpburger 7 years ago

      Vim was designed for editing _text_. It was not designed for semantic analysis of _code_. The semantic plugins for Vim are hacky addons.

      Having Vim bindings in IntelliJ is indeed the best of both worlds.

    • andrewfromx 7 years ago

      this is _exactly_ my point. Take the plunge. Go IDE-less. Discover how you can play the piano and rename methods yourself with something called "typing" and auto-import is so much fun, it's like a game where I yank and paste the right import from another file. I know it sounds crazy. But at the end of the day I don't fight Intellij but just play music on my keyboard. Disclaimer I was avid eclipse java programmer for years and one day went to vim and never looked back.

  • mda 7 years ago

    Sure, but I bet Intellij is a bit better when it comes to debugging java applications. A good IDE beats the crap out of Vim for a lot of tasks.

    • flukus 7 years ago

      > Sure, but I bet Intellij is a bit better when it comes to debugging java applications.

      I don't know about intelliJ specifically, but a good debugger beats the crap off the limited interface an IDE provides to them. It looks like IntelliJ only offers basic breakpoint/step through, etc. For a quick overview of what you're missing out on checkout "Give me 15 minute and I'll change you min on GDB": https://www.youtube.com/watch?v=PorfLSr3DDI (hopefully the right video, can't check at work)

  • chimpburger 7 years ago

    We have this and it works very well https://github.com/JetBrains/ideavim

    Plain Vim does not have the semantic / refactoring capabilities of a real IDE. This plugin gives the best of both worlds.

ausjke 7 years ago

vim for command line, pycharm for python, webstorm for web, geany for everything else that needs a GUI, works great!!

used vscode for 2 years on and off, finally decided to part away two months ago and bought webstorm instead, the time spent on vscode with all the configuration and plugins and settingsync(which is not reliable) is way more expensive than webstorm's license fee(same as pycharm)

munk-a 7 years ago

There appears to be a small issue with this article, it seems to have confused vi with the widely favored editor nano. It might be good for an editor to fix this omission as I'm sure it was in error. /s

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection