I'm working with python code. After some modifications, I want to update the identation but obviously, select everything and press '=' doesn't work, python being python.

So, is there any other way to add (and/or remove) some character (here, tabs) at the beggining of each line ?

  • 4
    Try this: :help v_>. Oct 15, 2015 at 10:35

2 Answers 2


As Sato mentioned in comments, :help v_> will show you help for the best tool you can use for this. >> in normal mode will indent the current line; >3> will indent the current line and the following two lines; << will decrease indentation.

Another feature that works will in combination with > can be found at :help text-objects. (aB, a[, and so on.) For example in C-style code that uses curly braces, >aB or >iB to indent the current block including curly braces, or only indent the lines between the curly braces, respectively. For Python code, >ap (indent a paragraph) may be more useful, but using visual mode to select the lines as described in :help v_> is even more adjustable.

For the general answer to "How to add a character/some text at the beginning of each line?" i.e., when you want to insert something other than tabs or spaces, there are a couple ways:

:%normal Itext to insert will prepend text to insert to every line in the file. % can be replaced with any range you like. (See :help range and also :help :normal)

Or you can use Ctrlvto enter blockwise-visual mode, use j and k to select a column of characters, then I (capital) to insert text at that point in all selected lines. (It will only be visible in all the lines after you Esc and then make another motion of any sort.) This has the advantage that you can enter text at ANY point in the line, not only at the beginning. (See :help v_b_I)


Follow the steps:

  1. Press Esc to get into normal mode

  2. :set number This will show the line numbers

  3. Run :<from_line_number>,<to_line_number>>

For example, :279,$> will indent all lines from line number 279 by 1 tab space (the actual indent amount depends on various options).

  • I've made some formatting edits, and also changed "command mode" to "normal mode"—while to some they are synonymous, to others "command" means "command-line" (aka Ex), which you get to with :. "Normal" is the least ambiguous option. cf. :help Normal-mode which uses both, but clearly prefers "Normal."
    – D. Ben Knoble
    Nov 3, 2021 at 13:13
  • (PS if you have multiple accounts, please let us know that they belong to the same person so that we may merge them. That also makes it easier for you to, e.g., edit your own posts, accrue reputation, etc.)
    – D. Ben Knoble
    Nov 3, 2021 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.