2012-02-06 108 views
1

在vim中,我想要做的事,像这样部分vim的命令行映射

function! ModuleFile() 
    let $module = input("Module of file> ") 
    :e **/${module}_ 
endfunction 
map <Leader>e :call ModuleFile()<CR> 

我想到的是,例如,如果我键入模块“ABC”,我会得到这个命令行中VIM:

:e **/ABC_ 

,随后输入新的文本,如 “name_of_file”,会得到我:

:e **/ABC_name_of_file 

最后按下Enter将执行该命令。这一点是为了能够得到制表符完成。

+0

Uhmm,什么是“模块文件”,什么是应该做的正是这样的功能? – Rook 2012-02-07 00:36:08

回答

2

在vim脚本中不需要sigils,${...}$var用于环境变量。

function! ModuleFile() 
    let module = input("Module of file> ") 
    let name = input("Search pattern> ") 
    execute 'args **/' . module . '_' . name 
endfunction 
map <Leader>e :call ModuleFile()<CR> 

您的评论后,你想要的东西可能是:

map <leader>e :args **/<c-r>=input("Module of file: ") . '_' . input("Search pattern: ")<cr> 
+0

我想让它离开我的指挥线。因此,在按 e之后,例如ABC为模块和图形为搜索模式,然后输入“abcdefg ”后缀,我想要执行以下命令: ':e **/ABC_Graphicsabcdefg' – solinent 2012-02-21 21:09:50

+0

@solinent:回答。应该符合你的标准。 – Benoit 2012-02-21 22:19:08