以GTD方式使用Vim

时间:2017-01-02 10:14:04

标签: vim vimgrep gtd vim-quickfix

我想以记笔记的方式改变我的习惯。

我希望在目录中添加名为YYYYmmddHHiiss.txt的文件并以这种方式启动它们:

=Call somebody (title of my note)
@work (context of my note)
!todo (type of the note, I'll use !inbox, !todo, !waiting, !someday and !reference, each one his habit)
#project_name
#call
#Name of the person
#other tags if needed...

Details...

我想要的是:

  • 使用Vim(没有插件,只有内置功能;没有外部程序;我个人vimrc中只有一些autocmd,映射和函数)
  • 将我的所有笔记保存在一个目录中,并信任Vim和我的标签以找到我需要的内容。
  • 使用此类:GtdGrep命令开始使用此系统,并在一段时间内考虑是否需要更多。

模型

:GtdGrep !todo @work
:GtdGrep !inbox
:GtdGrep @waiting @home
:GtdGrep !todo @work #this_project
:GtdGrep #name_of_a_co-worker #this_project

既然我已经向你介绍了我的需求,我就可以开始描述我的问题^^我想在GtdGrep命令背后创建函数但是有很多东西我无法收集......这是我的。草案

let gtd_dir=expand($HOME)."/Desktop/notes"

function! GtdGrep(...)
    execute "silent! vimgrep /\%<10l".join(a:000, "\\_.*")."/j ".gtd_dir."/**"
    execute "copen"
endfunction
command! -nargs=* GtdGrep call GtdGrep(<f-args>)
  1. 如何在第一个空行之前限制搜索?我设法使用正则表达式\%<10l在前9行中查找我的标签,但就是这样。
  2. 如何查找我的代码,无论其在文件中的位置如何?我刚刚成功地使用\_.* regexp在几行上执行grep,这是用于返回行的。
  3. 锦上添花的结果是,quickfix窗口上的显示会集中在我的笔记的标题部分(/^=之后)。我认为有可能使用^=\zs.*\ze,但在单个vimgrep中对我来说太过分了!
  4. 修改

    我通过在之前的结果上执行连续的vimgrep来解决我的“AND”vimgrep问题。这是一个很好的解决方案吗?

    let gtd_dir=expand($HOME)."/Desktop/notes"
    
    function! GtdGrep(...)
        let dest = g:gtd_dir."/**"
        for arg in a:000
            execute "silent! vimgrep /^".arg."$/j ".dest
            let dest = []
            let results = getqflist()
            if empty(results)
                break
            else
                for res in results
                     call add(dest, bufname(res.bufnr))
                endfor
                let dest = join(dest, ' ')
            endif
        endfor
    
        " Last vimgrep to focus on titles before displaying results
        let results = getqflist()
        if !empty(results)
            echom dest
            execute "silent! vimgrep /\\%<10l^=.*/j ".dest
            execute "copen"
        else
            echom "No results"
        endif
    endfunction
    command! -nargs=* GtdGrep call GtdGrep(<f-args>)
    

    我想在第一个空行之前限制我的vimgrep,但我没有成功。有什么想法吗?

1 个答案:

答案 0 :(得分:0)

首先,如果您使用动态字符串作为模式,您应该知道风险。例如。您的project_name包含[].*()...

你可以尝试的是,建立这个命令:

vimgrep '/\%<10l\(foo\|bar\|blah\|whatever\)' path/*