Improved jumps to definition - plugins

When we're using ctags in vim and want to go to particular definition of variable or function we press ctrl + ], when we want to go back we press ctrl + T.
When we want to autocomplete a name of a variable we press ctrl + N and from a little violet window we can choose the right word.
Is it possible to improve go to definition so that we won't jump in the document, but only the little window with the function or variable definition will appear?
thank you

You want a way to see the function's signature without actually jumping to its definition?
I know about two plugins supposed to provide exactly this feature:
EchoFunc,
Tag Signature Balloons
The last time I tried echofunc it didn't work for JavaScript, at least for me, but it worked well for the few PHP files I've tested it with. I didn't try the other one because it's GVim-only and I use the CLI version almost as often as the GUI version.
But you can also use TagList and/or TagBar: two very useful plugins providing great code navigation based on ctags. Both will display the signature of the tag under your cursor if you hit <Space>.

Related

Doom Emacs lsp-ui action hotkeys

I'm a complete newbie when it comes to emacs. I recently installed Doom emacs and I've been really enjoying it. One thing that I'm struggling to find out is how do I quickly access/select on of the actions that are given to me by lsp-mode (I assume it's lsp-ui). I've attached a screenshot - the actions that I'm referring to are on the right-hand side.
Quick side questions:
When I jump to definition (spc-c-d) how do I jump back? Do I just kill the buffer?
Using ivy, how can I easily go through the list? - using control-n is a bit hard
You can come back to the previous buffer using CTRL+O
You can go down or up in the list using CTRL+j or CTRL+k
There are some tricks to get the answer:
first, try to find the action or function you know.
example 1. "M-x action-you-want-to-know"
example 2. "C-h k then-type-the-shortcut-key-you-want-to-search"
second, try to get the answer from project issues
The answer to your question:
1: press "C-o" jump backward
2: Try to input multi keywords in your search field to narrow down the search scope, just like increment search.
If you get too many lines after ivy-search some keyword you input, that means you donot know what you want to search, right?

VS Code: Case sensitive replacement after pressing Crtl - D

Let's suppose I have the following code:
But I change my mind and I don't want to call it plan anymore. I want to call it schedule. So, because VS Code is so amazing and I'm so lazy, I press Ctrl + D hoping for VS Code to change the name respecting the case. But suddenly:
Is it there any way to tell VS Code to respect the case?
With 1.37 (July 2019), it is possible through a find/replace (which now can replace by preserving case).
Issue 9798 has been implemented by PR 78003.
issue 78397 has been implemented by PR 79111 (1.38 only) for search/replace.
From 1.37 release notes:
You can now preserve case when doing replacement in the editor's Find widget. The feature is turned on when the Preserve Case option (AB button) is turned on in the editor's Replace input box.
Currently VS Code only supports preserve Full Upper Case, Full Lower Case, and Title Case.
Shortcuts are Alt + C for case sensitive. There is a little toolbar appears at the top-right corner of the VS Code, to let you toggle search options.
or you just Ctrl + F to toggle replace mode.
The v1.38 release in early September will extend the Preserve Case functionality to replacements while searching across files using the Search Panel. See add Preserve Case to Searches (all files).
.
There is also a new case preservation mode for hyphen-separated words.
v1.39 is adding preserve case for _underscore separated words. Like foo_bar.
See https://github.com/microsoft/vscode/pull/79660
If you want to achieve this without using the find/replace menu, there is an extension which solves your problem: https://marketplace.visualstudio.com/items?itemName=Cardinal90.multi-cursor-case-preserve
As far as I know it isn't, a workaround could be using the buttons that appear on top right after you press Ctrl + D. The second lets you select occurrences respecting the case, this way you could replace the text in 2 steps, first Plan and then plan.
So select the code bit, ctrl+h to open replace, edit find and replace, turn off match case in find, turn on preserve case within replace, Alt+L to find all occurences in selection, and Ctrl+Alt+Enter to execute.
9/10 cases you'll get it wrong, doesn't worth the effort. Just use ctr+d, then do the same for the uppercase.
Personally looking forward for a simpler/safer solution through the ctrl+d way. :)

View All Eclipse shortcuts

