{"thread":{"id":"22923","subject":"using gvim as editor on Windows","startedAt":"2010-03-06T07:06:28Z","lastAt":"2010-03-11T09:36:48Z","messageCount":10,"participants":["Tait","Jacob Helwig","Markus Heidelberg","Junio C Hamano","Johannes Sixt"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"136230","messageId":"20100306070628.GM2480@ece.pdx.edu","threadId":"22923","inReplyTo":null,"subject":"using gvim as editor on Windows","fromName":"Tait","fromEmail":"git.git@t41t.com","sentAt":"2010-03-06T07:06:28Z","receivedAt":"2010-03-06T07:06:28Z","isPatch":false,"sender":{"key":"git.git@t41t.com","avatar":null},"body":"\nI'd prefer to use gvim as an editor on Windows XP instead of vim. (I also\nprefer it as a difftool, but that's a separate issue.) Gvim releases\nthe terminal when it launches, which git doesn't like too much. So I\ncreate gvimf.cmd in my path and use it for core.editor. Gvimf.cmd is\nquite simple; it calls:\n\tstart \"dummy\" /b /wait \"C:\\Program Files\\Vim\\vim72\\gvim.exe\" %*\n\nIn .gitconfig:\n[core]\n\teditor = gvimf.cmd\n\nThis works well enough for git commit. However, git rebase -i is not\nhappy. It errors:\n\tC:\\path to\\repo> git rebase -i HEAD~10\n\tThe system cannot find the file dummy.\n\tCould not execute editor\n\nOkay, I can fix that. I change core.editor to \"cmd \\\\/c gvimf.cmd\". (This\nis the same pattern I use for gvim as a difftool.) Now my .gitconfig has:\n[core]\n\teditor = cmd \\\\\\\\/c gvimf.cmd\n\nGit rebase is happy, but git commit is not. It errors:\n\tC:\\path to\\repo> git commit\n\t'OMMIT_EDITMSG' is not recognized as an internal or external command,\n\toperable program or batch file.\n\terror: There was a problem with the editor 'cmd \\\\/c gvimf.cmd'.\n\tPlease supply the message using either -m or -F option.\n\nIn the selfish hope to avoid work, has anyone else already encountered\nand solved how to use gvim as an editor?\n\nTait\n"},{"id":"136232","messageId":"8c9a061003052322v446acddbm5792038af450d0b9@mail.gmail.com","threadId":"22923","inReplyTo":"20100306070628.GM2480@ece.pdx.edu","subject":"Re: using gvim as editor on Windows","fromName":"Jacob Helwig","fromEmail":"jacob.helwig@gmail.com","sentAt":"2010-03-06T07:22:34Z","receivedAt":"2010-03-06T07:22:34Z","isPatch":false,"sender":{"key":"jacob.helwig@gmail.com","avatar":"https://avatars.githubusercontent.com/u/14557?v=4"},"body":"On Fri, Mar 5, 2010 at 23:06, Tait <git.git@t41t.com> wrote:\n>\n> I'd prefer to use gvim as an editor on Windows XP instead of vim. (I also\n> prefer it as a difftool, but that's a separate issue.) Gvim releases\n> the terminal when it launches, which git doesn't like too much. So I\n> create gvimf.cmd in my path and use it for core.editor. Gvimf.cmd is\n> quite simple; it calls:\n>        start \"dummy\" /b /wait \"C:\\Program Files\\Vim\\vim72\\gvim.exe\" %*\n>\n> In .gitconfig:\n> [core]\n>        editor = gvimf.cmd\n>\n> This works well enough for git commit. However, git rebase -i is not\n> happy. It errors:\n>        C:\\path to\\repo> git rebase -i HEAD~10\n>        The system cannot find the file dummy.\n>        Could not execute editor\n>\n> Okay, I can fix that. I change core.editor to \"cmd \\\\/c gvimf.cmd\". (This\n> is the same pattern I use for gvim as a difftool.) Now my .gitconfig has:\n> [core]\n>        editor = cmd \\\\\\\\/c gvimf.cmd\n>\n> Git rebase is happy, but git commit is not. It errors:\n>        C:\\path to\\repo> git commit\n>        'OMMIT_EDITMSG' is not recognized as an internal or external command,\n>        operable program or batch file.\n>        error: There was a problem with the editor 'cmd \\\\/c gvimf.cmd'.\n>        Please supply the message using either -m or -F option.\n>\n> In the selfish hope to avoid work, has anyone else already encountered\n> and solved how to use gvim as an editor?\n>\n> Tait\n>\n\nUse the -f (stay in the foreground) flag.  I haven't tried this in\nWindows, but that's how I've used it in Linux.\n\n[core]\n    editor = gvim -f\n"},{"id":"136233","messageId":"20100306073729.GN2480@ece.pdx.edu","threadId":"22923","inReplyTo":"8c9a061003052322v446acddbm5792038af450d0b9@mail.gmail.com","subject":"Re: using gvim as editor on Windows","fromName":"Tait","fromEmail":"git.git@t41t.com","sentAt":"2010-03-06T07:37:29Z","receivedAt":"2010-03-06T07:37:29Z","isPatch":false,"sender":{"key":"git.git@t41t.com","avatar":null},"body":"> > I'd prefer to use gvim as an editor on Windows XP instead of vim...\n> >     start \"dummy\" /b /wait \"C:\\Program Files\\Vim\\vim72\\gvim.exe\" %*\n>\n> Use the -f (stay in the foreground) flag.  I haven't tried this in\n> Windows, but that's how I've used it in Linux.\n>\n> [core]\n>     editor = gvim -f\n\nOn Windows, gvim -f is basically a shortcut for the start invocation I\npasted above. It works well enough for commit, but not for rebase (or\nalternately, for rebase -- so long as it doesn't open an editor for git\ncommit -- but not commit).\n\nTait\n"},{"id":"299172","messageId":"201003061317.38422.markus.heidelberg@web.de","threadId":"22923","inReplyTo":"20100306073729.GN2480@ece.pdx.edu","subject":"Re: using gvim as editor on Windows","fromName":"Markus Heidelberg","fromEmail":"markus.heidelberg@web.de","sentAt":"2010-03-06T12:17:38Z","receivedAt":"2010-03-06T12:17:38Z","isPatch":false,"sender":{"key":"markus.heidelberg@web.de","avatar":"https://avatars.githubusercontent.com/u/6334512?v=4"},"body":"Tait, 2010-03-06 08:37:\n> > > I'd prefer to use gvim as an editor on Windows XP instead of vim...\n> > >     start \"dummy\" /b /wait \"C:\\Program Files\\Vim\\vim72\\gvim.exe\" %*\n> >\n> > Use the -f (stay in the foreground) flag.  I haven't tried this in\n> > Windows, but that's how I've used it in Linux.\n> >\n> > [core]\n> >     editor = gvim -f\n> \n> On Windows, gvim -f is basically a shortcut for the start invocation I\n> pasted above.\n\nNot necessarily. You can avoid using the .bat wrappers from C:\\Windows,\nwhich cause the problem, but use gvim.exe directly by setting your PATH\nappropriately. It will also work for git-difftool.\n\nMarkus\n"},{"id":"136400","messageId":"20100308185439.GO2480@ece.pdx.edu","threadId":"22923","inReplyTo":"201003061317.38422.markus.heidelberg@web.de","subject":"Re: using gvim as editor on Windows","fromName":"Tait","fromEmail":"git.git@t41t.com","sentAt":"2010-03-08T18:54:39Z","receivedAt":"2010-03-08T18:54:39Z","isPatch":false,"sender":{"key":"git.git@t41t.com","avatar":null},"body":"> > On Windows, gvim -f is basically a shortcut for the start invocation I\n> > pasted above.\n>\n> Not necessarily. You can avoid using the .bat wrappers from C:\\Windows,\n> which cause the problem, but use gvim.exe directly by setting your PATH\n> appropriately. It will also work for git-difftool.\n\nI was hoping for a little more life in this thread.\n\nDoes calling the .exe directly work for you? If I call gvim.exe directly\n(with or without -f -- it doesn't matter), it opens a new file called\n$@. After quitting, the commit is aborted for lack of a commit message. I\ncan do an ugly work-around by making core.editor \"gvim.exe -f $@\" but\nthen gvim opens two buffers, one for the commit message and another for\nthe literal $@.\n\nWith rebase -i, calling the executable directly (with or without -f)\nworks to open the commit list. Rebase -i with $@ in the setting fails. It\nappears the filename is not quoted correctly and vim is opening multiple\nbuffers with various components of the path name as filenames.\n\nThe problem seems to be unique to me, so I'll find some time to look at\nwhat rebase and/or commit are doing wrong.\n\nTait\n"},{"id":"136438","messageId":"201003090032.10037.markus.heidelberg@web.de","threadId":"22923","inReplyTo":"20100308185439.GO2480@ece.pdx.edu","subject":"Re: using gvim as editor on Windows","fromName":"Markus Heidelberg","fromEmail":"markus.heidelberg@web.de","sentAt":"2010-03-08T23:32:09Z","receivedAt":"2010-03-08T23:32:09Z","isPatch":false,"sender":{"key":"markus.heidelberg@web.de","avatar":"https://avatars.githubusercontent.com/u/6334512?v=4"},"body":"Tait, 2010-03-08 19:54:\n> > > On Windows, gvim -f is basically a shortcut for the start invocation I\n> > > pasted above.\n> >\n> > Not necessarily. You can avoid using the .bat wrappers from C:\\Windows,\n> > which cause the problem, but use gvim.exe directly by setting your PATH\n> > appropriately. It will also work for git-difftool.\n> \n> I was hoping for a little more life in this thread.\n\nFirst of all: do you have the problems in cmd.exe or Git Bash or both?\n\n> Does calling the .exe directly work for you? If I call gvim.exe directly\n> (with or without -f -- it doesn't matter), it opens a new file called\n> $@.\n\nI don't know where the $@ should come from. You apparently don't invoke\ngvim.exe directly. git-commit is a C program, not a shell script, there\nshould come no $@ from this side. What does invoking gvim.exe on the\ncommand line without the use of git do?\n\nI have:\ncore.editor=gvim -f\nC:\\Programme\\Vim\\vim72 in PATH (both before or after C:\\WINDOWS works here)\nWorks with cmd.exe and Git Bash.\n\n> The problem seems to be unique to me, so I'll find some time to look at\n> what rebase and/or commit are doing wrong.\n\nI guess neither rebase nor commit are wrong in this case.\n\nMarkus\n"},{"id":"136418","messageId":"20100309024523.GU2480@ece.pdx.edu","threadId":"22923","inReplyTo":"201003090032.10037.markus.heidelberg@web.de","subject":"Re: using gvim as editor on Windows","fromName":"Tait","fromEmail":"git.git@t41t.com","sentAt":"2010-03-09T02:45:23Z","receivedAt":"2010-03-09T02:45:23Z","isPatch":false,"sender":{"key":"git.git@t41t.com","avatar":null},"body":"> First of all: do you have the problems in cmd.exe or Git Bash or both?\n\ncmd.exe\n\nI've never used git bash until now, but the behavior is the same there.\n\n> > Does calling the .exe directly work for you? If I call gvim.exe directly\n> > (with or without -f -- it doesn't matter), it opens a new file called\n> > $@.\n> \n> I don't know where the $@ should come from.\n\nIt comes from line 33 of editor.c, in launch_editor().\nif (strcmp(editor, \":\")) {\n    /* ... */\n    if (strcspn(editor, \"$ \\t'\") != len) {\n        /* there are specials */\n        strbuf_addf(&arg0, \"%s \\\"$@\\\"\", editor);\n        args[i++] = \"sh\";\n        args[i++] = \"-c\";\n        args[i++] = arg0.buf;\n    }\n    args[i++] = editor;\n    args[i++] = path;\n    args[i] = NULL;\n    /* ... */\n}\n\nIt looks like this was added to detect EDITOR=: but it also\nmanages to catch Windows paths. I'm not familiar with the EDITOR=:\nconvention. What is that supposed to indicate? Can we narrow the\ndetection to that specific case, or does a : anywhere in EDITOR need\nto be handled this way?\n\nRebase doesn't use launch_editor, instead just calling the editor\ndirectly. Coming up with a combination of quoting and escaping that\ncan pass both cases will be difficult or impossible.\n\nIt appears that e97c9a removed the code above from editor.c, but \nit's still present in prepare_shell_cmd() with even more legal \nfilename characters like = and ;.\n\nThanks for the help Markus.\n\nTait\n"},{"id":"136469","messageId":"7vzl2hw972.fsf@alter.siamese.dyndns.org","threadId":"22923","inReplyTo":"20100309024523.GU2480@ece.pdx.edu","subject":"Re: using gvim as editor on Windows","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-03-09T20:07:13Z","receivedAt":"2010-03-09T20:07:13Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Tait <git.git@t41t.com> writes:\n\n> It comes from line 33 of editor.c, in launch_editor().\n> if (strcmp(editor, \":\")) {\n\nThis says \"if 'editor' is not exactly the string ':'\", then come into this\nblock.  If you set editor to \":abc\", or \"c:\\path to\\my editor.exe\", they\nare not \"exactly the string ':'\" and the codepath inside will be executed.\n\n> ... I'm not familiar with the EDITOR=:\n> convention. What is that supposed to indicate?\n\nLiterally, it means \"run ':' command as the editor\".  ':' command takes\nand ignores arbitrary arguments and returns success without doing\nanything.  As such, the codepath pretends that it ran ':' command without\nactually running it, and returns as if it ran ':' command that left the\ninput file given as its argument unmodified.\n\n> Can we narrow the\n> detection to that specific case, or does a : anywhere in EDITOR need\n> to be handled this way?\n\nNo, and the if statement is already narrow enough.  I think the problem is\nthat you have a broken shell (\"sh\").\n\n    /* ... */\n    if (strcspn(editor, \"$ \\t'\") != len) {\n        /* there are specials */\n        strbuf_addf(&arg0, \"%s \\\"$@\\\"\", editor);\n        args[i++] = \"sh\";\n        args[i++] = \"-c\";\n        args[i++] = arg0.buf;\n    }\n    args[i++] = editor;\n    args[i++] = path;\n    args[i] = NULL;\n    /* ... */\n\n\nIf you have editor='\"c:\\some path\\editor\" -f', strcspn() notices that you have a\nfunny character in the path, and creates this string in arg0:\n\n    \"c:\\some path\\editor\" -f \"$@\"\n\nand feeds '-c', the above arg0, editor, and finally the name of the file,\nto your shell; it is the same as running this from the command line:\n\n    sh -c '\"c:\\some path\\editor\" -f \"$@\"' '\"c:\\some path\\editor\" -f' path-to-file\n\nNow shell is supposed to expand \"$@\" into positional parameters, i.e. $1\n(in this case, path-to-file) and run the named editor with it, IOW, your\neditor program should see \"-f\" as its first parameter, and path-to-file as\nits second parameter (and argv[] is terminated with NULL after that).\n\nIf you end up with a file whose name literally is '$@', that probably\nmeans your \"sh\" did not expand it correctly.\n"},{"id":"136565","messageId":"20100311090424.GV2480@ece.pdx.edu","threadId":"22923","inReplyTo":"7vzl2hw972.fsf@alter.siamese.dyndns.org","subject":"Re: using gvim as editor on Windows","fromName":"Tait","fromEmail":"git.git@t41t.com","sentAt":"2010-03-11T09:04:24Z","receivedAt":"2010-03-11T09:04:24Z","isPatch":false,"sender":{"key":"git.git@t41t.com","avatar":null},"body":"> This says \"if 'editor' is not exactly the string ':'\", ...\n\nOh right; I ... yeah, something. (I've got no excuse for mis-thinking\nthat one.)\n\n> If you end up with a file whose name literally is '$@', that probably\n> means your \"sh\" did not expand it correctly.\n\nIt does expand the $@ when I add it explicitly to core.editor though. Maybe\nit's the \"\"s. I'll have to figure out how to compile git for Windows\nto try a patch.\n\nOddly enough, if I remove the : from the file path, it does work as\nexpected. Adding the : back introduces the faulty behavior described\nearlier.\n\nTait\n"},{"id":"136566","messageId":"4B98B9B0.2010806@viscovery.net","threadId":"22923","inReplyTo":"20100311090424.GV2480@ece.pdx.edu","subject":"Re: using gvim as editor on Windows","fromName":"Johannes Sixt","fromEmail":"j.sixt@viscovery.net","sentAt":"2010-03-11T09:36:48Z","receivedAt":"2010-03-11T09:36:48Z","isPatch":false,"sender":{"key":"j6t@kdbg.org","avatar":"https://avatars.githubusercontent.com/u/14810926?v=4"},"body":"Tait schrieb:\n>> If you end up with a file whose name literally is '$@', that probably\n>> means your \"sh\" did not expand it correctly.\n> \n> It does expand the $@ when I add it explicitly to core.editor though. Maybe\n> it's the \"\"s. I'll have to figure out how to compile git for Windows\n> to try a patch.\n> \n> Oddly enough, if I remove the : from the file path, it does work as\n> expected. Adding the : back introduces the faulty behavior described\n> earlier.\n\nWhich : are you talking about?\n\n-- Hannes\n"}]}