You are viewing a single thread.
View all comments
17 points

Ctl-U to delete everything on the line before cursor.

Ctl-E to skip to end of line.

Ctl-A to skip to beginning of line.

permalink
report
reply
12 points

Or, just use Home and End like they were intended! Kids these days….

permalink
report
parent
reply
6 points
*

Kids these days….

These Ctrl keys are shortcuts from Emacs - there’s a Bash settings to switch to vi-mode if you so wish. Anyway, the first Emacs was written in 1981, probably on a PDP-11, which did not have Home and End! Same reason Neovim uses “yank” instead of “copy”. ctrl-c/ctrl-v did not exist as a shortcut back when vi was being written!

I know you didn’t intend to be mean or anything, but maaaaaan kids these days don’t know their history (not entirely your fault, btw)😆

permalink
report
parent
reply
2 points

This tip is super useful to me because not everyone is using a PC. On a PC sure, I would use the Home and End keys all the time. Now I’m using a laptop as my main computer and the Home and End keys are in a weird position that even to this day, 4ish years of laptop use, I still have to actually look at the keys to find them.

permalink
report
parent
reply
0 points
*

That’s horrible for muscle memory, every time I switch desk/keyboard I have to re-learn the position of the home/end/delete/PgUp/PgDn keys.

I got used to Ctrl-a / Ctrl-e and it became second nature, my hands don’t have to fish for extra keys, to the point that it becomes annoying when a program does not support that. Some map Ctrl-a to “Select all” so, for input fields where the selection is one line, I’d rather Ctrl-a then left/right to go to the beginning/end than fish for home/end, wherever they are.

permalink
report
parent
reply
7 points

Ctrl-y to paste what Ctrl-u deleted or cut

permalink
report
parent
reply
2 points

That’s a new one for me. Thanks!

permalink
report
parent
reply
2 points
*

ctrl-b: move cursor back one character

ctrl-f: move cursor foward one character

ctrl-d: delete character under cursor

permalink
report
parent
reply
1 point

But that’s more key presses than just using existing keys

permalink
report
parent
reply
1 point

I find it easier using my pinky to hit ctrl than taking my fingers off the home row to use the arrow keys.

permalink
report
parent
reply
2 points

If you’re a VIM motions fan, you can always install the zsh-vi-mode: https://github.com/jeffreytse/zsh-vi-mode.

permalink
report
parent
reply
1 point
*
  • Alt-delete deletes the whole word before cursor
  • Alt-d deletes the whole word after cursor
  • Ctrl-k deletes (kill) everything after the cursor

Whatever is deleted is stored in the “killring” and can be pasted(yanked) back with Ctrl-y (like someone else already mentioned), consecutive uses of Alt-delete/Alt-d add to the killring.

  • Alt-b / Alt-f moves one word backwards / forwards
  • Alt-t swaps (translocates) the current word with the previous one
  • Ctrl-_ undo last edit operation

All those bindings are the same as in emacs.

Also, normally Ctrl-d inserts the end-of-file character, and typically can be used to close an active shell session or when you have some other interpreter open in the terminal for interactive input.

permalink
report
parent
reply

Programming

!programming@programming.dev

Create post

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person’s post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you’re posting long videos try to add in some form of tldr for those who don’t want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



Community stats

  • 3.4K

    Monthly active users

  • 754

    Posts

  • 5.9K

    Comments