Function to turn local variable into class variable - android-studio

How to add these two functions to android studio, to turn a existing (not accessible) variable into a private/public? The screenshot is faked and not real, but it is the aim of my question.
To turn a local variable into private/public I have to do the following steps:- Cut [variable-class] [variable-name] - Write [private/public] - Change cursor position to class-head- Paste [variable-class] [variable-name] - Copy [variable-name] - Change cursor position to class-method - Paste [variable-name]

Ctrl+Alt+F will extract your local variable into the class field.
To learn other available refactorings, you can read the Intellij Idea Reference Card.

Thank you #Ofek! Your answer was okay but not perfect ;) So I'm going to add some details.
1. Change cursor position to variable2. Press Ctrl+Alt+F
3. To open extra settings press Ctrl+Alt+F once again:
4. If you have finished, press Enter:
Additional:
To change Ctrl+Alt+F to a desired combination follow this answer.

Go to Settings->Editor->Key-Map, search for "field" and define a shortcut to Extract a Field.

Related

Change Keyboard Mapping

Hello and thank you in advance,
I am wondering if there is a way to change the layout of my keyboard (software-wise).
The problem is that, on my laptop's keyboard, the Page Up and Page Down keys are combined with the Home and End keys respectively (i.e. to use Home, I have to use the command fn+PgUp/Home).
Is there a way for me to switch what my keyboard receives in Windows 8? If I press the PgUp/Home key I would like the Home command to be entered, and if I entered fn+PgUp/Home I would like the PgUp command to be entered.
I have tried googling for this using several different keywords, but haven't been able to find anything.
Any help is appreciated,
Zach
This is a duplicate question.
You can find an answer here:
https://superuser.com/questions/694465/remapping-a-keyboard-key-in-windows-8-1
Keep in mind this does require registry edits which can be dangerous and can lead to critical failures if not done correctly. Always create a restore point before making any registry edits.

Visual Studio hot key - switch Find context/location

Is there a hot key to toggle the search context/location in the "Find"/"Find in Files" commands (Ctr+F and Shift+Ctrl+F respectively )? I'm talking about the drop down that asks where to search for example Current Project, Current Document, Entire Solution etc.
"Find" is probably my most used feature since working with markup and CSS very often I can't just F12 to a selector definition or Shift+F12 to Find Usages, a regular text search is really the only option and I want to make this as efficient as possible.
Yes, I can tab to it but this takes 6-tabs and if I do it fast, often get the count wrong and prematurely execute bad searches; so it's not cutting it.
If there isn't a hotkey how can I set one? Ctrl + F3 would work well since F3 is "Find Next"
Thanks
I'm not sure if there is a command in Visual Studio that does what you are looking for.
If there is one, you can set the shortcut key in the Tools\Options menu (Environment\Keyboard).
In the screenshot, I'm searching for all the VS command that contain "find". Perhaps one of these is what you need.
Then move to the Press shortcut keys textbox and choose your desired key binding.

Tab behavior Resharper Intellisense Options

A product like Resharper has many settings, and I can't seem to find the right settings to get the exact behavior I desire from it.
The behavior I am trying to change is this:
Suppose the endresult I want is
but the line currently is
As you expect I start typing:
and after a tab I get this
but I wanted it to become
Does anyone know how I can change the Resharper settings in such a manner that my desired behavior is realized?
Thank you.
EDIT: Note that tab does perform the desired behavior in the default VS Intellisense.
In this particular case, here's what you should do:
Go to ReSharper > Options > Environment > IntelliSense > IntelliSense Behavior, and set Automatically insert parentheses after completion to Opening only.
Now, with the caret right before SomeMethod(), type in Math.Ab, and complete Abs with Enter, as correctly suggested by Rob H. You'll end up with Math.Abs(SomeMethod();
Finally, press Ctrl+Shift+Enter to invoke the Complete Statement, which in this case will insert the required parenthesis at the end of the statement, and put the caret on the next line.
Keep in mind though that this might not be the optimal solution provided that you probably have plenty of other usages of code completion that could conflict with this kind of settings change.
If that kind of similar code modification is required in multiple places, you should possibly create a search and replace pattern instead.
Hitting Enter instead of Tab will insert without overwriting, although you then end up with
Math.Abs()SomeMethod();

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.

Can resharper navigate to a method?

I know how to navigate to a file or a class, but can I navigate to a class's method?
Oh and say I am viewing a different class's file
With respect to my correctly configured keybindings, all of the previous answers seem outdated/invalid to me.
I say:
Hit Alt + \ to list all file members.
Then find your method in the list and navigate to it.
If you use "Resharper 2.x or IntelliJ IDEA" keyboard scheme:
Ctrl + Shift + Alt + N -> navigate to symbol
In Visual Studio Scheme:
Shift + Alt + T
For future reference and other options check https://www.jetbrains.com/resharper/features/navigation_search.html
If you are using Resharper IDEA Scheme, do ctrl + F12 and you can enter a member name, fastest way to navigate to a method, property etc on that file
Ctrl + Click (or Right Click > Go To Declaration). Works on Methods, Fields, Properties, Types, and just about everything else.
With VS2015 and ReSharper 10 press Ctrl + T. This will search for types, symbols and files. It will search through everything in your solution.
Update: works the same in VS2017 and ReSharper 2017.2.
You can also press Ctrl + T followed by / mm to search for just methods.
Another tip for the current file is to use the File Structure window - can also drag and drop members around from the window.
I have used Dpack (f/oss) for years and it can go to methods and/or properties by pressing a shortcut and then start typing. For those who get Resharper's ctrl-T working it is like that one but within the file.
Dpack provides the same functionality for finding files and open files. The former is a better version of Visual Studio 2015's ctrl-;.
(I have done some remapping of keys too but in my experience something (resharper?) overwrites my changes from time to time.)
(Also with VS2015 and R#9.2 I think Dpack does a better job at this.)

Resources