Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6645293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:16:09+00:00 2026-05-26T00:16:09+00:00

Quite a common task in programming is to remove the condition on the current

  • 0

Quite a common task in programming is to remove the condition on the current block.

In vim, is there an easy way to delete the first line (the ‘if’ statement) and last line (the closing curly brace) of the current block and perhaps reindent accordingly. If there is no simple key combination for this built in, what is a straightforward way to script it?

Thinking about this a bit further, of course the condition on the if statement may span multiple lines so presumably a script is required to capture this completely. However, for my code just deleting the first and last lines would capture 95% of cases.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:16:10+00:00Added an answer on May 26, 2026 at 12:16 am

    Possible solution

    yiBvaBVpgv<
    
    • yiB yanks the inner block
    • vaBV viaually select a block, then select it linewise
    • p paste over visually selected text
    • gv< reselect text and de-indent

    Surround like mappings aka delete surrounding block:

    nnoremap dsB yiBvaBVpgv<
    

    ib provided a shorter solution. This solution will not mutate the visual marks: '<, '>

    diB]pkdk
    
    • diB deletes the current inner block
    • ]p paste the newly deleted text below the end of the block but adjust the indent.
    • kdk move up a line and then delete 2 lines up thereby deleting the start and end of the block.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I guess, it is quite common task. There is a table A let's say
I need to implement task which is quite common feature for RichTextEditors - take
I have a quite common problem, as I saw in the various user groups
It's quite common to have a form with a checkbox stating Use foo immediately
Quite often, in programming we get situations where null checks show up in particularly
Is there a way to modify existing .NET assemblies without resorting to 3rd party
In Python, this idiom for string formatting is quite common s = hello, %s.
Quite a common use case, it seems, is when re-populating an object from a
We have a quite common object in our application. In this case, we'll call
Minifying JS and CSS is quite common. The benefits of minifying JS are much

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.