9 ms·
Does anyone have a good video comparing vim speed coding vs vscode using built in editor features? I’ve been using vscode for years and the YouTube videos that
by ricksharp 6y ago
Does anyone have a good video comparing vim speed coding vs vscode using built in editor features?
I’ve been using vscode for years and the YouTube videos that demo vim features are shallow (like how to enter a blank line - really?). I can do the same thing I have seen in vim videos without memorizing a bunch of strange key bindings all while being able to edit code instantly without changing modes.
I would love to see a fair comparison between someone using vim at 100% and someone using vscode at 100%.
Of course some vscode shortcuts might not be fair (like F12 to jump to definition, F2 to rename every usage, etc.)
But even in raw editing:
With vscode, I can do multi-line editing, I can navigate quickly, jump to specific words, etc all very fast.
If there is no video like this, would anyone be interested in a race?
- cat199 6y agocopy 10 lines from the current position into buffer q, go to the start of function jnk, copy 5 lines into buffer w, jump to line 10, paste contents of q, contents of w, and contents of q sequentially one after the other: "q10yy /jnk "w5yy 10G "qp "wp "qp now, go to the start of the document and indent the next 20 lines by 10 spaces: 0G .,+20s:^: : ok great, now find JUNK and replace 'a1' with 'A1' in the 15 lines that follow: /JUNK .,+15s/a1/A1/g probably not as efficient for multi-file refactoring, but for raw 'drag race' style text munging, everything is there, loaded in muscle memory, and under the home row of your keyboard so you don't have to lift your hands at all.
- lostmsu 6y ago> now find JUNK and replace 'a1' with 'A1' in the 15 lines that follow The real scenario is usually to replace, for example, in a function block. How do you do that? Counting function lines seems like a non-starter.
- jcranmer 6y agoHighlighting the initial { of a function and then typing 'va}' ('v' for entering visual mode, and 'a}' moves to the matching close brace. Similar commands work the [], (), and <> pairs) selects the entire function body. From there, a regular s command will operate on the entire selected text.
- joatmon-snoo 6y agoMine is v% :)
- tvb12 6y agoIf the language uses curly braces to define blocks, it's easier: ciB. Parentheses are easy as well: cib. Otherwise, I'm not sure there's a good solution currently. You can substitute by indentation with a plugin (https://github.com/kana/vim-textobj-indent/blob/master/doc/textobj-indent.txt https://github.com/kana/vim-textobj-indent/blob/master/doc/t...). For Lua, I usually do c/end<enter>. I believe this is an area where treesitter can help, so I'm looking forward to Neovim's integration.
- alwillis 6y agoYou know these aren’t new issues, right? Vim has been around since 1991 and back to 1976 from Bill Joy’s editor. Of course Vim can replace a function block easily and has been able to do so for decades.
- ricksharp 6y agoThank you for that example! Just thinking out loud how to do that in vscode for comparison: - I don’t think repeating actions a specific number of times makes sense in most use cases. Counting 10 lines would take longer than doing shift up/down n times (which would be exact with feedback) to select the desired lines. - Multiple Copy Paste buffers sounds interesting, I might look up a vscode extension for that. (Had a copy paste queue in Visual Studio but it would break sometimes and would lose something important). - go to start of function jnk, there are many ways to do that in vscode. Ctrl+f jnk enter would be one. - Goto start of document is Ctrl+Home - Indent 20 lines by 10 spaces, could do Alt+PageDown, then up/down to get to the right place (without counting or caring that it is exactly 20 lines), then with multi-line insertions could space,tab, etc. That operation would probably justify mouse usage though, in which you simply hold alt, drag ~20 columns/~10 cells and hit space - which itself would be faster than counting 20 lines. - find junk: ctrl+f junk enter - select 15 lines (shift+page down,up/down to adjust) I can preview I have selected the correct area, other possibilities to select current function, etc. - Ctrl+h to replace, a1 tab A1 Alt+L Enter - of course in most cases, I am renaming a symbol, so “F2 A 1 Enter“ would do I think the reality is that counts are not known before hand, so being able to increment/decrement with visual feedback is perhaps faster than a miscount, but I’d have to see it to know. Anyway, thanks for the detailed examples! I can certainly see how it would be powerful if committed to muscle memory, but even with vscode there are many shortcuts I don’t use because of formed habits.
- MAGZine 6y agoI have a plug-in installed in vim and vscode (and ilellij) that provide me with relative line numbers in addition to absolute line numbers. So, the current active line might display "353" in the gutters for the 353rd line. Both the line above and below are 1. The next lines above and below are 2. And so on. There is never any "counting lines". If I need line's number, I can do a quick addition/substraction in my head or j/k $offset to see the other line's absolute number. I can do line-based operations a lot faster than shift-tapping or click-dragging, with exact precision because my editor has been customized to provide the data I need. Eventually you get pretty good at estimating line numbers and character columns too.
- 6y ago
- ricksharp 6y agoOk, also am curious about multi-insertion with cntr-left/right that vscode does: For example, let’s say I have a json object with variety of field names, one per line and I want to remove the quotes. With vscode, I can alt select all lines, Home Ctrl+right del cntl+right del. The trick is the field names are different length, does vim have multi-edit with the ability to navigate relative to each insertion point? Edit: Here is a good video example (https://youtu.be/iomWEDMBlcE https://youtu.be/iomWEDMBlcE) Can vim do something like that?
- stewbrew 6y agoI vaguely remember there is a plugin that does multi line edits - what I never found useful. I personally would rather use :s (search-replace) for that. Regexp is your friend.
- dhmiller 6y agoThere are things that vim does better. There are things that VS Code does better. There are things that Visual Studio does better. You can memorize all sorts of things about your particular editor of choice and you will be more efficient and effective in that editor. If I wanted to cherry pick examples of what vim does better, I could start all of them with, "first ssh into a random server." What makes vim great is that it has a tremendous number of features and is available nearly everywhere. Can VS Code do that?
- imtringued 6y agosshing into a server invalidates all the time you spent on customizing your local vim.
- alwillis 6y agoIf you’re on your machine, you can do all of your stuff because you can edit files remotely from within Vim using SSH as the transport: http://usevim.com/2012/03/16/editing-remote-files http://usevim.com/2012/03/16/editing-remote-files If you’re on a new machine, you can grab your dotfile repo from wherever you keep it—like GitHub for example—and you’ve got your complete config, since there just text files. Takes 5 minutes. But even plain vanilla Vim is more than enough for many tasks on a new Unix/Linux box.
- CGamesPlay 6y agoI find it interesting how we use vim so differently. I'd never type "10yy", I'd use "y9j". I never use "10G", I use ":10<CR>" (<CR> = enter for those not familiar). Similarly, "0G" is "gg" for me. Call me a notepad user, but that whole second snippet for me would be "ggV19j>" followed by "." until things lined up correctly. Similarly, the third would have been "V14j:s/a1/A1/g". Nit pick: "q selects register q. A buffer is a different thing.
- cat199 6y agoyep - probably a few ways to do things and I might not be doing the cleanest, just the way I learned/figgured it out
- tomgis 6y ago> I can do the same thing I have seen in vim videos without memorizing a bunch of strange key bindings you totally can! I could talk for a while about customization and ctags to address some other points you made but at the end of the day its a text editor, vim and vscode are both text editors. it sounds like you really like using vscode so you should stick with it, I really love vim and it works really well for me, and my boss loves using a near vanilla sublimetext 2 install. programming will never be about typing and editing speed but being comfortable with your development environment and hopefully even enjoying it is very important.
- city41 6y agoJump to definition and rename every usage are really handled by the language server. Vim supports language servers quite well. I do both those commands in vim all the time. And vim complements them with (book)marks, return to last edit, etc.
- spekcular 6y agoI've found keyboard-only vim is much slower than a mouse for editing papers, because the edits are often random-access and vim isn't great at that. You also can't use SyncTeX (which is amazing) without a mouse.
- Lio 6y agoWhy would you use vim keyboard only since vim supports using a mouse in the terminal? It even supports using a mouse over ssh. I don’t know SyncTex so can’t comment on that.
- goalieca 6y agoVim can jump to definitions and stuff too. It integrates with ctags. It can also do code completion and everything else. I have it bound to clang-format with ctrl-k.
- RMPR 6y agoJust feel the urge to mention cscope which is ctags on steroids
- joelthelion 6y agoAnd LSP is yet SO MUCH better
- RMPR 6y agoHeard good things about it, but I'm on an endeavour to learn how to do things with Vanilla Vim first to avoid abusing my use of plug ins for things Vim can handle gracefully ootb. Now you're the creator of autojump, I just want to say your software is definitely a time saver, especially with this https://github.com/fdw/ranger-autojump https://github.com/fdw/ranger-autojump, keep up with the great work.
- joelthelion 6y agoI'm with you with avoiding too many plugins. But LSP is not just another plugin, it's the standard for languages to implement IDE support. I find it hard to justify not using it if you're doing serious software development (depending on the language of course). Thanks for the kind words on autojump :) I'm no longer involved with the project, but I feel the general idea is still relevant.
- jtr1 6y agoBetween the awkward file navigation and the feeling of building my own editor from the ground up, I just never found it worthwhile to fully commit to Vim. So I work in VSCode in my day job. What I did take from those efforts, though, was Vim's text navigation key bindings. They are a joy to use and most text editors have some sort of emulator for them. The beauty is in the chording, almost all of which maps to easily remembered mnemonics. Delete everything between quotes? Use di". Change curly brackets to square? Change surround, or cs{[. Once you've gotten used to switching between move and edit modes, you can layer these in bit by bit. At a certain point it becomes second nature and you do feel like you can edit code at the speed of thought. It's a powerful feeling.
- pengaru 6y agoThere's too many little things to mention, they do all add up to be quite significant in the course of programming. Here's a tiny sample of some stuff I use constantly: Move cursor forward word at a time: w ignoring punctuation: W reverse: b B Move cursor to next occurrence of character Z: fZ reverse: FZ Delete forward to next occurrence of character Z: dfZ reverse: dFZ Change forward to next occurrence of character Z: cfZ reverse: cFZ (like delete but leaves in insert mode afterwards) Repeat latest edit from current cursor position: . A lot of the vi commands are composable, as illustrated to some extent above. To search for say the next line starting with void: /^void To delete from the current line up to the next line starting with void: d/^void Note the similarity to dfZ/fZ from above, it's not 100% consistent but most times you can take a chance composing things as you'd expect and things work correctly. There are far more sophisticated things too of course, but I'm not writing a vim tutorial in an HN comment. You can do things like rename a function while rearranging its arguments either file-wide, or on a number of lines, or on an interactively selected visual region, or a section selected similar to d/^void... I presume other editors have such capabilities, but I'm most familiar with vim. In vim the actual renaming and rearranging is done using a regular expression containing backreferences: s/old_func(\([^,]*\), \([^)]*\))/new_func(\2, \1)/ You may constrain that to a subset of lines a variety of ways, and on top of that can suffix a 'c' on the end of the substitution regexp to make it conditional and you'll get a chance to interactively yay/nay the substitution at every match in the considered lines. The conditional suffix is a godsend as it lets you be fast and sloppy with your regexps and just skip the false positives.
- brabel 6y agoHonestly, I can do almost all of these things with any standard editor as well, with standard shortcuts. The ones I can't do directly, I can do via Search/Replace functionality that is also standard in most modern editors. Your example about refactoring a function by using text editing capabilities is actually pretty bad unless you mean Vim can actually parse your programming language and perform the refactoring over all your code-base (not just a single file), like any IDE will do. This list you gave me just convinced me I don't need Vim.
- 6y ago
- gaogao 6y agoOne vim hack I like is multi-line macro application. It's a good fallback in case, as I often forget the syntax for certain things. To facilitate this, I've remapped ctrl-space in visual line mode to apply my `q` macro to every selected line. As an example, say I need to add a comma to a bunch of lines. I will record the macro on that line appending a comma to the end, visually select all of the other lines to copy the macro on, and then jam my hotkey to apply the macro. It's often much quicker than reaching for a regex for short segments of code.
- RMPR 6y agoFWIW, your particular example is doable with vanilla Vim with the same efficiency (with less strain) V<count>j (3) :'<,'>norm A, (8 - The angular brackets are automatically added by vim) Vs qq (2) A,<ESC> (3) q (1) V<count>j (3) <CTRL><Space> (2)
- ur-whale 6y agoGoogle "vim golf"
- macromaniac 6y agoHere's a video of some more advanced vim features I threw together. I'd be surprised if you can do this using e.g. vanilla vscode https://www.youtube.com/watch?v=UDGG3hK4Bg8 https://www.youtube.com/watch?v=UDGG3hK4Bg8 Its a simplified version of a problem from work a while ago where we had to generate ui from lots of csv files. The last dev on it was taking weeks, but with vim I was able to come in and finish the boilerplate instantly. (We were commited to non-dynamic ui at that point, I think I made the right play especially with how we ended up using it). Vim is, in my opinion, inferior to an ide or a good text editor, but if you have it as a plugin you get the best of both worlds and vim suddenly can do... basically anything you can think of. Like here's putting a breakpoint on every line in a file https://imgur.com/SFhlEr7 https://imgur.com/SFhlEr7 The best part of vim in an ide is when you're pair programming and you do something fancy, and your friend says "Wait, go back, howd you do that??"
- zoid_ 6y agoNice vim demo on youtube, how does the sequenced numbering work? Can vim increment a number without any plugins?
- alwillis 6y agoYes.
- macromaniac 6y agoYa, basically go up, grab number, go down, paste number, increment number, go down, repeat 50 times. Needed for generating xaml that had row and column #s from the csv, interestingly excel could gen the code too relatively quickly.
- ricksharp 6y agoThat’s pretty cool. It seemed a bit slow creating the “macro” but pretty cool to see it run through all the lines. The way I would do that in vscode would be with a multi-edit, but it would get iffy at that many lines. I‘ll record a video doing the same for comparison tomorrow. This makes me wish there was a site for recording challenges like this where developers could race using their favorite tools. Vim vs VScode would be an amazing way to learn tips from experts on both sides.
- spupy 6y agoThere's no point in comparing them, in my opinion. VS Code is a tool for programming; I would call it an IDE but I 'm not very familiar with the app. Vim is still "just an editor". You can still use it for programming (not just coding bash scripts), but that's making your life harder than it needs to be. In my experience the amazing text editing features of vim are only very rarely useful in a software developer's work. I feel the same about multiline editing though. And Vim has amazing text editing features, but severely lacking code editing features.
- maxnoe 6y agoMy (neo)vim can do more than vs code in default config. Both support plugins, so the possibilities are basically endless
- Lio 6y agoIf you care for them vim has access to many of the same features as VSCode via LSP and the same plugins that VSCode uses. Why would one be suitable for programming but not the other? It just comes down to UI preference and whether you want to configure things yourself or not.
- jng 6y agoHere's my best take at this so far, I wrote it in 2007: Why, oh WHY, do those #?@! nutheads use vi? http://www.viemu.com/a-why-vi-vim.html http://www.viemu.com/a-why-vi-vim.html
- funcDropShadow 6y agoThis post has been my enlightenment about modal editing. Thank you for this excellent piece. And I've referred dozens of people to it after me.
- jng 6y agoMy pleasure :)