git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2 1/2] Add project-wide .vimrc configuration

From
Christian Brabandt <cb@256bit.org>
Date
Dec 9, 2020, 08:53 UTC
Message-ID
<20201209085356.GJ22416@256bit.org>
In-Reply-To
<20201209065537.48802-2-felipe.contreras@gmail.com>
Hi,
Felipe Contreras schrieb am Mittwoch, den 09. Dezember 2020:
Show 8 quoted lines
> +augroup git
> +	au BufRead,BufNewFile */Documentation/*.txt set filetype=asciidoc
> +
> +	au FileType c setl noexpandtab tabstop=8 shiftwidth=0 cino=(s,:0,l1,t0
> +	au FileType sh setl noexpandtab tabstop=8 shiftwidth=0
> +	au FileType perl setl noexpandtab tabstop=8 shiftwidth=0
> +	au FileType asciidoc setl noexpandtab tabstop=8 shiftwidth=0 autoindent
> +augroup END

This will set filetype specific options. So after this file has been loaded, it will set e.g. set tabstop and shiftwidth options for filetypes outside of the git project.

Shouldn't this only apply to files inside the git code repository?
Show 12 quoted lines
> +
> +" vim: noexpandtab tabstop=8 shiftwidth=0
> diff --git a/contrib/vim/plugin/gitvimrc.vim b/contrib/vim/plugin/gitvimrc.vim
> new file mode 100644
> index 0000000000..c3946e5410
> --- /dev/null
> +++ b/contrib/vim/plugin/gitvimrc.vim
> @@ -0,0 +1,21 @@
> +let s:gitvimrc_whitelist = get(g:, 'gitvimrc_whitelist', [])
> +
> +function LoadGitVimrc()
> +  let l:top = trim(system('git rev-parse --show-toplevel'))

trim needs at least vim 8.0.1630. Is this recent enough? Could also use systemlist()[0] which is available starting at vim 7.4.248 or just a simple split(system(), "\n")[0] which should be compatible with vim 7.

Show 6 quoted lines
> +  if l:top == '' | return | endif
> +  let l:file = l:top . '/.vimrc'
> +  if !filereadable(l:file) | return | endif
> +
> +  let l:found = 0
> +  for l:pattern in s:gitvimrc_whitelist

You could directly use `get(g:, 'gitvimrc_whitelist', [])` directly, so the script local var s:gitvimrc_whitelist is not really needed.

> +    if (match(l:top, l:pattern) != -1)

This uses a regex match. Perhaps do a string comparsion? If this is needed, consider adding "\C" to force matching case and perhaps also \V to force a literal match. Otherwise the options magic, ignorecase, smartcase etc are applied to the matching.

Show 10 quoted lines
> +      let l:found = 1
> +      break
> +    endif
> +  endfor
> +  if !l:found | return | endif
> +
> +  exec 'source ' . fnameescape(l:file)
> +endf
> +
> +call LoadGitVimrc()

On the style: I personally dislike the `l:` prefix for function local variables, as this does not add anything. But perhaps this is just my personal preference.

Best, Christian

Previous: Felipe ContrerasNext: Felipe Contreras
Message 3 of 22 in “vim: configuration and sharness syntax”
  1. 0/2 vim: configuration and sharness syntaxFelipe Contreras, Dec 9, 2020
  2. 1/2 Add project-wide .vimrc configurationFelipe Contreras, Dec 9, 2020
  3. Christian BrabandtDec 9, 2020
  4. Felipe ContrerasDec 9, 2020
  5. Christian BrabandtDec 9, 2020
  6. Jeff KingDec 9, 2020
  7. Felipe ContrerasDec 10, 2020
  8. Jeff KingDec 10, 2020
  9. Felipe ContrerasDec 11, 2020
  10. brian m. carlsonDec 10, 2020
  11. Felipe ContrerasDec 11, 2020
  12. brian m. carlsonDec 11, 2020
  13. Felipe ContrerasDec 11, 2020
  14. Jeff KingDec 15, 2020
  15. Felipe ContrerasDec 15, 2020
  16. Jeff KingDec 15, 2020
  17. Felipe ContrerasDec 15, 2020
  18. 2/2 contrib: vim: add sharness syntax fileFelipe Contreras, Dec 9, 2020
  19. Eric SunshineDec 9, 2020
  20. Felipe ContrerasDec 9, 2020
  21. Jeff KingDec 9, 2020
  22. Felipe ContrerasDec 10, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.