6 ms·
I constantly find myself duplicate lines in vim (shift+y). You've never had to edit a line that's really similar to another? Or when debugging, I don't want to
by cold_fact 7y ago
I constantly find myself duplicate lines in vim (shift+y). You've never had to edit a line that's really similar to another?
Or when debugging, I don't want to change the old code, so I copy the line, comment it out, and work with the duplicated line.
You've never had to do that?
- mickeyp 7y agoWell, everyone edits things in different ways. The Emacs way of solving a workflow problem is instructing Emacs how to solve it for you. For instance, you mention: 1. Copy the line the cursor (point) is on; 2. Insert the copied line below/above point; 3. Commenting out the line you copied; By the sound of things you do 1 and 2 with a command in Vim and the 3rd option with another command. In Emacs, I would simply program a function to do all 3 and bind it to a key.
- OskarS 7y agoThe point is that "duplicating a line" is a very fundamental building block to other operations, and it should be supported natively. For instance, lets say you have to do several different function calls with only minor differences, you might write it out once and then duplicate a few times, then go in and edit them. "Writing a function for the full change" is simply not a tenable thing to do. "Duplicate a line" is fundamental in the same way that "go to start of line" or "indent this line one more tabstop" is. As someone who has spent years using both Emacs in "Emacs mode", and vim/evil-mode, there's no question to me that the modal vim-style editing is superior to Emacs's. That's not to say that "Emacs mode" is bad: it's far superior to most editing styles. Just not evil/vim :) Don't get me wrong: I adore Emacs, and I use it for hours and hours every day. But if it weren't for evil-mode, I would go back to Vim in a heartbeat.
- TeMPOraL 7y ago> "Writing a function for the full change" is simply not a tenable thing to do. "Duplicate a line" is fundamental in the same way that "go to start of line" or "indent this line one more tabstop" is. So write a function for "duplicate line" and use it from now on. It's very easy to do. Just as it's easy to write function for a full edit. A general algorithm to get one started: 1) Execute the edit you want to reuse. 2) Press C-h l, or M-x view-lossage, to see all the keypresses you made recently, along with elisp commands they executed. 3) You now know all the operations you did. Most of the time, you can recreate the edit by just wrapping them in parens, and then wrapping the whole block with (progn). 4) You're now ready to turn it into a function. Read up on 'defun and 'interactive forms. For best results, check out the documentation for each command you used during edit, via C-h f - some commands are meant for direct usage, and have a (faster, better) variant meant for use from within code; this is usually documented. 5) Tweak your function to make it more general along the dimensions you need, bind it to a key, and now you've just implemented what elsewhere would take a large plugin.
- Rediscover 7y agoI love view-lossage. How often do You use C-x <esc> <esc> which shows elisp for what ya just did? Eg, switch buffer then try it.
- TeMPOraL 7y agoOh, I didn't even know about that! That's great! Also, it reads straight from command-history variable (another thing I didn't know about). You can preview and browse it via C-h v command-history. Or, write your own elisp operating on it (perhaps interactively, by IELM - the elisp REPL).
- w0m 7y agoYou do it because it's so easy :) I say that as a Vim user that duplicates lines constantly. Vim definitely changes your coding patterns; for better or worse because it can be soo frictionless.
- michael-ax 7y agomillions of times. but with magit and a complete disregard for commit messages you can cure yourself of the crud-making habit in an afternoon!