【问题标题】:Visual Studio 2015/ReSharper keyboard shortcut for unquoting text用于取消引用文本的 Visual Studio 2015/ReSharper 键盘快捷键
【发布时间】:2016-09-21 19:13:48
【问题描述】:

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

  • VIM + vim-环绕:

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

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

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

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

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

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

我从 Visual Studio 库 中安装了 Macros for Visual Studio 扩展,但这并没有在录制宏时注册与“查找/替换”对话框的交互。

我尝试根据Using Search and Replace Macros in Visual Studio 自己编写一个宏,但它不起作用。我收到错误,例如vsFindTargetvsFindPatternSyntax.vsFindPatternSyntaxRegExpr 未定义。

这是我失败的宏代码:

dte.ExecuteCommand("Edit.Replace");

dte.Find.FindWhat = "\"(.+?)\"|'(.+?)'";
dte.Find.ReplaceWith = "$1"
dte.Find.Target = vsFindTarget.vsFindTargetCurrentDocument
dte.Find.PatternSyntax = vsFindPatternSyntax.vsFindPatternSyntaxRegExpr
dte.Find.ResultsLocation = vsFindResultsLocation.vsFindResultsNone
dte.Find.Action = vsFindAction.vsFindActionReplace
dte.Find.Execute()

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

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

【问题讨论】:

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


【解决方案1】:

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

  1. VS 中,转到 工具 > 外部工具... > 添加

    • 标题&Vim
    • 命令C:\[...]\usr\bin\mintty.exe(或任何你有 mintty.exe 的地方 - 例如,它是 Windows 版 Git 安装的一部分)
    • 参数"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(对我来说,前者是可行的):

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

如果文件在 VS 中(或 Vim 之外的任何其他地方)被更改,上述内容确保 Vim 自动重新加载文件。检查发生在 Vim 内的光标移动时,但不超过每 5 秒一次。

  1. 返回 VS,转到 工具 > 选项 > 环境 > 文档和厚Detect when file is changed outside the environmentReload modified files unless there are unsaved changes

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

    • 转到工具 > 选项 > 环境 > 键盘显示包含的命令>:Tools.ExternalCommand1(假设 Vim 是第一个外部工具)。
    • 按下快捷键下,我使用了[Ctrl]+[`](反引号)组合;随意使用。

就是这样。现在您可以在 Vim 中快速打开您在 VS 中查看的文件,并保留光标位置。保存的更改也会在编辑器之间自动同步。对于文本取消引用,请确保您的 Vim 中有 vim-surround plugin

【讨论】:

  • 我现在已经用了 10 天了,效果很好。我改变的一件事是启动 Vim 的组合键。现在它是 [Ctrl]+[Alt]+[Shift]+[v] 并且它似乎没有与任何东西发生冲突。由于我没有收到其他完整的答案,因此我接受此作为选择的解决方案。
猜你喜欢
  • 1970-01-01
  • 2015-12-13
  • 2017-05-16
  • 1970-01-01
  • 1970-01-01
  • 2015-12-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多