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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T15:12:54+00:00 2026-06-14T15:12:54+00:00

I am trying to use vim substitute commands to transform type specific C-code into

  • 0

I am trying to use vim substitute commands to transform type specific C-code into macro Code. This example snippet

#define LIST_GEN_FUNCS(TYPE)
struct list_##TYPE* list_generate() {  
struct list_##TYPE* ret = malloc(sizeof(struct list));
ret->len = 0; ret->first = 0;
return ret;
}

needs to look like that:

#define LIST_GEN_FUNCS(TYPE)                               
struct list_##TYPE* list_generate() {                     \
struct list_##TYPE* ret = malloc(sizeof(struct list));    \
ret->len = 0; ret->first = 0;                             \
return ret;                                               \
}                                                         \

To do this, i need a way to fill up all columns with whitespaces until a fixed line length, then add ‘\’ after each line ending.

%s/$/\= submatch(0) . " " . repeat(" ", 78 - LENGTH_OF_LINE)

Now, here is my problem. I was not able to find out how to get the length of a matched line. Could anyone tell me, what to insert as LENGTH_OF_LINE?

  • 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-06-14T15:12:55+00:00Added an answer on June 14, 2026 at 3:12 pm

    One solution is to add spaces to the end of the line and then delete to a specific column. For example:

    :%norm80A <C-v><Esc>d80|s\<cr>
    

    The <C-v><Esc> inserts a literal ^[ character and the <cr> ends the command.

    If you want to find the length of a line in VimL you can use strlen(getline(6)) for example if you wanted to get the length of line 6. If you wanted to implement that into your existing solution you could do

    :%s/$/\=repeat(" ", 79-strlen(getline(".")))."\\"
    

    As Zyx says in the comments, a better way is

    :%s/$/\=repeat(" ", 80-virtcol("$"))."\\"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to know how vim experts use macro's in vim for day-to-day coding
I'm trying to use a vim script that issues commands to sas, When i
I am trying to use this color scheme https://github.com/goatslacker/mango.vim It works when I open
I've been trying to use vim to simplify writing latex. To this end, I
I am trying to use vim properly - to aid me I've mapped my
I am trying to use ctags with VIM, and I am a newbie to
I am need paint my image. I'm trying use JQuery in here this link:
I am trying to use copyDirectory() method from ApacheCommnonsIO package. My code is: First
I'm trying to use the Vim snipMate plugin, and I've installed it as it
I'm trying to use the Search command in Vim: :Rs/F/T/X R = range F

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.