• PhAzE@lemmy.ca
    link
    fedilink
    arrow-up
    16
    ·
    edit-2
    10 hours ago

    Ctrl + R and start typing the command, it’ll come up, press enter. Im just more lazy because I know there are still faster ways.

    Edit: instead of hitting enter, keep pressing ctrl + R to cycle through history commands that contain what you typed in

  • rumba@lemmy.zip
    link
    fedilink
    English
    arrow-up
    8
    ·
    11 hours ago

    You’re in vim, you forgot to sudo, the file is read only and you have loads of changed you don’t feel like saving off to /tmp and playing the copy file shell game.

    [esc]:w !sudo tee %

    it shoves the current buffer through tee (termina adapter) with sudo privs vim will warn you that the file changed, just [esc]:q! and don’t let it save, you already saved it.

      • Lebernashi@lemmy.world
        link
        fedilink
        arrow-up
        5
        ·
        11 hours ago

        Every time you hit the up arrow, it shows the previous command you used in the terminal.

        So hitting the arrow once gives your last used, hitting it twice gives your second to last command, and so on.

        • djvinniev77@lemmy.ca
          link
          fedilink
          arrow-up
          2
          ·
          11 hours ago

          Yup and that is me. I could just history grep the command I want but I SWEAR it was just 2 commands ago, or 15 up arrows. lol.

          • Jarix@lemmy.world
            link
            fedilink
            arrow-up
            1
            ·
            edit-2
            10 hours ago

            Ohhh! I can absolutely relate to this as well! Using a zmud client to play games on. which is probably not much different, looking, than a terminal anyways

  • Zink@programming.dev
    link
    fedilink
    arrow-up
    6
    ·
    edit-2
    14 hours ago

    Ah crap how did I set my battery charge interval again?

    history | grep battery

    history | grep bios

    history | grep sudo smbios

    Ah! There you are you little shit!

    edit to add: Actually, I think the last time I did this I remembered some numbers I set it to before. So it worked well with something like “history | grep 75” even though there were a bunch of results.

    • Buddahriffic@lemmy.world
      link
      fedilink
      arrow-up
      1
      ·
      14 hours ago

      Is there a good way to do this when you use a lot of terminal tabs and aren’t sure which tab you used for the command you’re looking for?

  • bridgeenjoyer@sh.itjust.works
    link
    fedilink
    arrow-up
    4
    ·
    14 hours ago

    Nah just save all your commands in a text file on the desktop then make an alias to open it in nano so you just have to type “com”. Works for dumb ol me

  • ___f____g___@lemmy.ca
    link
    fedilink
    arrow-up
    9
    ·
    edit-2
    18 hours ago

    I see everyone posting about Ctrl+R, here’s a couple more useful CLI shortcuts you might enjoy:

    cd - (change directory to $OLDPWD usually the previous directory)

    git checkout - (similarly checkout the previous branch)

    Ctrl+A (return caret to beginning of command, great when you forgot a positional argument and you were almost done typing the command)

    Ctrl+E (similar to Ctrl+A but move to the end of the command)

    • YTG123@sopuli.xyz
      link
      fedilink
      arrow-up
      5
      ·
      13 hours ago

      Ctrl+A, Ctrl+E

      Many more basic Emacs keybindings work, actually! Including C-f, C-b, C-p and C-n (if you prefer them over arrow keys) as well as M-f and M-b to move by words, C-k, M-d and C-y for killing/yanking (but not M-w) and C-SPC, C-w, C-x C-x for region manipulation (tested in Bash and ZSH)

      • abbotsbury@lemmy.world
        link
        fedilink
        English
        arrow-up
        2
        ·
        12 hours ago

        fellow fish user, I just like its autocomplete and how I can just type ‘help’ and an interactive HTML page opens up where I can look stuff, and fish_config does the same except with settings and themes

  • JATth@lemmy.world
    link
    fedilink
    English
    arrow-up
    12
    ·
    22 hours ago

    zsh-history-substring-search

    I lazily type part of the thing I want like “sys” and then ctrl+⬆️/⬇️ and sudo systemctl start libvirtd etc. appear like magic.

    • apftwb@lemmy.world
      link
      fedilink
      arrow-up
      2
      ·
      edit-2
      6 hours ago

      ⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️⬆️

      CTL+C

      history

      history | less

      ⬆️⬆️⬆️

      Pg-up

      Pg-up

      q

      ! 2648

    • merc@sh.itjust.works
      link
      fedilink
      arrow-up
      1
      ·
      15 hours ago

      The worst is when you remember doing something before, but don’t remember enough details to be able to effectively search for it.

      Although, even then, I’m not going to just mindlessly hit “up”. Last time it happened I fed my command history through grep and removed all the things that I knew the command wasn’t. Just removing “ls” and “cd” from your history cuts the number of commands down by 80% or something.

      • Korthrun@lemmy.sdf.org
        link
        fedilink
        arrow-up
        4
        ·
        12 hours ago

        Check out the fzf shell bindings. Reverse history search with fuzzy matching is one of the features.

        • merc@sh.itjust.works
          link
          fedilink
          arrow-up
          1
          ·
          12 hours ago

          That doesn’t help when you remember what effect the command had but nothing about what the command itself looked like.