调用自定义VIM(Python)函数后如何将状态发送到VIM状态行 [英] How to send status to the VIM status line after calling custom VIM (Python) function

查看:34
本文介绍了调用自定义VIM(Python)函数后如何将状态发送到VIM状态行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚创建了我的第一个 VIM 脚本,我用 Python 编写了它.这是一个从目录 (/vim/etc/colors) 切换配色方案的简单脚本.我想知道如何在配色方案更改后将所选配色方案的名称发送到vim 'statusline' 的通知.

I've just created my first VIM script, I wrote it in Python. It's a simple script to switch color schemes from a directory (/vim/etc/colors). I would like to know how to send a notification after the color scheme changed with the name of the selected color scheme to the vim 'statusline'.

rson 回答了我的问题,这里是脚本的更新(和调试)版本,供感兴趣的人使用(在我测试范围内工作正常)

rson gave an answer to my question, here is an updated (and debugged) version of the script for who is interested (works fine as far as I can test)

实施(某种)AI 和 Caleb 的建议,谢谢!:

Implemented (kind of) the suggestions of AI and Caleb, thanks!:

" 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" 之后会导致重绘(重绘通常是推迟到您输入内容),强制重绘用 |:redraw|命令.示例:

A later redraw may make the message disappear again. And since Vim mostly postpones redrawing until it's finished with a sequence of commands this happens quite often. To avoid that a command from before the ":echo" causes a redraw afterwards (redraws are often postponed until you type something), force a redraw with the |:redraw| command. Example:

:新 |重绘|echo "有一个新窗口"

:new | redraw | echo "there is a new window"

这篇关于调用自定义VIM(Python)函数后如何将状态发送到VIM状态行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