I'm using nerdcommenter alongside neovim, and every time I comment out a block of code with <leader>cc, the code isn't really spaced out:
fn main() {
//println!("Hello, world!");
}
I want to get an output of something like this:
fn main() {
// println!("Hello, world!");
}
Is there a command or configuration that I'm missing out on? (I haven't configured nerdcommenter at all in my vimrc)
See the plugin docs : use g:NERDSpaceDelims configuration option
" Add spaces after comment delimiters by default
let g:NERDSpaceDelims = 1
Or for Neovim with Lua configuration :
vim.g.NERDSpaceDelims = 1
Related
I like using the Toggle Block Comment command (editor.action.blockComment) with its default keybinding, but I don't like the fact that it only makes block comments that look like this
/*
I don't like this
*/
I want something more like this
/**
* Oh yeah...
**/
Is there a way to edit what the Toggle Block Comment command (editor.action.blockComment) does?
You can make your own custom extension to achieve this. Here is the code:
let selectedText = activeEditor.document.getText(activeEditor.selection);
selectedText = selectedText.replace(/^/gm, "* ");
selectedText = '/** \n' + selectedText + '\n**/';
activeEditor.edit((edittedText) => {
edittedText.replace(activeEditor.selection, selectedText);
})
I am also working on an extension where you will find exactly this. I will update the name once it hits the marketplace.
I'm running a flutter application in VSCode and want to print to console using this code:
stdout.write('Text');
But the console doesn't show anything after executing this line. Why is that?
(print statements work as expected).
EDIT:
the print function works fine. I just wanted to print something inside a for loop without a newline, that's why I was trying to use stdout.writeln. I ended up building the string I wanted to print in the for loop and printing it only once with the print function.
I had the same problem, "solved" it using StringBuffer and one final print:
final StringBuffer buffer = StringBuffer();
for (var i = 0; i < 100; i++) {
buffer.write('$i, ');
}
print(buffer.toString());
Just use print("Hello console"); =D
I had the same problem myself.
Unfortunately I can't tell you the reason why stdout doesn't work on terminal logs but I can tell you that you can see them using Dart DevTools on the part of Logging
Same here. In my case this code
import 'dart:io';
void main() {
for (int i = 0; i <= 10; i = i + 2) {
stdout.write('$i ');
}
}
Do not show this output in VS Code console.
0 2 4 8 10
It does in other IDEs so I guess it's VS Code problem.
Visual Studio Code Does Not Comment-out Empty Lines
I've searched everywhere for a solution to this issue but couldn't find anything, and it's been bugging me for months now.
Basically what happens is that VS Code ignores empty lines when you tell it to comment out multiple lines of code.
So for example, let's say I highlighted all the code below and told VS Code to comment it out:
package com.mycompany.app;
public class MyApp {
public static void main(String[] args) {
SayHello();
}
static void SayHello() {
System.out.println("Hello!");
}
}
What I expected to get:
// package com.mycompany.app;
//
// public class MyApp {
// public static void main(String[] args) {
// SayHello();
// }
//
// static void SayHello() {
// System.out.println("Hello!");
// }
// }
What I got instead:
// package com.mycompany.app;
// public class MyApp {
// public static void main(String[] args) {
// SayHello();
// }
// static void SayHello() {
// System.out.println("Hello!");
// }
// }
I've only experienced this with Java and Golang so far, but I assume this happens for all other languages inside VS Code too.
The reason I want my comments to stay connected to each other is so I know which lines I commented out together in case I need to uncomment them back.
I am also aware of the Shift + Alt + A shortcut, but that typically uses Block Comments (which I don't like using), and I only want Line Comments.
Is there a setting I'm missing? Because I tried searching within VS Code and couldn't find anything either.
Any help would be greatly appreciated.
An option to have empty lines commented out is coming to v1.48. See https://github.com/microsoft/vscode-docs/blob/vnext/release-notes/v1_48.md#thank-you and https://github.com/microsoft/vscode/pull/93160
New setting:
Editor > Comments: Ignore Empty Lines default is true (will ignore)
[editor.comments.includeEmptyLines]
In Insiders' Build already v1.48.
A new VS Code setting has been added that resolves this issue:
"editor.comments.ignoreEmptyLines": false
Unfortunately, it is only tagged as "insiders-released" despite being included in Stable versions of VS Code.
Hopefully, this issue gets addressed in future versions.
Multi-line Editing seems to be the only alternative solution so far.
Press and hold the Alt key and press either Up or Down so your cursor expands to multiple lines. Then just add // manually.
It isn't very intuitive, but it works. Hopefully, the VS Code team will address this issue someday.
UPDATE: This feature has now been added to the VS Code backlog! (https://github.com/microsoft/vscode/issues/88480)
In a normal buffer of nvim, the following ex command works.
:normal! GAabcd
This adds the text "abcd" to the current normal buffer.
But in a terminal buffer of nvim, the above ex command doesn't work!
:normal! GAabcd
This just converts the terminal buffer into '-- TERMINAL --' mode and the "abcd" isn't added!
Why isn't the text added? How can I accomplish that?
I digged the neovim sources and maybe found the answer by myself.
In edit funtion of edit.c, there is the following comment.
bool edit(int cmdchar, bool startln, long count)
{
if (curbuf->terminal) {
if (ex_normal_busy) {
// Do not enter terminal mode from ex_normal(), which would cause havoc
// (such as terminal-mode recursiveness). Instead set a flag to force-set
// the value of `restart_edit` before `ex_normal` returns.
restart_edit = 'i';
force_restart_edit = true;
} else {
terminal_enter();
}
return false;
}
...
I think it means that it's not possible to enter terminal mode(insert mode) while processing normal commands in ex-mode. Therefore the text 'abcd' wasn't added in terminal mode but was just processed as normal commands.
Your answer is correct in that it's not possible to append text using :normal! GAfoo. However, in the interests of answering your last question, you can do this:
:normal! "0p
So if you happen to have what you need in a register, you can always paste it.
EDIT: It is Beautify that is adding the new lines. Not sure which rule though.
Is there a way to stop parameter lists and import lists from adding new lines per each list item when formatting code with?
E.g stop this:
function view(state$) {
return state$.map(({weight,height,bmi}) =>
div([
renderWeightSlider(weight),
renderHeightSlider(height),
h2('BMI is ' + bmi)
])
);
}
from becoming this:
function view(state$) {
return state$.map(({
weight,
height,
bmi
}) =>
div([
renderWeightSlider(weight),
renderHeightSlider(height),
h2('BMI is ' + bmi)
])
);
}
When right-clicking and selecting "format document"?
It also does it with imports like so:
import {
makeDOMDriver,
h1,
a
} from '#cycle/dom';
However it is unwanted.
create or edit .jsbeautifyrc file in your root from you vscode project and put in to the file this json property
{
"brace_style": "collapse,preserve-inline"
}
this will also prevent to format all JavaScript object
Include "brace_style": "collapse,preserve-inline" as Yitzchak said inside the .json settings file located here:
C:\Users\***\AppData\Roaming\Code\User\settings.json
2021 Update for Eze_82's answer:
Instead of just "brace_style": "collapse,preserve-inline", you now need to include the following in the settings.json file of VSCode:
"beautify.config": {
"brace_style": "collapse,preserve-inline"
}
The location of the settings.json is still the same.