openbsd.vim 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. " $OpenBSD: openbsd.vim,v 1.1 2013/03/16 22:56:44 sthen Exp $
  2. " Copyright (c) 2007-2008 Sean C. Farley <scf@FreeBSD.org>
  3. " All rights reserved.
  4. "
  5. " Redistribution and use in source and binary forms, with or without
  6. " modification, are permitted provided that the following conditions
  7. " are met:
  8. " 1. Redistributions of source code must retain the above copyright
  9. " notice, this list of conditions and the following disclaimer,
  10. " without modification, immediately at the beginning of the file.
  11. " 2. Redistributions in binary form must reproduce the above copyright
  12. " notice, this list of conditions and the following disclaimer in the
  13. " documentation and/or other materials provided with the distribution.
  14. "
  15. " THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  16. " IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  17. " OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  18. " IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  19. " INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  20. " NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  21. " DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  22. " THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. " (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  24. " THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. "
  26. " $FreeBSD: src/tools/tools/editing/freebsd.vim,v 1.2.6.1.4.1 2012/08/05 23:54:33 kensmith Exp $
  27. " This is a plugin for Vim (tested with Vim v7.1) to follow the OpenBSD style(9)
  28. " indentation. It registers a macro (see below) for changing a buffer's
  29. " indentation rules but does not change the indentation of existing code.
  30. " Load only once.
  31. if exists('loaded_OpenBSD')
  32. finish
  33. endif
  34. let loaded_OpenBSD = 1
  35. " OpenBSD mapping to switch current buffer to style(9). This is generally '\f'.
  36. nmap <silent> <Leader>f :call OpenBSD_Style()<CR>
  37. " Ignore indents caused by parentheses in OpenBSD style.
  38. function! IgnoreParenIndent()
  39. let indent = cindent(v:lnum)
  40. if indent > 4000
  41. if cindent(v:lnum - 1) > 4000
  42. return indent(v:lnum - 1)
  43. else
  44. return indent(v:lnum - 1) + 4
  45. endif
  46. else
  47. return (indent)
  48. endif
  49. endfun
  50. " Follow the OpenBSD style(9).
  51. function! OpenBSD_Style()
  52. setlocal cindent
  53. setlocal cinoptions=(4200,u4200,+0.5s,*500,:0,t0,U4200
  54. setlocal indentexpr=IgnoreParenIndent()
  55. setlocal indentkeys=0{,0},0),:,0#,!^F,o,O,e
  56. setlocal noexpandtab
  57. setlocal shiftwidth=8
  58. setlocal tabstop=8
  59. setlocal textwidth=80
  60. endfun