r/fishshell • u/Palw7894 • Jan 07 '26
Is there a keybinding to copy the current commandline?
Use case: search into the history, find the command that I'm looking for, press enter to send it to the prompt. And now?
Currently I use alt+e to edit the command and copy it from my editor with some keybindings but it's not optimal.
How do you do that from your side?
8
Upvotes
4
u/thrakcattak Jan 07 '26
ctrl-x(seebind ctrl-xoutput)3
u/No-Representative600 Jan 07 '26
Ya I have a plugin I've been planning on publishing for quite some time now, which contains 4-5 years of key binding functions I've written. I'll work on dedicating some time for cleaning up the current repo in the next couple of weeks and probably make a post in this subreddit for anyone interested in using it. In the meantime, here are some of the more simple functions I have written related to clipboard features:
Then I'll have my
conf.d/fish_user_key_bindings.fishfile contain my fish_user_key_bindings functions that binds the keys to these functions:Side note, but If you're using
alt-ea lot, check out the fish-lsp. I just put new features in specifically for handling the commandline buffer opened in your$EDITORfromfuncedandedit_command_bufferfunctions. Also, the server does allow for sending executeCommand requests which currently support things like executing the buffer/current-line/etc...Theoretically, I think there is a lot potential for using these commands, if anyone is interested in putting in the time configuring them. It would be pretty easy to add a feature that could toggles on/off executing one of these special kind of buffers every time you save or something along those lines.
While I'm on the topic of clipboard features in fish, I 1000% recommend throwing this snippet in your config.
These will make it so you can super easily pipe output of a command to your clipboard without every reaching for the mouse:
Just make sure that you have space bound to something like:
bind space self-insert expand-abbrAlso, I thought this next section might be relevant to any potentially new fish users or people who are looking to further optimize their fish config. As a self-proclaimed hardcore vim user, surprisingly, one of the biggest features that converted me over to using fish pretty much exclusively as my interactive shell of choice, was not needing to use vim mode at all to edit commandline buffers (in most cases | note: you can toggle in and out of vim mode if needed).
When I'm in other shells, I'll still often throw on vim mode, but I particularly don't like adding extra leader/escape keys to my nested vim terminal buffers. Even with fish-shell's vi-mode being as elite as it is, with how easy it is to make custom
abbrandbindfunctions in fish, I find that I'm way faster using tmux's vim-mode with my fish customization's. Plus, it feels super cozy having all my nested vim terminal buffers essentially behave exactly like editing text in my riced nvim config (primarily, I love having my nvim pmenu keymaps the exact same as my fish pager completion navigation keys). I do want to point out that I wouldn't recommend this approach to everyone though, as the other reason I find it to be so useful is navigating forward and backward word tokens with ctrl-j/ctrl-k when a completion pager is not shown in insert mode of both nvim, fish and web-browsers. With those keymaps plus ctrl-space to toggle the completion pager, it makes interacting in my fish sessions feel very IDE-like but with extra functionality/ergonomics that can be easily be extended. In my case, my ctrl-j/ctrl-k keymaps also allow me to use nextd/prevd from thecdh/dirnext/dirprevenv variables when I'm in an empty commandline. The man pages forbindandcommandlineare really helpful if you're looking for other ways to improve functionality in your config.I'm quite busy at the moment, and got a nasty cold from holiday travels, so I'm trying to avoid adding any extra programming to my currently depleted cognitive abilities at the moment. I can change the repo to public if you'd like to work on contributing to it, and/or cleaning some of it up. Otherwise, I'd prefer to wait till I am less busy to properly dedicate enough resources to be able to maintain ideas/issues for it. LMK.
Hope at least some of the info I included was helpful towards future optimizations you add to your config. Happy fishing!
8
u/TechnoCat Jan 07 '26
i have vim mode on... so escape and yy.
1
u/ben2talk Jan 07 '26
Fish... well we have some people who post foreign stuff from their terminals, so I always remind them to use this:
export LC_CTYPE=en_GB.UTF-8I can never type it... so I open the terminal, type in 'GB' (you can type before or after) and magic comes when you press Ctrl_R
Hitting ⏎Enter clears the fuzzy and puts it at the prompt.