Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

In vim, I can find the matching if statement and prepend the appropriate comment symbol. (e.g. %s/.alarm./#\0/g), but then I am left with dangling endifs that I have to find manually. I could simplify the process by using macro, but I could I achieve this with sed (more specifically one in vim)?

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

The problem with a simple regular expression is dealing with nested conditionals; you cannot simply search for the next endif and comment it out. Fortunately, the matchit plugin that comes with Vim has this problem solved (for many filetypes); when on the if, the % mapping will take you to the corresponding endif.

Combine that with a plugin like NERDCommenter, and you can easily build a mapping for it:

:nmap <Leader>cif <Leader>cc%<Leader>cc
share|improve this answer
    
Thank you. I never thought about using those plugins that way! –  Forethinker Apr 14 '13 at 10:48
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.