22 ms·
Serious question: I keep seeing Vim thrown up and down like it's the holy grail. I've been using VS Code for two years maybe now, and I don't see how Vim could
by fbnlsr 7y ago
Serious question: I keep seeing Vim thrown up and down like it's the holy grail. I've been using VS Code for two years maybe now, and I don't see how Vim could help me be a better/more productive coder. What am I missing?
- kamek 7y agoTo put it simply, it's just a very efficient way to manipulate text with a keyboard. Once you get accustomed to it, writing and especially modifying text without it seems laborious, almost like you're writing with your wrong hand. The problem is, the opposite is true until you reach some level of proficiency. Until then, vim is hard to get used to. I know I haven't provided a concrete answer, but many blog posts have been written on the matter. I personally started learning vim by running through vimtutor once a day as part of a New Year's resolution about ten years ago.
- 02abhishekjain 7y agoThe vim key bindings can help you write code faster and more efficiently. Try the vim plugin for vscode. It's pretty good.
- criddell 7y agoI'm always skeptical of this claim (and yes I do know vim fairly well). Programming isn't that much typing. For every burst of typing there's probably an equally long or longer lull where you are leaning back and looking at the screen or sketching something out on paper. If your productivity is limited by how fast you can type then you are either a far, far better programmer than most people or your skills are being under utilized.
- xwdv 7y agoVim commands are more than just typing. It’s searching, deleting, replacing, selecting, moving entire lines of code. I can get to any location in a massive codebase within seconds. I can drop the cursor to any character I see damn near instantly. I can construct entire macros on the fly and repeat them endlessly until I’m satisfied and destroy repetitive tasks. I can move entire sections of code to anywhere else I please, just tell the line numbers and it’s done. I don’t even have to open the files. When you’re working really fast in Vim it’s easy to get a high from the amount of code you are slicing through. In short, classical editors are like a ball and chain for developers trying to get shit done, and I cringe every time I see a developer using a mouse or trackpad while working. It’s so slow, so inefficient, I can’t stand it anymore. I need vim-like shortcuts in every application I use.
- criddell 7y agoYou say it's more than just typing but then you go on to describe a bunch of stuff that's essentially just typing. I think just about any modern programmer's editor can do all the things you describe. I work most of the day in Visual Studio and I know it can do all that. For programming I think vim is handicapped somewhat because it doesn't "understand" what it's working on.
- tcoff91 7y agoThe great thing about vim is every IDE has a plug-in to emulate it. Why would I learn separate shortcuts for android studio and vscode when I can just install vim plugins?
- OGWhales 7y agoI'm trying to learn vim, thanks to this thread. How do I "drop the cursor to any character I see damn near instantly." I'm digging moving things around quickly and all that. But I don't know how to get my cursor where I want it quickly.
- tcoff91 7y agoFirst of all, I recommend that you turn on relative line numbers AND also normal line numbers. This means that the line the cursor is on will show the absolute line number, but lines above and below will show how many lines away they are from the current line. :set relativenumber :set number This makes it really easy to get to the line you are looking at. You look at the relative line number, see it's 9 lines above, so you start out with pressing 9k to jump up 9 lines. Let's say you're trying to get to an instance of the 'a' character. The character is to the right of your cursor, so you press fa to jump to the next instance of the 'a' character. However, it turns out that there are multiple instances of the 'a' character before the one you are trying to get to. So you repeatedly press ; to keep going to the next 'a' character until you get to the one you want. You've accidentally passed the one you want, so you press , to go back one. So all together you something like 9kfa;; Also related to the f motion are the F, t, and T motions. I use the t motion all the time. t and T are like f and F but they put you on the character before the one you specify. Very useful for jumping to the first character before the next parentheses and things like that. purely for putting the cursor exactly where you want it there are more powerful things like the emacs acejump plugin or easymotion for vim but they aren't all that necessary IMO.
- agentwiggles 7y agoIt's not so much typing that Vim helps with, it's _editing_. It's definitely not about raw text entry - it's about thinking things like "hey I want to move these 3 lines up to this spot" and being able to do that with 3 or 4 keystrokes. The reason folks talk about feeling crippled when they use a regular editor is that you get used to things like `f(` to take you to the front of some function's arg list, or `ci{` to quickly change some block of code.
- criddell 7y ago> being able to do that with 3 or 4 keystrokes. I get that. My point is that I decide to move that chunk of code after looking at the screen for 4 minutes so it doesn't matter if it's 3 or 4 keystrokes or 5 or 6. Once you know your editor well, you aren't thinking about the keystrokes anyway. It becomes entirely automatic. There are lots of editor operations that I couldn't tell you what the keystrokes actually are without sitting at a keyboard and doing it.
- deleted 7y ago[deleted]
- buboard 7y agoit's also a different "way" of working with text: it feels like photoshop, or a game, with the keyboard being your joystick. The command keystrokes are as compressed as can be, and having regexps literally at your fingertips all the time helps maximize their benefit.
- atonse 7y agoThis is how I explain VIM to people (although I used to use it full time, I now use Atom with the VIM plugin): Most of what programmers do is a lot of navigation and text manipulation correct? In normal scenarios, what keys are available to us to do that? Just the arrow keys and modifiers (Ctrl, Alt, Command). But what if we had essentially the entire keyboard available to us for either text manipulation or navigation? We could move around or manipulate text in more efficient ways because we have more keys available to us to do different things (like say "delete until the next closed parenthesis" rather than control shift right-arrow 20 times). That's why VIM is useful for programmers or anyone who manipulates plain text all day.
- shantly 7y ago> Most of what programmers do is a lot of navigation and text manipulation correct? Possibly I'm a terrible programmer, but most of what I do is thinking and looking shit up. Entering or modifying code, and navigating non-linearly within one file is like... a couple percent of what I do on an average day? Maybe 5% tops? Some days it may get as high as 20% of my time. Maybe. [EDIT] add "communicating", broadly, to the list of things I do a lot of at work that's not editing code.
- benji-york 7y agoYes and no. Feedback cycles are important. It's better for a test to fail than to notice a bug in production. It's also better for you to be able to get that thought from your head to the file in 3 seconds instead of 10.
- KlayySOC 7y agoDoesn't a modern IDE with context aware autocomplete help more with that than slightly faster text editing? Perhaps it also depends on what kind of development you're doing
- bloopernova 7y agovim has its roots in a time when ed was widely used on teletype style user interfaces. The idea was that you didn't have a continuously-updating screen, so conservation of keystrokes and screen updates was very important. It just so happens that this paradigm (which is a much-maligned word!) is still useful today. You interact with text in a couple of different ways, which vim maps onto "modes". You type in text, you select text, and you transform text. Insert mode, where you type in text, is how most editors work these days. Let's look at an example, I hope I can do this justice: You've been asked to refactor and update some code. In vim, you open up the right file and you hit '}' a few times to jump down "paragraphs" to get to the right spot to add your code. You hit 'i' to enter insert mode, then type in the extra class methods or whatever you need. Once done typing, you hit escape to exit insert mode. Now you have to remove some methods, so you type '/' to search, followed by the method name, then hit enter until you find the right part of the code. You hit '^' to go to the beginning of the line, then you hit 'd}'. That's the combination of an action 'd' and movement '}'. That removes up to the next blank line. Now you need to update places within this file that reference that method, and update them to the new method you added. You type ':%s/productComponent/productExponent/gc' which is a search and replace, 'g'lobally with 'c'onfirmation. Once the changes are made, you type ':wq' to write the file and exit out of vim. Your consulting firm charge the client $50,000. And your hands didn't leave the keyboard to mess with the mouse. Think of vim like a computer game where you have to learn a bunch of moves, or a simulator where you have to learn a lot of key combos to control a spaceship or aeroplane. I hope that helped, I don't advocate trying to jump in and replace vscode with vim immediately. But definitely install vim and try some tutorials and experiment with your normal workflows to see if you feel it is a good match to your keyboard usage/style.
- Keloo 7y ago> I keep seeing Vim thrown up and down like it's the holy grail. It's not. People tend to be religious about their choices, you can achieve the same result in any editor. Also most likely the bottleneck in your productivity is not the speed at which you manipulate text. Anyway I will highlight few things that I consider great about vim. 1. It's more about consistency. (vim shortcuts are used in a lot of other places, ex: linux commands like `less`, `screen` etc.., tmux or other pane manager, etc..) When you learn linux you start to get a feeling about it, at some point you enter a command you somehow magically know the shortcuts to navigate/close/search inside there, Vim feels like a complementary thing to the whole linux environment knowledge. 2. It is everywhere! You need 0 time to prepare your work environment if you switch your job/workstation, and you also don't need to exit the remote machine/datacenter to write your stuff. You basically ssh into the machine[s]/datacenter and there you go, at the end of you day you just detach from the session, go home, and next day attach back and continue, all the commands, fancy log searches, processes monitoring, everything is there still running and waiting for you. P.S. I also use VS Code sometimes especially for pet projects.
- NotATroll 7y ago> What am I missing? Touching your mouse less. Might sound weird, but that's honestly my main reason for learning modal editing and emacs with evil. Less flip flopping between mouse and keyboard might not be "more productive", but it's more comfortable. And beneath that you start to find better fuzzy project searching with tools like ripgrep, an easier time navigating your project, powerful in-file movement commands, etc. I'm mostly an emacs evil user, so I also have workspaces, projectile, magit, and a whole host of other extremely powerful tools. And I don't really lose out on much wrt code completion, or other functionalities you normally get from an IDE. Since I can use the same language servers you would use in vscode. That's not to say there aren't things that suck though. Emacs in particular isn't for someone that's unwilling to make changes to their config.
- hombre_fatal 7y agoimo, the best parts of Vim are its shortcuts which is why I am happy with only Vim-like keybindings in other apps and don't need them to impl the whole kitchen sink. For example, right now, how do you make a blank line above your cursor and move your cursor there? Do you maybe go ctrl-a to move the cursor to the front of the current line, carriage return to move the current line own, then press up-arrow to move your cursor to the new, empty line? In Vim, it's just capital O. lower-case o to create an empty line below you and move your cursor there. And I could go on for all sorts of simple tasks that have most people reaching for their mouse. Entry-level Vim keybindings just make these basic tasks more pleasant. I got pretty hard-core into Vim when I was in uni and had time to care and credentialize in Vim. Nowadays, I'm switching between so many editors that I'm happy just using basic Vim keybindings.
- KlayySOC 7y agoMaybe I'm missing something, but wouldn't ctrla+a select all text? To add a newline above, I just press home and enter. For newline below end and enter. The keys are right next to each other. Vim doesn't seem more convenient for this case
- stjohnswarts 7y agomore things are available from the home row than with typical windows editor keystrokes; less pinky and more big 3 finger locations than in your typical windows editor keyboard shortcuts as well. Also once you get the basics down you can learn more powerful keystroke combinations than you ever imagined on windows text editors.
- flylikeabanana 7y ago"Your problem with vim is that you don't grok vi" A perennial answer to this question: https://gist.github.com/nifl/1178878 https://gist.github.com/nifl/1178878
- weaksauce 7y agoTry the vim extension in vscode. It’s pretty good for about 75% of vim. Definitely good enough to be useful.
- newman8r 7y agoIf you're just coding, you're not going to have as much use for it as someone who spends a considerable amount of time in a terminal - but at that point it becomes a vital skill. Still, I always use vim plugins in my IDE, it's just not as useful there, but it can save a small amount of time depending on your level of vim skills.
- stjohnswarts 7y agoI use vs code with the vim plugin and it's a happy medium. It's certainly not Vim but it suffices.
- Liron 7y agoI recommend VS Code plus install the extension for vim key bindings