Vim Tips Wiki
Edit Page
We recommend that you log in before editing. This will allow other users to leave you a message about your edit, and will let you track edits via your Watchlist. Creating an account is quick and free.

The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.

Latest revision Your text
Line 1: Line 1:
 
{{ScriptComments|a: switch between alternate files quickly (.c --> .h etc)}}
 
{{ScriptComments|a: switch between alternate files quickly (.c --> .h etc)}}
   
==Three files==
+
==Comments==
  +
  +
===Three files===
 
Nice plugin, but it doesn't seem to work correctly when there are three files:
 
Nice plugin, but it doesn't seem to work correctly when there are three files:
 
i.e. foo.h foo.inl and foo.cpp
 
i.e. foo.h foo.inl and foo.cpp
   
:Solution: This is because already open files are scored higher than other files. Thus when there you have foo.h and foo.inl loaded, foo.cpp won't be considered. To fix, change the body of BufferOrFileExists to "return filereadable(a:fileName)". I also changed FindOrCreateBuffer to ignore a:findSimilar - I don't know if thats strictly necessary.
+
Solution: This is because already open files are scored higher than other files. Thus when there you have foo.h and foo.inl loaded, foo.cpp won't be considered. To fix, change the body of BufferOrFileExists to "return filereadable(a:fileName)". I also changed FindOrCreateBuffer to ignore a:findSimilar - I don't know if thats strictly necessary.
   
==Separate folders==
+
===Separate folders===
 
Thanks for your contribution.
 
Thanks for your contribution.
 
But I have a challenge in switching between header files and source files when they are in directories such as src/ and include/.
 
But I have a challenge in switching between header files and source files when they are in directories such as src/ and include/.
Line 13: Line 15:
 
If I'm editing foo.c in src/, it will look for foo.h in src. But I have foo.h in include/. Can you please help.
 
If I'm editing foo.c in src/, it will look for foo.h in src. But I have foo.h in include/. Can you please help.
   
:Solution: the docs has a section on g:alternateSearchPath
+
Solution: the docs has a section on g:alternateSearchPath
   
 
==Bugs==
 
==Bugs==
This is a great plugin. The only drawback is that it does not handle folders with commas in it, unfortunately. For example, if I'm editing src,/foo.c, and want to switch to src,/foo.h, then :A does not work.
+
This is a great plugin. The only drawback is that it does not handle folders with comma's in it, unfortunately. For example, if I'm editing src,/foo.c, and want to switch to src,/foo.h, then :A does not work.
   
<leader>is is mapped to <Esc>:IHS<CR>:A<CR>, even in insert mode. My <leader> is space, so every time I type " is" it invokes that, which is really annoying. Thanks for your work.
+
&lt;leader&gt;is is mapped to &lt;Esc&gt;:IHS&lt;CR&gt;:A&lt;CR&gt;, even in insert mode. My &lt;leader&gt; is space, so every time I type " is" it invokes that, which * is* really annoying. Thanks for your work.
   
== Directory structures ==
+
=== Directory structures ===
   
 
Very nice plugin. But I have some trouble with my directory structure and the regexp mode in alternateSearchPath. Imagine the following files structure:
 
Very nice plugin. But I have some trouble with my directory structure and the regexp mode in alternateSearchPath. Imagine the following files structure:
<pre>
+
<code>
foo/include/foo/base.h
+
foo/include/foo/base.h
foo/src/foo/base.cpp
+
foo/src/foo/base.cpp
bar/include/bar/base.h
+
bar/include/bar/base.h
bar/src/bar/base.cpp
+
bar/src/bar/base.cpp
</pre>
+
</code>
Then load the following files into Vim:
+
Then load the following files into vim:
<pre>
+
<code>
foo/include/foo/base.h
+
foo/include/foo/base.h
bar/src/bar/base.cpp
+
bar/src/bar/base.cpp
</pre>
+
</code>
 
Using these alterativeSearchPath:
 
Using these alterativeSearchPath:
<pre>
+
<code>
let g:alternateSearchPath='reg:/include/src/g/,reg:/src/include/g/'
+
let g:alternateSearchPath
  +
='reg:/include/src/g/,reg:/src/include/g/'
</pre>
+
</code>
 
When I use :A while in base.h this will not open up foo/src/foo/base.cpp but bar/src/bar/base.cpp.
 
When I use :A while in base.h this will not open up foo/src/foo/base.cpp but bar/src/bar/base.cpp.
   
  +
Why?
Why? --October 3, 2015
 
 
==Comments==
 
Please note that all contributions to the Vim Tips Wiki are considered to be released under the CC-BY-SA
Cancel Editing help (opens in new window)

Template used on this page: