Hacker News new | ask | show | jobs
by stevelosh 2380 days ago
You're talking about how it's easy to move to a function or a file, and then you're "ready to edit", but edanm is talking about actually doing the editing.

For example: say I jump to this function and want to fix a bug (the `search` should strip off the first two characters here, not just one). So I need to change `regex.search(s[1:], ...)` to `regex.search(s[2:], ...)`:

    def compile_hg_glob(line):
        pat = glob_to_re(line)
    
        # Mercurial ignore globs are quasi-rooted at directory boundaries or the
        # beginning of the pattern.
        pat = '(^|/)' + pat
    
        # Mercurial globs also have to match to the end of the pattern.
        pat = pat + '$'
    
        try:
            regex = re.compile(pat)
            return lambda s: regex.search(s[1:] if s.startswith('./') else s)
        except:
            warn("could not parse hgignore pattern '%s'" % line)
            return lambda s: True
If I've just used a fancy shortcut key to jump to this function, my cursor is probably on the function name. In Vim, I'd do `cinr2:<esc>`. Seven keystrokes. I could also do `/[<cr><ctrl-a>` which is only four keystrokes, but a little more awkward to reach. If I tried to do this editing with arrow keys and backspaces I'd need 12 down keystrokes just to get to the right line.

Or suppose I'm looking at this and want to add a `,` character to the end of each of the type entries, because I forgot Python likes its commas:

    result = result | {
        'a': TYPES_ALL
        'e': TYPES_FILE_REAL
        'x': TYPES_FILE_SYMLINK
        'c': TYPES_DIR_REAL
        'y': TYPES_DIR_SYMLINK
        'f': TYPES_FILE
        'd': TYPES_DIR
        'r': TYPES_REAL
        's': TYPES_SYMLINK
    }[c.lower()]
In Vim I'd press `j` to get to the first entry, then `A,<esc>` to append the `,` after the first one, then `j.` to move down and repeat the action. I then press `j.` a bunch more times (which is really easy to do rapidly with your index and ring finger on Qwerty) and in 2 seconds I'm done. Vim's `.` to repeat the last action is really powerful and can save you a ton of time for small ad-hoc edit repetitions that don't warrant doing a full macro with `q`.

These kinds of things happen constantly, and when you've got Vim burned into your fingers trying to edit text without it (actually edit text, not just jumping to something) feels like typing with oven mitts on.

5 comments

Or just use the mouse to point and click in the same time. With laptop mousepads it's just moving a finger. Most devs aren't writing that much code and all these Vim efficiencies are vastly overstated.

I've seen many Vim/Emacs-only devs being easily beaten in speed by others using modern IDEs that have tooling and functionality (auto formatting, refactoring, templating, etc) focused on actually getting things done.

Exactly this. I pick type, and I've never found that it feels too slow. I spend more time thinking about the change I want to make, and reading the code to plan that, than actually making the change most of the time. My typing speed wouldn't address the bottleneck. I think vim is the same. Sure you can edit the text faster, but that's not the bottleneck anyway.
Vim was never about typing efficiency. However, it is indeed the best way to navigate and edit text. This statement is very subjective because, just like any tool, it depends on the user. Chainsaw looks ugly, heavy, cumbersome and dangerous to someone who doesn't know how to use it. But with some practice it becomes an incredibly efficient tool. People make ice sculptures using chainsaws.

And I'm not talking about Vim the editor. I'm talking about Vim as an idea. Which is today implemented for pretty much every single [popular] editor and IDE in use. That fact alone is pretty illustrative of awesomeness of the idea of Vim.

And the comment about Emacs is quite disingenuous. I have never been inside a Formula One cockpit, but I can totally get "the job done" with my Camry, because it is totally more efficient for parallel parking.

I have used many IDEs, including InteliJ (which I used for about seven years). Emacs wins solely by its extensibility, no editor/IDE has ever matched its capabilities. For some people that is not an important factor, just like the efficient parallel parking might not be important for Formula One pilots. But when you can automate pretty much anything it feels very empowering and liberating.

Small example: when I'm about the create a new commit, an emacs-lisp script can figure out the current ticket I'm working on (based on currently clocked Org-mode task), generate a branch name based on the ticket description, generate part of the commit message (in the way that it is in compliance with git tool like gommit), I would just have to type the rest of the message.

