Repository navigation
Ability to configure a default editor for use with gh #308
Description
Activity
we can set the
EDITORenvironment variable tovim, seeLines 32 to 34 in c03b0d1
if e := os.Getenv("EDITOR"); e != "" { editor = e } Reacted by Toni Bustos, Leonhardt Wille, Ryan Brainard, Noah Lee, Joshua Mabina, Joe Previte, Victor, Naoto Fukuda, Dmytro Gaivoronsky, Nikolai Røed Kristiansen and 10 moreCurrently our hope is users set
EDITORin their environment (I use and <3 vim and that's what I do forpr create); we default tonanoin the hope that it would be less surprising for people new to editing on the terminal.That said, I think this issue highlights that we should be explicitly documenting use of
EDITORand should call it out:- in the README or similarly visible place
- in the help output for
gh pr createandgh issue create
Reacted by Joe Previte, François Risoud, Joshua Mabina, Jouke van der Maas, Edgar Ramírez Mondragón, Vinicius Lima, Nicolas Del Piano, Marti, Aimar Ibarra, no-yan and 3 more- changed the title
[-]Add support for vim during `gh pr create`[/-][+]Make it clear how to use vim with gh during command line editing[/+]on Feb 5, 2020 nanois not default installed in some distros, vi/vim is more a default than vi/vim for developers, we should movenano --> vi/vimReacted by Drew Harris, Bryson Holland, Joe Khoury, John Losito, Jazeem Azeez and Andreas OsberghausI would like to set
EDITORon my.bashrcbut got thinking is way to generic, it may be more app specific something likeGH_EDITORyou never know if other app is looking for the same ENV VAR. and is better to track your ENV's (I have way to much now and is hard to know why they are there)Reacted by Joon Park and François Risoudnanois not default installed in some distros, vi/vim is more a default than vi/vim for developers, we should movenano --> vi/vimYeah that's true & I'm myself a strong vim user, but users might very likely get stuck if they're new to vi/vim, as mentioned be @vilmibm, & I think that the default here is good.
Reacted by Forrest Hopkins and Philip JagielskiI think it would make most sense to honour
GIT_EDITORsince that is likely what people will have set if they are already usingvimfor editing git commit messages. Using VISUAL and EDITOR can have other non-desired side effects, for example causingbashto work invimode instead ofemacsmode. What I generally do is look for: GIT_EDITOR then VISUAL then EDITOR in that order, and if none of those are set, use a sane default. https://www.git-scm.com/book/en/v2/Git-Internals-Environment-VariablesReacted by Carlos Eduardo Arango Gutierrez, Jonas Ostir, Gordon Chiam, Ahmed El Gabri, Joe Previte, Kipras Melnikovas, John Bates, Toni Bustos, Luc Patiny, Anna Railton and 41 more++ to @gabeguz idea
@gabeguz @ArangoGutierrez done #329
@jsjoeio I'm curious if @ahmedelgabri's fix in #329 properly satisfies your use case, or if you think an explicit way to set the editor in
ghwould still be an important piece. It strikes me as something that might be useful down the road, but given that you can specify your preferred default in your environment, I'm inclined to think we should wait for more feedback on this before pursuing something with more UX around it and that maybe #329 should close this issue for now. Thoughts?@billygriffin I think that makes sense. I agree with his point (I've already set that to
vim) and I assume most people will too so I think that fulfills my case.Although, I do believe documentation is super important so it would be a good idea to document how it works (so people don't have to dig through issues/prs/code to see implementation).
Don't know if that should fall under this issue or be a separate issue. Feel free to close this if you think we're good!
- changed the title
[-]Make it clear how to use vim with gh during command line editing[/-][+]Document how to specify a default editor for use with `gh`[/+]on Feb 7, 2020 I like the distinction you drew, thanks @jsjoeio. I updated the title to clarify that this is purely a documentation task. Thanks a bunch for your feedback thus far, it's been really helpful - and thanks @ahmedelgabri for such a quick PR to improve things!
Reacted by Ahmed El GabriReacted by Joe PreviteSince this issue is more active than #372, and this is something we're still seeing a lot of despite it now being documented (https://cli.github.com/manual/installation) and respecting environment variables, we think it's reasonable to change the scope of this issue to have more of a first class experience, as originally suggested and as suggested in #372.
I'm going to update the title and we'll look at it in the context of #622 where we're thinking about other things that we'd like to make configurable.
One consideration I was thinking about is what happens if what's specified in the environment variables clashes with what's in the config. I assume we'd use the config first and then fall back to environment variables, but just something to consider in implementation.
Reacted by Leandro and Joe Previte11 remaining items
Okay sorry, you implemented a way to set it:
Line 52 in 80d7513
$ gh config set editor vim Thank you, it works now via
gh config set editor vim.Reacted by Mislav Marohnić, Noob Tsai, Lakh Bawa, Mikael Midtgaard, Hossein Monjezi, Catarina Pimenta de Paula Bressan, Alex Ginns, Frans Caisar Ramadhan, Özgür Odabaşı, Kent Robin Haugen and 9 moreReacted by Alex Ginns, Alex, haider, Norah H. and Joe PreviteReacted by Lakh Bawa, Alex Ginns, Alexandre Rocco Alvarenga, Erik Schierboom, Jeremiah Tabb and Joe PreviteI wanted to follow up on this. With 0.7 you can now set an editor within gh, like @kud describes above. Here are the docs on how that works: https://cli.github.com/manual/gh_config
@kud The new config value
gh config set editor ...is the right way to do this since 0.7; however, without any editor being configured, the EDITOR environment variable should still be picked up and respected. I'm not sure howEDITOR=vim gh issue createdid not work for you.Reacted by Billy Griffin, Erwann Mest, Happy Singer and Noob TsaiTo be honest, @mislav, my config at first is
export EDITOR=subland it never openssubltoo, haha. So yeah I don't know. 😬My config : https://github.com/kud/my/blob/master/dotfiles/.zshrc
@kud Your setup looks fine to me! Generally, if nothing is set as
gh config get editorand you have EDITOR exported in your shell, the EDITOR value should absolutely get picked up and used on a non-Windows platform. Since that doesn't happen for you, I encourage you to open a new bug report.In your report, please also include the values of GIT_EDITOR and VISUAL environment variables. If you have the time and the will to add some debugging statements to Go code, you can try sprinkling some
fmt.Printlnstatements hereand runningLines 25 to 35 in a7931a0
func init() { if runtime.GOOS == "windows" { defaultEditor = "notepad" } else if g := os.Getenv("GIT_EDITOR"); g != "" { defaultEditor = g } else if v := os.Getenv("VISUAL"); v != "" { defaultEditor = v } else if e := os.Getenv("EDITOR"); e != "" { defaultEditor = e } } make && bin/gh issue createto see what's up.Thank you!
When I do:
func init() { if runtime.GOOS == "windows" { fmt.Println("windows") defaultEditor = "notepad" } else if g := os.Getenv("GIT_EDITOR"); g != "" { fmt.Println("GIT_EDITOR") defaultEditor = g } else if v := os.Getenv("VISUAL"); v != "" { fmt.Println("VISUAL") defaultEditor = v } else if e := os.Getenv("EDITOR"); e != "" { fmt.Println("EDITOR") defaultEditor = e } fmt.Println(defaultEditor) }
I've got:
$ make && bin/gh issue create VISUAL nanoSo I tried
echo $VISUAL nano
That's why.
I never set
nanoas$VISUALanywhere but it sounds to be like it's by default.So this is the reason.
Maybe I should set
sublfor$VISUALandvimfor$EDITOR. And setvimforgh.@kud Glad you solved it! 🎉
Reacted by Erwann MestSo whilst this issue is closed, I encountered an issue whilst trying to modify things - like creating issues, adding PR comments - today, and thought I'd share my experience for others who might stumble here.
I tried to configure my editor (using
gh config set editor vim), but every time I went to a step which triggered it to open, I was met with:? What would you like to edit? Body? Body [(e) to launch vim] exec: "vim": executable file not found in $PATH ... a few moments later... ? Body [(e) to launch code --wait, enter to skip] exec: "code": executable file not found in $PATHTrying a few different options, even the one from here (https://cli.github.com/manual/gh_config_set), all of them returned a similar error state. It was until I uninstalled the 'snap' version of the package and installed any of the other recommendations here (https://github.com/cli/cli/blob/trunk/docs/install_linux.md), it worked as expected, with no further issues.
I'm glad I noticed this whilst looking at alternative install options:
https://github.com/cli/cli/blob/trunk/docs/install_linux.md#snap-do-not-use
then casperdcl#7tl;dr don't use the snap package - it has issues, and is not recommended anyways.
Reacted by Mislav MarohnićAm I right that in Windows it's always going to be "notepad"? ☹
@fkthat Absolutely not. The default editor on Windows is
notepad.exe. You can change that with environment variablesGH_EDITOR,VISUAL, andEDITOR, or by settinggh config set editor "C:\Path\to\myeditor".Note that because Windows paths typically have spaces, you have to additionally quote any such path within the editor string. Often that will require you to have nested quotes (e.g. double quotes within single quotes). Note that Windows can mangle double quotes appearing within values (I am not aware of a workaround).
@mislav , the environment variables (at least EDITOR) doesn't seem to work, but 'gh config set editor' is absolutely OK, however it looks like it should be typed as either
C:\\Path\\to\\myeditor.exe(with a double backslash) orC:/Path/to/myeditor.exe(with a forward slash) - this way it's all right. Thanks a lot.Ah, my apologies. It seems I was looking at the old version of the code that manages environment variable. You are right that environment variables EDITOR and VISUAL are ignored on Windows 😕
Lines 22 to 30 in 8272035
if runtime.GOOS == "windows" { defaultEditor = "notepad" } else if g := os.Getenv("GIT_EDITOR"); g != "" { defaultEditor = g } else if v := os.Getenv("VISUAL"); v != "" { defaultEditor = v } else if e := os.Getenv("EDITOR"); e != "" { defaultEditor = e } GH_EDITOR might still work due to it being respected elsewhere regardless of plaform.
This is not working for me on fedora:
OS: Fedora Linux 37 (Workstation Edition) x86_64 Kernel: 6.2.14-200.fc37.x86_64$ gh config get editor subl
But still when I do:
$ gh pr status
The pr status is opened in vim :(
@Vyom-Yadav The
editorconfig is only respected in commands that offer you to edit some text. Typically those arecreateandeditcommands, butgh pr statusdoes not invoke an editor. It does pass its output to the PAGER program, so you can check yourecho $PAGERorecho $GH_PAGERsetting to see if vim is configured there.- locked as resolved and limited conversation to collaborators
on May 14, 2023
Describe the feature or problem you’d like to solve
I used
gh pr create(surprised that it defaulted to open my PR from a fork into the upstream repo - it was awesome🤩) and when I went to edit the PR body, it defaulted tonanobut I'd prefer it to usevim.Proposed solution
ghprompt them to choose a default editor:How will it benefit CLI and its users?
Additional context
N/A