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

有没有办法在Vim中引用命令中当前选定的文本?

发布时间:2020-12-15 22:21:52 所属栏目:安全 来源:网络整理
导读:在我的C头文件中说我想包含另一个尚未创建的文件: #include "AnotherFile.h" /*not being created yet*/ 现在,我在Visual Mode中选择文件, ??????#include“AnotherFile.h” 如何使用我选择的名称创建一个新文件?我的意思是, :e {something that refers to
在我的C头文件中说我想包含另一个尚未创建的文件:

#include "AnotherFile.h" /*not being created yet*/

现在,我在Visual Mode中选择文件,
??????#include“AnotherFile.h”

如何使用我选择的名称创建一个新文件?我的意思是,

:e  {something that  refers to what I selected}

解决方法

我能想到的最接近的是创建一个函数:

function! W() range
  execute "e " .  getline("'<")[getpos("'<")[2]-1:getpos("'>")[2]] 
endfu

然后,您可以选择单词并键入:call W()enter,它应该打开新的缓冲区.

编辑如果修改了包含#include的缓冲区,则上述函数无法正常工作.在这种情况下,以下功能更适合:

function! W() range
  let l:fileName = getline("'<")[getpos("'<")[2]-1:getpos("'>")[2]] 
  new      
  execute "w " . l:fileName
endfu

编辑2您也可以尝试输入:e< cfile> (参见:help< cfile>).

编辑3最后,在:帮助gf你发现隐藏

If you do want to edit a new file,use: >
        :e <cfile>
To make gf always work like that: 
        :map gf :e <cfile><CR>

(编辑:李大同)

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

    推荐文章
      热点阅读