Is there a Vim plugin that can handle smart semicolon insertion, like the one in Eclipse?
Example (pipe character is insertion cursor):
foobar(|)
I type a semicolon:
foobar();|
Similarly:
foobar("blah|")
I type a semicolon:
foobar("blah");|
If I want a semicolon at the original cursor position, I press backspace after the smart re-position:
foobar("hello|")
foobar("hello");|
foobar("hello;|")
This version shall not pose problems with
for
if your snippets engine expands it intoIf the open bracket is on a newline, it will mess things up.
You could easily change the regex to
'"\=)\+$'
to answer your initial question.However, I don't think it's a good idea. In that case, the mapping for
<bs>
will be:You should try Cosco.vim plugin.
I use the following function and a mapping to insert a semicolon to the end of the line and to delete the remaning spaces:
So if you have something like:
Pressing . or ,. if you remap the leader, you get the following:
I want to do the same thing, I works on it whole night, tons of code, but at last, I got a simple solution.
and if I am in a brace, I want to add a semicolon or a dot at the end, like this
I press
;;<cr>
or..<cr>
to do thisI use this mapping:
It's not
;
because I use semicolons often and in more than one context.<C-o>
is used to input a single normal mode command.A;
means "add a;
at the end of the line".The code above will check if there is
;
at the end of the line.If
;
not exists, then it will add;
otherwise do nothing.