vimtricks.wiki Concise Vim tricks, one at a time.

How do I insert text at the very first column of a line, ignoring indentation?

Answer

gI

Explanation

Most Vim users know I to insert at the start of a line — but I actually jumps to the first non-blank character, skipping leading whitespace. gI is the lesser-known counterpart: it places the cursor at the absolute first column (column 1), regardless of indentation. This matters whenever the content at column 1 is significant.

How it works

  • I — jumps to the first non-whitespace character on the line, then enters Insert mode
  • gI — jumps to column 1 (byte offset 0) unconditionally, then enters Insert mode
  • Both accept a count: 3gI inserts at column 1 on the current line (count is ignored for gI, unlike some motions)

Example

Given an indented Python line:

    def my_function():

With the cursor anywhere on that line:

  • I → cursor lands before def (column 5), ready to type there
  • gI → cursor lands at column 1 (before the leading spaces)

Typing # after gI produces:

#     def my_function():

Using I instead would have produced:

    # def my_function():

Tips

  • gI is essential when column 1 carries semantic meaning: Makefile rules, FORTRAN continuation lines, HERE-doc delimiters, and diff conflict markers all require content exactly at column 1
  • In Visual Block mode, use I or A to prepend/append to all selected lines — these still respect indentation, so for column-1 insertions use a macro with gI instead
  • Combine with . to repeat a column-1 insertion on subsequent lines

Next

How do I use capture groups in Vim substitutions to rearrange or swap matched text?