问题描述
nnoremap <leader>c :Ack ’^class ’ <c-r>=&path<cr><home><right><right><right><right><right><right><right><right><right><right><right><right>
大意是在 &path 路径下使用 Ack 搜索 pattern.
这条映射中的 n*<right> 丑死了, 可以怎样优化下?
经过社区帮助, 我把最终的方法放到下面:
' help inputfunction! AckClass() let l:classPattern = input(’Pattern: ’) execute ' Ack ’^class ' . l:classPattern . '’ ' . &pathendfunctioncommand! AckClass call AckClass()
问题解答
回答1:不知道你要交互到什么程度
function! ChangeFileencoding() let encodings = [’GB18030’, ’GBK’, ’cp936’, ’utf-8’, ’big5’, 'latin1', 'euc-kr', 'euc-jp', 'ucs-bom', 'shift-jis'] let prompt_encs = [] let index = 0 while index < len(encodings)call add(prompt_encs, index.’. ’.encodings[index])let index = index + 1 endwhile let choice = inputlist(prompt_encs) if choice >= 0 && choice < len(encodings)execute ’e ++enc=’.encodings[choice].’ %:p’ endifendf
这是我的vimrc的换编码打开文件的函数,会展现一个选项列表,供你参考

