6 ms·
copy 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, conten
by cat199 6y ago
copy 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