I was trying to learn all the eclipse shortcuts... I couldn't find anything useful.
There are some shortcuts available for easy ones, like Find, Find in Files, Comment, Uncomment etc.
Is there any way to view all the eclipse shortcuts?
Clicking Ctrl+Shift+L from eclipse, will list all the shortcuts. This is pretty useful, as you don't need to switch to another window... You can do your work without any interruption.. :-)
Open Windows->Preferences->General->Keys. Now you can use the filter to find your shortcut and change its binding.
CTRL + SHIFT + L
Shows you a list of your currently defined shortcut keys.
However this will only show you custom short cuts that user have added therefore, Please find useful eclipse short-cuts below
CTRL + /
In line Comment
CTRL + SHIFT + /
Block Comment
CTRL + D
Delete row. Try it! You no longer need to grab the mouse and select the line, or select Home, Shift + End, Delete. Quick and clean.
ALT + Up/Down Arrow
Move the row (or the entire selection) up or down. Very useful when rearranging code. You can even select more rows and move them all at once. Notice, that it will be always correctly indented.
ALT + Left/Right Arrow
Move to the last location you edited. Imagine you just created a class "Foo", and now you are working on a class "Boo". Now, if you need to look at the "Foo" class, just press Alt+Left Arrow. Alt+Right Arrow brings you back to "Boo".
CTRL+SHIFT+O
Organize imports. What happens when you first use a class you have not yet imported? You will see an error. But when you press this magical combination, all your missing classes will be imported, and the unused imports will vanish.
CTRL+1
Probably the most useful one. It activates the quick fix. Imagine you create a class, which implements some interface. You will get an error, because the inherited methods are not yet implemented. While you are on line where the error occurs, press this combination to activate the quick fix. Now, select the "Add unimplemented methods" option. You can use the quick fix at every error you ever receive.
Quick fix comes in handy in other situations too. My favorite is the "Split variable declaration". Sometimes I need to broaden the scope of a variable. I activate the quick fix, split declaration, and use alt + arrow to put it where it belongs. You can find even more uses: Convert local variable to field, rename in file, inline local variable, etc...
You could use the "Split variable declaration" on the bar variable, and then move it with Alt+Arrows above the try block..
Or you could use the "Add unimplemented methods" fix here.
The best thing you can do if you see an error is to use the quick fix.
CTRL+SHIFT+T
Open Type. Imagine, that you need to have a look at the "Foo" class. But, where is the "Foo" class? Is it in the "Boo" project and in the "foo.bar" package? Or somewhere else? With this shortcut, you don't need to know. Just press it, type "Foo" and you are in.
CTRL+E
Shows you a list of all open editors.
CTRL+F6
Use to move between open editors. This is a slower alternative to Ctrl + E. It comes in handy in a situation when you want to periodically switch between two editors, something that is nearly impossible with Ctrl+E as it sorts entries quite randomly. Or you might just use Alt+Arrows...
CTRL+F7
Move between views. When in the editor, press Ctrl+F7 to switch to the Package Explorer, or hold Ctrl and press F7 multiple times to switch to other views.
CTRL+F8
Move between perspectives. The same as the previous.
CTRL + F11
Runs the application. What gets launched depends on your settings. It will either launch the last launched class (my preferred way) or it will launch the currently selected resource (the default way). If you want to change its behavior read the previous post.
CTL + N
Open new type wizard. This is not very quick because you have to select the wizard type (whether you want to create new class, jsp, xml or something else) in the next step. A much faster way would be if you could just hit the shortcut and invoke the particular wizard. It is possible, just keep reading...
CTRL + M
Maximize or umaximize current tab.
CTRL + I
Corrects indentation.
CTRL + SHIFT + F
Formats code. You can make beautiful looking code out of a mess with this. It requires a bit of setup, but it is well worth it. You can find its settings under Window->Preferences->Java->Code style->Formatter
CTRL + J
Incremental search. Similar to the search in firefox, it shows you results as you type. Don't be surprised if when you hit this combination nothing happens - at the first glance. Just start typing and eclipse will move your cursor to the first occurence.
CTRL+SHIFT+G
Bind this to "Generate getters and setters". This is a "must have".
ALT+C
Bind this to SVN/CVS "Commit".
ALT+U
Bind this to SVN/CVS "Update".
yes, you can go Window - Preferencee - General - Keys and see all available shortcuts. Also you can reorder keys here.
Also you can read more about eclipse shortcuts here

Eclipse Code Assist inside method or type name

I'm used to Visual Studio, where when you start typing System.Context list will appear and you will be able to choose not only from type names that start with Context, but also from names like ActivationContext.
This gives me the ability to quickly find a method just by guessing it's name. Especially important when I'm beginning to learn to program for Android. For example, I was sure that ListView must have a method for setting ListAdapter, but I was dumb enough not to figure it will be just setAdapter. In VS I would just type adapter and setAdapter would have appeared.
Is there something similar in Eclipse?
In Eclipse you can use the keyboard shortcut Ctrl + Space and it will try and suggest items for you. You can do this after you have already started typing in a piece of the "suggestion". It is a little more strict:
Example: On a String object, you try and find, equalsIgnoreCase() (your string is called test). Typing test.e then CTRL + SPACE gives three options (endsWith, equals, equalsIgnoreCase). If you type test.ignore then CTRL + SPACE you get no results. For filtering help, you can just use test. and then CTRL + SPACE and it will show all results so you can hunt that way.

What's the trick to write code faster in Eclipse?

