4 ms·
Higher precision in intent for many standard operations. These aren't perfectly Vim commands, but from the Vim-like 'evil mode' for emacs, I have some examples
by Fellshard 6y ago
Higher precision in intent for many standard operations. These aren't perfectly Vim commands, but from the Vim-like 'evil mode' for emacs, I have some examples of common idioms I use frequently:
- 'I want to change the name of this variable. <cw> (Change Word)'
- 'I want to copy the contents of this braced block. <yi{> (Yank Inside Matching-braces)'
- 'I want to surround this word in parentheses. <vaws(> (Visual-mode (region selection) Around Word Surround-with Matching-parens)'
You get used to the separate modes fairly quickly. Your existing editor already works that way when switching between 'region' and 'insert' modes; it's just the command mode that throws people off initially. It's not that rough, especially if you have a reasonably placed key to return to command mode.
- fao_ 6y ago> - 'I want to surround this word in parentheses. <vaws(> (Visual-mode (region selection) Around Word Surround-with Matching-parens)' Holy shit, thank you. I've been looking for something like this for half a decade and never found it (I don't even know how I missed it!)
- Fellshard 6y agoI believe Vim-proper needs a plugin for that behaviour, so keep that in mind.
- fao_ 6y agoDo you know what plugin it is? I will try to search for an evil version (Or I could just write my own, but my task list is large and my energy very low these days)
- benjaminogles 6y agohttps://github.com/tpope/vim-surround https://github.com/tpope/vim-surround
- wraithy 6y agoThis is vim-surround by tpope[1]. It does way more than just basic brackets! [1]: https://github.com/tpope/vim-surround https://github.com/tpope/vim-surround
- artificialLimbs 6y agobcw()<Esc>P will do it without plugins.
- mellavora 6y agoysiwb yank-surround-in-word-brackets also does it. If you have https://github.com/tpope/vim-surround/ https://github.com/tpope/vim-surround/ installed.
- Fellshard 6y agoThanks for the translation! I'll keep that around for future reference.
- spectramax 6y agoCould you please explain why we use Yank here? From what I understand yank puts the surround-in-word in a register. But there is nothing surrounding the word! I thought yank was for copying and pasting stuff. I can't understand why ysiwb works :(
- gnubison 6y agoI believe that this is just an arbitrary choice that doesn't collide with other keys and is fairly consistent with the other keybindings — cs for changing delimiters, ds for deleting delimiters, and ys for creating delimiters.
- spectramax 6y agoThanks! That's really thorny. It goes against the grain of composability and logically destructuring the command into verbs and actions and modifiers. They should not overload y for yank. Choose anything else that's not used.