vim enter a new line with tabspaces - vim

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

Related

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).

VIM wrap block in curly braces (CSS code)

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

Show multilayer function relationship by cscope in vim

I know source insight can show multilayer function relationship in one window.
For example, we have four functions as below
void example_A()
{
example_B();
}
void example_B()
{
example_C();
}
void example_C()
{
example_D();
}
void example_D();
{
return 5;
}
When I click example_D() in source insight, source insight show example_C() is calling the function.
Moreover, when I click example_C(), I see example_B() is calling the function.
The relationship is like this:
Example_D()
|
-->Example_C()
|
-->Example_B()
|
-->Example_A()
Could I see the relationship in one window by using cscope in vim?
Thank you.
CCTRee plugin for vim does this kind of visualization using cscope
https://sites.google.com/site/vimcctree/
http://www.vim.org/scripts/script.php?script_id=2368
https://github.com/hari-rangarajan/CCTree

How to disable vim's indentation after "case"?

I want my code indent like this:
switch (msg)
{
case WM_CREATE:
{
DoSomething();
}
}
But Vim always indent code like this:
switch (msg)
{
case WM_CREATE:
{
DoSomething();
}
}
My vimrc file is:
set autoindent
filetype plugin indent on
What's more, I hava tried:
set cindent
set smartindent
set cinoption=l1
But they all do not work,
I really do not know how to fix it,
Can you help me?
BYW: I am not English native speaker, please forgive me if there are any errors about grammar.
Add this to your .vimrc file:
set cino==0
That sets the indent after case to zero. You can find the various options for cindent here.

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...)

Resources