-
Notifications
You must be signed in to change notification settings - Fork 2.1k
support editing the command line with an external editor #1215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Probably this can be done with a custom binding. |
Cool, thanks. Would be interested to see how, if it's possible. For a On Sun, Dec 29, 2013 at 11:54 PM, ridiculousfish
|
I use the following piece of code function edit_cmd --description 'Edit cmdline in editor'
set -l f (mktemp --tmpdir=.)
set -l p (commandline -C)
commandline -b > $f
vim -c set\ ft=fish $f
commandline -r (more $f)
commandline -C $p
rm $f
end then bind -k F4 edit_cmd The user might want to change temporary folder for /tmp so the command could work in any directory. |
Thanks for sharing, @maxfl. When I try that though I get:
I'm on OS X 10.9.1 + homebrew fish version 2.1.0. |
@Skivvies, 'mktmp' should return unique name for the temp filename. set -l f /tmp/fish.cmd.(random) On Mon, Dec 30, 2013 at 9:44 PM, skivvies notifications@github.com wrote:
|
Ah, BSD (OS X's) mktemp doesn't accept a --tmpdir argument. This works though: function edit_cmd --description 'Input command in external editor'
set -l f (mktemp /tmp/fish.cmd.XXXXXXXX)
if test -n "$f"
set -l p (commandline -C)
commandline -b > $f
vim -c 'set ft=fish' $f
commandline -r (more $f)
commandline -C $p
command rm $f
end
end
function fish_user_key_bindings
bind \ev 'edit_cmd'
end Thanks for the tip, @maxfl. |
I think this would be worth including, although we would have to use $EDITOR or $VISUAL rather than hard-encoding vim. |
I note that in Bash, Any suggestions for a default binding? We don't support multi-character sequences yet, so C-x C-e is out. M-e? |
I use M-e and F4 bindings. They seem not to intersect with anything. |
Thanks all! Super useful |
@maxfl's snippet seems to have stopped working for me at some point. Did anything change in fish? |
It's because of #2210. |
Thanks! I'll keep an eye on that then. |
something like this can be useful for completion, etc., depending on your editor:
if you're on OS X, you'll need homebrew's |
In the past year I've seen several solutions documented in other issues. The one I've been using for a long time is an enhanced version of @skivvies that works whether you're using BSD or GNU mktemp:
Something like that should be bundled with fish. What the default bindings should be is TBD. I use |
Also from my comment in issue #3477 regarding the function I just mentioned:
|
@krader1961 works for me on El Capitan with emacsclient (with that weird but harmless error when saving an empty command) |
This question and various solutions has occurred often enough that I decided it was time to make my solution more robust. I've modified the function I posted above to make it more robust and will open a pull request to invite review of it. |
To everyone who started to copy/paste the solution of @krader1961 like me. This is not needed anymore. This got merged into fish and got even two shortcuts. Alt-e and Alt-v. Documentation: https://fishshell.com/docs/current/ (search for "edit the current command line in an external editor") |
Also, Alt-e and Alt-v are equivalent according to the documentation. |
In bash you can press C-x C-e and it will drop you into your $EDITOR so you can input commands with it. Could fish support something similar?
The text was updated successfully, but these errors were encountered: