Re: Windows, 'path', and "~"/$HOME
I figured it might be worthwhile for me to post my results for posterity, now that I've whittled out a comfortable setup, in light of how non-trivial and full of pitfalls I found it. Hopefully this may be of use to another hapless soul on WinXP (or, for that matter, for myself, should the unthinkable happen... disk crash, virus, etc. :) Here's the path-setting setup in my _vimrc: if has("win32") || has("win32unix") let esc_home=escape($HOME,' ') let &path =',,.' let &path.=','.esc_home.'\python\import' let &path.=','.esc_home.'\research\exp_acc_plan' let &path.=','.esc_home.'\research\toolbox' let &path.=','.esc_home.'\research\gltext' The backslashes are a nightmare. Here's the "reading list", useful prior to starting: :help path # pay attention to all the special rules and exceptions :help dos-backslash :help option-backslash :help filename-backslash Pitfalls and things to watch out for: - do not escape backslashes! (i.e., bad -> escape($HOME, ' \')); the double backslashes cause Vim to drop any leading drive letter spec, and treat the whole thing as a UNC name (e.g., "\\Foo\bar\baz") - do not put a backslash as last character of a directory: if you append another directory to it, the '\,' between them will be interpreted in a special way (e.g., "...path\foo\bar\,path\foo\baz\" == bad! use "...path\foo\bar,\path\foo\baz") I'm not sure how you'd have to escape the comma to have this work properly otherwise. - keep in mind that "foo\*" does not actually match any files in directory "foo", only files in its (immediate) subdirectories
Re: Windows, 'path', and "~"/$HOME
Maciej Kalisiak wrote: Thanks for a meaty reply Tony, plenty for me to read up on. Just one minor related issue: what is the convention of handling "~" in Vim under Windows? The problem is that under WinXP, when I use $HOME in Vim, it gets translated to "~" (i.e., the Unix convention for home directory), rather than the full absolute path. Yet at the same time it seems to me that Vim does not treat "~" as a home directory here, as :find does not find stuff if my path is set to "~/src" (which I originally set to "$HOME/src"). Since there are no spaces in "~/src", I don't think there's any escaping to do, hence this should've worked if Vim internally expanded out the tilde. Oh, one other minor one: under Windows, are "\" and "/" *always* interchangeable in Vim as path seperators, or are there instances where you must use the Windows backslash convention? I ask because I thought I read in the manual that they are interchangeable, yet having exchanged them I was seeing different results. I suspect the issue was my improper escaping of the backslashes, but I'd like to eliminate this one potential source of error before going on to debug... [...] For internal use, Vim for Windows can use either '\' or '/' as path separators, or even both of them in the same path. However, '\' is also sometimes used to escape characters which would otherwise have a "separator" meaning. This depends on context. When Vim knows that some value is a file/folder name, it will usually interpret any of '/', '\' or '\\' as a path separator, to be passed to the OS as a single backslash, except where a backslash is obviously meant as an escape prefix. As a general rule, single-quoted strings are used literally while backslashes in double-quoted strings or (as in :set) in unquoted strings are usually meant as escape characters. When a single string is interpreted repeatedly before being used, it may be necessary to double the backslashes as many times as there are "passes". see :help dos-backslash :help option-backslash :help filename-backslash For internal use also, Vim uses $NAME to designate environment variables, and ~ (at the start of a path) as a synonym for $HOME, like Unix and not like Dos. When paths are to be passed to a Dos/Windows program, including but not limited to the shell (COMMAND.COM or cmd.exe), they are to be expressed according to Dos/Windows conventions, with only '\' as path separators, and possibly with double-quoting if spaces within the path would otherwise cause premature termination of the string. With the default settings of the relevant options, Vim is usually clever enough to pass the right value, but it may err in borderline cases. When environment variables or the name of a home directory are to be passed to a Dos/Windows program, Vim usually passes the value, not the name; however if you want to pass the name for evaluation by a Dos shell you must use %NAME%, not $NAME and not ~, because that is the Dos convention. Best regards, Tony.
Re: Windows, 'path', and "~"/$HOME
Thanks for a meaty reply Tony, plenty for me to read up on. Just one minor related issue: what is the convention of handling "~" in Vim under Windows? The problem is that under WinXP, when I use $HOME in Vim, it gets translated to "~" (i.e., the Unix convention for home directory), rather than the full absolute path. Yet at the same time it seems to me that Vim does not treat "~" as a home directory here, as :find does not find stuff if my path is set to "~/src" (which I originally set to "$HOME/src"). Since there are no spaces in "~/src", I don't think there's any escaping to do, hence this should've worked if Vim internally expanded out the tilde. Oh, one other minor one: under Windows, are "\" and "/" *always* interchangeable in Vim as path seperators, or are there instances where you must use the Windows backslash convention? I ask because I thought I read in the manual that they are interchangeable, yet having exchanged them I was seeing different results. I suspect the issue was my improper escaping of the backslashes, but I'd like to eliminate this one potential source of error before going on to debug... On 27/06/06, A.J.Mechelynck <[EMAIL PROTECTED]> wrote: :let escaped_home = escape(substitute($HOME,'/','\\',''),' ') :let &path = escaped_home . '\src' :let &path .= ',' . escaped_home . '\include' etc. See under ":help 'path'", the paragraph starting "Spaces can also" about using the ":set" command to set a 'path' with spaces in it. ":set option=foo\\\ bar" is equivalent to ":let &option = 'foo\ bar'". If $HOME contains spaces, you must backslash-escape them, either manually like you did, or by using the escape() function as shown above. Alternately, you can use the short name of the $HOME directory, which has no spaces in it (because spaces are forbidden in short names): :let short_home = 'C:\DOCUME~1\User\MYDOCU~1\Home' :exe "set path=" . short_home . '\src' :exe "set path+=" . short_home . '\include' etc. Note the difference between single and double quotes in Vim: 'foo\ bar' is equivalent to "foo\\ bar" and its value has one backslash in it.
Re: Windows, 'path', and "~"/$HOME
Maciej Kalisiak wrote: I'm under Windows XP, and I'm having a devil of a time trying to set 'path' to a bunch of directories in my home directory. My $HOME (and thus presumably "~") point at c:\Documents and Settings\User\My Documents\Home. Doing something like set path=$HOME/src does not work (e.g., ":find" does not find files that are there). I've tried many variations, even expanding out $HOME in various forms, and the single variation I have gotten to work was let &path='c:\Documents\ and\ Settings\User\My\ Documents\Home\src\' IIRC, using forward slashes breaks this, using ":set path" instead of ":let &path" breaks this, using ~ or $HOME breaks this, etc. Also, with this form I can't seem to be able to later do "let &path+='c:\'. (I get E734) Is there an easier way to set 'path' in Windows?? I'd like to add something like 5 to 10 directories to path, and this form is s unwieldly and ugly... :let escaped_home = escape(substitute($HOME,'/','\\',''),' ') :let &path = escaped_home . '\src' :let &path .= ',' . escaped_home . '\include' etc. See under ":help 'path'", the paragraph starting "Spaces can also" about using the ":set" command to set a 'path' with spaces in it. ":set option=foo\\\ bar" is equivalent to ":let &option = 'foo\ bar'". If $HOME contains spaces, you must backslash-escape them, either manually like you did, or by using the escape() function as shown above. Alternately, you can use the short name of the $HOME directory, which has no spaces in it (because spaces are forbidden in short names): :let short_home = 'C:\DOCUME~1\User\MYDOCU~1\Home' :exe "set path=" . short_home . '\src' :exe "set path+=" . short_home . '\include' etc. Note the difference between single and double quotes in Vim: 'foo\ bar' is equivalent to "foo\\ bar" and its value has one backslash in it. Best regards, Tony.