开发者

Resharper completion without overwriting existing code

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?


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( .. ).


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.


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 ;)


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