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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:26:56+00:00 2026-06-14T06:26:56+00:00

I use the following code to make cc preserve the existing indentation when the

  • 0

I use the following code to make cc preserve the existing indentation when the line is not empty, and to use the calculated indentation (using indentexpr) when the line is empty.

function SmartCC()
  if getline('.') !~# '\S'
    return 'cc'
  else
    let spaces = repeat(' ', indent('.'))
    return '0d$i' . spaces
  endif
endfunction
nnoremap <expr> cc SmartCC()

The only problem I have with it is that, unlike the built-in cc, this inserts “real” spaces and not “tentative” spaces that get deleted automatically if nothing is typed on that line.

Is there a way to insert such tentative spaces?

Or maybe what I’m trying to achieve is already available by setting some secret option?

To make it clear, a plugin that removes all trailing spaces is not a solution.

  • 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-14T06:26:57+00:00Added an answer on June 14, 2026 at 6:26 am

    Try the following hack:

    function SmartCC_IndentExpr(indent, savedindentexpr)
        let &l:indentexpr=a:savedindentexpr
        return a:indent
    endfunction
    function SmartCC()
        if getline('.')=~#'\S'
            let &l:indentexpr='SmartCC_IndentExpr('.indent('.').', '.string(&l:indentexpr).')'
        endif
        return 'cc'
    endfunction
    nnoremap <expr> cc SmartCC()
    

    . The idea is to set &l:indentexpr only for the period of evaluation cc. As it is known that cc checks indent only once and nothing triggers the check before cc under such circumstances then the &l:indentexpr itself can be used to restore &l:indentexpr back before indent is checked for the second time for another reason.

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

Sidebar

Related Questions

I'm trying to use the following code to make an image fadeOut and, only
I use the following code to fill all empty keys in sub-arrays with ``
I use the following code to make fixed row headers in my UIScrollView descendant.
Im trying to use the following code to eventually make a game. The code,
I use the following code to make sure I go back to a particular
I added the following code to make use of appearance on newer versions of
I tried to use the following code to make my ImageButton invisible, but clicking
I am using the following to code make an image gallery, but I would
I use the following code to make Propel 1.4 works in a php file.
How to change the following code to make use of all my 4 textboxes

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.