Search-fu power is eluding me for this one.
Have many Nagios (*.cfg
) files under audit, using Vim
to work on them.
Notice that doing gg=G
is not correctly formatting the files or a block if using =
with movement commands.
My .vimrc
looks like this:
syntax on
filetype on
filetype plugin on
filetype indent on
set t_Co=256
set title
set hlsearch
set incsearch
set ignorecase
set shiftround
set smarttab
set expandtab
set shiftwidth=2
set softtabstop=2
set tabstop=2
set smartindent
set copyindent
set autoindent
set mouse=a
set laststatus=2
set number
if v:version > 703
set relativenumber " Introduced from v7.3 onwards
endif
set ruler
set showcmd
set background=dark
colorscheme elflord
" MultipleSearch
"======================
"let g:MultipleSearchMaxColors = 20
"let g:MultipleSearchColorSequence="darkcyan,gray,LightCyan,LightBlue,LightGreen,blue,green,magenta,cyan,gray,brown"
"let g:MultipleSearchTextColorSequence= "white,DarkRed,black,black,black,white,black,white,red,black,white"
" block cursor (and blinking?) mostly (a fix) for cygwin
let &t_ti.="\e[1 q"
let &t_SI.="\e[5 q"
let &t_EI.="\e[1 q"
let &t_te.="\e[0 q"
" Allow saving of files as sudo when I forgot to start vim using sudo.
cmap w!! w !sudo tee > /dev/null %
Thing is, that when formatting a file full of this kind of blocks with gg=G
:
define service{
use prod
host_name some_host
service_description some_service_desc
servicegroups some_sgroup
notes_url https://some.notes.comh/notes.md
check_period somep_S21h00-S09h00
notification_period somep_S21h00-S09h00
contact_groups some_contacsg
notification_options c,r
check_command check_nrpe_timeout!30!check_proc2!java!1:1!prod!"important-process"
}
Expected:
define▪service{¬
▪▪use▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪prod¬
▪▪host_name▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪some_host¬
▪▪service_description▪▪▪▪▪some_service_desc¬
▪▪servicegroups▪▪▪▪▪▪▪▪▪▪▪some_sgroup¬
▪▪notes_url▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪https://some.notes.comh/notes.md¬
▪▪check_period▪▪▪▪▪▪▪▪▪▪▪▪somep_S21h00-S09h00¬
▪▪notification_period▪▪▪▪▪somep_S21h00-S09h00¬
▪▪contact_groups▪▪▪▪▪▪▪▪▪▪some_contacsg¬
▪▪notification_options▪▪▪▪c,r¬
▪▪check_command▪▪▪▪▪▪▪▪▪▪▪check_nrpe_timeout!30!check_proc2!java!1:1!prod!"important-process"¬
}¬
But, getting instead:
define▪service{¬
▪▪use▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪prod¬
▪▪▪▪host_name▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪some_host¬
▪▪▪▪service_description▪▪▪▪▪some_service_desc¬
▪▪▪▪servicegroups▪▪▪▪▪▪▪▪▪▪▪some_sgroup¬
▪▪▪▪notes_url▪▪▪▪▪▪▪▪▪▪▪▪▪▪▪https://some.notes.comh/notes.md¬
▪▪▪▪check_period▪▪▪▪▪▪▪▪▪▪▪▪somep_S21h00-S09h00¬
▪▪▪▪notification_period▪▪▪▪▪somep_S21h00-S09h00¬
▪▪▪▪contact_groups▪▪▪▪▪▪▪▪▪▪some_contacsg¬
▪▪▪▪notification_options▪▪▪▪c,r¬
▪▪▪▪check_command▪▪▪▪▪▪▪▪▪▪▪check_nrpe_timeout!30!check_proc2!java!1:1!prod!"important-process"¬
}¬
Some settings from the .vimrc
have been applied locally with no avail.
setlocal expandtab smarttab smartindent shiftwidth=2 softtabstop=2 tabstop=2 autoindent mouse=a hlsearch incsearch ignorecase
Probably, I am missing a basic thing here or is just the normal behavior from the filetype
for *.cfg
files, thanks for the pointers.
after
). For example, the only one I have globally isautoindent
, plusfiletype plugin indent on
. I useafter/ftplugin/…
to customize each filetype withsetlocal
:set filetype?
" (with the question mark as part of the command) show?.vimrc
config file and trying with only the systems defaults and also with some options insetlocal
mode, still the same bad indentation results.=
uses theC-indenting
/lisp
way to format things (according to the:help =
) but generally this does the job O.K., not this time. To answer your question with/without my.vimrc
I getfiletype=cfg
which is fine, changingfiletype
won't affect the formatting since it will still use the defaults for=
.macro
or something like vim-autoformat, tabular or vim-easy-align, but I try to avoid plugins for portability issues, looking maybe to build my ownindent.vim
file for this kind of file.