Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

vim wrong indent when comment lines of yaml file

Tags:

vim

yaml

I have tried the autocmd way, not work for me.

  1. One line comment with i, indent wrong.

Press i at begin of the line, then press #, the # and cursor auto indent.

one line comment with i

  1. One line comment with I, indent right.

Press I at begin of the line, the cursor auto indent; then press #.

one line comment with I

  1. Block comment with Ctrl+v, followed with Shift + i, followed with Esc, indent wrong.

block comment

---------------------Edit------------------------

  1. Block comment with cursor on the -

The first block and the second block bahaves different.

enter image description here

like image 999
icycandy Avatar asked Jun 27 '18 09:06

icycandy


1 Answers

This drove me nuts too! Thankfully the solution is pretty simple:

autocmd FileType yaml,yaml.ansible setlocal indentkeys-=0#

You need to use "yaml.ansible" if you use the ansible-vim plugin. Using "setlocal" instead of "set" is optional but after decades with Vim I've learned that it is a good idea to specify local when you know you only want it local to avoid nasty surprises.

like image 62
ggustafsson Avatar answered Nov 06 '22 05:11

ggustafsson