Sample Header Ad - 728x90

Disable vim from auto indenting my comment lines, but continue to autoindent everything else

3 votes
1 answer
1384 views
I want vim to stop auto indenting any time I add a # to the beginning of a link after its white space. Here is an example of the problem: Original text:
dog
    cat
        moose
If I add a # comment to the "cat" line, this automatically happens (Which I dont want): updated text:
dog
#cat
        moose
If I add a # comment to the "dog" line, this automatically happens (Which I dont want): updated text:
#dog
#cat
        moose
What I do want is the following, force vim to IGNORE any time I add a #, just don't indent, leave the line alone. Original text:
#dog
    #cat
        moose
Here is my vimrc currently.
set number 
set nowrap 
set linebreak 
set tabstop=4 
set softtabstop=4 
set shiftwidth=4 
set shiftround 
set expandtab 
set title
set mouse=a
set hlsearch
set smarttab
set autoindent
set background=dark
filetype indent on
set filetype=html
set smartindent
set nocompatible
syn on
set splitright
What I have tried: I have tried adding these settings with no success:
set nosmartindent 
set cindent 
set cinkeys-=0# 
set indentkeys-=0#
I also tried many of the suggestions in this post with no success. I like vim autoindent, I want vim to use autoindent, but NOT when I use a # at any time. How can I force vim to ingore applying an autoindent when # is used?
Asked by Dave (700 rep)
Apr 22, 2022, 12:59 PM
Last activity: Apr 22, 2022, 04:14 PM