1 " Copyright (c) 1998-2006
2 " Michael Sharpe <feline@irendi.com>
4 " We grant permission to use, copy modify, distribute, and sell this
5 " software for any purpose without fee, provided that the above copyright
6 " notice and this text are not removed. We make no guarantee about the
7 " suitability of this software for any purpose and we are not liable
8 " for any damages resulting from its use. Further, we are under no
9 " obligation to maintain or extend this software. It is provided on an
10 " "as is" basis without any expressed or implied warranty.
12 " Directory & regex enhancements added by Bindu Wavell who is well known on
15 " Patch for spaces in files/directories from Nathan Stien (also reported by
18 " Do not load a.vim if is has already been loaded.
19 if exists("loaded_alternateFile")
22 if (v:progname == "ex")
25 let loaded_alternateFile = 1
27 let alternateExtensionsDict = {}
29 " setup the default set of alternate extensions. The user can override in thier
30 " .vimrc if the defaults are not suitable. To override in a .vimrc simply set a
31 " g:alternateExtensions_<EXT> variable to a comma separated list of alternates,
32 " where <EXT> is the extension to map.
33 " E.g. let g:alternateExtensions_CPP = "inc,h,H,HPP,hpp"
34 " let g:alternateExtensions_{'aspx.cs'} = "aspx"
37 " This variable will be increased when an extension with greater number of dots
38 " is added by the AddAlternateExtensionMapping call.
39 let s:maxDotsInExtension = 1
41 " Function : AddAlternateExtensionMapping (PRIVATE)
42 " Purpose : simple helper function to add the default alternate extension
44 " Args : extension -- the extension to map
45 " alternates -- comma separated list of alternates extensions
47 " Author : Michael Sharpe <feline@irendi.com>
48 function! <SID>AddAlternateExtensionMapping(extension, alternates)
49 " This code does not actually work for variables like foo{'a.b.c.d.e'}
50 "let varName = "g:alternateExtensions_" . a:extension
51 "if (!exists(varName))
52 " let g:alternateExtensions_{a:extension} = a:alternates
55 " This code handles extensions which contains a dot. exists() fails with
58 " FIXME this line causes ex to return 1 instead of 0 for some reason??
59 "silent! echo g:alternateExtensions_{a:extension}
61 "let g:alternateExtensions_{a:extension} = a:alternates
64 let g:alternateExtensionsDict[a:extension] = a:alternates
65 let dotsNumber = strlen(substitute(a:extension, "[^.]", "", "g"))
66 if s:maxDotsInExtension < dotsNumber
67 let s:maxDotsInExtension = dotsNumber
72 " Add all the default extensions
73 " Mappings for C and C++
74 call <SID>AddAlternateExtensionMapping('h',"c,cpp,cxx,cc,CC")
75 call <SID>AddAlternateExtensionMapping('H',"C,CPP,CXX,CC")
76 call <SID>AddAlternateExtensionMapping('hpp',"cpp,c")
77 call <SID>AddAlternateExtensionMapping('HPP',"CPP,C")
78 call <SID>AddAlternateExtensionMapping('c',"h")
79 call <SID>AddAlternateExtensionMapping('C',"H")
80 call <SID>AddAlternateExtensionMapping('cpp',"h,hpp")
81 call <SID>AddAlternateExtensionMapping('CPP',"H,HPP")
82 call <SID>AddAlternateExtensionMapping('cc',"h")
83 call <SID>AddAlternateExtensionMapping('CC',"H,h")
84 call <SID>AddAlternateExtensionMapping('cxx',"h")
85 call <SID>AddAlternateExtensionMapping('CXX',"H")
87 call <SID>AddAlternateExtensionMapping('psl',"ph")
88 call <SID>AddAlternateExtensionMapping('ph',"psl")
90 call <SID>AddAlternateExtensionMapping('adb',"ads")
91 call <SID>AddAlternateExtensionMapping('ads',"adb")
92 " Mappings for lex and yacc files
93 call <SID>AddAlternateExtensionMapping('l',"y,yacc,ypp")
94 call <SID>AddAlternateExtensionMapping('lex',"yacc,y,ypp")
95 call <SID>AddAlternateExtensionMapping('lpp',"ypp,y,yacc")
96 call <SID>AddAlternateExtensionMapping('y',"l,lex,lpp")
97 call <SID>AddAlternateExtensionMapping('yacc',"lex,l,lpp")
98 call <SID>AddAlternateExtensionMapping('ypp',"lpp,l,lex")
100 call <SID>AddAlternateExtensionMapping('ml',"mli")
101 call <SID>AddAlternateExtensionMapping('mli',"ml")
103 call <SID>AddAlternateExtensionMapping('aspx.cs', 'aspx')
104 call <SID>AddAlternateExtensionMapping('aspx.vb', 'aspx')
105 call <SID>AddAlternateExtensionMapping('aspx', 'aspx.cs,aspx.vb')
107 " Setup default search path, unless the user has specified
108 " a path in their [._]vimrc.
109 if (!exists('g:alternateSearchPath'))
110 let g:alternateSearchPath = 'sfr:../source,sfr:../src,sfr:../include,sfr:../inc'
113 " If this variable is true then a.vim will not alternate to a file/buffer which
114 " does not exist. E.g while editing a.c and the :A will not swtich to a.h
116 if (!exists('g:alternateNoDefaultAlternate'))
117 " by default a.vim will alternate to a file which does not exist
118 let g:alternateNoDefaultAlternate = 0
121 " If this variable is true then a.vim will convert the alternate filename to a
122 " filename relative to the current working directory.
123 " Feature by Nathan Huizinga
124 if (!exists('g:alternateRelativeFiles'))
125 " by default a.vim will not convert the filename to one relative to the
126 " current working directory
127 let g:alternateRelativeFiles = 0
131 " Function : GetNthItemFromList (PRIVATE)
132 " Purpose : Support reading items from a comma seperated list
133 " Used to iterate all the extensions in an extension spec
134 " Used to iterate all path prefixes
135 " Args : list -- the list (extension spec, file paths) to iterate
136 " n -- the extension to get
137 " Returns : the nth item (extension, path) from the list (extension
138 " spec), or "" for failure
139 " Author : Michael Sharpe <feline@irendi.com>
140 " History : Renamed from GetNthExtensionFromSpec to GetNthItemFromList
141 " to reflect a more generic use of this function. -- Bindu
142 function! <SID>GetNthItemFromList(list, n)
149 let itemStart = itemEnd + 1
150 let itemEnd = match(a:list, ",", itemStart)
154 let itemEnd = strlen(a:list)
160 let item = strpart(a:list, itemStart, itemEnd - itemStart)
165 " Function : ExpandAlternatePath (PRIVATE)
166 " Purpose : Expand path info. A path with a prefix of "wdr:" will be
167 " treated as relative to the working directory (i.e. the
168 " directory where vim was started.) A path prefix of "abs:" will
169 " be treated as absolute. No prefix or "sfr:" will result in the
170 " path being treated as relative to the source file (see sfPath
173 " A prefix of "reg:" will treat the pathSpec as a regular
174 " expression substitution that is applied to the source file
175 " path. The format is:
177 " reg:<sep><pattern><sep><subst><sep><flag><sep>
179 " <sep> seperator character, we often use one of [/|%#]
180 " <pattern> is what you are looking for
181 " <subst> is the output pattern
182 " <flag> can be g for global replace or empty
184 " EXAMPLE: 'reg:/inc/src/g/' will replace every instance
185 " of 'inc' with 'src' in the source file path. It is possible
186 " to use match variables so you could do something like:
187 " 'reg:|src/\([^/]*\)|inc/\1||' (see 'help :substitute',
188 " 'help pattern' and 'help sub-replace-special' for more details
190 " NOTE: a.vim uses ',' (comma) internally so DON'T use it
191 " in your regular expressions or other pathSpecs unless you update
192 " the rest of the a.vim code to use some other seperator.
194 " Args : pathSpec -- path component (or substitution patterns)
195 " sfPath -- source file path
196 " Returns : a path that can be used by AlternateFile()
197 " Author : Bindu Wavell <bindu@wavell.net>
198 function! <SID>ExpandAlternatePath(pathSpec, sfPath)
199 let prfx = strpart(a:pathSpec, 0, 4)
200 if (prfx == "wdr:" || prfx == "abs:")
201 let path = strpart(a:pathSpec, 4)
202 elseif (prfx == "reg:")
203 let re = strpart(a:pathSpec, 4)
204 let sep = strpart(re, 0, 1)
205 let patend = match(re, sep, 1)
206 let pat = strpart(re, 1, patend - 1)
207 let subend = match(re, sep, patend + 1)
208 let sub = strpart(re, patend+1, subend - patend - 1)
209 let flag = strpart(re, strlen(re) - 2)
213 let path = substitute(a:sfPath, pat, sub, flag)
214 "call confirm('PAT: [' . pat . '] SUB: [' . sub . ']')
215 "call confirm(a:sfPath . ' => ' . path)
217 let path = a:pathSpec
219 let path = strpart(path, 4)
221 let path = a:sfPath . "/" . path
226 " Function : FindFileInSearchPath (PRIVATE)
227 " Purpose : Searches for a file in the search path list
228 " Args : filename -- name of the file to search for
229 " pathList -- the path list to search
230 " relPathBase -- the path which relative paths are expanded from
231 " Returns : An expanded filename if found, the empty string otherwise
232 " Author : Michael Sharpe (feline@irendi.com)
233 " History : inline code written by Bindu Wavell originally
234 function! <SID>FindFileInSearchPath(fileName, pathList, relPathBase)
237 let pathListLen = strlen(a:pathList)
240 let pathSpec = <SID>GetNthItemFromList(a:pathList, m)
242 let path = <SID>ExpandAlternatePath(pathSpec, a:relPathBase)
243 let fullname = path . "/" . a:fileName
244 let foundMatch = <SID>BufferOrFileExists(fullname)
246 let filepath = fullname
258 " Function : FindFileInSearchPathEx (PRIVATE)
259 " Purpose : Searches for a file in the search path list
260 " Args : filename -- name of the file to search for
261 " pathList -- the path list to search
262 " relPathBase -- the path which relative paths are expanded from
263 " count -- find the count'th occurence of the file on the path
264 " Returns : An expanded filename if found, the empty string otherwise
265 " Author : Michael Sharpe (feline@irendi.com)
266 " History : Based on <SID>FindFileInSearchPath() but with extensions
267 function! <SID>FindFileInSearchPathEx(fileName, pathList, relPathBase, count)
271 let pathListLen = strlen(a:pathList)
274 let pathSpec = <SID>GetNthItemFromList(a:pathList, m)
276 let path = <SID>ExpandAlternatePath(pathSpec, a:relPathBase)
278 let spath = spath . ','
280 let spath = spath . path
290 let spath = spath . ','
292 let spath = spath . &path
295 let filepath = findfile(a:fileName, spath, a:count)
299 " Function : EnumerateFilesByExtension (PRIVATE)
300 " Purpose : enumerates all files by a particular list of alternate extensions.
301 " Args : path -- path of a file (not including the file)
302 " baseName -- base name of the file to be expanded
303 " extension -- extension whose alternates are to be enumerated
304 " Returns : comma separated list of files with extensions
305 " Author : Michael Sharpe <feline@irendi.com>
306 function! EnumerateFilesByExtension(path, baseName, extension)
310 silent! echo g:alternateExtensions_{a:extension}
312 let extSpec = g:alternateExtensions_{a:extension}
315 if (has_key(g:alternateExtensionsDict, a:extension))
316 let extSpec = g:alternateExtensionsDict[a:extension]
323 let ext = <SID>GetNthItemFromList(extSpec, n)
326 let newFilename = a:path . "/" . a:baseName . "." . ext
328 let newFilename = a:baseName . "." . ext
330 if (enumeration == "")
331 let enumeration = newFilename
333 let enumeration = enumeration . "," . newFilename
344 " Function : EnumerateFilesByExtensionInPath (PRIVATE)
345 " Purpose : enumerates all files by expanding the path list and the extension
347 " Args : baseName -- base name of the file
348 " extension -- extension whose alternates are to be enumerated
349 " pathList -- the list of paths to enumerate
350 " relPath -- the path of the current file for expansion of relative
351 " paths in the path list.
352 " Returns : A comma separated list of paths with extensions
353 " Author : Michael Sharpe <feline@irendi.com>
354 function! EnumerateFilesByExtensionInPath(baseName, extension, pathList, relPathBase)
358 let pathListLen = strlen(a:pathList)
361 let pathSpec = <SID>GetNthItemFromList(a:pathList, m)
363 let path = <SID>ExpandAlternatePath(pathSpec, a:relPathBase)
364 let pe = EnumerateFilesByExtension(path, a:baseName, a:extension)
365 if (enumeration == "")
368 let enumeration = enumeration . "," . pe
379 " Function : DetermineExtension (PRIVATE)
380 " Purpose : Determines the extension of a filename based on the register
381 " alternate extension. This allow extension which contain dots to
382 " be considered. E.g. foo.aspx.cs to foo.aspx where an alternate
383 " exists for the aspx.cs extension. Note that this will only accept
384 " extensions which contain less than 5 dots. This is only
385 " implemented in this manner for simplicity...it is doubtful that
386 " this will be a restriction in non-contrived situations.
387 " Args : The path to the file to find the extension in
388 " Returns : The matched extension if any
389 " Author : Michael Sharpe (feline@irendi.com)
390 " History : idea from Tom-Erik Duestad
391 " Notes : there is some magic occuring here. The exists() function does not
392 " work well when the curly brace variable has dots in it. And why
393 " should it, dots are not valid in variable names. But the exists
394 " function is wierd too. Lets say foo_c does exist. Then
395 " exists("foo_c.e.f") will be true...even though the variable does
396 " not exist. However the curly brace variables do work when the
397 " variable has dots in it. E.g foo_{'c'} is different from
398 " foo_{'c.d.e'}...and foo_{'c'} is identical to foo_c and
399 " foo_{'c.d.e'} is identical to foo_c.d.e right? Yes in the current
400 " implementation of vim. To trick vim to test for existence of such
401 " variables echo the curly brace variable and look for an error
403 function! DetermineExtension(path)
406 while i <= s:maxDotsInExtension
407 let mods = mods . ":e"
408 let extension = fnamemodify(a:path, mods)
409 if (has_key(g:alternateExtensionsDict, extension))
413 silent! echo g:alternateExtensions_{extension}
422 " Function : AlternateFile (PUBLIC)
423 " Purpose : Opens a new buffer by looking at the extension of the current
424 " buffer and finding the corresponding file. E.g. foo.c <--> foo.h
425 " Args : accepts one argument. If present it used the argument as the new
428 " Author : Michael Sharpe <feline@irendi.com>
429 " History : + When an alternate can't be found in the same directory as the
430 " source file, a search path will be traversed looking for the
432 " + Moved some code into a separate function, minor optimization
433 " + rework to favor files in memory based on complete enumeration of
434 " all files extensions and paths
435 function! AlternateFile(splitWindow, ...)
436 let extension = DetermineExtension(expand("%:p"))
437 let baseName = substitute(expand("%:t"), "\." . extension . '$', "", "")
438 let currentPath = expand("%:p:h")
441 let newFullname = currentPath . "/" . baseName . "." . a:1
442 call <SID>FindOrCreateBuffer(newFullname, a:splitWindow, 0)
446 let allfiles1 = EnumerateFilesByExtension(currentPath, baseName, extension)
447 let allfiles2 = EnumerateFilesByExtensionInPath(baseName, extension, g:alternateSearchPath, currentPath)
451 let allfiles = allfiles1 . ',' . allfiles2
453 let allfiles = allfiles1
456 let allfiles = allfiles2
466 let onefile = <SID>GetNthItemFromList(allfiles, n)
467 let bestFile = onefile
468 while (onefile != "" && score < 2)
469 let score = <SID>BufferOrFileExists(onefile)
470 if (score > bestScore)
471 let bestScore = score
472 let bestFile = onefile
475 let onefile = <SID>GetNthItemFromList(allfiles, n)
478 if (bestScore == 0 && g:alternateNoDefaultAlternate == 1)
479 echo "No existing alternate available"
481 call <SID>FindOrCreateBuffer(bestFile, a:splitWindow, 1)
482 let b:AlternateAllFiles = allfiles
485 echo "No alternate file/buffer available"
490 " Function : AlternateOpenFileUnderCursor (PUBLIC)
491 " Purpose : Opens file under the cursor
492 " Args : splitWindow -- indicates how to open the file
494 " Author : Michael Sharpe (feline@irendi.com) www.irendi.com
495 function! AlternateOpenFileUnderCursor(splitWindow,...)
496 let cursorFile = (a:0 > 0) ? a:1 : expand("<cfile>")
497 let currentPath = expand("%:p:h")
500 let fileName = <SID>FindFileInSearchPathEx(cursorFile, g:alternateSearchPath, currentPath, openCount)
502 call <SID>FindOrCreateBuffer(fileName, a:splitWindow, 1)
503 let b:openCount = openCount
504 let b:cursorFile = cursorFile
505 let b:currentPath = currentPath
507 echo "Can't find file"
511 " Function : AlternateOpenNextFile (PUBLIC)
512 " Purpose : Opens the next file corresponding to the search which found the
514 " Args : bang -- indicates what to do if the current file has not been
517 " Author : Michael Sharpe (feline@irendi.com) www.irendi.com
518 function! AlternateOpenNextFile(bang)
520 if (exists("b:cursorFile"))
521 let cursorFile = b:cursorFile
525 if (exists("b:currentPath"))
526 let currentPath = b:currentPath
530 if (exists("b:openCount"))
531 let openCount = b:openCount + 1
534 if (cursorFile != "" && currentPath != "" && openCount != 0)
535 let fileName = <SID>FindFileInSearchPathEx(cursorFile, g:alternateSearchPath, currentPath, openCount)
537 call <SID>FindOrCreateBuffer(fileName, "n".a:bang, 0)
538 let b:openCount = openCount
539 let b:cursorFile = cursorFile
540 let b:currentPath = currentPath
542 let fileName = <SID>FindFileInSearchPathEx(cursorFile, g:alternateSearchPath, currentPath, 1)
544 call <SID>FindOrCreateBuffer(fileName, "n".a:bang, 0)
546 let b:cursorFile = cursorFile
547 let b:currentPath = currentPath
549 echo "Can't find next file"
555 comm! -nargs=? -bang IH call AlternateOpenFileUnderCursor("n<bang>", <f-args>)
556 comm! -nargs=? -bang IHS call AlternateOpenFileUnderCursor("h<bang>", <f-args>)
557 comm! -nargs=? -bang IHV call AlternateOpenFileUnderCursor("v<bang>", <f-args>)
558 comm! -nargs=? -bang IHT call AlternateOpenFileUnderCursor("t<bang>", <f-args>)
559 comm! -nargs=? -bang IHN call AlternateOpenNextFile("<bang>")
560 imap <Leader>ih <ESC>:IHS<CR>
561 nmap <Leader>ih :IHS<CR>
562 imap <Leader>is <ESC>:IHS<CR>:A<CR>
563 nmap <Leader>is :IHS<CR>:A<CR>
564 imap <Leader>ihn <ESC>:IHN<CR>
565 nmap <Leader>ihn :IHN<CR>
567 "function! <SID>PrintList(theList)
569 " let oneFile = <SID>GetNthItemFromList(a:theList, n)
570 " while (oneFile != "")
572 " let oneFile = <SID>GetNthItemFromList(a:theList, n)
576 " Function : NextAlternate (PUBLIC)
577 " Purpose : Used to cycle through any other alternate file which existed on
579 " Args : bang (IN) - used to implement the AN vs AN! functionality
581 " Author : Michael Sharpe <feline@irendi.com>
582 function! NextAlternate(bang)
583 if (exists('b:AlternateAllFiles'))
584 let currentFile = expand("%")
586 let onefile = <SID>GetNthItemFromList(b:AlternateAllFiles, n)
587 while (onefile != "" && !<SID>EqualFilePaths(fnamemodify(onefile,":p"), fnamemodify(currentFile,":p")))
589 let onefile = <SID>GetNthItemFromList(b:AlternateAllFiles, n)
595 let foundAlternate = 0
596 let nextAlternate = ""
598 let nextAlternate = <SID>GetNthItemFromList(b:AlternateAllFiles, n)
599 if (nextAlternate == "")
604 if (<SID>EqualFilePaths(fnamemodify(nextAlternate, ":p"), fnamemodify(currentFile, ":p")))
607 if (filereadable(nextAlternate))
608 " on cygwin filereadable("foo.H") returns true if "foo.h" exists
609 if (has("unix") && $WINDIR != "" && fnamemodify(nextAlternate, ":p") ==? fnamemodify(currentFile, ":p"))
612 let foundAlternate = 1
616 if (foundAlternate == 1)
617 let s:AlternateAllFiles = b:AlternateAllFiles
618 "silent! execute ":e".a:bang." " . nextAlternate
619 call <SID>FindOrCreateBuffer(nextAlternate, "n".a:bang, 0)
620 let b:AlternateAllFiles = s:AlternateAllFiles
622 echo "Only this alternate file exists"
625 echo "Could not find current file in alternates list"
628 echo "No other alternate files exist"
632 comm! -nargs=? -bang A call AlternateFile("n<bang>", <f-args>)
633 comm! -nargs=? -bang AS call AlternateFile("h<bang>", <f-args>)
634 comm! -nargs=? -bang AV call AlternateFile("v<bang>", <f-args>)
635 comm! -nargs=? -bang AT call AlternateFile("t<bang>", <f-args>)
636 comm! -nargs=? -bang AN call NextAlternate("<bang>")
638 " Function : BufferOrFileExists (PRIVATE)
639 " Purpose : determines if a buffer or a readable file exists
640 " Args : fileName (IN) - name of the file to check
641 " Returns : 2 if it exists in memory, 1 if it exists, 0 otherwise
642 " Author : Michael Sharpe <feline@irendi.com>
643 " History : Updated code to handle buffernames using just the
644 " filename and not the path.
645 function! <SID>BufferOrFileExists(fileName)
648 let lastBuffer = bufnr("$")
650 while i <= lastBuffer
651 if <SID>EqualFilePaths(expand("#".i.":p"), a:fileName)
659 let bufName = fnamemodify(a:fileName,":t")
660 let memBufName = bufname(bufName)
661 if (memBufName != "")
662 let memBufBasename = fnamemodify(memBufName, ":t")
663 if (bufName == memBufBasename)
669 let result = bufexists(bufName) || bufexists(a:fileName) || filereadable(a:fileName)
674 let result = filereadable(a:fileName)
679 " Function : FindOrCreateBuffer (PRIVATE)
680 " Purpose : searches the buffer list (:ls) for the specified filename. If
681 " found, checks the window list for the buffer. If the buffer is in
682 " an already open window, it switches to the window. If the buffer
683 " was not in a window, it switches to that buffer. If the buffer did
684 " not exist, it creates it.
685 " Args : filename (IN) -- the name of the file
686 " doSplit (IN) -- indicates whether the window should be split
687 " ("v", "h", "n", "v!", "h!", "n!", "t", "t!")
688 " findSimilar (IN) -- indicate weather existing buffers should be
691 " Author : Michael Sharpe <feline@irendi.com>
692 " History : + bufname() was not working very well with the possibly strange
693 " paths that can abound with the search path so updated this
695 " + updated window switching code to make it more efficient -- Bindu
696 " Allow ! to be applied to buffer/split/editing commands for more
697 " vim/vi like consistency
698 " + implemented fix from Matt Perry
699 function! <SID>FindOrCreateBuffer(fileName, doSplit, findSimilar)
700 " Check to see if the buffer is already open before re-opening it.
701 let FILENAME = escape(a:fileName, ' ')
703 let lastBuffer = bufnr("$")
706 while i <= lastBuffer
707 if <SID>EqualFilePaths(expand("#".i.":p"), a:fileName)
715 let bufName = bufname(a:fileName)
716 let bufFilename = fnamemodify(a:fileName,":t")
719 let bufName = bufname(bufFilename)
723 let tail = fnamemodify(bufName, ":t")
724 if (tail != bufFilename)
729 let bufNr = bufnr(bufName)
730 let FILENAME = bufName
735 if (g:alternateRelativeFiles == 1)
736 let FILENAME = fnamemodify(FILENAME, ":p:.")
739 let splitType = a:doSplit[0]
740 let bang = a:doSplit[1]
742 " Buffer did not exist....create it
744 if (splitType == "h")
745 silent! execute ":split".bang." " . FILENAME
746 elseif (splitType == "v")
747 silent! execute ":vsplit".bang." " . FILENAME
748 elseif (splitType == "t")
749 silent! execute ":tab split".bang." " . FILENAME
751 silent! execute ":e".bang." " . FILENAME
758 " Find the correct tab corresponding to the existing buffer
761 for i in range(tabpagenr('$'))
762 " get the list of buffers in the tab
763 let tabList = tabpagebuflist(i + 1)
765 " iterate each buffer in the list
766 while idx < len(tabList)
767 " if it matches the buffer we are looking for...
768 if (tabList[idx] == bufNr)
769 " ... save the number
779 " switch the the tab containing the buffer
781 execute "tabn ".tabNr
784 " Buffer was already open......check to see if it is in a window
785 let bufWindow = bufwinnr(bufNr)
787 " Buffer was not in a window so open one
789 if (splitType == "h")
790 silent! execute ":sbuffer".bang." " . FILENAME
791 elseif (splitType == "v")
792 silent! execute ":vert sbuffer " . FILENAME
793 elseif (splitType == "t")
794 silent! execute ":tab sbuffer " . FILENAME
796 silent! execute ":buffer".bang." " . FILENAME
802 " Buffer is already in a window so switch to the window
803 execute bufWindow."wincmd w"
804 if (bufWindow != winnr())
805 " something wierd happened...open the buffer
807 if (splitType == "h")
808 silent! execute ":split".bang." " . FILENAME
809 elseif (splitType == "v")
810 silent! execute ":vsplit".bang." " . FILENAME
811 elseif (splitType == "t")
812 silent! execute ":tab split".bang." " . FILENAME
814 silent! execute ":e".bang." " . FILENAME
824 " Function : EqualFilePaths (PRIVATE)
825 " Purpose : Compares two paths. Do simple string comparison anywhere but on
826 " Windows. On Windows take into account that file paths could differ
827 " in usage of separators and the fact that case does not matter.
828 " "c:\WINDOWS" is the same path as "c:/windows". has("win32unix") Vim
829 " version does not count as one having Windows path rules.
830 " Args : path1 (IN) -- first path
831 " path2 (IN) -- second path
832 " Returns : 1 if path1 is equal to path2, 0 otherwise.
833 " Author : Ilya Bobir <ilya@po4ta.com>
834 function! <SID>EqualFilePaths(path1, path2)
835 if has("win16") || has("win32") || has("win64") || has("win95")
836 return substitute(a:path1, "\/", "\\", "g") ==? substitute(a:path2, "\/", "\\", "g")
838 return a:path1 == a:path2