What setting in vim counteracts smartindent's refusal to indent # comments in shell scripts?
Find the indent file, (e.g. /usr/share/vim/vim71/indent/sh.vim on my system)
This line looks like the problem:
setlocal indentkeys-=:,0#
Perhaps you can fix this in your .vimrc or load a custom indent file manually.
edit: It looks more complicated than I thought, but maybe there is something specifically set in the indenting file that you would need to fix.
2nd edit: Looks like I was completely wrong, Check out:
Restoring indent after typing hash
or
howto-configure-vim-to-not-put-comments-at-the-beginning-of-lines-while-editing
Well, after exploring some options, including using ':set cindent
' instead of ':set smartindent
', I've ended up reverting to just using ':set autoindent
'. There probably are ways to make this stuff work exactly as I want it to, but it is messy enough and fiddly enough that I can't be bothered. I've worked fine with autoindent
for the previous 20-odd years, and the benefits from the extra bells and whistles provided by smartindent
are outweighed by the what I regard as its misbehaviour.
Thank you, Juan, for your assistance. Believe it or not, it did help - quite a lot.
I also discovered a couple of other neat commands, though, while following up on this:
>i}>a}
These right-shift the block of code you are in. The 'i
' version indents the body and not the closing braces (my preferred style), and the 'a
' version indents the closing braces to (the version that is required at work).
Also, you can apply qualifiers to '%
' in commands executed at the shell:
:make %:r.o
This would run make on the 'root' of the current file name (that's '%:r
') followed by '.o
'. Or, in other words, if I'm editing somefile.c
, this executes make somefile.o
.
Add the line below in your .vimrc
filetype indent on
(it will set the right indent mode depending on the filetype)