首页 \ 问答 \ Vim:如何从一个缓冲区读取到另一个缓冲区(Vim: How to read from one buffer into another)

Vim:如何从一个缓冲区读取到另一个缓冲区(Vim: How to read from one buffer into another)

在vim中,使用read命令可以轻松地将文件读入当前缓冲区:

:r my.file

但是如果文件的路径很长,并且文件在另一个缓冲区中打开,我怎样才能读取缓冲区的内容,即

:r {buffer_number}

有没有一种方法可以直接从一个缓冲区读取到另一个缓冲区而不使用yank缓冲区?


In vim it easy to read a file into the current buffer with the read command:

:r my.file

But if the path to the file is really long, and the file is open in another buffer, how can I read in the contents of the buffer instead i.e.

:r {buffer_number}

Is there a way of reading from one buffer directly into another without using the yank buffer??


原文:https://stackoverflow.com/questions/37859530
更新时间:2024-03-05 16:03

最满意答案

在代码停止执行之前,屏幕不会呈现。 这几乎总是期望的行为,因为它阻止DOM呈现不一致的状态。

假设您确实需要运行长同步任务,并且可以修复它或将其推迟到webworker ,那么解决方案是使用setTimeout

function run_test() {
    $('#test1').hide();
    $('#test2').show();
    
    setTimeout(function(){
       long_synchronous_function_call()
    
       $('#test2').hide();
       $('#test1').show();
    },0);
}

function long_synchronous_function_call() {
    $('#test1').html('<p>Some other data</p>');
    var date = new Date();
	while ((new Date()) - date <= 5000) {}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<div id="test1">
    <p>Some data</p>
</div>

<div id="test2" style="display:none">
    <p>Loading...</p>
</div>

<button onclick="run_test()">Call a long synchronous function!</button>

只是为了确保我没有帮你隐藏一个bug: 永远不要做同步ajax调用

当你在浏览器中真正进行合法且有些长时间的同步操作时(例如计算或构建复杂的GUI),做我的建议合理的。


The screen won't be rendered until your code stops execution. This is almost always the desired behavior, as it prevents the rendering of the DOM in an inconsistent state.

Supposing you really need to run a long synchronous task, and you can fix that or defer it to a webworker, then a solution is to use setTimeout:

function run_test() {
    $('#test1').hide();
    $('#test2').show();
    
    setTimeout(function(){
       long_synchronous_function_call()
    
       $('#test2').hide();
       $('#test1').show();
    },0);
}

function long_synchronous_function_call() {
    $('#test1').html('<p>Some other data</p>');
    var date = new Date();
	while ((new Date()) - date <= 5000) {}
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
<div id="test1">
    <p>Some data</p>
</div>

<div id="test2" style="display:none">
    <p>Loading...</p>
</div>

<button onclick="run_test()">Call a long synchronous function!</button>

Just to be sure I'm not helping you hiding a bug: NEVER do synchronous ajax calls.

It is reasonable to do what I suggest when you really have a legitimate and somewhat long synchronous operation happening in your browser, though (for example a computation or the building of a complex GUI).

相关问答

更多
  • 首先,一个不相关的提示 - 稍微更新jQuery是一个好主意(如果没有任何东西取决于你正在使用的旧版本)。 live将无法使用,相反,您需要将其替换为.on ,否则这是一个好主意。 其次,听起来像你正在寻找的是hide和show一些过渡。 您可以使用fadeIn()和fadeOut()替换它们。 你也可以使用toggle功能一次性完成所有功能(虽然使用悬停时可能行为不当,因为它会像疯了一样翻转)。 这是一个小片段,向您展示它们的工作原理: $(document).ready(function() { ...
  • 在代码停止执行之前,屏幕不会呈现。 这几乎总是期望的行为,因为它阻止DOM呈现不一致的状态。 假设您确实需要运行长同步任务,并且可以修复它或将其推迟到webworker ,那么解决方案是使用setTimeout : function run_test() { $('#test1').hide(); $('#test2').show(); setTimeout(function(){ long_synchronous_function_call() ...
  • 它适合我 。 你可能在问题和答案之间有一些其他元素。 如果是这样,请将其更改为 $(this).nextAll(".answer:first").toggle(); 或者,您可能在解析之前在 标记中运行代码。 如果是这样,请将