使用 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,或者(很可能)我只是没有得到它。
任何帮助将不胜感激。谢谢!
答案 0 :(得分:0)
我决定将 Vim 与 Visual Studio using Vim as an external tool集成,但是使用控制台 Vim 而不是 gVim :
在 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)
创建~/.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
如果 Vim 在 VS (或 Vim 之外的任何其他地方)已更改,则 Vim 会自动重新加载该文件。光标移动在 Vim 中进行检查,但不会超过每5秒。
返回 VS ,转到工具&gt; 选项&gt; 环境&gt; 文档和厚Detect when file is changed outside the environment
以及Reload modified files unless there are unsaved changes
在 VS 中为 Vim 外部工具添加键盘快捷键:
Tools.ExternalCommand1
(假设 Vim 是第一个外部工具)。就是这样。现在,您可以在 Vim 中快速打开您在 VS 中查看的文件,并保留光标位置。保存的更改也会在编辑器之间自动同步。对于不引用的文字,请确保 Vim 中有vim-surround plugin。