VIM wrap block in curly braces (CSS code) - vim

kind of new to VIM so be kind please.
I want to do the following:
.css-class {
some: 'rule';
}
to:
.another-class {
.css-class {
some: 'rule';
}
}
I tried surround.vim with S{ in visual mode with the block selected. But this ends up here:
{ .css-class {
some: 'rule';
} }
which doesn't really help much. If it would add the line breaks it would help but still... What would be the best way to do it?

Use Visual-line mode, V, instead of v.
VipSB.another-class
You can also use the yS operator if you do not want to use visual mode:
ySipBi.another-class

Related

What's the best way to write a custom format! macro?

I'm trying to create a custom crash! macro that essentially just wraps eprintln!, but it could be any other format!-like macro. It currently looks like this.
macro_rules! crash {
($fmt_str:literal, $($args:expr),*) => {{
eprintln!($fmt_str, $args);
std::process::exit(1);
}};
}
I can't use $args directly as it's still repeating, so I need some way to break it apart, but I'm not sure how to do that.
While your solution work, the best way to forward macro arguments is to capture them as tt. In your case, since all you want is to forward them, you can use $($t:tt)*:
macro_rules! crash {
($($t:tt)*) => {{
eprintln!($($t)*);
std::process::exit(1);
}};
}
This has the advantage that it is completely transparent and enables everything the underlying macro enables. For instance, in this case, the tt version supports early-expanded format string, while your original version does not (playground):
// crash!(concat!("a", "b")); // Does not compile
crash_tt!(concat!("a", "b"));
Turns out I was just having a mental blank, and ended up answering my own question. I just needed to expand $args... Just for anyone else who ends up here, the solution looks like this:
macro_rules! crash {
($fmt_str:literal) => {{
eprintln!($fmt_str);
std::process::exit(1);
}};
($fmt_str:literal, $($args:expr),*) => {{
eprintln!($fmt_str, $($args),*);
std::process::exit(1);
}};
}

How to keep empty line in Dart code inside curly braсets?

How to keep empty line in dart code inside curly braсets? By default, Android studio automaticaly removes them. How to change that?
Don't fight the formatter. It will win.
The way to avoid a { and } being collapsed is to have something between them.
I'd recommend something like:
Future<void> displayRangePicker(BuildContext context) async {
// Intentionally left empty.
}
or even just:
Future<void> displayRangePicker(BuildContext context) async {
return;
}
(which is equivalent to what you wrote, just being explicit about the return).

How can I turn off specific messages in syntastic (vim)?

I'm trying to turn off some of the messages in syntastic.
For example, SC20148 in bash files (it complains there's no shebang).
After looking through the documentation, it seemed that perhaps this might be done through:
let g:synstatic_quiet_messages = {
\ 'type': 'syntax',
\ 'regex': 'SC20148' }
However this doesn't seem to work. How do I turn off specific messages?
The Devil is in the details:
the variable is actually called g:syntastic_quiet_messages
the error is actually SC2148
you probably don't want to disable syntax messages.
Thus:
let g:syntastic_quiet_messages = { 'regex': 'SC2148' }
Or just:
let g:syntastic_sh_shellcheck_args = '-e SC2148'
Turn off multiple kinds of warnings in syntastic in vim:
Add this line to your .vimrc
let g:syntastic_quiet_messages = { 'regex': 'SC2148\|SC1234\|SC6789' }
Also you can do it against the message itself like this:
let g:syntastic_quiet_messages = { "regex": 'superfluous-parens\|too-many-instance-attributes\|too-few-public-methods' }
Agree with accepted answer, but wished to add some extra context.
You can run :h syntastic_quiet_messages to get the official docs with explanation of the commands.
You can use syntastic_quiet_messages or, if you have a particular filetype and checker, then use syntastic_<filetype>_<checker>_quiet_messages.
Here is a snippet from my .vimrc:
" keep some globals quiet
let g:syntastic_javascript_standard_quiet_messages = { 'regex': ['alert',
\ 'localStorage',
\ 'auth0js',
\ 'auth0'] }
Above, I am keeping global errors quiet, and use an array to list more than one item. Only wish to apply this to javascript files, using the standard style lint checker.

Is there a vim command to move the cursor to the parent bracket?

Is there a vim command to move the cursor to the parent bracket?
I have a configuration file like this one, and I want to go straight to the parent bracket. Is there a simple movement command to do this, or is there a way to combine commands to do what I want?
PARENT{ // I want to move my cursor here
CHILD { stuff... }
CHILD { stuff... }
CHILD { stuff... }
...
CHILD { stuff... } // my cursor is on this line
CHILD { GRANDCHILD { more stuff } }
CHILD { stuff... }
}
Yes. Do [{ in normal mode for that. It might not work for all languages though.
Many move commands are available at :help [.
Also you can press % and it will show your open or close bracket
It looks like [[ does what you want. And ][ moves to the bottom-most brace. (With many thanks to #Benoit for cluing me in that this might be possible...)

vim enter a new line with tabspaces

Lets say that i have this block of text
public function __construct() {
parent::__construct();
}
and i want to insert a new line above parrent::construct at the same level. Like:
public function __construct() {
// this is the new line.
parent::__construct();
}
how can i do this. I try'ed to do Ctrl+Enter in command mode but that will move the { down also. I managed to do it by going with the cursor to beginning of parent and do Ctrl+Enter.
Isn't there a way to do it when the cursor is at the end of the first line ? or a shortcut to jump faster to parrent ?
Try O and o in the normal mode.
Maybe you should enable auto indention? That might solve your problems.
In your .vimrc file:
:set autoindent

Resources