from Hacker News

Ask HN: What are your favourite programming shortcuts

by janpmz on 3/29/24, 4:46 PM with 18 comments

My favourites are in VS Code:

Navigate back: Alt + left

Navigate forward: Alt + right

Switch tabs: CTRL + Page up/down

Split tabs: CTRL + ALT + left/right

  • by solardev on 3/31/24, 2:25 PM

    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.

  • by joehx2 on 3/29/24, 10:20 PM

    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 -
  • by fuzztester on 4/1/24, 4:37 AM

    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.

  • by az09mugen on 3/31/24, 11:21 PM

    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
  • by khaledh on 3/31/24, 9:30 AM

    In JetBrains IDEs: pressing shift twice while some text is selected opens the Find in Files dialog with the selected text already populated.
  • by pwg on 3/29/24, 5:42 PM

    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.

  • by yen223 on 3/29/24, 10:12 PM

    "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.

  • by kebsup on 3/31/24, 6:20 PM

    After more than 5yrs of coding in jetbrains, I've recently started using F2 to go to the next error.
  • by interbased on 3/29/24, 11:26 PM

    Not a shortcut persay but I love setting alias’s in my .zshrc file to make all my common commands a few key strokes.
  • by useRust on 4/2/24, 10:53 PM

    Anyone has useful mac shortcuts?
  • by jytechdevops on 3/29/24, 10:20 PM

    pushd popd
  • by fragmede on 3/29/24, 10:30 PM

    command-shift-3 in bash comments out the current line and hits enter.
  • by KomoD on 3/29/24, 8:25 PM

    ctrl+c, ctrl+v