获得“可用"vim脚本中的窗口宽度 [英] Get "usable" window width in vim script

查看:12
本文介绍了获得“可用"vim脚本中的窗口宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 vim 脚本中获取 3 的宽度(在图像中用绿色标记)?

How do I get the width of 3 (marked with green color in the image) in vim script?

如果没有signs栏,也没有其他特殊栏",我可以用

If there is no signs column, and there are no other "special columns", I can get it with

winwidth(0) - (max([len(line('$')), &numberwidth-1]) + 1)

推荐答案

我认为,您应该能够使用以下方法获得该宽度:

I think, you should be able to get that width using:

:set virtualedit=all
:norm! g$
:echo virtcol('.')

或者,您可以检查是否存在 signcolumn(例如使用 redir)

Alternatively, you could check, whether a signcolumn is present (e.g. using redir)

:redir =>a |exe "sil sign place buffer=".bufnr('')|redir end
:let signlist=split(a, '\n')
:let width=winwidth(0) - ((&number||&relativenumber) ? &numberwidth : 0) - &foldcolumn - (len(signlist) > 1 ? 2 : 0)

这篇关于获得“可用"vim脚本中的窗口宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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