I've been happily using vim for years for C and C++ projects. My code formatting/indentation rules have been cobbled together over the years based on solutions to at-the-time needs...which is to say, I'm no expert at .vimrc syntax, so I couldn't articulate why it works correctly for C and C++ projects, just that it does.
Once in a while I'll have to deal with a Makefile or CMakeLists.txt, and because that's so infrequent, I usually deal manually with any need for indentation adjustment.
Recently, though, I'm having to deal with Jenkins Pipeline Scripts. The filenames are typically simply Jenkinsfile, i.e. no extension. Broadly speaking, the files themselves follow what Wikipedia calls "the one true brace style, variant 1"
Is there a way I can have vim apply my current indentation rules for C/C++ to files named Jenkinsfile?
My current .vimrc:
filetype plugin indent on
syntax on
set termguicolors
if has('nvim')
" https://github.com/neovim/neovim/wiki/FAQ
set guicursor=n-v-c:block-Cursor/lCursor-blinkon0,i-ci:ver25-Cursor/lCursor,r-cr:hor20-Cursor/lCursor
endif
filetype plugin on
colorscheme Base2Tone_MorningDark
"colorscheme Base2Tone_DrawbridgeDark
"colorscheme Base2Tone_LavenderDark
"colorscheme Base2Tone_PoolDark
"colorscheme Base2Tone_SuburbDark
set expandtab " Expand tab to spaces
set hlsearch
set number " Line numbers
" set ruler
set backspace=indent,eol,start
set cino=(0 " Indent N chars from the line w/ unclosed paren
set laststatus=2 " Status-line always
set scrolloff=4 " Start scrolling when cursor is N lines from top/bottom
set shiftwidth=2 " Number of spaces for each step of autoindent
set softtabstop=2 " Number of spaces that <tab> counts for
set textwidth=80
set statusline=
set statusline+=%F
set statusline+=%=%l/%L " Line n/N
set statusline+=%4v " virtual column
set statusline+=%#warningmsg#
set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
set formatoptions+=q " Allow formatting of comments with "gq"
set formatoptions+=t " Auto-wrap using textwidth, auto-insert comment leader
set formatoptions+=j " Remove comment leader when joining lines
set t_ut=
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 1
let g:syntastic_c_config_file = '.syntastic_c_config'
"let g:syntastic_debug = 1
"let g:syntastic_auto_loc_list = 1
With this .vimrc, vim seems to apply no indentation rules to Jenkinsfiles. I.e. whenever I hit Enter, despite any existing indendtation of curly-brace, vim takes me to column 0 of the next line.
:verbose set filetype?report in aJenkinsfile? You could probably trim down the reproducibility with How to debug my vimrc. You probably need to detectJenkinsfileas some filetype (e.g.,jenkins) and then add a local ftplugin (e.g.,~/.vim/after/ftplugin/jenkins.vim) whichsetlocalscindentor similar. (PS You havefiletype plugin onin your vimrc twice. Alsoformatoptionsis buffer-local and unfortunately many ftplugins mess with it, so you may find that your settings get overwritten.) – D. Ben Knoble May 19 '21 at 21:55:verbose set filetyperesponds withfiletype=, i.e. "filetype", an equals-sign, then end-of-string (or whitespace only). – StoneThrow May 19 '21 at 22:16