- Notifications
You must be signed in to change notification settings - Fork6
Clojure syntax highlighting and indentation for Vim and Neovim.
License
clojure-vim/clojure.vim
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Clojure syntax highlighting for Vim and Neovim, including:
- Augmentable syntax highlighting.
- Configurable indentation.
- Basic insert-mode completion of special forms and public vars in
clojure.core
. (Invoke with<C-x><C-o>
or<C-x><C-u>
.)
These files are included in both Vim and Neovim. However if you would like thelatest changes just install this repository like any other plugin.
Make sure that the following options are set in your vimrc so that all featuresare enabled:
syntaxonfiletypepluginindenton
Settingg:clojure_fold
to1
will enable the folding of Clojure code. Anylist, vector or map that extends over more than one line can be folded usingthe standard Vim fold commands.
(Note that this option will not work with scripts that redefine the bracketregions, such as rainbow parenphesis plugins.)
Syntax highlighting of public vars inclojure.core
is provided by default,but additional symbols can be highlighted by adding them to theg:clojure_syntax_keywords
variable.
letg:clojure_syntax_keywords= {\'clojureMacro': ["defproject","defcustom"],\'clojureFunc': ["string/join","string/replace"]\}
(Sees:clojure_syntax_keywords
in thesyntax script fora complete example.)
There is also a buffer-local variant of this variable (b:clojure_syntax_keywords
)that is intended for use by plugin authors to highlight symbols dynamically.
By settingb:clojure_syntax_without_core_keywords
, vars fromclojure.core
will not be highlighted by default. This is useful for namespaces that haveset(:refer-clojure :only [])
.
Set this variable to1
to enable highlighting of the"discard reader macro".Due to current limitations in Vim's syntax rules, this option won't highlightstacked discard macros (e.g.#_#_
). This inconsitency is why this option isdisabled by default.
Clojure indentation differs somewhat from traditional Lisps, due in part tothe use of square and curly brackets, and otherwise by community convention.These conventions are not universally followed, so the Clojure indent scriptoffers a few configuration options.
(If the current Vim does not includesearchpairpos()
, the indent script fallsback to normal'lisp'
indenting, and the following options are ignored.)
Sets maximum scan distance ofsearchpairpos()
. Larger values tradeperformance for correctness when dealing with very long forms. A value of0 will scan without limits. The default is 300.
The'lispwords'
option is a list of comma-separated words that mark specialforms whose subforms should be indented with two spaces.
For example:
(defnbad []"Incorrect indentation")(defngood []"Correct indentation")
If you would like to specify'lispwords'
with a pattern instead, you can usethe fuzzy indent feature:
" Defaultletg:clojure_fuzzy_indent=1letg:clojure_fuzzy_indent_patterns= ['^with','^def','^let']letg:clojure_fuzzy_indent_blacklist= ['-fn$','\v^with-%(meta|out-str|loading-context)$']
g:clojure_fuzzy_indent_patterns
andg:clojure_fuzzy_indent_blacklist
arelists of patterns that will be matched against the unqualified symbol at thehead of a list. This means that a pattern like"^foo"
will match all thesecandidates:foobar
,my.ns/foobar
, and#'foobar
.
Each candidate word is tested for special treatment in this order:
- Return true if word is literally in
'lispwords'
- Return false if word matches a pattern in
g:clojure_fuzzy_indent_blacklist
- Return true if word matches a pattern in
g:clojure_fuzzy_indent_patterns
- Return false and indent normally otherwise
Some forms in Clojure are indented such that every subform is indented by onlytwo spaces, regardless of'lispwords'
. If you have a custom construct thatshould be indented in this idiosyncratic fashion, you can add your symbols tothe default list below.
" Defaultletg:clojure_special_indent_words='deftype,defrecord,reify,proxy,extend-type,extend-protocol,letfn'
Align subsequent lines in multi-line strings to the column after the openingquote, instead of the same column.
For example:
(defdefault"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.")(defaligned"Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.")
By default, parenthesized compound forms that look like function calls andwhose head subform is on its own line have subsequent subforms indented bytwo spaces relative to the opening paren:
(foo bar baz)
Setting this option to1
changes this behaviour so that all subforms arealigned to the same column, emulating the default behaviour ofclojure-mode.el:
(foo bar baz)
Pull requests are welcome! Make sure to read theCONTRIBUTING.md
for useful information.
Clojure.vim is a continuation ofvim-clojure-static.Vim-clojure-static was created bySung Pae. Theoriginal copies of the packaged runtime files came fromMeikel Brandmeyer'sVimClojure project with permission.
Thanks toTim Pope for advice in#vim.
Clojure.vim is licensed under theVimLicense fordistribution with Vim.
- Copyright © 2020–2021, The clojure-vim contributors.
- Copyright © 2013–2018, Sung Pae.
- Copyright © 2008–2012, Meikel Brandmeyer.
- Copyright © 2007–2008, Toralf Wittner.
SeeLICENSEfor more details.
About
Clojure syntax highlighting and indentation for Vim and Neovim.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.