在Vim中,有没有办法:b以类似于:ls命令的方式列出打开缓冲区旁边的缓冲区数字,但不必重新输入:b之后?
答案 0 :(得分:3)
这个由a most valuable member of the community推广的精彩地图完全符合您的要求:
nnoremap gb :ls<CR>:b
更通用的方法......
Vim使用该非交互式列表来显示许多其他有用命令的结果。我写了这个简单的函数,每次在<CR>
之后按下其中一个命令后插入正确的“存根”:
function! CmdCR()
" grab the content of the command line
let cmdline = getcmdline()
if cmdline =~ '\C^ls'
" like :ls but prompts for a buffer command
return "\<CR>:b"
elseif cmdline =~ '/#$'
" like :g//# but prompts for a command
return "\<CR>:"
elseif cmdline =~ '\v\C^(dli|il)'
" like :dlist or :ilist but prompts for a count for :djump or :ijump
return "\<CR>:" . cmdline[0] . "jump " . split(cmdline, " ")[1] . "\<S-Left>\<Left>"
elseif cmdline =~ '\v\C^(cli|lli)'
" like :clist or :llist but prompts for an error/location number
return "\<CR>:silent " . repeat(cmdline[0], 2) . "\<Space>"
elseif cmdline =~ '\C^old'
" like :oldfiles but prompts for an old file to edit
return "\<CR>:edit #<"
else
" default to a regular <CR>
return "\<CR>"
endif
endfunction
cnoremap <expr> <CR> CmdCR()