That is not only more efficient, but also reduces frustration. Compare that with the workflow in any other editor and IDE - most of these steps will have to be manual. Then someone might say: oh there's actually a plugin for Editor X that does some of that stuff for Jira. But what if I join a different company that uses Pivotal Tracker instead? I can extend my emacs-lisp script. Whereas if that's an InteliJ plugin I would either have to go through daunting process of forking and modifying the plugin or submit a feature request and wait for something that may never happen.

I switched to vscode recently from emacs and was embarrassed about how much more productive I was, almost immediately.
I think where the IDE’s are really powerful is when refactoring. Need that one class renamed? File is automatically renamed too, and all references in every file that link to it (instantiations, calls, imports) are updated too.
Exactly, the code structure, navigation and intellisense features are far more useful and let you code at the same level of abstraction as the logic you're coding.

Moving a little bit faster through the text file to edit characters is rarely the issue and I certainly wouldn't give up IDE features for it.

1: ctrl-f, 2:, esc

2: select the first :, ctrl+d until all are selected, right arrow, comma

Doesn’t sound any more efficient? Plus, who writes code without an auto-formatter these days? Problem two would have been solved by the linter the moment you wrote that.

It's not just code and linting though - this kind of thing happens when you're editing YAML files, when you're editing pure text, when you're editing CSVs, when you're editing some obscure thing no one's heard of - once you have the primitives down, it's just so easy to apply it everywhere.
Did you read what I just wrote? Those commands are not specific to any language.
Sorry, I was referring to the second part (about the linter.)

Obviously the first part is language-neutral, and is exactly why I think multiple cursors is one of the greatest inventions in text editing! :)

This is a bit frowned upon in HN, but may I just say I'm a fan. I'm not sure, but it's likely I got my way of speaking of vim as a language from you, and as you can see in my other comments, it's stuck with me :)
> In Vim I'd press `j` to get to the first entry, then `A,<esc>` to append the `,` after the first one, then `j.` to move down and repeat the action. I then press `j.` a bunch more times (which is really easy to do rapidly with your index and ring finger on Qwerty) and in 2 seconds I'm done. Vim's `.` to repeat the last action is really powerful and can save you a ton of time for small ad-hoc edit repetitions that don't warrant doing a full macro with `q`.

Eh. I'd probably do 'qqA,<esc>j0q', and then '8@q'.

That's also probably not the best example, since that's also trivial if you have an editor supporting multiple cursors.

That's hardcore, I would rarely use a macro for something like that :)

That said, I think multiple cursors are the greatest addition to text editing since, well, vim. I was an enthusiastic user of Sublime Text 1, right before I learned about vim.

Luckily, vim has multiple cursor support, which is... decent. Not great, but decent. I actually think that the only thing that makes multiple cursors more awesome, is being able to combine them with vim's commands, since multiple cursors rely on you being able to do precise things at each cursor, and vim gives you the language for it.

> That's also probably not the best example, since that's also trivial if you have an editor supporting multiple cursors.

Yeah, it's hard to come up with a decent example because I don't even think about it any more, it's just burned into my fingers. I just know how excruciating it feels to edit without Vim (I even wrote that last comment in Vim and then copied it into the browser because writing it in a text field is miserable).

I long ago created a special script (in Macos it's via something called Hammerspoon, I used to have a Windows version).

It basically gives vim-like keys anywhere you want, when holding down the caps lock key. So e.g. caps+h/j/k/l are movement keys.

It goes a lot farther than that: I have a key to delete a line, a key to select a word, a key to go up/down by 4 lines, a key to delete the last word, etc. I even mapped caps+f to jump forward 20 characters (to badly simulate using 'f [letter]' in vim).

This makes so it I never have to leave home position on the keyboard, because while holding caps I have all the movement keys I want at my disposal. It's a total lifesaver, and the only way I can effectively use a keyboard outside of vim :)

I guess even easier would be to go to the visual mode, then selecting all the lines and append the commas all at once :)

<c-v>8j$A,<esc>

Isn't `$` is redundant
Not in visual mode.
For your second example, I'd do :2,8s/$/,/<enter>