I know there is a trick that when you type quickly code in Eclipse, you can hit some secret keys and it will auto-complete the missing parts. Who knows them?
example: I have someVeryLongVariablesWhichIWantToTypeFast and I start typing someVeryLongVa but nothing happens. Only when I type method names a yellow box appears that wants to help me.
Ctrl + Space is the autocomplete shortcut
All shortcuts you can find under Window -> Preferences -> General -> Keys
As mentioned the command is Ctrl+Space to auto complete.
You can speed it up using camelCase...so in your example:
someVeryLongVariablesWhichIWantToTypeFast
you could start typing sVL then Ctrl+Space should auto complete or list all variables that match.
CamelCase also works for specify classes, searching for classes etc.
Others I like/use:
type sysCtrl+Space to get System.out.println statement (or err)
type foreCtrl+Space after an array/list line to foreach it
Click on an argument to a method and Ctrl+1 to create a field for it and assign it, great for constructors
Ctrl+1 on any local variable to convert to field, split declaration, or inline it
if you have
object.method().method2().method3()
selecting object.method() and type Ctrl+1 to assign to a field or local variable, then you get
Object objLocal=object.method()
objLocal.method2().method3()
//Can now select objLocal.method2() and do the same again
My favourites:
Ctrl + Space - auto complete
Ctrl + 1 - show quick fix options when you are over an error / warning
Shift + Ctrl + L - list short cuts
One trick that I love in Eclipse for Java is writing backwards (meaning you write the client before the code it calls). We typically think of autocomplete to help us with methods and variables that already exist. This is okay, but even cooler is when a method/class does not exist.
Try typing this code into a method (anywhere, really):
Who who = new Who();
who.whatUpMan("hi", 32);
Now left-click on the Who at the beginning. It will give you the choice to create a class, interface, enum, etc.
Now left-click on the whatUpMan. It will prompt you to create the method with the right parameter types and everything.
These are called "Quick Fixes" in Eclipse and they give you total freedom to code from the client "backwards" to classes it utilizes. And when you've already got the method, of course, control-space and control-shift-space (to see parameters for methods) are your friends.
http://eclipse-tools.sourceforge.net/EclipseEmacsKeybindings_3_1.pdf
Some more time savers that don't seem to be mentioned:
Ctrl+3 'Quick Access' which basically let's you reach anything without clicking around too much. E.g. type 'nav' in the popup dialog, rather than Window | Show View | General | Navigator or wherever it is.
Ctrl+O 'Quick Outline': when editing Java (and some other things), pops up a lighweight dialog so that you find anything in the file by a few keystrokes
Shift+Alt+T 'Refactoring', and things below that menu - look for shortcuts there, use 'Rename', 'Move', 'Extract method', 'Change method signature' often
Alt+Up/Down move blocks of code up/down without cut/paste
Alt+Shift+Up/Down select various levels of code (expressions,statements, methods, class) easily
Ctrl+1 on the selected code offers you cool stuff eg. Extract to variable/constant/method; Split variable declaration -- see others above, or just try it on anything
Ctrl+Shift+R find any file in the workspace, similar to Ctrl+Shift+T to find types
Ctrl + Shift + O : resolve all dependances automaticall. In Java, it's a life saver as it cleans old packages and add the required one without a single line to write.
"Right click" then "refactor" : all the features are handy, but I espacially love "rename" (Ctrl + Shift + R, c.f comments) because it will apply the changes to all the project. No more tricky find / replace wit regexp to do ensure you breal nothing else :-)
"Right click" then "source" : equally useful, with a special mention to "generate getter and setter" and "implement methods"
Ctrl + D : delete a line. Kinda cool.
I kind of remember CTRL+SPACE was the shortcut for autocomplete.
Another time-saver is formatting the code automatically using Ctrl + Shift + F.
Formatter preferences http://img187.imageshack.us/img187/5866/eclipseformatter.png
General Eclipse tips
Get rid of all the crap that you'll never use
if you do web-dev ... install the database, php, pydev, modules and plugins
install svn/cvs/git plugin
use Trac
have different code enviornments for different code types, i.e. one for python-dev, c++, and so on.
wait a few weeks to months before updating
i have about 100 premade mini scripts that i use frequently.
learn to develop your own plugins, as it's easy and fun.
For some applications, the answer is to generate the code using EMF. But the EMF learning curve is significant.
I would suggest go to Eclipse -> Preferences -> General -> Editor -> Keys and to configure your own keyboard shortcuts for all common tasks so that you can have custom keybindings that are perfect for you.
Probably this might not exactly answer your question but it is very relevant to your question title.
You can define templates in Eclipse to magically type and get a bunch of code typed for you. For instance you may type something like syso or sout to get System.out.println() in your Java code.
This can be done by following Window -> Preferences -> Java -> Editor -> Templates. You can also add a Template View, which you find at Window -> Show View -> Other -> Search for Templates.
Here is an image to clarify
* Original related answer in here as well.
Hope it is helpful to someone :)