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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T16:50:28+00:00 2026-05-29T16:50:28+00:00

The default VIM indentation commands indent by shiftwidth spaces e.g. >> Indent line by

  • 0

The default VIM indentation commands indent by shiftwidth spaces

e.g.

>>   Indent line by shiftwidth spaces
<<   De-indent line by shiftwidth spaces

Is there any way to indent with one or n (where n != shiftwidth) space(s)?

One way to do that is to vertically select a column in the block with Ctrl+V then, I to insert vertically and then type a space and <Esc>. But is there a better way?

  • 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-29T16:50:31+00:00Added an answer on May 29, 2026 at 4:50 pm

    I’m not sure that there is a better way. But, there are a few ways that you could do it (that I can think of anyway)…

    Your Visual Block Solution

    Like you said: press Ctl-V select the lines you want, press I to insert, and enter the number of spaces.

    Search

    Similar to the above but a little more flexible – you can use with with the ‘select paragraph’ vip command, or any range really: press v or vip or what have you to select the range, and the type :s/^/{n spaces} where {n spaces} is the number of spaces you want to insert.

    Its a little more verbose, but works pretty well for pretty much any range. Heck, if you wanted to do the whole file you could do Ctl-A (OS dependent) and indent the whole file (or just skip the whole visual mode thing and just do it command mode…as in :1,$s/^/{n spaces}

    Note that you don’t have to include the third slash in s/// since you aren’t putting any switches at the end of the search.

    Global

    Maybe you want to only indent lines that match some pattern. Say…all lines that contain foo. No problem: type :g/foo/s/^/{n spaces}

    Global is especially handy if its multi-line sections with a similar pattern. You can just escape into normal mode land and select the lines you want and indent accordingly: :g/foo/norm Vjj:s/^/{n spaces}Ctl-V{Enter}. Little more complicated with that extra Ctl-V{Enter} at the end but useful under certain circumstances.

    Use tabstop and shiftwidth

    Yes, if your doing it a lot – I’d do :set ts=2 and :set et and :set sw=2 and use >> and << every which way…

    Make a Function

    Okay, so still not brief enough and for whatever reason you need to do this a lot and you can’t abide messing with sw, et and ts settings. No problem, just write up a quick function and give it a localleader mapping:

    function! AddSpace(num) range
      let s:counter = 0
      let s:spaces = ''
      while s:counter < a:num
        let s:spaces .= ' '
        let s:counter = s:counter + 1
      endwhile
        execute a:firstline .','. a:lastline .'s/^/'. s:spaces
    endfunction
    
    :map <LocalLeader>i :call AddSpace(3)Ctl-V{enter}
    

    Maybe just knowing more than one way to do this is better than only knowing one? After all, sometimes the best solution depends on the problem 🙂

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

Sidebar

Related Questions

I use _vimrc to configure my vim 7.2 (windows) default settings. One setting set
By default IntelliJ IDEA 7.0.4 seems to use 4 spaces for indentation in XML
I have a makefile that looks like: default: lua blah.lua Now, in Vim, I
Where is the default location for the folder ~/.vim/syntax/ on a Linux system? I
The default behaviour of :help in Vim opens the help in a horizontal split.
How do I set up a default syntax for files that have no extension
I believe there is a method to write a comment in a file that
By default code completion in VIM searches from the start of the word. Is
I'm using CentOS, which appears to have vim installed by default. I located the
I am long time-vim user and recently discovered that emacs has viper-mode, offering best

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.