Aubrey Portwood

WordPress — Stoicism — 🎾

Vim tabbing awful for HTML, JavaScript, CSS, PHP

| Permalink

[iframe width=”100%” height=”340″ src=”″]

The video is a result of the following tip/fix:

I usually edit a .html or .php file and do HTML, PHP, CSS and JavaScript coding inside that filetype. Vim, as far as I can tell, just doesn’t get it when it comes to tabbing/indentation (especially with PHP). Vim ships with indenting files built in $VIMRUNTIME/indent. Even when I downloaded scripts that help support the indention built it, it still didn’t work. All I really wanted was for Vim to keep the indention of the previous line. Once I figured it out it solved all my tabbing/indention woes.

First I used…

[sourcecode]set noexpandtab
set autoindent "keeps previous lines indent
set copyindent
set preserveindent
set softtabstop=0
set shiftwidth=4
set tabstop=4[/sourcecode]

… to get my tabs and indention working in Vim. Notice that autoindent and copyindent are the key settings that cause Vim to keep the previous line’s indentation.

Then, I disabled the shipped indentation rules that come with Vim…

[sourcecode]filetype indent off[/sourcecode]

This keeps Vim from loading any indenting rules, and now Vim will just follow the previous indention.

I’ve include my _vimrc file for you to examine. I may be releasing my Vim/_vimrc/Plugins, etc as an “ultimate Vim for HTML, PHP, CSS & Javascript” that everyone can use soon.

_vimrc-aubrey-island-javascript-php-html-css (txt)

Leave a Comment