3

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?

2
  • Honestly? This is the default behaviour for C files, but not general default. What kind of file (filename extension) do you have? Commented Apr 22, 2022 at 15:26
  • .yaml is the problem file I am working with. Commented Apr 22, 2022 at 15:28

1 Answer 1

0

0# is part of indentkeys in the default yaml.vim (some /usr/share/vim/…/indent/yaml.vim). On opening a yaml file, this will overwrite the indentkeys setting in your ~/.vimrc.

My first idea is to include an autocmd in your ~/.vimrc on opening yaml files:

autocmd BufNewFile,BufRead *.yaml set indentkeys-=0# 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.