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

  • SEARCH
  • Home
  • 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 891069
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:49:56+00:00 2026-05-15T13:49:56+00:00

Is there any easy way to toggle do/end and {} in ruby in Vim?

  • 0

Is there any easy way to toggle “do/end” and “{}” in ruby in Vim?

(TextMate does this with ^{.)

  • 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-15T13:49:56+00:00Added an answer on May 15, 2026 at 1:49 pm

    You’d have to either use searchpair(), or to play with % (as long as matchit is installed, and as you are on begin/end), then mark the two positions, test whether it’s text or brackets, and finally update the two lines.

    nnoremap <buffer> <c-x>{ :call <sid>ToggleBeginOrBracket()<cr>
    
    let s:k_be = [ 'begin', 'end' ]
    function! s:ToggleBeginOrBracket()
      let c = lh#position#char_at_mark('.')
      if c =~ '[{}]'
        " don't use matchit for {,}
        exe 'normal! %s'.s:k_be[1-(c=='}')]."\<esc>``s".s:k_be[(c=='}')]."\<esc>"
      else
        let w = expand('<cword>')
        if w == 'begin'
          " use mathit
          normal %
          exe "normal! ciw}\<esc>``ciw{\<esc>"
        elseif w == 'end'
          " use mathit
          normal %
          exe "normal! ciw{\<esc>``ciw}\<esc>"
        else
          throw 'Cannot toggle block: cursor is not on {, }, begin, nor end'
        endif
      endif
    endfunction
    

    Where lh#position#char_at_mark() is defined here.

    PS: this is definitively a SO question as it combines ruby context, and advanced vim scripting.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 499k
  • Answers 499k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer var nums = new int?[] {1, null, 3}; var total… May 16, 2026 at 12:43 pm
  • Editorial Team
    Editorial Team added an answer <style type="text/css"> .clear{ clear: both; } .top{ width: 100%; }… May 16, 2026 at 12:43 pm
  • Editorial Team
    Editorial Team added an answer Their algorithms aren't officially released to the public, but if… May 16, 2026 at 12:43 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

Is there any easy way to retrieve table creation DDL from Microsoft Access (2007)
Is there any easy way to explicitly make an already threaded application utilise a
Is there an easy way to select either a file OR a folder from
I am trying to make it so the container on this page http://s72956.gridserver.com/dev/toggle.html# will
I want to display a basic html table with controls to toggle showing/hiding of
I'm trying to find a simple way to attach click events to an element,
I have a page which is used to display numerous forms for the user
I am developing CDC driver for USB device and I stumble on some problem.
I have a menu with submenus that can be toggled (hide/show type deal). Is
I would like to use XmlSerializer and deserialize attributes with empty string values into

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.