Correct easily if without block instructions code

0 views
Skip to first unread message

epanda

unread,
Nov 26, 2009, 9:06:42 AM11/26/09
to vim_use
Hi,


I would like to know if I have to add instructions bloc in this case :

if ( cond1 &&
cond2 )

/* general comment
// a comment

*
*/

return result;


==> has to become

if ( cond1 &&
cond2 )
{
/* general comment
// a comment

*
*/
return result;
}


Thanks
Best Regards

Francisco Dibar

unread,
Nov 26, 2009, 12:36:29 PM11/26/09
to vim...@googlegroups.com
If I understood you well, you need to surround some lines of code
between braces. That can be done with the surround plugin as follows:
- select the lines of text you wish to surround
- type s{

To indent properly, you can type vi{ to select the block of text
between braces, and then type = (or shift+>) to indent correctly.

bye.
Message has been deleted

Tony Mechelynck

unread,
Dec 25, 2009, 5:22:53 PM12/25/09
to vim...@googlegroups.com, epanda
On 26/11/09 18:44, epanda wrote:
[top-posted reply reordered]
> On 26 nov, 18:36, Francisco Dibar<frandi...@gmail.com> wrote:
> Yes, I want to surround first line of code after if instruction ...
>
> but with vimscript, not from normal mode
>

what about (untested, and starting with the cursor on the line
containing the closing parenthese at the end of the "if")

put ='{'
/;$/put ='}'

Best regards,
Tony.
--
... If forced to travel on an airplane, try and get in the cabin with
the Captain, so you can keep an eye on him and nudge him if he falls
asleep or point out any mountains looming up ahead ...
-- Mike Harding, "The Armchair Anarchist's Almanac"

Ben Fritz

unread,
Dec 27, 2009, 10:30:08 AM12/27/09
to vim_use

On Nov 26, 11:36 am, Francisco Dibar <frandi...@gmail.com> wrote:
> To indent properly, you can type vi{ to select the block of text
> between braces, and then type = (or shift+>) to indent correctly.
>

Or, you can just type =i{ instead of the two-step process of selecting
and then indenting.

Reply all
Reply to author
Forward
0 new messages