![](/img/trans.png)
[英]Is there a way to move within a file in Vim similar to Emacs' Isearch?
[英]Move File within Vim
有没有办法在Vim中移动文件? 我在Vim中打开了一个文件foo / bar.txt。 我知道有两种方法来移动这个文件:
第一解决方案
:bd bar.txt
mv foo/bar.txt foo/bar2.txt
在shell上执行移动 :e foo/bar2.txt
二解决方案:
但这两种解决方案令人尴尬。 我知道,有一个用于重命名文件vim-enuch的插件,但是没有Vim方式来执行这样的基本功能吗?
您还可以使用netrw(默认文件资源管理器)重命名功能。
:E
/
搜索它(例如/bar.txt
) R
然后,系统将提示您输入新的文件路径。 完成输入文件路径后点击<CR>
<CR>
打开它 虽然此解决方案可能不如使用vim-eunch快,但它允许您在重命名文件时查看项目的结构。 这也允许您一次移动多个文件。
进一步阅读运行:help netrw-move
没有原子方法来移动这样的文件,但这应该是关闭的:
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
如果你在bar.txt缓冲区:
:w bar2.txt
:!rm bar.txt
如果当前目录中已存在bar2.txt ,请使用:w!
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.