Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

Thanks!

like image 453
David Avatar asked Apr 11 '11 14:04

David


People also ask

How do I stop Vim from auto tabbing?

vim" in 'runtimepath'. This disables auto-indenting for files you will open. It will keep working in already opened files. Reset 'autoindent', 'cindent', 'smartindent' and/or 'indentexpr' to disable indenting in an opened file.

How do I change the indentation in Vim?

To indent the current line, or a visual block: ctrl-t, ctrl-d - indent current line forward, backwards (insert mode) visual > or < - indent block by sw (repeat with . ) then try hitting the F5 key while in insert mode (or just :set paste ).


1 Answers

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
like image 163
abcd Avatar answered Oct 24 '22 01:10

abcd