Vim Tips Wiki
No edit summary
 
(Added to Automated_Text_Insertion Category ; contents reformated)
Line 1: Line 1:
  +
<!-- to do: apply the comments to the tip -->
  +
[[Category:Automated_Text_Insertion]]
 
{{review}}
 
{{review}}
 
{{Tip
 
{{Tip
Line 9: Line 11:
 
|rating=4/3
 
|rating=4/3
 
|text=
 
|text=
The WHY:
+
==The WHY: ==
   
  +
Some include paths (VC7 in particular) are very deep, so much so that I opted to "<tt>set complete-=i</tt>" (which is to say to NOT 'scan current and included files' during completion; see {{help|'complete'}}).
   
   
  +
This allowed me to <tt>&lt;ctrl+n&gt;</tt>/<tt>&lt;ctrl+p&gt;</tt> without delay, and when I knew what I was trying to complete was in the system includes (sprintf for instance) I could use CTRL-X CTRL-I (see: {{help|i_CTRL-X_CTRL-I}}) as needed, for instance '<tt>spr&lt;ctrl-x&gt;&lt;ctrl-i&gt;</tt>'. This worked like a charm for many moons. Until recently when I've found a need to have a different set of includes to search and I wanted normal <tt>CTRL-N</tt>/<tt>CTRL-P</tt> to search these files and NOT the system include. I was also getting kind of tired of not searching the current directory via CTRL-N/CTRL-P as well.
Some include paths (VC7 in particular) are very deep, so much so that I opted
 
   
to "set complete-=i" (which is to say to NOT 'scan current and included files'
 
 
during completion; see :h complete).
 
 
 
 
This allowed me to &lt;ctrl+n&gt;/&lt;ctrl+p&gt; without delay, and when I knew what I was
 
 
trying to complete was in the system includes (sprintf for instance) I could
 
 
use CTRL-X CTRL-I (see: :h i_CTRL-X_CTRL-I) as needed, for instance
 
 
'spr&lt;ctrl-x&gt;&lt;ctrl-i&gt;'. This worked like a charm for many moons. Until recently
 
 
when I've found a need to have a different set of includes to search and I
 
 
wanted normal CTRL-N/CTRL-P to search these files and NOT the system include. I
 
 
was also getting kind of tired of not searching the current directory via
 
 
CTRL-N/CTRL-P as well.
 
 
 
 
 
 
 
 
A Solution: aka Enter hair brained scheme &#35;1
 
 
 
 
The concept is simple, search the path each time (i.e."set complete+=i", which
 
 
is default) but limit what the path is.
 
   
  +
==A Solution: aka Enter hair brained scheme &#35;1 ==
   
  +
The concept is simple, search the path each time (i.e."<tt>set complete+=i</tt>", which is default) but limit what the path is.
   
 
The solution.. well it is pretty simple too really.
 
The solution.. well it is pretty simple too really.
   
  +
I decided on a few global scoped variables to hold my paths and then a function/command to help set &amp;path. Seemed easy enough. This is from my .vimrc and as you can see it is a mess. It does (as far as I know!) function properly with no adverse effects, but I am very definitely not certain of that yet.
   
  +
if has("win32")
 
  +
" Base path :".,,"
I decided on a few global scoped variables to hold my paths and then a
 
  +
let g:feral_path_B = &amp;path
 
  +
" System include path
function/command to help set &amp;path. Seemed easy enough.
 
  +
set path=C:/PROGRA~1/MICROS~1.NET/Vc7/include/**
 
  +
" set path+=C:/Program\ Files/Microsoft\ Visual\ Studio\ .NET/Vc7/PlatformSDK/include/prerelease/**
 
  +
let g:feral_path_S = &amp;path
 
  +
" project include path
 
  +
set path=C:/Program\ Files/ClanLib/include/**
 
  +
"" set path=C:/Program\ Files/ClanLib/ClanLib-0.7/Sources/**
This is from my .vimrc and as you can see it is a mess. It does (as far as I
 
  +
let g:feral_path_P = &amp;path
 
  +
know!) function properly with no adverse effects, but I am very definitely not
 
  +
" start off with base path
 
  +
execute "set path=".g:feral_path_B
certain of that yet.
 
  +
 
  +
function Feral_Path(whichpaths)
 
  +
if strlen(a:whichpaths)
 
  +
let old_path = &amp;path
--------------------------------------------------
 
  +
set path=
 
  +
let paths_to_use = a:whichpaths
 
  +
while strlen(paths_to_use)
 
  +
" call confirm("SO:"."\npath_to_use:".paths_to_use."\npath_to_use[0]:".paths_to_use[0]."\nExists?".exists("g:feral_path_{paths_to_use[0]}") )
if has("win32")
 
  +
if exists("g:feral_path_{paths_to_use[0]}")
 
  +
" call confirm("is1:".g:feral_path_{paths_to_use[0]})
" Base path :".,,"
 
  +
execute "set path+=".substitute(g:feral_path_{paths_to_use[0]}, "\\ ", "\\\\ ", "g")
 
  +
"execute "set path+=".substitute("C:/Program\ Files/ClanLib/include/**", "\\ ", "\\\\ ", "g")
let g:feral_path_B = &amp;path
 
  +
"execute "set path+="."C:/Program\\ Files/ClanLib/include/**"
 
  +
" System include path
 
  +
" call confirm("is2:".&amp;path)
 
  +
" remove the first char from paths_to_use now
set path=C:/PROGRA~1/MICROS~1.NET/Vc7/include/**
 
  +
let paths_to_use = strpart(paths_to_use,1)
 
  +
" call confirm("is3:".paths_to_use)
" set path+=C:/Program\ Files/Microsoft\ Visual\ Studio\ .NET/Vc7/PlatformSDK/include/prerelease/**
 
  +
else
 
  +
" not found; remove this char and see if we can try again.
let g:feral_path_S = &amp;path
 
  +
let paths_to_use = strpart(paths_to_use,1)
 
  +
" call confirm("is4:".paths_to_use)
" project include path
 
  +
endif
 
  +
endwhile
set path=C:/Program\ Files/ClanLib/include/**
 
  +
" call confirm("outside while")
 
  +
"" set path=C:/Program\ Files/ClanLib/ClanLib-0.7/Sources/**
 
  +
if strlen(&amp;path) == 0
 
  +
" call confirm("restoring path as it was when we got here.")
let g:feral_path_P = &amp;path
 
  +
execute "set path=".old_path
 
  +
endif
 
  +
endif
 
  +
" call confirm("outside outer if")
" start off with base path
 
  +
endfunction
 
  +
execute "set path=".g:feral_path_B
 
  +
command -nargs=1 FP call Feral_Path(&lt;q-args&gt;)
 
 
 
function Feral_Path(whichpaths)
 
 
if strlen(a:whichpaths)
 
 
let old_path = &amp;path
 
 
set path=
 
 
let paths_to_use = a:whichpaths
 
 
while strlen(paths_to_use)
 
 
" call confirm("SO:"."\npath_to_use:".paths_to_use."\npath_to_use[0]:".paths_to_use[0]."\nExists?".exists("g:feral_path_{paths_to_use[0]}") )
 
 
if exists("g:feral_path_{paths_to_use[0]}")
 
 
" call confirm("is1:".g:feral_path_{paths_to_use[0]})
 
 
execute "set path+=".substitute(g:feral_path_{paths_to_use[0]}, "\\ ", "\\\\ ", "g")
 
 
"execute "set path+=".substitute("C:/Program\ Files/ClanLib/include/**", "\\ ", "\\\\ ", "g")
 
 
"execute "set path+="."C:/Program\\ Files/ClanLib/include/**"
 
 
 
 
" call confirm("is2:".&amp;path)
 
 
" remove the first char from paths_to_use now
 
 
let paths_to_use = strpart(paths_to_use,1)
 
 
" call confirm("is3:".paths_to_use)
 
 
else
 
 
" not found; remove this char and see if we can try again.
 
 
let paths_to_use = strpart(paths_to_use,1)
 
 
" call confirm("is4:".paths_to_use)
 
 
 
endif
 
endif
   
  +
==The Usage: ==
endwhile
 
 
" call confirm("outside while")
 
 
if strlen(&amp;path) == 0
 
 
" call confirm("restoring path as it was when we got here.")
 
 
execute "set path=".old_path
 
 
endif
 
 
endif
 
 
" call confirm("outside outer if")
 
 
endfunction
 
 
command -nargs=1 FP call Feral_Path(&lt;q-args&gt;)
 
 
endif
 
 
 
 
--------------------------------------------------
 
 
 
 
 
 
 
 
The Usage:
 
 
 
 
To use this the above code frag must be sourced, in my case this is in my
 
 
.vimrc.
 
 
 
 
You need some paths to switch between, these global variables must start with
 
 
"g:feral_path_" and the last character is used to identify (NOTE: SINGLE CHAR
 
 
ONLY!) the path.
 
   
  +
To use this the above code frag must be sourced, in my case this is in my .vimrc.
   
  +
You need some paths to switch between, these global variables must start with "<tt>g:feral_path_</tt>" and the last character is used to identify (NOTE: SINGLE CHAR ONLY!) the path.
   
 
For instance:
 
For instance:
 
 
 
--------------------------------------------------
 
 
 
set path=C:/PROGRA~1/MICROS~1.NET/Vc7/include/**
 
set path=C:/PROGRA~1/MICROS~1.NET/Vc7/include/**
  +
" set path+=C:/Program\ Files/Microsoft\ Visual\ Studio\ .NET/Vc7/PlatformSDK/include/prerelease/**
   
  +
Note how I use '<tt>set path=</tt>' and thus can use this more or less naturally, including += to add an additional path. Not strickly necessary but does not hurt anything as far as I know.
" set path+=C:/Program\ Files/Microsoft\ Visual\ Studio\ .NET/Vc7/PlatformSDK/include/prerelease/**
 
 
--------------------------------------------------
 
 
 
 
Note how I use 'set path=' and thus can use this more or less naturally,
 
 
includeing += to add an additional path. Not strickly necessary but does not
 
 
hurt anything as far as I know.
 
 
 
 
--------------------------------------------------
 
   
 
let g:feral_path_S = &amp;path
 
let g:feral_path_S = &amp;path
   
  +
I then set my global variable (this one is referenced as 'S') to the current value of &amp;path.
--------------------------------------------------
 
 
 
 
I then set my global variable (this one is referenced as 'S') to the current
 
 
value of &amp;path.
 
 
 
   
 
It is a bit messy but it is straight forward and to the point.
 
It is a bit messy but it is straight forward and to the point.
   
  +
I also define the base path (referenced as 'B'), and my project path (referenced as 'P'). NOTE how 'B' is set to <tt>&amp;path</tt>'s initial value; which in my case is the default for the system.
 
 
I also define the base path (referenced as 'B'), and my project path
 
 
(referenced as 'P'). NOTE how 'B' is set to &amp;path 's initial value; which in
 
 
my case is the default for the system.
 
 
 
 
--------------------------------------------------
 
   
 
" Base path :".,,"
 
" Base path :".,,"
 
 
let g:feral_path_B = &amp;path
 
let g:feral_path_B = &amp;path
 
 
" System include path
 
" System include path
 
 
set path=C:/PROGRA~1/MICROS~1.NET/Vc7/include/**
 
set path=C:/PROGRA~1/MICROS~1.NET/Vc7/include/**
  +
" set path+=C:/Program\ Files/Microsoft\ Visual\ Studio\ .NET/Vc7/PlatformSDK/include/prerelease/**
 
" set path+=C:/Program\ Files/Microsoft\ Visual\ Studio\ .NET/Vc7/PlatformSDK/include/prerelease/**
 
 
 
let g:feral_path_S = &amp;path
 
let g:feral_path_S = &amp;path
 
 
" project include path
 
" project include path
 
 
set path=C:/Program\ Files/ClanLib/include/**
 
set path=C:/Program\ Files/ClanLib/include/**
  +
"" set path=C:/Program\ Files/ClanLib/ClanLib-0.7/Sources/**
 
"" set path=C:/Program\ Files/ClanLib/ClanLib-0.7/Sources/**
 
 
 
let g:feral_path_P = &amp;path
 
let g:feral_path_P = &amp;path
 
--------------------------------------------------
 
 
 
   
 
So this gives us 3 paths to play with, B (base), S (system) and P (project).
 
So this gives us 3 paths to play with, B (base), S (system) and P (project).
 
 
   
 
I set &amp;path to the default value I want directly:
 
I set &amp;path to the default value I want directly:
 
--------------------------------------------------
 
   
 
" start off with base path
 
" start off with base path
 
 
execute "set path=".g:feral_path_B
 
execute "set path=".g:feral_path_B
   
  +
Now, to use this when you are coding away you can *easily* change &amp;path via the :FP command.
--------------------------------------------------
 
 
 
 
 
 
Now, to use this when you are coding away you can *easily* change &amp;path via the
 
 
:FP command.
 
 
 
 
:FP takes one argument, that argument is the one-word group of paths to set,
 
 
use the one character to reference each path;
 
 
   
  +
<nowiki>:</nowiki>FP takes one argument, that argument is the one-word group of paths to set, use the one character to reference each path;
   
 
i.e.
 
i.e.
  +
:FP B
 
  +
echo &amp;path: .,,
:FP B
 
 
echo &amp;path: .,,
 
   
 
to set path to basic and system, i.e.
 
to set path to basic and system, i.e.
  +
:FP BS
 
  +
echo &amp;path: .,,,C:\PROGRA~1\MICROS~1.NET\Vc7\include**
:FP BS
 
 
echo &amp;path: .,,,C:\PROGRA~1\MICROS~1.NET\Vc7\include**
 
 
 
   
 
or if I wanted system then basic:
 
or if I wanted system then basic:
  +
:FP SB
 
  +
echo &amp;path: C:\PROGRA~1\MICROS~1.NET\Vc7\include**,.,,
:FP SB
 
 
echo &amp;path: C:\PROGRA~1\MICROS~1.NET\Vc7\include**,.,,
 
 
 
 
 
   
 
As you can see it is pretty simple to manipulate &amp;path now via the :FP command.
 
As you can see it is pretty simple to manipulate &amp;path now via the :FP command.
 
 
 
 
   
 
You can specify one or more paths to set:
 
You can specify one or more paths to set:
  +
:FP BPS
  +
echo &amp;path: .,,,C:/Program Files/ClanLib/include/**,C:/PROGRA~1/MICROS~1.NET/Vc7/include/**
   
  +
All in all this should be fairly simple to use, the major problem I see is forgetting the reference chars, but hopefully with clever naming this won't be a problem.
:FP BPS
 
 
echo &amp;path: .,,,C:/Program Files/ClanLib/include/**,C:/PROGRA~1/MICROS~1.NET/Vc7/include/**
 
 
 
 
 
 
All in all this should be fairly simple to use, the major problem I see is
 
 
forgetting the reference chars, but hopefully with clever naming this won't be
 
 
a problem.
 
 
 
 
 
   
 
An alternative to the above mess:
 
An alternative to the above mess:
   
  +
You could of course forgot the above mess and just have menu entries/commands/mappings/what have you that sets <tt>&amp;path</tt> directly.
   
   
  +
==Closing remarks: ==
You could of course forgot the above mess and just have menu
 
   
  +
All in all this is a simple, quick HACK that perhaps no one will every find of use.
entries/commands/mappings/what have you that sets &amp;path directly.
 
   
  +
I submit this as a tip in the hopes that it might be useful in someway to someone.
   
  +
I suggest you be a little leery of the code, though it *should* be fine. But, we all know how that goes! (=
 
 
 
 
 
 
 
 
 
Closing remarks:
 
 
 
 
All in all this is a simple, quick HACK that perhaps no one will every find of
 
 
use.
 
 
 
 
I submit this as a tip in the hopes that it might be useful in someway to
 
 
someone.
 
 
 
 
I suggest you be a little leery of the code, though it *should* be fine. But,
 
 
we all know how that goes! (=
 
 
   
   
Line 399: Line 158:
   
 
== Comments ==
 
== Comments ==
Note to self, author editbox eats angle brackts.
 
Author should read:
 
sreny--AT--srenyqernzf.pbz (Rot13ed)
 
 
sreny--AT--srenyqernzf.pbz (Rot13ed)
 
, March 24, 2005 20:00
 
----
 
 
You should write a C++ book. Good stuff.
 
You should write a C++ book. Good stuff.
   
Line 413: Line 165:
 
Thank you for the kind words Ragini (=
 
Thank you for the kind words Ragini (=
   
  +
BUG: The above contains problems when the path's have spaces in them. As mentioned in :h path a space must be escaped and proceeded with an extra backslash.
 
BUG: The above contains problems when the path�s have spaces in them. As
 
mentioned in :h path a space must be escaped and proceeded with a n extra
 
backslash.
 
   
 
The below is how it should have been in the first place.
 
The below is how it should have been in the first place.
   
  +
" Base path :".,,"
  +
let g:feral_path_B = &amp;path
  +
" System include path
  +
set path=C:/Program\\\ Files/Microsoft\\\ Visual\\\ Studio\\\ .NET\\\ 2003/Vc7/include/
  +
set path+=C:/Program\\\ Files/Microsoft\\\ Visual\\\ Studio\\\ .NET\\\ 2003/Vc7/PlatformSDK/Include/
  +
let g:feral_path_S = &amp;path
  +
" ClanLib include path
  +
set path=C:/Program\\\ Files/ClanLib/include/
  +
"" set path=C:/Program\\\ Files/ClanLib/ClanLib-0.7/Sources/
  +
let g:feral_path_C = &amp;path
  +
" DirectX include path
  +
set path=C:/Program\\\ Files/Microsoft\\\ DirectX\\\ 9.0\\\ SDK\\\ (February\\\ 2005)/Include
  +
let g:feral_path_D = &amp;path
  +
  +
" start off with base path
  +
execute "set path=".g:feral_path_B
  +
  +
function Feral_Path(whichpaths)
  +
if strlen(a:whichpaths)
  +
let old_path = &amp;path
  +
set path=
  +
let paths_to_use = toupper(a:whichpaths)
  +
while strlen(paths_to_use)
  +
if exists("g:feral_path_{paths_to_use[0]}")
  +
execute "set path+=".substitute(g:feral_path_{paths_to_use[0]}, "\\ ", "\\\\\\\\ ", "g")
  +
" remove the first char from paths_to_use now
  +
let paths_to_use = strpart(paths_to_use,1)
  +
else
  +
" not found; remove this char and see if we can try again.
  +
let paths_to_use = strpart(paths_to_use,1)
  +
endif
  +
endwhile
  +
if strlen(&amp;path) == 0
  +
execute "set path=".old_path
  +
endif
  +
endif
  +
endfunction
  +
command -nargs=1 FP call Feral_Path(&lt;q-args&gt;)
   
  +
NOTE: that the chars you pass to the :FP command are now upper cased (via call to toupper() ) this may or may not be desirable for you.
-------------------------
 
 
" Base path :".,,"
 
let g:feral_path_B = &amp;path
 
" System include path
 
set path=C:/Program\\\ Files/Microsoft\\\ Visual\\\ Studio\\\ .NET\\\ 2003/Vc7/include/
 
set path+=C:/Program\\\ Files/Microsoft\\\ Visual\\\ Studio\\\ .NET\\\ 2003/Vc7/PlatformSDK/Include/
 
let g:feral_path_S = &amp;path
 
" ClanLib include path
 
set path=C:/Program\\\ Files/ClanLib/include/
 
"" set path=C:/Program\\\ Files/ClanLib/ClanLib-0.7/Sources/
 
let g:feral_path_C = &amp;path
 
" DirectX include path
 
set path=C:/Program\\\ Files/Microsoft\\\ DirectX\\\ 9.0\\\ SDK\\\ (February\\\ 2005)/Include
 
let g:feral_path_D = &amp;path
 
 
" start off with base path
 
execute "set path=".g:feral_path_B
 
 
 
function Feral_Path(whichpaths)
 
if strlen(a:whichpaths)
 
let old_path = &amp;path
 
set path=
 
let paths_to_use = toupper(a:whichpaths)
 
while strlen(paths_to_use)
 
if exists("g:feral_path_{paths_to_use[0]}")
 
execute "set path+=".substitute(g:feral_path_{paths_to_use[0]}, "\\ ", "\\\\\\\\ ", "g")
 
" remove the first char from paths_to_use now
 
let paths_to_use = strpart(paths_to_use,1)
 
else
 
" not found; remove this char and see if we can try again.
 
let paths_to_use = strpart(paths_to_use,1)
 
endif
 
endwhile
 
if strlen(&amp;path) == 0
 
execute "set path=".old_path
 
endif
 
endif
 
endfunction
 
command -nargs=1 FP call Feral_Path(&lt;q-args&gt;)
 
 
 
-------------------------
 
 
 
NOTE: that the chars you pass to the :FP command are now upper cased (via call
 
to toupper() ) this may or may not be desirable for you.
 
   
   

Revision as of 18:56, 12 July 2007

Previous TipNext Tip

Tip: #902 - Easily change the path option

Created: March 24, 2005 19:58 Complexity: intermediate Author: <sreny--AT--srenyqernzf.pbz> (Rot13ed) Version: 6.0 Karma: 4/3 Imported from: Tip#902

The WHY:

Some include paths (VC7 in particular) are very deep, so much so that I opted to "set complete-=i" (which is to say to NOT 'scan current and included files' during completion; see :help 'complete').


This allowed me to <ctrl+n>/<ctrl+p> without delay, and when I knew what I was trying to complete was in the system includes (sprintf for instance) I could use CTRL-X CTRL-I (see: :help i_CTRL-X_CTRL-I) as needed, for instance 'spr<ctrl-x><ctrl-i>'. This worked like a charm for many moons. Until recently when I've found a need to have a different set of includes to search and I wanted normal CTRL-N/CTRL-P to search these files and NOT the system include. I was also getting kind of tired of not searching the current directory via CTRL-N/CTRL-P as well.


A Solution: aka Enter hair brained scheme #1

The concept is simple, search the path each time (i.e."set complete+=i", which is default) but limit what the path is.

The solution.. well it is pretty simple too really.

I decided on a few global scoped variables to hold my paths and then a function/command to help set &path. Seemed easy enough. This is from my .vimrc and as you can see it is a mess. It does (as far as I know!) function properly with no adverse effects, but I am very definitely not certain of that yet.

if has("win32") 
  " Base path :".,," 
  let g:feral_path_B = &path 
  " System include path 
  set path=C:/PROGRA~1/MICROS~1.NET/Vc7/include/** 
  " set path+=C:/Program\ Files/Microsoft\ Visual\ Studio\ .NET/Vc7/PlatformSDK/include/prerelease/**
  let g:feral_path_S = &path 
  " project include path 
  set path=C:/Program\ Files/ClanLib/include/** 
  "" set path=C:/Program\ Files/ClanLib/ClanLib-0.7/Sources/** 
  let g:feral_path_P = &path 

  " start off with base path 
  execute "set path=".g:feral_path_B 

  function Feral_Path(whichpaths) 
    if strlen(a:whichpaths) 
      let old_path = &path 
      set path= 
      let paths_to_use = a:whichpaths 
      while strlen(paths_to_use) 
        " call confirm("SO:"."\npath_to_use:".paths_to_use."\npath_to_use[0]:".paths_to_use[0]."\nExists?".exists("g:feral_path_{paths_to_use[0]}") ) 
        if exists("g:feral_path_{paths_to_use[0]}") 
          " call confirm("is1:".g:feral_path_{paths_to_use[0]}) 
          execute "set path+=".substitute(g:feral_path_{paths_to_use[0]}, "\\ ", "\\\\ ", "g") 
          "execute "set path+=".substitute("C:/Program\ Files/ClanLib/include/**", "\\ ", "\\\\ ", "g") 
          "execute "set path+="."C:/Program\\ Files/ClanLib/include/**" 

          " call confirm("is2:".&path) 
          " remove the first char from paths_to_use now 
          let paths_to_use = strpart(paths_to_use,1) 
          " call confirm("is3:".paths_to_use) 
        else 
          " not found; remove this char and see if we can try again. 
          let paths_to_use = strpart(paths_to_use,1) 
          " call confirm("is4:".paths_to_use) 
        endif 
      endwhile 
      " call confirm("outside while") 

      if strlen(&path) == 0 
        " call confirm("restoring path as it was when we got here.") 
        execute "set path=".old_path 
      endif 
    endif 
    " call confirm("outside outer if") 
  endfunction 

  command -nargs=1 FP call Feral_Path(<q-args>) 
endif 

The Usage:

To use this the above code frag must be sourced, in my case this is in my .vimrc.

You need some paths to switch between, these global variables must start with "g:feral_path_" and the last character is used to identify (NOTE: SINGLE CHAR ONLY!) the path.

For instance:

set path=C:/PROGRA~1/MICROS~1.NET/Vc7/include/** 
" set path+=C:/Program\ Files/Microsoft\ Visual\ Studio\ .NET/Vc7/PlatformSDK/include/prerelease/** 

Note how I use 'set path=' and thus can use this more or less naturally, including += to add an additional path. Not strickly necessary but does not hurt anything as far as I know.

let g:feral_path_S = &path 

I then set my global variable (this one is referenced as 'S') to the current value of &path.

It is a bit messy but it is straight forward and to the point.

I also define the base path (referenced as 'B'), and my project path (referenced as 'P'). NOTE how 'B' is set to &path's initial value; which in my case is the default for the system.

" Base path :".,," 
let g:feral_path_B = &path 
" System include path 
set path=C:/PROGRA~1/MICROS~1.NET/Vc7/include/** 
" set path+=C:/Program\ Files/Microsoft\ Visual\ Studio\ .NET/Vc7/PlatformSDK/include/prerelease/** 
let g:feral_path_S = &path 
" project include path 
set path=C:/Program\ Files/ClanLib/include/** 
"" set path=C:/Program\ Files/ClanLib/ClanLib-0.7/Sources/** 
let g:feral_path_P = &path 

So this gives us 3 paths to play with, B (base), S (system) and P (project).

I set &path to the default value I want directly:

" start off with base path 
execute "set path=".g:feral_path_B 

Now, to use this when you are coding away you can *easily* change &path via the :FP command.

:FP takes one argument, that argument is the one-word group of paths to set, use the one character to reference each path;

i.e.

:FP B 
echo &path: .,, 

to set path to basic and system, i.e.

:FP BS 
echo &path: .,,,C:\PROGRA~1\MICROS~1.NET\Vc7\include** 

or if I wanted system then basic:

:FP SB 
echo &path: C:\PROGRA~1\MICROS~1.NET\Vc7\include**,.,, 

As you can see it is pretty simple to manipulate &path now via the :FP command.

You can specify one or more paths to set:

:FP BPS 
echo &path: .,,,C:/Program Files/ClanLib/include/**,C:/PROGRA~1/MICROS~1.NET/Vc7/include/** 

All in all this should be fairly simple to use, the major problem I see is forgetting the reference chars, but hopefully with clever naming this won't be a problem.

An alternative to the above mess:

You could of course forgot the above mess and just have menu entries/commands/mappings/what have you that sets &path directly.


Closing remarks:

All in all this is a simple, quick HACK that perhaps no one will every find of use.

I submit this as a tip in the hopes that it might be useful in someway to someone.

I suggest you be a little leery of the code, though it *should* be fine. But, we all know how that goes! (=


Happy Vimming!

Comments

You should write a C++ book. Good stuff.

Ragini , March 26, 2005 9:04


Thank you for the kind words Ragini (=

BUG: The above contains problems when the path's have spaces in them. As mentioned in :h path a space must be escaped and proceeded with an extra backslash.

The below is how it should have been in the first place.

" Base path :".,," 
let g:feral_path_B = &path 
" System include path 
set path=C:/Program\\\ Files/Microsoft\\\ Visual\\\ Studio\\\ .NET\\\ 2003/Vc7/include/ 
set path+=C:/Program\\\ Files/Microsoft\\\ Visual\\\ Studio\\\ .NET\\\ 2003/Vc7/PlatformSDK/Include/ 
let g:feral_path_S = &path 
" ClanLib include path 
set path=C:/Program\\\ Files/ClanLib/include/ 
"" set path=C:/Program\\\ Files/ClanLib/ClanLib-0.7/Sources/ 
let g:feral_path_C = &path 
" DirectX include path 
set path=C:/Program\\\ Files/Microsoft\\\ DirectX\\\ 9.0\\\ SDK\\\ (February\\\ 2005)/Include 
let g:feral_path_D = &path 

" start off with base path 
execute "set path=".g:feral_path_B 

function Feral_Path(whichpaths) 
  if strlen(a:whichpaths) 
    let old_path = &path 
    set path= 
    let paths_to_use = toupper(a:whichpaths) 
    while strlen(paths_to_use) 
      if exists("g:feral_path_{paths_to_use[0]}") 
        execute "set path+=".substitute(g:feral_path_{paths_to_use[0]}, "\\ ", "\\\\\\\\ ", "g") 
        " remove the first char from paths_to_use now 
        let paths_to_use = strpart(paths_to_use,1) 
      else 
        " not found; remove this char and see if we can try again. 
        let paths_to_use = strpart(paths_to_use,1) 
      endif 
    endwhile 
    if strlen(&path) == 0 
      execute "set path=".old_path 
    endif 
  endif 
endfunction 
command -nargs=1 FP call Feral_Path(<q-args>) 

NOTE: that the chars you pass to the :FP command are now upper cased (via call to toupper() ) this may or may not be desirable for you.


sreny--AT--srenyqernzf.pbz (Rot13ed) , April 2, 2005 21:50