用于取消引用文本的Visual Studio 2015 / ReSharper键盘快捷键

时间:2016-05-24 13:59:11

标签: visual-studio visual-studio-2015 macros resharper keyboard-shortcuts

使用 VIM ,我可以使用Tim Pope精彩的 vim-surround 插件将光标放在字符串中并发出ds"键盘序列以便取消引用它。如何在 VS 本地或 Resharper 中实现等效?

  • VIM + vim-surround

    "aaa|aaaaa" --->按ds" ---> aaa|aaaaa

  • VS 中,我知道我可以使用正则表达式查找/替换查询:

    |"aaaaaaaa" --->按Ctrl+H ---> ...

    查找"(.+?)"|'(.+?)' 替换$1

    ...按Alt+R替换下一个,我们有: aaaaaaaa (选择下一个匹配的引用字符串)

...但我想把它变成一个由键盘快捷键触发的宏。

我从 Visual Studio Gallery 安装了宏的Visual Studio 扩展程序,但在录制宏时,这并没有注册与查找/替换对话框的交互

我尝试根据Using Search and Replace Macros in Visual Studio自己编写一个宏,但它不起作用。我收到了错误,例如<{1}}和vsFindTarget未定义。

这是我失败的宏代码:

vsFindPatternSyntax.vsFindPatternSyntaxRegExpr

我看了Microsoft's documentation mentioned in this SO answer,但我遇到了上述问题。让我觉得用于Visual Studio扩展的在原生 VS API之上拥有它自己的API,或者(很可能)我只是没有得到它。

任何帮助将不胜感激。谢谢!

1 个答案:

答案 0 :(得分:0)

我决定将 Vim Visual Studio using Vim as an external tool集成,但是使用控制台 Vim 而不是 gVim

  1. VS 中,转到工具&gt; 外部工具...... &gt; 添加

    • 标题&Vim
    • 命令C:\[...]\usr\bin\mintty.exe(或您mintty.exe的任何地方 - 例如,它是 Git for Windows 安装的一部分)
    • 参数"C:\[...]\usr\bin\vim.exe" +"call cursor($(CurLine),$(CurCol))" +"runtime visualstudioinvoke.vim" "$(ItemFileName)$(ItemExt)"(使用vim.exe的实际路径;非常长的路径可能无效)
    • 初始目录$(ItemDir)
    • 或者,为方便起见,将工具设置为第一个工具(参见第4点)
    • 点击确定
  2. 创建~/.vim/visualstudioinvoke.vim~/vimfiles/visualstudioinvoke.vim,具体取决于以下内容(对我来说,前者有效):

  3. 
        set autoread
        autocmd CursorMoved,CursorMovedI * call CheckTime()
    
        " How many seconds to wait between file timestamp checks
        let s:check_time_delay=5
        let s:last_check_time=reltime()
    
        function CheckTime()
          if(reltime(s:last_check_time)[0] > s:check_time_delay)
            let s:last_check_time=reltime()
            checktime %
          endif
        endfunction
    
    

    如果 Vim VS (或 Vim 之外的任何其他地方)已更改,则 Vim 会自动重新加载该文件。光标移动在 Vim 中进行检查,但不会超过每5秒。

    1. 返回 VS ,转到工具&gt; 选项&gt; 环境&gt; 文档和厚Detect when file is changed outside the environment以及Reload modified files unless there are unsaved changes

    2. VS 中为 Vim 外部工具添加键盘快捷键:

      • 转到工具&gt; 选项&gt; 环境&gt; 键盘显示包含的命令:Tools.ExternalCommand1(假设 Vim 是第一个外部工具)。
      • 按快捷键下,我使用了 [Ctrl] + [`] (反引号)组合;使用你喜欢的任何东西。
    3. 就是这样。现在,您可以在 Vim 中快速打开您在 VS 中查看的文件,并保留光标位置。保存的更改也会在编辑器之间自动同步。对于不引用的文字,请确保 Vim 中有vim-surround plugin