Skip to main content

Vim function GetProjectForFile()

Posted in

function! GetProjectForFile(filePath)
    if a:filePath == ""
        return ""

    " read projects file
    for sLine in readfile(g:projectFile)
        " if line is not empty
        if l:sLine !~ '^\s*$' && l:sLine !~ '^\s*\#.*$'
            let l:projectPath = l:sLine
            if stridx(a:filePath, l:projectPath) == 0
                return l:projectPath
    return ""

This function has been written in order to be able to find out which project the file belongs to. The project top directories are listed in ~/.vim_projects file. The projects file looks like this:

[Proj 1]
[Proj 2]

Post new comment

The content of this field is kept private and will not be shown publicly.
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
         .oOOOo.   o.OOOo.           OOooOoO     Oo    
OooOOo o o O `o o o O
o O. o O O O o
O `OOoo. O o oOooO oOooOoOo
ooOOo. `O o O .oOoO O o O
O o O o o O o O o
o O. .O o .O' O o o o O
`OooO' `oooO' OooOO' `OoOo O' O. O
Enter the code depicted in ASCII art style.