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

121275Re: Incorrect working directory in gvim launched from Konqueror

Expand Messages
  • Jürgen Krämer
    Mar 1, 2011

      Jean Johner wrote:
      > Thank you for your answers.
      > In summary:
      > - Using "autochdir" is better than nothing, with the complications
      > described by Marco
      > - 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.

      > solves the problem (don't ask me why). Thank you Jürgen.

      The VimEnter event is triggered after all configurations file have been
      read and the first file, if any, has been loaded. If there is at least
      one file the % register contains its name. %:h gives the path to this
      file. %:p:h might actually be a better solution, because this takes care
      of file names without a path. On non-Unix-system this is no problem
      because :cd only prints the current directory if called without a path,
      but on Unix-systems :cd without a path changes the current directory to
      the user's home directory.

      > - I see no fatality why gvim is unable to have this behaviour by
      > default. Launching Nedit or emacs in the same conditions results in
      > the correct working directory. I will submit the problem to vim_dev
      > (did you eNG1Ne ?)

      I like the current behaviour. It's easier to change to the directory of
      a loaded file once you are inside Vim than to go back to the directory
      Vim was started from once the current directory has changed. I have
      defined two commands for this task:

      :command -bar -nargs=0 CD cd %:p:h
      :command -bar -nargs=0 LCD lcd %:p:h

      Also the current directory is much more predictable for this use-case

      vim **/files-in-subdirectories.txt

      ;-) It's still the directory from where you have issued the command and
      not some semi-random subdirectory.


      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
    • Show all 19 messages in this topic