For me, all this talk about "speed and efficiency" has put me off of trying vim for a good while—I thought it was a waste to spend time and effort improving the speed of something that was never a bottleneck to start with.
However I did give vim a try eventually and use it now exclusively, but the reason I like it is comfort. Navigating around and doing operations is sooo much more comfortable now that I don't have to use a mouse or repeated key presses, plus all the many helpful shortcuts it has.
It's not the shortcuts, it's how they work. The thing about vi shortcuts is that they form a composable "language" of sorts, so instead of having to memorize a set of shortcuts for doing specific things, you memorize motions and actions and the rules to compose these.
For example, in another editor you might have ctrl-K to delete a line (dd in vim) , but what about deleting 4 lines? in vim, it's 4dd.
Or you might want to delete from the start of a block to the end... The motion for block in vim is %, so to delete a block, you'd do "d%". Similarly, deletion to the end of the line is d$
In visual block mode (ctrl-v) you can select a bunch of text and apply an action (eg. a simple replace, which would be :s/foo/bar) on only that text.
Even if you just learn a bit at the surface, the free composability of motions with actions makes even classic vi (which doesn't even support arrow keys for moving around) extremely comfortable to use, and most of the time you don't need to twist your hands into uncomfortable chords involving multiple modifier keys.
"Another editor" presumably means Emacs, but isn't Vi vs Emacs dead? In 2017, the argument is really Vi-or-Emacs vs other editors.
In Emacs, deleting four lines is Alt-4 Ctrl-K, usually written M-4 C-K.
One way to delete a whole block (meaning a paragraph?) is M-h Backspace. Deletion to the end of the link is C-K.
Selecting a region is done with C-Space, running a simple replace is then M-% foo bar !
I'm not an expert with Emacs. The most useful function I use is the macros, which saves me learning many other functions. F3 starts macro recording, F4 ends it, then F4 again runs the macro. It's easy to script changes and run them in this way.
Ctrl-K is just what came to mind. I think it works in both nano and emacs, and the mnemonic is "kill"
Emacs is without a doubt superior technology when compared to vim. There are perfectly usable vi clones that run on Emacs, after all. The main benefit vi has over emacs is that it's everywhere (except windows :() in some form, so even on a completely unfamiliar machine away from your highly developed dotfiles, your muscle memory still works to an extent.
The main reason I don't use an Emacs implementation of vi is that muscle memory is really bothersome to retrain, and the differences are enough to disrupt my workflow rather badly when using eg. Spacemacs. I just haven't found the benefits to be significant enough to outweigh the inconvenience of retraining myself.
It's more than keyboard shortcuts, vim has different sets of commands that can be composed to take different actions. Say, typing di" [d]eletes what's [i]nside a pair of ["] characters. Also vim is more powerful if used as a Unix tool instead of per se, it's more of a citizen of that ecosystem.
There are different paradigms in development environments, Unix+a text editor is one. There are also those like Emacs, Acme, and usual IDEs. One has to choose which is better for their use. Say if you're a Mac or iOS dev maybe XCode is better for you, but if you're writing C, Perl, Python, etc., Unix & Vi is a nice environment. If you're doing Lisp, Emacs is the best environment out there (though Emacs and Vim are extensible, so they have some tooling for all the languages out there).
It's not just that it has shortcuts, per se, but that these shortcuts are sort of "fundamental units", which combine in interesting and intuitive ways, often resulting in efficient text editing.
The latter is rather subjective. I love vim for small projects, which, being a grad student, is most of what I write. However, I prefer IDE's for large projects with multiple files and hierarchies.
You can get vim-shortcuts for other editors. I really like using those in Intellij for example.
One thing I have noticed however is, that once you are good at the vim keyboard shortcut "language" (as someone described it above), you tend to use other features in the editor a lot less. And if you don't use the features, you might as well just use vim neat.
in your editor, without leaving the keyboard, how would you search-and-replace using a 2-variable regex, only between lines 275 and 1305, and then turn every instance of 'TEST_' into a lowercase, but only on the lines that didn't match?
How often do you find yourself doing operations like this? I feel like it would take me more time to formulate and confirm that your set of commands are correct than it would for me to just ctrl+f to each instance and then ctrl-v the ones that needed to be changed. Don't get me wrong, I think it is really cool that you can do this, but it feels like this requires a level of fu that is beyond most typical programmers.
In almost all cases where I need to do a find/replace there are typically no more than 4-5 references that need to be updated. And I think a better way to phrase my behavior is I search, inspect the code to make sure that my change won't introduce a bug or some unintended consequence, and then replace. This may be slower, but in the grand scheme of things it barely registers on my overall productivity and if it saves even one bug from getting introduced into the code than the extra time spent probably pays for itself. If I need to update more than just a handful of references, than Sublime has a perfectly functional find/replace tool, but I have only ever really needed it maybe 3-4 times in the last few years.
To get back to the question at hand. How long does it take you to formulate these series of commands in your example? Because to me it feels like it would take longer to come up with a correct set of commands for your example than it would be to just search and replace 'by hand'. Of course if you are updating 100's of references than spending some extra time to formulate your solution makes sense, but in your example, you limited your search ~1000 loc, so presumably you are only updating a few lines, maybe a dozen at most? I understand that vim is powerful tool, but it seems to solve problems that I don't have (or that I don't consider to be problems), and I am genuinely curious as to the sort of problems and types of code bases that vim aficionados work on.
In vim, it would probably have to be done in two separate commands
# Search and replace using a 2-variable regex
:275,1305s/two_variable_regex/first\1second\2/g
# Replace TEST_ with test_
:275,1305g!/a_regex/s/TEST_/test_/g
But, if it's too convoluted to do something like this in vim, you can instead do something like:
I would do this in awk. I could specify the line numbers. Or I could use the editor option to pass selection through said awk script. Or I could pipe xclip to and from the script.
Someone else could do it with sed, but I prefer awk.
However I did give vim a try eventually and use it now exclusively, but the reason I like it is comfort. Navigating around and doing operations is sooo much more comfortable now that I don't have to use a mouse or repeated key presses, plus all the many helpful shortcuts it has.