我是vi的初学者。我不知道这个术语,但我想拆分我的gvim终端(屏幕?)分成2个窗口,每个窗口有5个不同的文件(缓冲区?)。我可以在一个窗口中打开前5个文件,然后拆分到第二个窗口,但我不知道如何在第二个窗口中打开另外5个不同的文件。我还没能找到这个信息。通常我会使用:n
和:prev
在文件之间切换。
再说一遍:我希望文件1-5在左侧窗口,文件6-10在右侧窗口。这个是可能的吗?
发布于 2013-07-13 19:56:02
您确实可以拥有窗口本地参数列表:
:arglocal
:args file1 file2 file3 file4 file5
:vsplit
:arglocal
:args file6 file7 file8 file9 file10
这样,您可以将一个参数列表(包含文件1-5)用于左侧窗口,将另一个参数列表(包含文件6-10)放在拆分的右侧窗口中。这样,像窗口中的:next
和:first
这样的命令就相互独立了。
发布于 2013-07-13 07:16:01
缓冲区是全局的。这意味着你不能有,比方说,两个垂直的窗口,容纳两组独占的缓冲区。当然,这同样适用于选项卡。
因此,只需使用两个实例:一个位于左侧,包含文件1-5,另一个位于左侧,包含文件6-10。
因为这两个实例是分开的,所以您可以安全地使用:n
et :prev
,而不会出现“溢出”。
发布于 2013-07-13 18:39:13
选项卡是窗口的视口,窗口是缓冲区的视口。您可以在任何窗口中查看任何缓冲区。我不认为创建一些解决方法是不可能的:例如,您可以通过:command
创建命令:NEXT
和:PREV
,并使它们仅迭代通过:EDIT
在此窗口中打开的缓冲区:如下面的代码所示。但我强烈建议使用一些有助于缓冲区切换的插件,如Command-T (我有用于缓冲区切换的nnoremap ,b :CommandTBuffer<CR>
),并且忘记效率极低的:next
/:previous
命令。
function s:Edit(args)
let w:winbuflist=get(w:, 'winbuflist', [bufnr('%')])
execute 'edit' a:args
let buf=bufnr('%')
if index(w:winbuflist, buf) == -1
call add(w:winbuflist, bufnr('%'))
endif
endfunction
function s:Switch(direction)
let buf=bufnr('%')
let w:winbuflist=get(w:, 'winbuflist', [buf])
let idx=index(w:winbuflist, buf)
if idx==-1 || w:winbuflist ==# [buf]
if idx == -1
echohl ErrorMsg
echomsg 'Current buffer was not opened using :E or was opened in another window'
echohl None
endif
execute a:direction
return
elseif a:direction is# 'next'
let idx += 1
if idx == len(w:winbuflist)
let idx=0
endif
elseif a:direction is# 'previous'
let idx -= 1
if idx == -1
let idx=len(w:winbuflist)-1
endif
endif
execute 'buffer' w:winbuflist[idx]
endfunction
function s:RemoveBuf(buf)
for tab in range(1, tabpagenr('$'))
for win in range(1, tabpagewinnr(tab, '$'))
call filter(getwinvar(win, 'winbuflist', []), 'v:val isnot '.a:buf)
endfor
endfor
endfunction
augroup BufWinList
autocmd! BufWipeout * :call s:RemoveBuf(+expand('<abuf>'))
augroup END
" \/\/\/\/\/\/\/ Warning: this is not a completion option. It also
" \/\/\/\/\/\/\/ makes command do the expansion of its arguments.
command -complete=file -nargs=? -bar EDIT :call s:Edit(<q-args>)
command -nargs=0 -bar NEXT :call s:Switch('next')
command -nargs=0 -bar PREV :call s:Switch('previous')
https://stackoverflow.com/questions/17623454
复制相似问题