VIM 标记和项目管理

发布于 2024-08-15 13:04:07 字数 282 浏览 4 评论 0原文

所以我一直在 vim 中使用 NERDTree,因为它添加了能够浏览文件系统的强大功能。借助书签功能,它非常适合在项目之间切换。

然而,我开始在 vim 中越来越多地使用标记,并且想知道是否有人知道一个允许你拥有标记集的插件。就像我希望 `C 转到我当前正在处理的项目中的配置文件一样。我可以在每次切换项目时设置它,但想知道是否有人知道打包它们的好方法。

只要想一想,我认为如果它在进入目录时只读取文件(例如使用 NERDTree 在书签之间切换...),那就太棒了。

无论如何,有人知道类似的事情吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

秋凉 2024-08-22 13:04:07

所以事实证明,标记没有存储在 会话 中,而是存储在在 viminfo 文件中!所以我使用了 vimrc 中的代码作为基础,并在 vim 帮助文件 创建一个功能,允许我保存会话和 viminfo 文件。创建对我来说非常有用的基本项目管理!

这是我最终得到的代码。

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()

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()
踏月而来 2024-08-22 13:04:07

我相信标记存储在会话文件中,这可以让您做您想做的事情。会话管理本身是另一个主题,但您可以在 此处找到一些想法。此代码已更新为包括对多个会话文件的支持,因此请在 此中获取最新信息 vimrc 文件。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文