以GTD方式使用Vim



我想改变记笔记的习惯。

我想在一个目录中添加名为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(没有插件,只有内置功能;没有外部程序;只有我的personnal 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. 锦上添花的是,快速修复窗口上的显示集中在我笔记的标题部分(在/^=之后)。我认为^=zs.*ze是可能的,但它对我来说太多了

编辑

我通过对之前的结果进行连续的vimgrep来解决我的"与"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,但我没有成功。知道吗?

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

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

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

最新更新