72
all 21 comments
sorted by: hot top new old
[-] some_guy@lemmy.sdf.org 16 points 2 years ago

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.

[-] astrsk@kbin.run 12 points 2 years ago

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

[-] ShaunaTheDead@fedia.io 2 points 2 years ago

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.

[-] Ferk@programming.dev 0 points 2 years ago* (last edited 2 years ago)

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.

[-] vipaal@aussie.zone 7 points 2 years ago

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

[-] some_guy@lemmy.sdf.org 2 points 2 years ago

That's a new one for me. Thanks!

[-] lobut@lemmy.ca 2 points 2 years ago

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

[-] Hammerheart@programming.dev 2 points 2 years ago* (last edited 2 years ago)

ctrl-b: move cursor back one character

ctrl-f: move cursor foward one character

ctrl-d: delete character under cursor

[-] lmaydev@lemmy.world 1 points 2 years ago

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

[-] Hammerheart@programming.dev 1 points 2 years ago

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

[-] Ferk@programming.dev 1 points 2 years ago* (last edited 2 years ago)
  • 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.

[-] ShaunaTheDead@fedia.io 5 points 2 years ago* (last edited 2 years ago)

My favorite tips are:

You can filter the output of a command. Most commands return parameters like (output, error) so you can filter them by number like 1>/dev/null will filter the output and only show the errors, and 2>/dev/null will filter the errors and only show the output. Also if you want a command to run silently but it doesn't have it's own built-in quiet mode you can add &>/dev/null which will filter everything.

Bash (and other shell's I assume) can be fully customized. In addition to the .bashrc file in your home directory, there are also a few common files that bash will look for like .bash_aliases, .bash_commands, .bash_profile or you can create your own and just add to the end of the .bashrc file ./YOUR_CUSTOM_BASH_FILE_NAME

Inside that file you can add any custom commands you want to run for every bash shell like aliases and what not.

I personally often use a simple update command like so alias up='sudo apt update -y && sudo apt upgrade -y && sudo apt autoremove -y' which just makes running updates, upgrades, and clean-up so much easier. Just type up and enter your password. I have previously added in things like &>/dev/null to quiet the commands and echo Fetching updates... to make some commands quieter but still give some simple feedback.

There's also the basics of moving around a terminal command as others have pointed out. The easiest and the one I use the most is if you hold CTRL+LEFT_ARROW the cursor will move entire words instead of one character at a time. Very helpful if you need to change something in the middle of a command.

[-] tyler@programming.dev 1 points 2 years ago

You can use - everywhere you can use a ref in a git command. I very often use

git checkout master
git pull
git checkout -
git merge -

(Of course that’s all aliased and I have other flags in there too, but that’s the gist)

[-] IllNess@infosec.pub 1 points 2 years ago

What can tmux do that you can't do using startup and exiting scripts?

[-] eager_eagle@lemmy.world 7 points 2 years ago* (last edited 2 years ago)

Retain sessions when you're over SSH and get disconnected.

I'm surprised this wasn't mentioned, since it's my only use case for tmux.

[-] matcha_addict@lemy.lol 2 points 2 years ago

I use dtach for this feature

[-] IllNess@infosec.pub 1 points 2 years ago

I should've just looked it up but got lazy to be honest.

I use Dreamhost to connect to IRC support channels using irssi. I go through Dreamhost since it hides my home IP address. It disconnects me frequently. This would be very useful.

Thank you for the info.

[-] Zachariah@lemmy.world -2 points 2 years ago

advanced terminal
or
advanced tips and tricks
?

this post was submitted on 22 Jul 2024
72 points (98.6% liked)

Programming

28447 readers
371 users here now

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



founded 3 years ago
MODERATORS