我刚开始使用vim脚本,并尝试使opencart语言文件的翻译更容易。我想有一个函数查找给定的搜索模式并选择它。如果文件中没有匹配,它将打开下一个文件进行编辑。我至今:在vim脚本中搜索模式匹配的VIM检查
function! Nextmatch()
normal /\(= *'\)\@<=.\{-\}\('\)\@=/
normal v//e
endfunction
function! Nextfile()
if !exists("s:filecounter")
execute "!find -iname *.php > files.txt"
normal <CR>
let s:filecounter=0
endif
let s:lines= system("wc -l < files.txt")
if s:filecounter<s:lines
w
let s:filecounter += 1
let s:sedcommand="sed '".s:filecounter."!d' files.txt"
let s:selectedfile=system(s:sedcommand)
execute 'edit' s:selectedfile
else
wq
endif
endfunction
我怎样才能做到这一点Nextfile()
被称为Nextmatch()
如果搜索模式不光标和当前文件的末尾之间发现了什么?在我的片段中,是否有一些你认为是不好的风格?
感谢很多的模式,我测试了它,它是我想要什么差不多。但是有两个问题:1.它与光标无关,即如果我执行':bnext',然后按下'F8',则会跳回到旧文件,并且它不会查看子目录。你有什么建议吗? – phinz
查看子目录:':vim // g **/*。php' – yolenoyer
关于游标位置:由于':cn'只是跳转到quickfix列表中的下一个元素,因此无法轻易完成。请参阅':h quickfix' – yolenoyer