Skip to content
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

Enable fish to call $EDITOR on command line #2027

Closed
GReagle opened this issue Apr 16, 2015 · 12 comments
Closed

Enable fish to call $EDITOR on command line #2027

GReagle opened this issue Apr 16, 2015 · 12 comments

Comments

@GReagle
Copy link
Contributor

GReagle commented Apr 16, 2015

This function was originally written by Sanne Wouda and modified by Greg Reagle. This feature is available in Bash as edit-and-execute-command (C-x C-e), and in zsh as edit-command-line.

Can this function be a standard part of fish, and bound to a key such as Ctrl-x Ctrl-e?

# Use $EDITOR to edit the current command
function edit-command
    set -q EDITOR; or return 1
    set -l tmpfile (mktemp); or return 1
    commandline > $tmpfile
    eval $EDITOR $tmpfile
    commandline -r (cat $tmpfile)
    rm $tmpfile
end
@ridiculousfish ridiculousfish added this to the fish-future milestone Apr 20, 2015
@tannhuber
Copy link
Contributor

I suggest to replace the second commandline command:

commandline -r -- (cat $tmpfile)

Look here: #1964

@zanchey
Copy link
Member

zanchey commented Apr 27, 2015

This will require cleverness to bind as ^X ^E.

@GReagle
Copy link
Contributor Author

GReagle commented Apr 28, 2015

@tannhuber The "--" prevents errors and is an improvement. Thank you.

@zanchey Yea, I have no idea how to get a multi-key binding to actually work in fish. It is not so important what the binding is, just that the feature is there.

@davidmh
Copy link

davidmh commented May 3, 2015

@zanchey @GReagle this seems to work as expected:

bind \cx\ce edit_commandline

oschrenk added a commit to oschrenk/dotfiles that referenced this issue May 3, 2015
@tannhuber
Copy link
Contributor

The function edit-command removes outer single and double quotes. Why? Is there a workaround?

Example:

echo 'single quotes will be removed' "double quotes will be removed" 'double quotes "will be removed"'

@GReagle
Copy link
Contributor Author

GReagle commented Aug 4, 2015

@tannhuber Good catch on the loss of quotes. Definitely a problem. The commandline builtin is not outputting the quotes. This is bug #2210.

@faho
Copy link
Member

faho commented Jan 13, 2016

This is actually a duplicate of #1215.

@faho faho closed this as completed Jan 13, 2016
@faho faho added the duplicate label Jan 13, 2016
@faho faho removed this from the fish-future milestone Jan 13, 2016
@hashier
Copy link

hashier commented Sep 19, 2018

To everyone who started to copy/paste the solution from here 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")
PR: #3627

@haakym
Copy link

haakym commented Jul 22, 2019

This doesn't seem to work in MacOS I just get ´or √ instead - any ideas?

@faho
Copy link
Member

faho commented Jul 22, 2019

@haakym: You want to confirm that $EDITOR (or $VISUAL) is set correctly. In particular if you set it to a GUI editor you need to make sure that it stays until you're done, frequently they fork off and let the shell return. For e.g. sublime this means using subl -w instead of plain subl.

@mfilej
Copy link
Contributor

mfilej commented Jul 23, 2019

Hmm, to me it sounds like your terminal might be producing the ´ character (which you get by typing ⌥e depending on the keyboard). There must be a setting somewhere to toggle this, depending on the terminal app that you use.

Alternatively, try esc+e instead.

@haakym
Copy link

haakym commented Jul 23, 2019

@faho Thanks for your response. The initial issue was as @mfilej mentioned below, but you were right I didn't have the $EDITOR or $VISUAL var set correctly. I now have this working with Vim via set -gx EDITOR vim.

In particular if you set it to a GUI editor you need to make sure that it stays until you're done, frequently they fork off and let the shell return. For e.g. sublime this means using subl -w instead of plain subl.

That's really handy to know as I was trying to get this working with VS Code and after exiting nothing ever happened. I've now got this working with set -gx VISUAL code -w

@mfilej Thank you - esc+e/esc+v works great. I'm using iTerm2 and found I can update the option key to function as Esc+ as mentioned here: [How do I make the option/alt key act like Meta or send escape codes?](How do I make the option/alt key act like Meta or send escape codes?)

Thanks again both for your help - really appreciate it! This is going to save my wrists some pain :)

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 16, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

9 participants