vimscript에서 파이썬을 사용하여이 작업을 수행하는 방법을 발견했습니다. 파이썬으로 나는 모든 버퍼의 이름을 vim.buffers[i].name
에서 얻을 수 있었고 os.path
과 os.sep
을 사용하여 전환 할 버퍼를 처리했습니다.
마지막으로 전환을 요청한 버퍼가 애매한 경우 아무 것도 수행하지 않는 것이 더 도움이된다고 결정했습니다.
는 여기있다 :
"Given a file, full path, or partial path, this will try to change to the
"buffer which may match that file. If no buffers match, it returns 1. If
"multiple buffers match, it returns 2. It returns 0 on success
function s:GotoBuffer(buf)
python << EOF
import vim, os
buf = vim.eval("a:buf")
#split the paths into lists of their components and reverse.
#e.g. foo/bar/baz.py becomes ['foo', 'bar', 'baz.py']
buf_path = os.path.normpath(buf).split(os.sep)[::-1]
buffers = [os.path.normpath(b.name).split(os.sep)[::-1] for b in vim.buffers]
possible_buffers = range(len(buffers))
#start eliminating incorrect buffers by their filenames and paths
for component in xrange(len(buf_path)):
for b in buffers:
if len(b)-1 >= component and b[component] != buf_path[component]:
#This buffer doesn't match. Eliminate it as a posibility.
i = buffers.index(b)
if i in possible_buffers: possible_buffers.remove(i)
if len(possible_buffers) > 1: vim.command("return 2")
#delete the next line to allow ambiguous switching
elif not possible_buffers: vim.command("return 1")
else:
vim.command("buffer " + str(possible_buffers[-1] + 1))
EOF
endfunction
편집 : 위의 코드는 몇 가지 버그를 갖고있는 것 같아요. 훨씬 나은 또 다른 대답이 있기 때문에 나는 그들을 고치려고하지 않습니다.
* 찡그린 미소 * 내가 아는 정력이 작업을 수행하는 기능을 할 것이다. 감사. –