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 6936873
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T12:17:27+00:00 2026-05-27T12:17:27+00:00

I am trying to compose a Vim script function to help format where the

  • 0

I am trying to compose a Vim script function to help format where the left braces are located at in C like functions blocks.

function! FixLeftBraces()
    "Set the cursor to the top of the file
    call cursor(1,0)
    while search(".\+{",'We') > 0
        exe "normal i\n\e"
    endwhile
endfunction

In this example my goal is to locate the left curly bracket that is on the same line as the function and relocate it to the next line. The We options prevent wrapping the file and reposition the cursor to the end of the search selection respectively.

When I perform a search in Vim using / mode entering in /.\+{ performs a search and highlights lines that I expect it to in source code.

For example C lines such as:

//is highlighted
int main(){

//is not highlighted
void otherFuncion()
{

When I use the created FixLeftBraces() after sourcing it, it does not appear to work. It just runs and does nothing.

If I change the search to search("{",'We') then FixLeftBraces() runs but adds a new line after every left curly bracket. So I am confused why FixLeftBraces() does not work with the search(".\+{",'We').

  • 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-27T12:17:27+00:00Added an answer on May 27, 2026 at 12:17 pm

    On the mentioned test cases, the search() function call keeps returning zero
    and, therefore, the whole function does not work as expected. The reason of
    that is incorrectly specified pattern. There are not a few special characters
    that can be added into a double-quoted string constant using \-syntax (see
    :help expr-"). Consequently, the \+ substring in the regexp literal is
    interpreted as a single + character, and the original intention of the
    pattern is mangled.

    To avoid this undesirable behavior, escape the backslash symbol changing the
    pattern string to

    ".\\+{"
    

    or switch to single-quoted string literal where backslashes do not have
    a special meaning (see :help expr-'),

    '.\+{'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello Friends I am trying to compose two images in imagemagick shell script commane
I am trying to compose a function of type (Floating a) => a ->
I'm trying to write a chrome extension that is used in the GMail compose
I am trying to figure out implement a Compose New Message view that works
I'm trying to compose a list of changed/added files in a svn repository, for
I'm trying to compose xml elements into each other, and the problem I am
I am trying to compose a SOAP message(including header) in C# .NET to send
I am trying to compose a SAML2 AuthnRequest for OpenAM. I have a URL
I'm trying to set the subject of a patch I'm sending manually, but for
I'm trying to compose a breakdown of forum ranks on a phpBB forum. Forum

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.