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

The Archive Base Latest Questions

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

String formatting in VIM is giving me headaches. I guess I feel very used

  • 0

String formatting in VIM is giving me headaches.

I guess I feel very used to string formatting in Python where you can specify how
output string are going to be delimited, with how many spaces in between and so on.

So I have a VIM plugin that outputs information to a scratch buffer that looks like:

Line: 1 ==>> ErrorName ==>> File Path: /foo

I build that string before appending it to a buffer and everything works fantastic. But whenever you have line numbers that are different (digit wise) you get things like this:

Line: 1 ==>> Error ==>> File Path: /foo
Line: 123  ==>> ErrorNameLong ==>> File Path: /foo
Line: 12  ==>> ErrorShort ==>> File Path: /foo

I have tried doing doing tabs instead of spaces but it only makes it worse (the spaces grow even bigger). So my ideal end result would have to be something like this:

Line: 1    ==>> Error         ==>> File Path: /foo
Line: 123  ==>> ErrorNameLong ==>> File Path: /foo
Line: 12   ==>> ErrorShort    ==>> File Path: /foo

I am well aware of plugins that help (e.g. tabular.vim) but since this is a plugin itself, I do not want to require a dependency on a different plugin just for simple string formatting.

These are the things I have tried so far:

  • Tabs (and tabs + spaces)
  • Search and replace with tabs (and tabs with spaces after rendering in buffer)

It seems to me that there must be a good approach to this and I am just missing it.

How can achieve the string formatting I need in VIM?

  • 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-20T00:09:52+00:00Added an answer on May 20, 2026 at 12:09 am

    I use two little functions, nothing fancy, one to add padding after string and one if I want to add in front of string. The PrePad function allows for an optional argument of the padding character, which I sometimes use to pad numbers with preceding 0’s.

    function! Pad(s,amt)
        return a:s . repeat(' ',a:amt - len(a:s))
    endfunction
    
     "  Pad('abc', 5) == 'abc  '
     "  Pad('ab', 5) ==  'ab   '
    
    
    function! PrePad(s,amt,...)
        if a:0 > 0
            let char = a:1
        else
            let char = ' '
        endif
        return repeat(char,a:amt - len(a:s)) . a:s
    endfunction
    
    " PrePad('832', 4)      == ' 823'
    " PrePad('832', 4, '0') == '0823'
    

    It would be simple to Pad() in building your original log messages. Something like:

    echo 'Line: ' . Pad(linenum,8) . '==>> ' . Pad(errmsg,12) . '==>> FilePath: ' . path
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

The string formatting concept found in sprintf can be found in almost any language
I am trying to use the python 2.5 string formatting however I have run
How can this easy to write (and read) string formatting routine be convert into
In Python, this idiom for string formatting is quite common s = hello, %s.
Using .NET string formatting you can plug the same value into a format string
There are various string formatting methods: Python <2.6: "Hello %s" % name Python 2.6+:
One of the nicest tools in Python is locals() in string formatting: >>> st=asdasd
If I have a string formatting program in C, that consists of only one
Is there any better alternative for doing string formatting in VC6, with syntax checking
I am trying to do some string concatenation/formatting, but it's putting all the parameters

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.