English 中文(简体)
VIM Marks and Project Management
原标题:

So I ve been using NERDTree in vim as it adds great functionality being able to browse around the file system. And with the Bookmarks capabilities it works great for switching between projects.

However, I ve started using Marks more and more in vim and wanted to know if anyone knew of a plugin that allowed you to have sets of marks. Like I want `C to go to the config file in the project I m currently working on. I can set it each time I switch projects, but was wondering if anyone knew of a good way to package them.

In just thinking about it, I think it would be awesome if it would just read a file when you got into a directory (like switching between bookmarks with NERDTree...).

Anyways, anyone know of anything like that?

最佳回答

So it turns out that marks are not stored in the session, but are stored in the viminfo file! So I used the code from your vimrc as a basis and the code found at the bottom of the section on sessions in the vim help files to create a function that will allow me to save save the session and viminfo file. Creating basic project management that works great for me!

Here is the code I ended up with.

if version >= 700
    " localoptions has to be here:
    " for some reason, new session loading code fails to set filetype of files in session
  set sessionoptions=blank,tabpages,folds,localoptions,curdir,resize,winsize,winpos
endif

command! -nargs=1 Project :call LoadProject( <args> )
command! -nargs=+ SaveProject :call SaveProject( <args> )

let s:projectloaded = 0
let s:loadingproject = 0
let s:projectname =   

function! LoadProject(name)

    let s:projectloaded = 1
    let s:projectname = a:name
    exe "source ~/vimfiles/projects/".a:name.".vim"
    exe "rviminfo! ~/vimfiles/projects/".a:name.".viminfo"

endfunction

function! SaveProject(name)

    if a:name ==#   
        if s:projectloaded == 1
            let pname = s:projectname
        endif
    else
        let pname = a:name
    endif

    if pname !=#   
        let s:projectloaded = 0
        let s:projectname =   
        exe "mksession! ~\vimfiles\projects\".pname.".vim"
        exe "wviminfo! ~\vimfiles\projects\".pname.".viminfo"
    endif

endfunction

autocmd VimLeave * call SaveProject()
问题回答

I believe marks are stored in session files, which may allow you to do what you want. Session management itself is another topic, but you can find some ideas here. This code has been updated to include support for multiple session files, so get the latest in this vimrc file.





相关问题
Autoupdate VIM Plugins?

Is it possible to update vim plugins automatically?

how to unindent in vim without leaving edit mode?

I m writing a lot of python code recently, and i used the tab-to-space mode in vim. I was just wondering how would i unindent in vim without leaving edit mode for example after i finished if...: block....

Scrolling inside Vim in Mac s Terminal

I ve been googling around trying to figure out if it s possible to use my mouse wheel to scroll while inside Vim in Mac s Terminal, with no luck. It seems as if only X11 or iTerm support this. Before ...

Vim - Deleting XML Comments

How do I delete comments in XML? If the opening and the closing comment tags are on the same line, I use :g/^<!--.*-->$/d to delete the comment. How to delete the comments that are spread ...

Limiting a match in vim to certain filetypes?

I have the following in my .vimrc to highlight lines longer than 80 chars: highlight OverLength ctermbg=red ctermfg=white guibg=#592929 match OverLength /\%81v.*/ This works quite well. However, the ...

Profiling Vim startup time

I’ve got a lot of plugins enabled when using Vim – I have collected plugins over the years. I’m a bit fed up with how long Vim takes to start now, so I’d like to profile its startup and see which of ...

热门标签