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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T02:21:02+00:00 2026-05-18T02:21:02+00:00

I edit files in Vim were I log terminal command lines along with descriptions

  • 0

I edit files in Vim were I log terminal command lines along with descriptions of what I did.
All my command lines start with $, so my files look like this:

This is a description of what this
command does, it can be quite long and
should have line breaks.

$ ./the_command.sh

These are actually Viki files, but I guess this question should apply to any file type. I have filetype detection on and the files are correctly identified.

The question now is:

I want (hard) line breaks to be inserted into all the text except for the actual copies of command lines, which could be easily identified by the leading $.

Is it possible in Vim to define an exception for applying the line break rule based on a pattern? Would I do that in the syntax file for viki files?

UPDATE
Using a combination of what Herbert and Jefromi suggested, I now have this in my .vimrc:

au CursorMovedI *.viki call SetTextWidth()

function! SetTextWidth()
    if getline(".")=~'^\$'
        set textwidth=1000
    else
        set textwidth=80
    endif
endfunction

It does exactly what I want. Thanks guys!

  • 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-18T02:21:02+00:00Added an answer on May 18, 2026 at 2:21 am

    I gather when you say you want “hard line breaks” you mean you want Vim to break a line automatically, as when it reaches a textwidth column. The best way to do this, I think, is to define an ‘au’ command that sets textwidth to a high number (higher than longest possible line) when it’s on a line that begins with a “$”.

    So something like this would change textwidth whenever you enter or exit insert mode on a line:

    au InsertEnter call SetTextWidth()
    au InsertLeave call SetTextWidth()
    
    function! SetTextWidth()
        if getline(line('.')) =~ '^\$'
            " [edit: 'set textwidth = 0' is preferable to line below]
            set textwidth =1000
        else
            set textwidth=78
        endif
    endfunction
    

    You might want to use the CursorMoved/CursorMovedI groups instead of InsertEnter/Leave since they’re more fine-grained. They get triggered whenever you move the cursor, so the function ends up getting called lots more times, but function is simple enough that it’s probably not going to introduce any noticeable degradation in performance.

    For doing without a function at all you could probably use something like this:

    au InsertEnter exec "set tw=" . getline(line('.'))=~'^\$' ? 1000 : 78
    au InsertLeave exec "set tw=" . getline(line('.'))=~'^\$' ? 1000 : 78
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to solve the following question which i can't get to work by
I want to get the header of a selected tab-item of a tab-control and

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.