加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

vim – 更换缓冲区时防止光标跳转到底部

发布时间:2020-12-16 01:18:35 所属栏目:安全 来源:网络整理
导读:我有内容存储在一个变量(out)中,我想用当前缓冲区替换它.我现在正在这样做(简化版): let splitted = split(out,'n')if line('$') len(splitted) execute len(splitted) .',$delete'endifcall setline(1,splitted) (详细:https://github.com/fatih/vim-go/
我有内容存储在一个变量(out)中,我想用当前缓冲区替换它.我现在正在这样做(简化版):
let splitted = split(out,'n')
if line('$') > len(splitted)
    execute len(splitted) .',$delete'
endif
call setline(1,splitted)

(详细:https://github.com/fatih/vim-go/blob/master/autoload/go/fmt.vim#L130)

但是setline()会导致某些机器和07??001的速度变慢.我自己对它进行了描述,但对我而言,setline不是问题.无论如何,我需要一个更快的解决方案.所以我想出了其他几个解决方案.

第一个是将输出放到寄存器中,删除所有行然后将其放回:

let @a = out
% delete _
put! a
$delete _

第二个解决方案是使用append()(之前在vim-go https://github.com/fatih/vim-go/commit/99a1732e40e3f064300d544eebd4153dbc3c60c7中使用过):

let splitted = split(out,'n')
%delete _
call append(0,splitted)
$delete _

他们都工作!然而,它们都会引起副作用,我仍然无法解决,也写在标题中.问题描述如下:

If a buffer is opened in another view (say next to next),and
we call one of the two solutions above,it breaks the cursor of
the other view and jumps to the bottom

这是一个GIF显示它更好(每当我打电话:w上面的一个程序被调用):http://d.pr/i/1buDZ

有没有办法,替换缓冲区的内容,这是快速的,不会打破布局?或者我如何使用上述程序之一阻止它?

谢谢.

你尝试过winsaveview()和winrestview()吗?
:let old_view=winsaveview()
:% delete _
:put! =out
:$delete _
:call winrestview(old_view)

但是我对以更快的方式粘贴文本一无所知

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读