gpt4 book ai didi

vim - 在Vim中移动文件

转载 作者:行者123 更新时间:2023-12-03 14:35:26 26 4
gpt4 key购买 nike

有没有办法在Vim中移动文件?例如。我在Vim中打开了一个文件foo / bar.txt。我知道两种移动此文件的方法:

第一个解决方案:

  • 使用:bd bar.txt删除缓冲区
  • 使用mv foo/bar.txt foo/bar2.txt
  • 在 shell 上执行移动
  • 使用:e foo/bar2.txt加载vim中的文件

  • 第二种解决方案:
  • 关闭Vim,因此所有缓冲区均已关闭。
  • 在 shell 上执行移动。
  • 启动Vim并加载文件。

  • 但是,这两种解决方案都令人尴尬。我知道,有一个用于重命名文件 vim-enuch的插件,但是没有Vim执行这种基本功能的方法吗?

    最佳答案

    没有原子的方式来移动这样的文件,但这应该很接近:

    function! MoveFile(newspec)
    let old = expand('%')
    " could be improved:
    if (old == a:newspec)
    return 0
    endif
    exe 'sav' fnameescape(a:newspec)
    call delete(old)
    endfunction

    command! -nargs=1 -complete=file -bar MoveFile call MoveFile('<args>')

    现在您可以说:
    :MoveFile file2.txt

    重命名为file2.txt
    :MoveFile %.0

    将file2.txt移动到file2.txt.0

    关于vim - 在Vim中移动文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10884520/

    26 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com