How to: Go to file (#) Go to for symbol in the same dialog - visual-studio-code

I am missing this feature from Sublime Text so much. Go to Symbol in Workspace feels so close to it and yet so far away.This is very useful in the following examples:
You have many classes that have the same symbol/function name, Pre-filtering the file lets you jump to the exact definition very fast
You know the name of the file, but you are not sure about the exact symbol/function name. Fuzzy searching it is super fast
You want to quickly preview the available symbols/functions in a given file
Here is a sample video demonstrating this feature in Sublime Text:
https://youtu.be/48f3N0hCaBU?t=109
If this is not currently possible, is it possible to implement as extension?

This is being added in v1.44. See https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_44.md#navigate-from-files-into-symbols
You can now continue to navigate into symbols of a file result simply
by typing #. For the file that is currently selected, all symbols will
appear and the editor will open in the background to reveal the active
symbol.

I created an extension that provide similar functionality:
https://marketplace.visualstudio.com/items?itemName=Cmacu.gotoanything

Related

VS Code - search for two different things in two files

In VS Code how do I search for one thing in one file, while at the same time searching for a different thing in a different file?
Using the normal Find when I try to search for something in a second file it overwrites any find I am doing in a previous file.
I see that the Search functionality enables me to open a search in an editor, but this functionality doesn't seem at all useful to me.
There is no obvious way to run a search on a specific file short of manually copy/pasting the file path into the advanced search options.
The editor that the search results open in contains adjacent context lines, which if you have a large number of results makes it useless as a simple list of search hits.
The editor that the search results open in is not editable, making it useless as an editor.
I need a list of results for each of two searches on two files.
Item 1 can be handled with an extension I wrote: Find and Transform. You could make a keybinding that opens the Search Panel with the current filename (or any file/folder/etc.) added to the files to include input. Actually I added a context menu command to the editor, or any editor tab or an editor in the Explorer to do just this.
Item 2. The search editor number of context lines is configurable and will remember your last setting.
Item 3. There is an extension, Search Editor: Apply Changes which can apply any changes you make in a search editor to those files.

Zoom/focus on a region/part of file in vscode?

Let's say I have a giant markdown file and want to edit one section, or a giant python file and want to edit one function. Is there any way to bring out that region of the file into a separate editor?
Desiderata:
Find (⌘F) and "add selection to next find match" (⌘D) should only go over focused contents.
Changes should appear in original file in the filesystem for version control purposes.
No text outside of focused section is visible anywhere.
Bad solutions:
'Fold all & unfold one' works ok in markdown, but e.g. if there is section text at a parent section, then there is no way to hide it. And ⌘F goes outside of it.
A temp file clutters the git logs if I commit as I go.
Extension keywords (no results):
File window
File region
Zoom to part of file
(Iterm2 has a feature like this for focusing on the last command output.)
It seems there is no good solution as of May 2021.

is there any eclipse plugin available for writing a memo on any line of code?

Doe anybody know of an eclipse plugin, which can be used to insert short text (in the form of memo) to remember what that line of code does or a block of code does to help me understand the existing code better and i can also refer it back later on.
Just like "Task" can be added on a line of code, although i can use "tasks" for this purpose, but that is not very convenient and intuitive.
If you want to add a short text to "remember what that line of code does or a block of code does to help me understand the existing code better", use comments. That's what they're for, and practically every formal language in the world has them.
If you want the ability to quickly jump to an arbitrary point in the code, using bookmarks is a convenient option - right click the bar immediately left of the text and choose to add a bookmark. You can then easily jump between bookmarks with the "bookmark view", which you can enable from the Window -> Show View menu.
The closest thing I can think of is bookmark support. There is native bookmark support in Eclipse and also several other vendors supply more function.
I'm assuming that there's a very good reason that you don't want to or can't modify the code.

What is the best way to insert source code examples into a Microsoft Word document?

I have to write some documents that will include source code examples. Some of the examples will be written from the IDE, and others would be written in place. My examples are primarily in Java.
As someone who is used to LaTeX, doing this in Word is extremely painful. However, I am bound to Word for this. The only options I have seen are:
Write or copy into the document,
then use a fixed type font, arrange
formatting and hope that Word didn't
uppercase stuff for you. Needless to
say, this looks like crap.
Copy and paste screenshots of source
code from the IDE. At least I keep
colors. However, if I change my font
size, I'm screwed. I'm also screwed
across page boundaries. And let's
admit it, Word is not great at
managing multiple images on a
document.
Write HTML (not really an option
here)
Is there some better (and ideally portable) way to do this? Is there at least some sort of verbatim style similar to the LaTeX environment? Is there at least some pretty printer that I could copy-and-paste as RTF?
I absolutely hate and despise working for free for Microsoft, given how after all those billions of dollars they STILL do not to have proper guides about stuff like this with screenshots on their damn website.
Anyways, here is a quick guide in Word 2010, using Notepad++ for syntax coloring, and a TextBox which can be captioned:
Choose Insert / Text Box / Simple Text Box
A default text box is inserted
Switch to NPP, choose the language for syntax coloring of your code, go to Plugins / NPPExport / Copy RTF to clipboard
Switch back to word, and paste into the text box - it may be too small ...
... so you may have to change its size
Having selected the text box, right-click on it, then choose Insert Caption ...
In the Caption menu, if you don't have one already, click New Label, and set the new label to "Code", click OK ...
... then in the Caption dialog, switch the label to Code, and hit OK
Finally, type your caption in the newly created caption box
I recently came across this post and found some useful hints. However, I ended up using an entirely different approach which suited my needs. I am sharing the approach and my reasoning of why I chose this approach. The post is longer than I would have liked, but I believe screenshots are always helpful. Hopefully, the answer would be useful to someone.
My requirements were the following:
Add code snippets to a word document, with syntax highlighting for easier visibility and differentiation of code and other text.
Code snippet shall be inline with other text.
Code snippet shall break across pages smoothly without any extra effort.
Code snippet shall have a nice border.
Code snippet shall have spell-check disabled.
My Approach is as listed below:
Use external tool to achieve syntax highlighting requirement 1 above.
One could use notepad plus plus as described above. However, I use the tool present here - https://syntax-highlighter.k26.ch/. This gives me the option to use line number, as well as very nice syntax highlighting (Please use Google Chrome for this step, because syntax highlight is not copied when using Mozilla Firefox, as also pointed out by couple of user comments). Steps to achieve syntax highlighting are listed below:
Open the website provided above in chrome and Copy the code snippet in the text area. I will be using a sample XML to demonstrate this (XML sample from here - http://www.service-architecture.com/articles/object-oriented-databases/xml_file_for_complex_data.html).
Select the language from drop down menu.
Click "Show Highlighted" button. It will open a new tab, with syntax-highlighted code snippet, in this case the XML sample we chose. See image below for example.
To Turn off the line numbers, inspect the page in chrome. Then, under styles, deselect the "margin" property in ".dp-highlighter ol", as shown in the image below. If you want to keep the line numbers, go to next step.
Select the syntax-highlighted code and click copy. Now your code is ready to be pasted into Microsoft word.
Thanks to this blog for providing this information - http://idratherbewriting.com/2013/04/04/adding-syntax-highlighting-to-code-examples-online-and-in-microsoft-word/.
2. To achieve requirements 2, 3 and 4 above, use table in Microsoft word, to insert the code snippet. Steps are listed below:
Insert a table with single column.
Paste the copied text from step 1. in the table column. I have kept the line numbers to show how well this works with Microsoft word.
Apply border, as you like. I have used size 1pt. Resulting Microsoft word snippet will appear as shown in screenshot below. Note how nicely it breaks across the page - NO extra effort needed to manage this, which you would face if inserting "OpenDocument Text" object or if using "Simple TextBox".
To achieve requirement 5, follow the steps below:
Select the entire table or the text.
Go to Review tab. Under Language, choose "Proofing Language". A new pop-up will be presented.
Select "Do not check spelling or grammar". Then, click OK.
Resulting text has spell-check disabled. Final result is shown in the image below and meets all the requirements.
Please provide if you have any feedback or improvements or run into any issues with the approach.
You need to define a style in your Word document and use that for source code. I usually have a style called "Code" which has a monospaced font in a small point size, fixed size tabs, single line spacing, no before/after paragraph spacing, etc. You only need to define this style once and then reuse it. You paste in your source code and apply the "Code" style to it.
Note that some editors (e.g. Xcode on the Mac) add RTF as well as text to the clipboard when copying/pasting between applications - Word recognises RTF and helpfully retains the formatting, syntax colouring, etc.
Source code in Xcode:
Copied and pasted to Word:
(Note: it's a good idea to disable spell-checking in your "Code" style in Word.)
It kind of depends on the IDE. Both Visual Studio and Eclipse, for example, will allow you to copy as RTF and paste into Word, keeping all your formatting.
Notepad++ has a plugin called "NppExport" (comes pre-installed) that allows you to copy to RTF, though I don't care much for Notepad++'s syntax highlighting (it'd definitely be passable though). What it does do is support dozens of languages, whereas the aforementioned IDEs are limited to a handful each (without other plug-ins).
Use this - http://hilite.me/
hilite.me converts your code snippets into pretty-printed HTML format, easily embeddable into blog posts, emails and websites.
How:
Just copy the source code to the left pane, select the language and the color scheme, and click "Highlight!". The HTML from the right pane can now be pasted to your blog or email, no external CSS or Javascript files are required.
For Microsoft Word document: Copy the the content from the Preview section and paste to your Microsoft Word document.
3 sections : Source Code , HTML and Preview
These answers look outdated and quite tedious compared to the web add-in solution; which is available for products since Office 2013.
I'm using Easy Code Formatter, which allows you to codify the text in-place. It also gives you line-numbering options, highlighting, different styles and the styles are open sourced here: https://github.com/armhil/easy-code-formatter-styles so you could extend the styling yourself. To install - open Microsoft Word, go to Insert Tab / click "Get Add-ins" and search for "Easy Code Formatter"
This is related to this answer: https://stackoverflow.com/a/2653406/931265
Creating an object solved all of my problems.
Insert > Object > Opendocument Text
This will open a document window, paste your text, format it how you want, and close it.
The result is a figure. Right click the object, and select 'add a caption'.
You can now make cross references, create a table of figures.
If you are still looking for an simple way to add code snippets.
you can easily go to [Insert] > [Object] > [Opendocument Text] > paste your code > Save and Close.
You could also put this into a macro and add it to your easy access bar.
notes:
This will only take up to one page of code.
Your Code will not be autocorrected.
You can only interact with it by double-clicking it.
On a Mac I find this solution with vim to be wonderful:
https://github.com/zerowidth/vim-copy-as-rtf
There is an easy way if you want simple code formatting.
Open word> Insert tab> click on "Get Add-ins"
search for "Content mixer"
3.click on "Add"
Then content mixer add will open automatically and you can copy paste your code in there and click on "Insert" to insert it in word doc.
You can use Open Xml Sdk for this. If you have the code in html with color and formatting. You can use altchunks to add it to the word documents.
Refer this post Add HTML String to OpenXML (*.docx) Document
Hope this helps!
This is what i did.
End results :
https://stackoverflow.com/a/25092977/1161594
You can using Plugin Syntax Highlight in Ms.Word https://store.office.com/syntax-highlighter-WA104315019.aspx?assetid=WA104315019 . i follow that step and it's work
In Word, it is possible to paste code that uses color to differentiate comments from code using "Paste Keep Source Formatting." However, if you use the pasted code to create a new style, Word automatically strips the color coded text and changes them to be black (or whatever the auto default color is). Since applying a style is the best way to ensure compliance with document format requirements, Word is not very useful for documenting software programs. Unfortunately, I don't recall Open Office being any better.
The best work-around is to use the default simple text box.
I have tried all your methods, but they didn't work for me, in fact I have created an easier method using MS Word Tables.
Pros:
More beautiful
Easier to manage & more consistent
Are less prone to problems
No need for external plugins or MS Word micro coding.
Easier to handle by simple users (such as myself).
Cons:
It will not maintain code colouring although someone could improve my trick.
Steps:
Insert a 3x3 table, in my case I always make the total width of the table equals the free page's width (3 rows minimum to test the tables style).
Use invisible borders ("No Borders" option), and activate "View Gridlines" option. it should have this aspect.
Be ware that those lines are for you to see the table's grid, and the will not be printed.
Make the adjustments to cells' spacing and columns' width to get the aspect you like. (You will have to get in "Table Properties" for fine tuning).
Create a "Paragraph Style" with the name of "Code" just for your code snippets (check https://stackoverflow.com/a/25092977/8533804 to get the idea, you don't have to follow all of it)
Create another "Paragraph Style" with the name of "Code_numberline" that will be based upon the previous created style.
In the newly created "Code_numberline" add the numbering style that you like (this will automate line numbering).
Apply "Code_numberline" to the first column, and "Code" to the 3 column.
Add a fill in the middle column.
Save that table style and enjoy!
So I've found the majority of answers on this question to either be only semi-functional or broken entirely (eg the website used is down). This solution is entirely self-contained in Word, works across multiple pages, and keeps your syntax highlighting.
Here's the steps:
Temporarily set your IDE's theme to a light one, so that the text will fit in with the rest of your document.
Copy the required code (HTML colourising info will be copied with it).
In Word, hit Ctrl+Alt+V and choose HTML Format to paste the coloured text.
Select all your text and then expand the styles gallery on the home tab of the ribbon.
Choose "Create a style". Use a name such as "Code"
Right click your new style in the gallery and choose "Modify".
Under the formatting section, change the font to Consolas or your choice of monospace font. Also set the line spacing to Condensed (this option is next to the text alignment options).
Under the format button in the bottom left, choose "Language", then enable the "Don't check spelling or grammar" option.
If you want this style to be available in future documents, change to the "New documents based on this template" radio button.
Optional: for line numbers...
Back in the Modify Style dialogue, choose the format button again and choose "Numbering".
Choose the "Define new number format" option.
Remove the dot after the number '1' in the number format box.
Choose "Right" as the number alignment.
Hit ok, then select your new number alignment option. Finally, hit ok on the Modify Style dialog.
Finally, select your code, and set it to be the Code style, which should apply all the required formatting.

Useful Eclipse features? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I have been using Eclipse as an IDE for a short amount of time (about 3 months of full use) and almost every day I learn about some shortcut or feature that I had absolutely no idea about. For instance, just today I learned that Ctrl+3 was the shortcut for a Quick Access window.
I was wondering what your most useful/favorite Eclipse features are. With the IDE being so big, it would be helpful to learn about the more commonly used parts of the program.
My most commonly used features are
ctrl+1 quick-fix / spell-checker
opening files
ctrl+shift+t load class file by classname
ctrl+shift+r load any file by filename
matches are made on the start of the class/filename. start your search pattern with a * to search anywhere within the filename/classname.
Formatting
ctrl+shift+f Format source file
(set up your formatting style in Window | preferences | java | code style | formatter)
ctrl+shift+o Organise imports
Generated code
alt+s,r to generate getters and setters
alt+s,v to insert method signatures for overidden methods from superclass or interface
Refactorings
alt+shift+l Extract text-selection as local variable (really handy in that it determines and inserts the type for you.
alt+shift+m Extract text-selection as a method
alt+shift+i inline selected method
Running and debugging.
alt+shift+x is a really handy prefix to run stuff in your current file.
alt+shift+x, t run unit tests in current file
alt+shift+x, j run main in current file
alt+shift+x, r run on server
There are more. The options are shown to you in the lower-right popup after hitting alt+shift+x.
alt+shift+x can be switched for alt+shift+d in all the above examples to run in the debugger.
Validation
As of the recent Ganymede release, you can now switch of validation in specified files and folders. I've been waiting for this feature for ages.
Go to Project | Properties | Validation
click on the ... button in the settings column of the validator you want to shut up
Add a rule to the exclude group
code navigation
hold down ctrl to make all variables, methods and classnames hyperlinks to their definitions.
alt+left to navigate back to where you clicked ctrl
alt+right to go "forwards" again
This is cool: If someone has emailed you a stack trace, you can copy and paste the stack trace into Eclipse's Console window. You can then click on class names in the stack trace as if your own code had generated it.
In terms of actual features, rather than shortcuts, I strongly recommend taking a look at Mylyn.
It essentially skins Eclipse with a task focussed view. It tracks the files you touch when working on a task, and focusses many aspects of the UI onto the resources that it decides are relevant to the job in hand. Eclipse can be somewhat busy to look at, especially with a big multi module project, and Mylyn helps cut through the cruft. The connectivity to issue tracking software and source control repositories is also excellent.
In my experience, it polarises opinion amongst those who try working with it, which is probably a sign that it is offering something interesting... Don't mean to sound like a fanboy - it is definitely worth a look though.
A shortcut that I use everyday is Ctrl+K. In your editor (not only Java file), simply select a text (like a variable, a function, etc.), and then use this shortcut to go to the next occurrence of this text in the current editor.
It's faster than using the Ctrl+F shortcut...
Note also that you can use Ctrl+Shift+K to search backwards.
Ctrl-Alt (up/down) Copy selected line(s) above or below current line.
Alt (up/down) Move current (or multiple selected) lines up or down
Ctrl-Shift-R Bring up the resource window, start typing to find class/resource
Ctrl-O Bring up all methods and fields for the current class. Hitting it again will bring up all methods and fields for current class and super classes.
Ctrl-/ or Ctrl-Alt-C Comment single or multiple lines with //
Ctrl-Shift-/ Comment selected lines with /* */
Ctrl-. Take you to the next error or warning line
CTRL+PAGE DOWN / CTRL+PAGE UP to switch between opened editors
CTRL+E to also switch between opened editors (allows to type the name)
CTRL+O is extremely important for me. You don't longer need the Outline View then (you can close it which will give you more space). Then, you can type a method name or just the beginning of it and you quickly can get to it. I also use it to inspect what stuff is available. For example: CTRL+O and then type get ... now I see all getters.
F3 while an element is selected in the code: brings you to its definition or it's source. e.g. used on a method call it brings you into the source code of that method.
CTRL+M to maximize the current window
As already said, CTRL+3 is extremely good. It basically allows you to use Eclipse completely without a mouse. Just type CTRL+3 and then package explorer for example.
CTRL+F8 cycle trough perspectives
CTRL+L allows to type a line number and brings you directly to that line.
CTRL+SHIFT+G searches for all references to the selected element in the workspace.
And not a shortcut: In the project settings under Java Editor you can find Save Actions. This allows you to set up the project so that the code is automatically cleaned up and formatted when you save a file. That's very good it safes you from constantly pressing CTRL+O and CTRL+F.
Eclipse auto refresh isn't on by default so if you make changes to a file outside of eclipse, the change won't be reflected in your build. this is very annoying if you just did an svn/git update/rebase and things aren't working the way they're supposed to.
Turn it on in windows->preferences->workspace and tick Refresh Automatically.
Local History
It's a great feature. Eclipse has its own mini-CVS for all files in a project. If you want to revert some change you made, or even restore deleted file - you can right click on the project and select "Restore from Local History".
Just saved my ass *tears of joy*
CTRL+Shift+P to jump to the matching bracket/parenthesis.
One key feature: Shift+Alt+T for the refactoring menu.
Ctrl-shift-T, but only type the initial characters (and even a few
more) of the class you're looking
for. For example, you can type
"NetLi" to find NetworkListener
In the Search window, Ctrl-. takes you to the first leaf of a tree branch
Alt-/ is Word Completion. Slightly different from Ctrl-space
CTRL+SHIFT+X selected text becomes UPPERCASE
CTRL+SHIFT+Y selected text becomes lowercase
I'd like to add two additional shortcuts:
CTRL+F6 Switch between open editors (CTRL+SHIFT+F6 to scroll through the list in the opposite direction)
CTRL+F11 start program in debug mode
F11 start program in normal mode
A lot of the key bindings depend on the perspective and view currently active.
My most used ones for the Java perspective:
ctrl-shift-r open resource
ctrl-shift-t open type
ctrl-1 quick fix/refactor
ctrl-j incremental search
ctrl-h search in files (select a base directory and set scope to selected resources)
ctrl-o list methods
ctrl-alt-h open call hierarchy
ctrl-shift-l list shortcut keys
hit ctrl-shift-l again to go directly to preferences to change key mappings
I am also a fan of Eclipse, however since I spend a majority of my time in Visual Studio, I will suggest that you read Eric Sink's series of articles "C# to Java" (parts 1-4). Not only is Eric always an entertaining read, but this brief series covers some awesome Eclipse insight for those who have not been into Eclipse or have been away from it for a while:
From C# to Java: Part 1
From C# to Java: Part 2
From C# to Java: Part 3
From C# to Java: Part 4
Ctrl-Shift-M while the cursor is on a class name in your java file, will specifically add that and only that class to your imports. This is different from Ctrl-Shift-O which will not only add those imports not already defined, but will also remove imports not currently needed, something you might not necessarily want to do.
I forgot about [Ctrl+2 -> r] scope variable rename. Place the cursor in the variable you wish to rename, press Ctrl+2, then r, then type the new name watching all instances of that variable get renamed at the same time.
It's awesome at refactoring Hungarian Notation.
alt-shift-a is extremely useful in a few situations.
I use a lot of the above and also like for quick search: CTRL+J then type what I am looking for, then CTRL+K for next occurrence.
Lately I've been using the MouseFeeds plugin to automatically tell me what the key stroke combinations are. That way by repetition I remember them better.
This link has a better picture and description of what it looks like and does.
Shift+Alt+b for the simple navigation row over the editor.
I've just released this blog post about Top 5 Useful Hidden Eclipse Features. It contains:
Favorites: Types and members that will always show up in auto-completion
The awesome block selection mode: For multi-line editing
The EGit staging view: Much better than git itself
Type filters: To remove awt and java.lang.Object stuff from auto-completion
Formatter tags: To delimit code sections that shouldn't be auto-formatted
Alt+left and Alt+ right will navigate you forward and back.
I find the project-specific settings useful in Eclipse 3.3.
For example, if you have several developers working on a project who have different code styles for curly braces, line spacing, number of imports etc. then you can specify the style settings for the project. Then you can configure the save actions so that the code is automatically formatted when a file is saved. The result is everyone's code is formatted the same before it's checked in.