Resharper completion without overwriting existing code

若如初见. 提交于 2019-12-06 22:24:29

问题


In Resharper when I go back to edit some existing code.. eg. wanting to insert a String.Format into this code:

<td>
    <%= Html.Encode(item.Address) %>
</td>

I move the cursor to before 'item' and type in 'String.F', getting Resharper's intellisense completion list that includes the 'Format' method.

However if I press TAB then it replaces 'item' with '.Format()'

Is there a way to use completing without replacing the existing text?


回答1:


There are two techniques you can use.

The first is to use the Enter key, the second is to pop a space between where you are going to start typing and the next bit of code, which will prevent the next bit of code from being overwritten.




回答2:


Stumbled upon using Enter instead of TAB to choose from the completion list. That does exactly what I want. It surrounds (in this case) 'item.Address' with the String.Format( .. ).




回答3:


There is an actual setting now to disable this (annoying) behavior.

Go to the Options dialog (Menu -> Resharper -> Options). In this Options dialog go to Environment -> IntelliSense -> Completion Characters.

Here you can set the Tab behavior to Insert instead of Replace.

Screenshot of Options

Resharper documentation about Completing Characters

This is an addition to the answer in 2010, for everyone that reaches this post via populair search engines ;)




回答4:


You could also use the String.Format surround template but you may have to map a hotkey to it for easier access.




回答5:


The keyboard command you want to use is called: Resharper_ForceCompleteItem. So if you go into Visual Studio's Tools > Options > Environment > Keyboard you could assign a keyboard shortcut there. Not sure if it would be possible to use Tab, though.



来源:https://stackoverflow.com/questions/3706632/resharper-completion-without-overwriting-existing-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!