Vim自动滚动缓冲区 [英] Vim automatic scroll buffer

查看:95
本文介绍了Vim自动滚动缓冲区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试做一个非常简单的事情:



我在Vim中有两个缓冲区,一个带有源代码(B1),另一个带有文本文件 a.txt (B2)。 B1中的源代码使用Vim中的自定义快捷方式运行,并在 a.txt 中填充文本。我希望Vim每次更新时都自动滚动B2,即使我的光标位于B1中。因此,我只希望缓冲区B2的行为与 tail -f 相同。



使用ConqueTerm做到这一点不能选择,因为缓冲区B2可以是其他插件的预览缓冲区。

解决方案

通常,vim事件会作为响应触发用户输入。它们不仅在后台连续运行。



这篇文章详细介绍了一些技巧,您可以将这些技巧重新用于编写一些自定义代码,以重新加载 tail -f缓冲区并定期滚动至底部。 / p>

不是尝试在vim中完成所有操作,而是另一种建议,使用 GNU屏幕(一个带有vim的终端区域,编辑文件 file1 ,另一个运行 tail -f 对另一个文件 file2 ):




  • 下载/安装 GNU屏幕(也许 apt-get安装屏幕

  • 运行屏幕

  • 运行 vim file1

  • 键入 Ctrl-A S 进行拆分终端水平向下(或在最新版本的屏幕中, Ctrl-A | 将其拆分为垂直居中)

  • 键入 Ctrl-A制表符切换到拆分的另一端

  • 键入 Ctrl-A c 在此侧启动新终端

  • 运行 tail -f file2



现在拆分的一侧显示 vim file1 ,另一面显示 tail -f file2 。这是结果的图像。




I'm trying to do something very simple:

I have two buffers in Vim, one with source code (B1), another one with a text file a.txt (B2). The source code in B1 is run with a custom shortcut in Vim, filling a.txt with text. I want Vim to automatically scroll B2 every time it updates, even if my cursor is in B1. So, I just want that the buffer B2 to behave the way tail -f does.

Doing this with ConqueTerm is not an option, since buffer B2 can be a preview buffer from other plugin.

解决方案

In general, vim events fire in response to user input. They don't just run continuously in the background.

This post details some tricks you could repurpose to write some customization code to reload your "tail -f" buffer and scroll to the bottom periodically.

Rather than trying to do this all in vim, here is a different proposal that would achieve a similar effect using GNU Screen (one terminal area with vim editing a file file1, another running tail -f against a different file file2):

  • download/install GNU Screen (perhaps apt-get install screen)
  • run screen
  • run vim file1
  • type Ctrl-A S to split the terminal down the middle horizontally (or, in recent versions of screen, Ctrl-A | to split it down the middle vertically)
  • type Ctrl-A Tab to switch to the other side of the split
  • type Ctrl-A c to start a new terminal on this side
  • run tail -f file2

Now one side of the split shows vim file1 and the other side shows tail -f file2. Here's an image of the result.

这篇关于Vim自动滚动缓冲区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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