Ask HN: What are your favourite programming shortcuts

  • In Jetbrains, you can shift-F6 to rename something (like a variable or function) via a built-in refactorer. It'll do it (somewhat) intelligently across not just the current file, but your whole project.

    Like in a React project, you can rename the first part of `[isThisThingOn, setIsThisThingOn] = useState()` and it'll automatically rename the setter and all the components that inherit that state. Or if you rename `<MyComponent/>` to something else, it'll rename that component, the imports, the filename itself, etc. across your whole project.

    It works pretty well but does have its quirks, like how it handles properties inside objects or type definitions, so it's worth double-checking the IDE's work for readability.

    VScode has something similar (F2), I think, but maybe only for some languages? https://code.visualstudio.com/docs/editor/refactoring#_renam.... It's cute that they kept the F2 shortcut key from the Windows (3.1?) days.

  • I've recently discovered `git switch -` and `git merge -`. It switches to the previous branch you were on or merges the previous branch you were own.

    No need to know the name.

    So if I need to pull updates on the previous branch I was on and merge them into my current branch, I can just:

        git switch -
        git pull
        git switch -
        git merge -

  • If you're a vi(m) user on a *nix OS, running:

    $ set -o vi

    at the (ba)sh prompt ($ by default), enables vi-mode command-line editing. (The default is emacs.). You are initially in append mode on the current command line. Now you can do ESC to go to command mode, then use k and j to move up and down respectively in the command history, b and w to move backward or forward, and can use many other vi(m) movement and editing commands on the history lines, including/ and n to search for patterns. Been using this since early days of using Unix. Invaluable productivity aid.

  • In sublime text ctrl+m (go to matching parenthesis/brace), ctrl+d (multiple selection), alt+F3 (multiselect all occurencies). In Jetbrains, alt+F7 to show usages of function/method

  • In JetBrains IDEs: pressing shift twice while some text is selected opens the Find in Files dialog with the selected text already populated.

  • Ctrl+[ - jump to matching paren./brace/bracket

    Ctrl+w - scroll up one line

    Ctrl+z - scroll down one line

    These are the mappings I have set in Joe on my system, the Ctrl+w/z is originally from Wordstar, although I first encountered that mapping in Turbo Pascal 4.

  • "Expand selection" in Intellij and similar, option + up by default.

    This shortcut is, no joke, a very big part of why I'm still paying for Jetbrains tools.

  • After more than 5yrs of coding in jetbrains, I've recently started using F2 to go to the next error.

  • Not a shortcut persay but I love setting alias’s in my .zshrc file to make all my common commands a few key strokes.

  • Anyone has useful mac shortcuts?

  • pushd popd

  • command-shift-3 in bash comments out the current line and hits enter.

  • ctrl+c, ctrl+v

  • [dead]