Alex Rivera | Logout

Vim editor indent problem when the first character of the line is a sharp # character

Asked 2011-04-11T14:00:15.923
13

This haven been bugging me since the first day using Vim for 3 years. Whenever I try to indent a line via Shift + > when the FIRST CHARACTER of the line starts with a "#", it doesn't work at all, regardless of the file types (.php, .txt, etc.). Because # is used for comment in PHP and I also use it for decoration for text files something like:

# This is a comment

### 1. Instruction one

# ------------ this is an sample --------------

I use Vim 7.2 in Ubuntu with the following .vimrc settings

syntax on
set t_Co=256
set incsearch
set hlsearch
set number
set nowrap
set nowrapscan
set ignorecase
set et
set sw=4
set smarttab
set smartindent
set autoindent
set textwidth=0
set noequalalways
set formatoptions=1
set lbr
set vb      
set foldmethod=marker
Edit
Report

1 Answer

5

Insert the following in your .vimrc:

set nosmartindent

It is smartindent that causes lines beginning with # to not be indented as you want. You can read more about it by typing :help smartindent. If you use an indenting file for python scripts (or any other syntax), include the following too.

filetype indent on
answered 2011-04-11T15:06:04.150

Your Answer