1
vim에서 정규 표현식과 일치하는지 여부에 따라 프로그래밍 방식으로 접기를 닫으 려합니다. 나는 그렇게 내의 vimrc에서 함수를 정의했습니다 :Vim : 특정 줄에서 접기 닫기
" Support python 2 and 3
if has('python')
command! -nargs=1 Python2or3 python <args>
elseif has('python3')
command! -nargs=1 Python2or3 python3 <args>
else
echo "Error: Requires Vim compiled with +python or +python3"
finish
endif
" Define function
func! FoldCopyrightHeader()
Python2or3 << EOF
import re
import vim
# Look at the first 30 lines
header = '\n'.join(vim.current.buffer[0:30])
pattern = 'Copyright .* by .* THE POSSIBILITY OF SUCH DAMAGE'
match = re.search(pattern, header, flags=re.MULTILINE | re.DOTALL)
if match:
# Find the line number of the block to fold
lineno = header[:match.start()].count('\n')
# Remember the current position
row, col = vim.current.window.cursor
# move cursor to the fold block
vim.command('cal cursor({},{})'.format(lineno, 0))
# close the fold
vim.command('call feedkeys("zc")')
# move back to the original position
vim.command('cal cursor({},{})'.format(row, col))
EOF
endfunc
아이디어가 존재하는 경우, 그 배를 닫습니다 키 명령을
zc
을 입력 패턴이 곳으로 이동 패턴을 검색하는 것입니다
, 원래 위치로 다시 이동하십시오.
그러나 이것은 제대로 작동하지 않습니다. :call FoldCopyrightHeader()
을 통해이 함수를 호출하면 현재 커서가있는 접기가 닫히고 다른 작업은 수행되지 않습니다.
제 생각 엔 feedkeys
명령이 비동기식 vim.command('call feedkeys("zc")')
이고 커서 이동 명령이 실행되기 전후에 일어나고있는 것 같습니다.
내가 이것을 막기 위해 할 수있는 일이 있습니까?