Live data from Hacker News

Ask HN: What are your favourite programming shortcuts

news.ycombinator.com

11–20 of 20 posts

Re: Ask HN: What are your favourite programming shortcuts

#12
post #8

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

Is this something special you have set up on your Mac? I keep getting screenshots when I hit command-shift-3. https://support.apple.com/en-us/102646

Found it in the readline manual

https://tiswww.cwru.edu/php/chet/readline/readline.html#inde...

insert-comment (M-#) Without a numeric argument, the value of the comment-begin variable is inserted at the beginning of the current line.

Re: Ask HN: What are your favourite programming shortcuts

#14
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 `` 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.

Re: Ask HN: What are your favourite programming shortcuts

#17
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.

Re: Ask HN: What are your favourite programming shortcuts

#18
post #5

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 -

Unfamiliar with 'switch'; i do 'git checkout -' all the time to toggle back and forth
Post reply on HN