Loading ...
Sorry, an error occurred while loading the content.

Re: Incorrect working directory in gvim launched from Konqueror

Expand Messages
  • Marco
    ... This line is still wrong. A single quote is missing. au VimEnter * if expand( % ) != | cd %:h | endif This line solves the problem for me. Thank you.
    Message 1 of 19 , Mar 2, 2011
    • 0 Attachment
      On 2011-03-01 Jürgen Krämer <jottkaerr@...> wrote:

      > > - Using
      > > au VimEnter * if expand('%') != ""' | cd %:h | endif
      > > (note that the double quote must be doubled)
      >
      > actually, there were no double quotes in the original command, just
      > two strings with single quotes: '%' and the empty string.

      This line is still wrong. A single quote is missing.

      au VimEnter * if expand('%') != '""' | cd %:h | endif

      This line solves the problem for me. Thank you. I would like to see this as
      default behaviour, too.


      Marco


      --
      You received this message from the "vim_use" maillist.
      Do not top-post! Type your reply below the text you are replying to.
      For more information, visit http://www.vim.org/maillist.php
    • Marco
      ... I totally agree. ... ACK ... +1 Marco -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the text you are
      Message 2 of 19 , Mar 2, 2011
      • 0 Attachment
        On 2011-03-01 Jean Johner <jean.johner@...> wrote:

        > Hi Jurgen,
        >
        > Thank you for your explanations.
        >
        > I can understand your preferences but consider the following facts:
        >
        > - launching gvim from the command line in a subdirectory always
        > results in the subdirectory to be the working directory.
        > I see no reason why double-clicking in Konqueror should behave
        > differently. In most situations, people launching gvim in a
        > subdirectory want to open other files in the same directory.

        I totally agree.

        > - The behaviour would be compatible with the behaviour of almost all
        > other text editors [...]

        ACK

        > Perhaps we could vote.

        +1


        Marco


        --
        You received this message from the "vim_use" maillist.
        Do not top-post! Type your reply below the text you are replying to.
        For more information, visit http://www.vim.org/maillist.php
      • Jürgen Krämer
        Hi, ... please read my mail again; the original line was correct regarding the single quotes. Your line checks if the current file is not one with a name
        Message 3 of 19 , Mar 2, 2011
        • 0 Attachment
          Hi,

          Marco schrieb:
          > On 2011-03-01 Jürgen Krämer <jottkaerr@...> wrote:
          >
          >>> - Using
          >>> au VimEnter * if expand('%') != ""' | cd %:h | endif
          >>> (note that the double quote must be doubled)
          >>
          >> actually, there were no double quotes in the original command, just
          >> two strings with single quotes: '%' and the empty string.
          >
          > This line is still wrong. A single quote is missing.
          >
          > au VimEnter * if expand('%') != '""' | cd %:h | endif
          >
          > This line solves the problem for me. Thank you. I would like to see this as
          > default behaviour, too.

          please read my mail again; the original line was correct regarding the
          single quotes.

          Your line checks if the current file is not one with a name consisting
          of two double quotes. However unlikely such a name is, the test is wrong.
          And it does not take care of the case where Vim is started without a
          filename.

          Regards,
          Jürgen

          --
          Sometimes I think the surest sign that intelligent life exists elsewhere
          in the universe is that none of it has tried to contact us. (Calvin)

          --
          You received this message from the "vim_use" maillist.
          Do not top-post! Type your reply below the text you are replying to.
          For more information, visit http://www.vim.org/maillist.php
        • Ben Schmidt
          ... This is still not what was intended, though syntactically correct. There should not be any double quotes at all: au VimEnter * if expand( % ) != | cd
          Message 4 of 19 , Mar 2, 2011
          • 0 Attachment
            > This line is still wrong. A single quote is missing.
            >
            > au VimEnter * if expand('%') != '""' | cd %:h | endif

            This is still not what was intended, though syntactically correct. There
            should not be any double quotes at all:

            au VimEnter * if expand('%') != '' | cd %:h | endif

            Ben.



            --
            You received this message from the "vim_use" maillist.
            Do not top-post! Type your reply below the text you are replying to.
            For more information, visit http://www.vim.org/maillist.php
          • Marco
            ... Sorry, you re right. My fault. Marco -- You received this message from the vim_use maillist. Do not top-post! Type your reply below the text you are
            Message 5 of 19 , Mar 2, 2011
            • 0 Attachment
              On 2011-03-02 Jürgen Krämer <jottkaerr@...> wrote:

              >
              > Hi,
              >
              > Marco schrieb:
              > > On 2011-03-01 Jürgen Krämer <jottkaerr@...> wrote:
              > >
              > >>> - Using
              > >>> au VimEnter * if expand('%') != ""' | cd %:h | endif
              > >>> (note that the double quote must be doubled)
              > >>
              > >> actually, there were no double quotes in the original command, just
              > >> two strings with single quotes: '%' and the empty string.
              > >
              > > This line is still wrong. A single quote is missing.
              > >
              > > au VimEnter * if expand('%') != '""' | cd %:h | endif
              > >
              > > This line solves the problem for me. Thank you. I would like to see this
              > > as default behaviour, too.
              >
              > please read my mail again; the original line was correct regarding the
              > single quotes.
              >
              > Your line checks if the current file is not one with a name consisting
              > of two double quotes. However unlikely such a name is, the test is wrong.
              > And it does not take care of the case where Vim is started without a
              > filename.

              Sorry, you're right. My fault.


              Marco


              --
              You received this message from the "vim_use" maillist.
              Do not top-post! Type your reply below the text you are replying to.
              For more information, visit http://www.vim.org/maillist.php
            • Christian Brabandt
              Hi Jean! ... The behaviour is already built into vim. But currently it only works when dragging a file onto gvim and holding down the shift key. I don t know,
              Message 6 of 19 , Mar 2, 2011
              • 0 Attachment
                Hi Jean!

                On Di, 01 Mär 2011, Jean Johner wrote:

                > I can understand your preferences but consider the following facts:
                >
                > - launching gvim from the command line in a subdirectory always
                > results in the subdirectory to be the working directory.
                > I see no reason why double-clicking in Konqueror should behave
                > differently. In most situations, people launching gvim in a
                > subdirectory want to open other files in the same directory. By the
                > way, other people in this thread seem to suffer from the present
                > situation.
                >
                > - The behaviour would be consistent with the Windows behaviour
                >
                > - The behaviour would be compatible with the behaviour of almost all
                > other text editors in KDE (Emacs, XEmacs, Nedit, Kwrite, Kate). An
                > exception is Kedit which behaves like gvim.

                The behaviour is already built into vim. But currently it only works
                when dragging a file onto gvim and holding down the shift key. I don't
                know, whether vim can distinguish between being called from a file
                manager and from the commandline.

                Hm, but wait, you should be able to script something? Using the solution
                from Jürgen, that can be slightly improved to the following:

                (untested)
                au VimEnter * if empty($TERM) | sil cd %:h | endif

                I think, it doesn't even matter, if the filename is given as relative or
                absolute path, because even when given just the filename without a path
                or no filename at all, ':h' will expand to '.' which is save in that
                case. In any case, the check for an empty $TERM variable should prevent
                changing the directory, when called from the command line.

                regards,
                Christian

                --
                You received this message from the "vim_use" maillist.
                Do not top-post! Type your reply below the text you are replying to.
                For more information, visit http://www.vim.org/maillist.php
              • John Little
                ... I ve got KDE 4, but in principle this stuff is controlled by desktop entry files (.desktop), which are used by gnome too so I don t think it s different
                Message 7 of 19 , Mar 2, 2011
                • 0 Attachment
                  On Feb 28, 9:34 am, Jean Johner <jean.joh...@...> wrote:
                  > Doing the same in KDE 3.5 Konqueror file manager opens file1.f but the
                  > working directory is always the user's home directory.

                  I've got KDE 4, but in principle this stuff is controlled by desktop
                  entry files (.desktop), which are used by gnome too so I don't think
                  it's different back in 3.5.

                  My KDE (in the absence of set autochdir and the like) starts gvim in
                  my $HOME/Documents; I suppose that's from system settings->about me-
                  >paths.

                  I suggest you check out

                  ~/.local/share/applications/gvim.desktop

                  If it's not there, copy it from /usr/share/applications. (I had to
                  customize mine because KDE didn't not honour my $PATH when running
                  gvim, and insisted on running /usr/bin/gvim when I wanted /usr/local/
                  bin/gvim.) Or, use the system settings to edit the gvim action, I
                  can't remember what it was like for KDE 3.5.

                  If there's a Path= entry, that will be used, but that's no good.

                  Changing the exec key to

                  f=%f;cd ${f%%/*};/usr/local/bin/gvim -f %F

                  worked, but looks dodgy in that it assumes bash is being used to run
                  it; the Desktop Entry specification (http://standards.freedesktop.org/
                  desktop-entry-spec/desktop-entry-spec-latest.html) doesn't say
                  anything about that. and I imagine that desktop environments are free
                  to exec the command directly.

                  Telling vim to do it seems to me to be supported; it's working for me
                  with:

                  /usr/local/bin/gvim -c "%%:h" -f %F

                  That sets the current directory to the path of the first file. The %
                  is doubled to escape it from the desktop mechanism.

                  NGN, you might like to try that too. I think the other editors (kate,
                  gedit, ...) are doing the equivalent of vim's set autochdir. IMO this
                  is not a vim issue, it's a desktop entry specification problem, in
                  that there's no obvious way to specify the path of the invoked file.

                  Regards, John

                  --
                  You received this message from the "vim_use" maillist.
                  Do not top-post! Type your reply below the text you are replying to.
                  For more information, visit http://www.vim.org/maillist.php
                • Jean Johner
                  ... In KDE 3.5, to launch gvim by clicking a .f file and have the good working directory (without adding anything in the .vimrc), you must pull the Konqueror s
                  Message 8 of 19 , Mar 6, 2011
                  • 0 Attachment
                    John Little wrote:
                    >
                    > Telling vim to do it seems to me to be supported; it's working for me
                    > with:
                    >
                    > /usr/local/bin/gvim -c "%%:h" -f %F
                    >
                    > That sets the current directory to the path of the first file. The %
                    > is doubled to escape it from the desktop mechanism.

                    In KDE 3.5, to launch gvim by clicking a .f file and have the good
                    working directory (without adding anything in the .vimrc), you must
                    pull the Konqueror's "Settings" menu, choose "Configure Konqueror"
                    then "File Associations", choose x_fortran in "text", click gvim then
                    "edit" then "Application". In "Command", I typed
                    $HOME/bin/gvim -c "cd %:h" %f

                    (note that the % is not doubled, even %f is optional. Also note that
                    you have forgotten cd in your command).

                    Alternatively, you may edit the
                    $HOME/.kde/share/applnk/.hidden/gvim.desktop
                    file.

                    I keep thinking that this command should be done by default by gvim.

                    Thank you John,

                    Best regards,

                    Jean Johner

                    --
                    You received this message from the "vim_use" maillist.
                    Do not top-post! Type your reply below the text you are replying to.
                    For more information, visit http://www.vim.org/maillist.php
                  • John Little
                    ... Sometimes, one wants to edit a file somewhere else but remain where you are . IMO vim isn t about telling you how to work just because other editors do
                    Message 9 of 19 , Mar 6, 2011
                    • 0 Attachment
                      On Mar 7, 10:58 am, Jean Johner <jean.joh...@...> wrote:

                      > I keep thinking that this command should be done by default by gvim.

                      Sometimes, one wants to edit a file "somewhere else" but remain "where
                      you are". IMO vim isn't about telling you how to work just because
                      other editors do it that way.

                      Regards, John

                      --
                      You received this message from the "vim_use" maillist.
                      Do not top-post! Type your reply below the text you are replying to.
                      For more information, visit http://www.vim.org/maillist.php
                    • Jean Johner
                      ... OK. I appreciate your art of abbreviations, what is NGN for ? (in a previous mail). Regards, Jean -- You received this message from the vim_use maillist.
                      Message 10 of 19 , Mar 7, 2011
                      • 0 Attachment
                        On Mar 7, 1:30 am, John Little <john.b.lit...@...> wrote:
                        > On Mar 7, 10:58 am, Jean Johner <jean.joh...@...> wrote:
                        >
                        > > I keep thinking that this command should be done by default by gvim.
                        >
                        > Sometimes, one wants to edit a file "somewhere else" but remain "where
                        > you are".  IMO vim isn't about telling you how to work just because
                        > other editors do it that way.
                        >
                        > Regards, John

                        OK.

                        I appreciate your art of abbreviations, what is NGN for ? (in a
                        previous mail).

                        Regards, Jean

                        --
                        You received this message from the "vim_use" maillist.
                        Do not top-post! Type your reply below the text you are replying to.
                        For more information, visit http://www.vim.org/maillist.php
                      Your message has been successfully submitted and would be delivered to recipients shortly.