VSCode inserts space after comment sequence - visual-studio-code

Whenever VSCode formats code, for almost all languages, it will insert spaces after the comment escape sequence (//, #, et cetera).
Although this does not work for C code, I assume that this might be some kind of global setting.
Is it possible to disable the insertion of this extra space somewhere? I follow a style where I don't use the extra spaces after "code-only" comments.
Any (lightweight) extensions that do this (or similar)? Should I make my own...?
I'd like for this solution to work for all languages, although Java is what I use the most.
I tried searching for some extensions related to comments, but it seems that there are none doing this. Is a linter what I need..?
Sorry and thank you in advance!

VS Code doesn't have a default formatter that works across every language so, there is no global solution for you. You will have to check, for every language you noticed such behavior, if the formatter is built in or not, and look for settings individually.
You commented about using Java, and VS Code Java support doesn't provides a formatter, so I suppose you have some Java extension installed, maybe from RedHat. If that's the case, I've noticed (based on extension's Readme) that It has a Java: Open Java Formatter Settings command, which says opens the Eclipse formatter settings. Creates a new settings file if none exists. It's been a long time I don't use Eclipse, so I'm not sure how its settings works, and if it does support the format rule you want. But I suggest you to take a look.
Hope this helps

There is a setting that should affect all languages:
Editor > Comments: Insert Space
It is enabled by default, uncheck it.

It seems that setting java.format.comments.enabled to false was somewhat helpful:
java.format.comments.enabled setting in VSCode
However, it disables formatting for all comments, even JavaDoc ones.

Related

Disable IDE auto format command

I have a code base that many developers work on. Some people blindly use auto format in their IDE and mess up the formatting of sql statements or other things. It appears that some IDE's like eclipse do have the ability to use //#Formatter:off (which I have put around many things I do want to not get formatted), but by default these are ignored. Thus, is there a way to either enable the setting so that will be used by default, or is there a way to disable any shortcut key linked to auto format using some sort of maven plugin? Basically I am looking for a way to enforce this for anyone who is working on the codebase since everyone can change their own formatter settings.
I found https://code.revelc.net/formatter-maven-plugin/format-mojo.html, but I dont think it can do either of those things.
Thanks in advance!

WebStorm formatting settings - port to another editor

Is there any way to get another editor, like VSCode, to format code ( JavaScript in my case, if it matters ) like the WebStorm IDE formats code by default? I'm not familiar with that IDE, but I'm hoping that it uses a config of some sort that can maybe be exported and imported in another editor. I tried looking for one, but couldn't find anything.
The core problem, if it matters, is that all of our team members use WS to write code and they use the built in formatter, so if I use another one it creates inconsistencies and long commits when editing already written files. As you are probably guessing by now, I would like to use another editor, because I find IDE's bloated and slow.
I don't know if there is a way to import Webstorm formatting rules into VS Code, but I think there is another solution:
I remember in one of the projects i worked on, we used a linter which also auto-formatted code. The advantage is that Webstorm and VSCode can pick pick the linter rules automatically, and then you have same formatting on both.
The downside is that you would need to agree with the team on what does rule will be and then configure them on the linter.

Eclipse equivalent of CTRL-K in Netbeans

Netbeans has a nifty shortcut completion, I use while I type. It works in comments, in strings. Pretty much places where regular completion is useless. It basically autocompletes using the editor scope (in other words, whatever word matches closes to the point you are typing). Is there something similar in Eclipse ? I am making a transition due to lack of mybatis/mylyn support in netbeans. You can read more about it here https://blogs.oracle.com/chengfang/entry/why_am_i_using_netbeans .
It's called Word Completion. The key binding may vary; Ctrl/Cmd+Shift+L to find out.
CTRL+Space will show and sometimes autocomplete (depends on the settings you choose) methods names, variables and etc.
You can read more about specific settings and further fine tuning here.

how to switch/control syntax highlighting in eclipse flexibly?

I have a file with extension .xml.
But it doesn't necessarily contain XML. It may also contain HTML and JavaScript. Now I would like to either have Eclipse decide inteligently/heuristically which syntax highlighting would be appropriate or to switch it myself.
Any ideas?
Eclipse associates files with an editor. You can let eclipse decide which editor to use (e.g. defaults per file extension) or select the editor by yourself. I guess you might already know that or have at least experienced it.
Syntax highlighting isn't always set seperately but instead part of some editor (together with stuff like keyboard shortcuts). So what you are going to need is an editor that behaves the way you want it to. I do not know if there is an editor like this available but one options is writing an eclipse plug-in and implementing such an editor.
Fortunately there are great editors for each of XML, javascript, HTML, etc that are all open source. I guess you might be able to use some of their code. Ideally as a client of their API / Objects or if it won't work out just by reusing code.
short answer: not possible. use PHPStorm instead :)

How to Make Eclipse More Like Emacs

I am very familiar with emacs--and I realize that there is nothing that it cannot do--but there are some things that it does not do well or efficiently. So, being between projects I am open to the idea of switching to a full-featured IDE such as Eclipse.
With muscle-memory being what it is, I would like to make Eclipse as emacs-like as possible. I have already discovered the excellent Emacs+ plugin which gets me about halfway there. However, I am still missing the following features of emacs which I routinely rely upon:
shell: It's not just a shell, it's also a buffer.
occur: Search->File... is close to what I want, but I just want it to search the current file--which might be a text file, a logfile, or a shell buffer, or whatever.
align-regexp: This awesome little command in emacs helps me make files more readable, and alignment helps with keyboard macros.
What plugins would you recommend to solve these issues? Are there any other emacs features you miss in Eclipse or plugins you would recommend?
Please, no emacs/vi zealots asking why on Earth I would do such a thing.
For the shell you have WickedShell
Ctrl+F is enough to trigger a Search within the current file. (does not create a new buffer with matched lines)
Only Mark Occurrences is about highlighting occurrences, but that is not as advanced as the Emacs function.
Formatter options can emulate "align-regex" function, as described here.
Preferences -> Java -> Code Style -> Formatter.
Click 'Edit' on the profile (you may need to make a new one since you can't edit the default).
In the indentation section select 'Align fields with columns'.
Then, in your code Ctrl+Shift+F will run that formatter.
I can confirm Brian's suggestion (Emacs key-bindings). What I do to resolve this dilemma is to use both Emacs and Eclipse simultaneously. They are both very good at reporting external changes to files so there is minimal chance of tromping on edits (but it can happen). More to the point, you can leverage the strengths of both tools without having to give up either one. The combination of using both tools and Eclipse having Emacs key-bindings makes this quite satisfactory for me.
IIRC (It's been a while since I've used eclipse) eclipse has a "use Emacs key-bindings" mode. I believe that there's also the option to tell eclipse to use emacs as its own editor...