Custom VIM (Python) 함수를 호출 한 후 VIM 상태 라인에 상태를 보내는 방법

StackOverflow https://stackoverflow.com/questions/1822619

문제

방금 첫 Vim 스크립트를 만들었습니다. Python으로 썼습니다. 디렉토리 (/vim/etc/colors)에서 색 구성표를 전환하는 간단한 스크립트입니다. 선택한 색 구성표의 이름으로 색 구성표가 Vim '상태 라인'으로 변경된 후 알림을 보내는 방법을 알고 싶습니다.

RSON은 내 질문에 대한 답을 주었다.

AI와 Caleb의 제안을 구현 (일종의) 감사합니다! :

" toggleColorScheme 0.9 (l) 2009 by Jasper Poppe <jpoppe@ebay.com>

" cycle through colorschemes with F8 and Shift+F8
nnoremap <silent><F8> :call ToggleColorScheme("1")<CR>
nnoremap <silent><s-F8> :call ToggleColorScheme("-1")<CR>

" set directory with color schemes to cycle through
let g:Toggle_Color_Scheme_Path = "/etc/vim/colors"


function! ToggleColorScheme(paramater)
python << endpython
import vim
import os

paramater = (vim.eval('a:paramater'))
scheme_path = vim.eval('g:Toggle_Color_Scheme_Path')

colorschemes = [color.split('.')[0] for color in os.listdir(scheme_path) if color.endswith('.vim')]
colorschemes.sort()

if not vars().has_key('position'):
    start_scheme = vim.eval('g:colors_name') + '.vim'
    if start_scheme in colorschemes:
        position = colorschemes.index(start_scheme)
    else:
        position = 0

position += int(paramater)
position %= len(colorschemes)

vim.command('colorscheme %s' % colorschemes[position])
vim.command('redraw | echo "%s"' % colorschemes[position])
vim.command('return 1')
endpython
endfunction
도움이 되었습니까?

해결책

vim.command('redraw | echo "%s"' % colorschemes[position])

에서 :help echo:

나중에 다시 그리기는 메시지를 다시 사라질 수 있습니다. 그리고 VIM은 대부분 일련의 명령으로 끝날 때까지 주로 연기를 연기하기 때문에 이것은 자주 발생합니다. ": echo"이전의 명령을 피하기 위해 나중에 다시 그리기를 일으킨다 (redraws는 종종 무언가를 입력 할 때까지 연기됩니다). | : redraw | 명령. 예시:

: 새로운 | redraw | Echo "새 창이 있습니다"

다른 팁

여기에서 스크립트를 업데이트하므로

대신에

if argument == 'next':
    position += 1
    if position == len(colorschemes) - 1:
        position = 0
elif argument == 'prev':
    position -= 1
    if position == -1:
        position = len(colorschemes) - 1

아마도

scroll['next'] = +1
scroll['prev'] = -1
position += scroll[argument]
position = position % len(colorschemes) 
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top