aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'runtime')
-rw-r--r--runtime/autoload/xmlformat.vim112
-rw-r--r--runtime/doc/change.txt49
-rw-r--r--runtime/doc/cmdline.txt5
-rw-r--r--runtime/ftplugin/xml.vim33
-rw-r--r--runtime/indent/sh.vim79
-rw-r--r--runtime/indent/tex.vim199
-rw-r--r--runtime/syntax/zsh.vim12
7 files changed, 325 insertions, 164 deletions
diff --git a/runtime/autoload/xmlformat.vim b/runtime/autoload/xmlformat.vim
new file mode 100644
index 0000000000..b21eccd8e3
--- /dev/null
+++ b/runtime/autoload/xmlformat.vim
@@ -0,0 +1,112 @@
+" Vim plugin for formatting XML
+" Last Change: Thu, 15 Jan 2015 21:26:55 +0100
+" Version: 0.1
+" Author: Christian Brabandt <cb@256bit.org>
+" Script: http://www.vim.org/scripts/script.php?script_id=
+" License: VIM License
+" GetLatestVimScripts: ???? 18 :AutoInstall: xmlformat.vim
+" Documentation: see :h xmlformat.txt (TODO!)
+" ---------------------------------------------------------------------
+" Load Once: {{{1
+if exists("g:loaded_xmlformat") || &cp
+ finish
+endif
+let g:loaded_xmlformat = 1
+let s:keepcpo = &cpo
+set cpo&vim
+
+" Main function: Format the input {{{1
+func! xmlformat#Format()
+ " only allow reformatting through the gq command
+ " (e.g. Vim is in normal mode)
+ if mode() != 'n'
+ " do not fall back to internal formatting
+ return 0
+ endif
+ let sw = shiftwidth()
+ let prev = prevnonblank(v:lnum-1)
+ let s:indent = indent(prev)/sw
+ let result = []
+ let lastitem = prev ? getline(prev) : ''
+ let is_xml_decl = 0
+ " split on `<`, but don't split on very first opening <
+ for item in split(getline(v:lnum), '.\@<=[>]\zs')
+ if s:EndTag(item)
+ let s:indent = s:DecreaseIndent()
+ call add(result, s:Indent(item))
+ elseif s:EmptyTag(lastitem)
+ call add(result, s:Indent(item))
+ elseif s:StartTag(lastitem) && s:IsTag(item)
+ let s:indent += 1
+ call add(result, s:Indent(item))
+ else
+ if !s:IsTag(item)
+ " Simply split on '<'
+ let t=split(item, '.<\@=\zs')
+ let s:indent+=1
+ call add(result, s:Indent(t[0]))
+ let s:indent = s:DecreaseIndent()
+ call add(result, s:Indent(t[1]))
+ else
+ call add(result, s:Indent(item))
+ endif
+ endif
+ let lastitem = item
+ endfor
+
+ if !empty(result)
+ exe v:lnum. ",". (v:lnum + v:count - 1). 'd'
+ call append(v:lnum - 1, result)
+ " Might need to remove the last line, if it became empty because of the
+ " append() call
+ let last = v:lnum + len(result)
+ if getline(last) is ''
+ exe last. 'd'
+ endif
+ endif
+
+ " do not run internal formatter!
+ return 0
+endfunc
+" Check if given tag is XML Declaration header {{{1
+func! s:IsXMLDecl(tag)
+ return a:tag =~? '^\s*<?xml\s\?\%(version="[^"]*"\)\?\s\?\%(encoding="[^"]*"\)\? ?>\s*$'
+endfunc
+" Return tag indented by current level {{{1
+func! s:Indent(item)
+ return repeat(' ', shiftwidth()*s:indent). s:Trim(a:item)
+endfu
+" Return item trimmed from leading whitespace {{{1
+func! s:Trim(item)
+ if exists('*trim')
+ return trim(a:item)
+ else
+ return matchstr(a:item, '\S\+.*')
+ endif
+endfunc
+" Check if tag is a new opening tag <tag> {{{1
+func! s:StartTag(tag)
+ return a:tag =~? '^\s*<[^/?]'
+endfunc
+" Remove one level of indentation {{{1
+func! s:DecreaseIndent()
+ return (s:indent > 0 ? s:indent - 1 : 0)
+endfunc
+" Check if tag is a closing tag </tag> {{{1
+func! s:EndTag(tag)
+ return a:tag =~? '^\s*</'
+endfunc
+" Check that the tag is actually a tag and not {{{1
+" something like "foobar</foobar>"
+func! s:IsTag(tag)
+ return s:Trim(a:tag)[0] == '<'
+endfunc
+" Check if tag is empty <tag/> {{{1
+func! s:EmptyTag(tag)
+ return a:tag =~ '/>\s*$'
+endfunc
+" Restoration And Modelines: {{{1
+let &cpo= s:keepcpo
+unlet s:keepcpo
+" Modeline {{{1
+" vim: fdm=marker fdl=0 ts=2 et sw=0 sts=-1
diff --git a/runtime/doc/change.txt b/runtime/doc/change.txt
index 1846b562aa..67f8aa47dd 100644
--- a/runtime/doc/change.txt
+++ b/runtime/doc/change.txt
@@ -1372,6 +1372,55 @@ to the name of an external program for Vim to use for text formatting. The
'textwidth' and other options have no effect on formatting by an external
program.
+ *format-formatexpr*
+The 'formatexpr' option can be set to a Vim Script function that performs
+reformatting of the buffer. This should usually happen in an |ftplugin|,
+since formatting is highly dependent on the type of file. It makes
+sense to use an |autoload| script, so the corresponding script is only loaded
+when actually needed and the script should be called <filetype>format.vim.
+
+For example, the XML filetype plugin distributed with Vim in the $VIMRUNTIME
+directory, sets the 'formatexpr' option to: >
+
+ setlocal formatexpr=xmlformat#Format()
+
+That means, you will find the corresponding script, defining the
+xmlformat#Format() function, in the directory:
+`$VIMRUNTIME/autoload/xmlformat.vim`
+
+Here is an example script that removes trailing whitespace from the selected
+text. Put it in your autoload directory, e.g. ~/.vim/autoload/format.vim: >
+
+ func! format#Format()
+ " only reformat on explicit gq command
+ if mode() != 'n'
+ " fall back to Vims internal reformatting
+ return 1
+ endif
+ let lines = getline(v:lnum, v:lnum + v:count - 1)
+ call map(lines, {key, val -> substitute(val, '\s\+$', '', 'g')})
+ call setline('.', lines)
+
+ " do not run internal formatter!
+ return 0
+ endfunc
+
+You can then enable the formatting by executing: >
+ setlocal formatexpr=format#Format()
+>
+Note: this function explicitly returns non-zero when called from insert mode
+(which basically means, text is inserted beyond the 'textwidth' limit). This
+causes Vim to fall back to reformat the text by using the internal formatter.
+
+However, if the |gq| command is used to reformat the text, the function
+will receive the selected lines, trim trailing whitespace from those lines and
+put them back in place. If you are going to split single lines into multiple
+lines, be careful not to overwrite anything.
+
+If you want to allow reformatting of text from insert or replace mode, one has
+to be very careful, because the function might be called recursively. For
+debugging it helps to set the 'debug' option.
+
*right-justify*
There is no command in Vim to right justify text. You can do it with
an external command, like "par" (e.g.: "!}par" to format until the end of the
diff --git a/runtime/doc/cmdline.txt b/runtime/doc/cmdline.txt
index e72799c65b..48229d8991 100644
--- a/runtime/doc/cmdline.txt
+++ b/runtime/doc/cmdline.txt
@@ -378,10 +378,13 @@ CTRL-D List names that match the pattern in front of the cursor.
match is inserted. After the last match, the first is used
again (wrap around).
The behavior can be changed with the 'wildmode' option.
+ *c_<S-Tab>*
+<S-Tab> Like 'wildchar' or <Tab>, but begin with the last match and
+ then go to the previous match.
*c_CTRL-N*
CTRL-N After using 'wildchar' which got multiple matches, go to next
match. Otherwise recall more recent command-line from history.
-<S-Tab> *c_CTRL-P* *c_<S-Tab>*
+ *c_CTRL-P*
CTRL-P After using 'wildchar' which got multiple matches, go to
previous match. Otherwise recall older command-line from
history.
diff --git a/runtime/ftplugin/xml.vim b/runtime/ftplugin/xml.vim
index 236e870537..573a6ba441 100644
--- a/runtime/ftplugin/xml.vim
+++ b/runtime/ftplugin/xml.vim
@@ -1,8 +1,10 @@
" Vim filetype plugin file
" Language: xml
-" Maintainer: Dan Sharp <dwsharp at users dot sourceforge dot net>
-" Last Changed: 20 Jan 2009
-" URL: http://dwsharp.users.sourceforge.net/vim/ftplugin
+" Maintainer: Christian Brabandt <cb@256bit.org>
+" Last Changed: May 08th, 2018
+" Repository: https://github.com/chrisbra/vim-xml-ftplugin
+" Previous Maintainer: Dan Sharp <dwsharp at users dot sourceforge dot net>
+" URL: http://dwsharp.users.sourceforge.net/vim/ftplugin
if exists("b:did_ftplugin") | finish | endif
let b:did_ftplugin = 1
@@ -10,16 +12,16 @@ let b:did_ftplugin = 1
" Make sure the continuation lines below do not cause problems in
" compatibility mode.
let s:save_cpo = &cpo
-set cpo-=C
+set cpo&vim
setlocal commentstring=<!--%s-->
-setlocal comments=s:<!--,m:\ \ \ \ \ ,e:-->
+" Remove the middlepart from the comments section, as this causes problems:
+" https://groups.google.com/d/msg/vim_dev/x4GT-nqa0Kg/jvtRnEbtAnMJ
+setlocal comments=s:<!--,e:-->
setlocal formatoptions-=t
-if !exists("g:ft_xml_autocomment") || (g:ft_xml_autocomment == 1)
- setlocal formatoptions+=croql
-endif
-
+setlocal formatoptions+=croql
+setlocal formatexpr=xmlformat#Format()
" XML: thanks to Johannes Zellner and Akbar Ibrahim
" - case sensitive
@@ -39,7 +41,6 @@ if exists("loaded_matchit")
\ '<\@<=\%([^ \t>/]\+\)\%(\s\+[^/>]*\|$\):/>'
endif
-"
" For Omni completion, by Mikolaj Machowski.
if exists('&ofu')
setlocal ofu=xmlcomplete#CompleteTags
@@ -47,17 +48,17 @@ endif
command! -nargs=+ XMLns call xmlcomplete#CreateConnection(<f-args>)
command! -nargs=? XMLent call xmlcomplete#CreateEntConnection(<f-args>)
-
" Change the :browse e filter to primarily show xml-related files.
-if has("gui_win32")
+if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
let b:browsefilter="XML Files (*.xml)\t*.xml\n" .
- \ "DTD Files (*.dtd)\t*.dtd\n" .
- \ "All Files (*.*)\t*.*\n"
+ \ "DTD Files (*.dtd)\t*.dtd\n" .
+ \ "XSD Files (*.xsd)\t*.xsd\n" .
+ \ "All Files (*.*)\t*.*\n"
endif
" Undo the stuff we changed.
-let b:undo_ftplugin = "setlocal commentstring< comments< formatoptions<" .
- \ " | unlet! b:match_ignorecase b:match_words b:browsefilter"
+let b:undo_ftplugin = "setlocal commentstring< comments< formatoptions< formatexpr< " .
+ \ " | unlet! b:match_ignorecase b:match_words b:browsefilter"
" Restore the saved compatibility options.
let &cpo = s:save_cpo
diff --git a/runtime/indent/sh.vim b/runtime/indent/sh.vim
index fd9a6a9c92..2a9688a4d7 100644
--- a/runtime/indent/sh.vim
+++ b/runtime/indent/sh.vim
@@ -3,7 +3,7 @@
" Maintainer: Christian Brabandt <cb@256bit.org>
" Previous Maintainer: Peter Aronoff <telemachus@arpinum.org>
" Original Author: Nikolai Weibull <now@bitwi.se>
-" Latest Revision: 2017-08-08
+" Latest Revision: 2018-05-12
" License: Vim (see :h license)
" Repository: https://github.com/chrisbra/vim-sh-indent
" Changelog:
@@ -59,12 +59,15 @@ function! GetShIndent()
if lnum == 0
return 0
endif
+ let line = getline(lnum)
let pnum = prevnonblank(lnum - 1)
-
+ let pline = getline(pnum)
let ind = indent(lnum)
- let line = getline(lnum)
- if line =~ '^\s*\%(if\|then\|do\|else\|elif\|case\|while\|until\|for\|select\|foreach\)\>'
+
+ " Check contents of previous lines
+ if line =~ '^\s*\%(if\|then\|do\|else\|elif\|case\|while\|until\|for\|select\|foreach\)\>' ||
+ \ (&ft is# 'zsh' && line =~ '\%(if\|then\|do\|else\|elif\|case\|while\|until\|for\|select\|foreach\)\>')
if line !~ '\<\%(fi\|esac\|done\|end\)\>\s*\%(#.*\)\=$'
let ind += s:indent_value('default')
endif
@@ -72,21 +75,35 @@ function! GetShIndent()
if !s:is_case_ended(line)
let ind += s:indent_value('case-statements')
endif
- elseif line =~ '^\s*\<\k\+\>\s*()\s*{' || line =~ '^\s*{' || line =~ '^\s*function\s*\w\S\+\s*\%(()\)\?\s*{'
+ " function definition
+ elseif s:is_function_definition(line)
if line !~ '}\s*\%(#.*\)\=$'
let ind += s:indent_value('default')
endif
elseif s:is_continuation_line(line)
- if pnum == 0 || !s:is_continuation_line(getline(pnum))
+ if pnum == 0 || !s:is_continuation_line(pline)
let ind += s:indent_value('continuation-line')
endif
- elseif pnum != 0 && s:is_continuation_line(getline(pnum))
- let ind = indent(s:find_continued_lnum(pnum))
+ elseif s:end_block(line) && !s:start_block(line)
+ let ind -= s:indent_value('default')
+ elseif pnum != 0 && s:is_continuation_line(pline) && !s:end_block(getline(v:lnum))
+ " only add indent, if line and pline is in the same block
+ let i = v:lnum
+ let ind2 = indent(s:find_continued_lnum(pnum))
+ while !s:is_empty(getline(i)) && i > pnum
+ let i -= 1
+ endw
+ if i == pnum
+ let ind += ind2
+ else
+ let ind = ind2
+ endif
endif
let pine = line
+ " Check content of current line
let line = getline(v:lnum)
- if line =~ '^\s*\%(then\|do\|else\|elif\|fi\|done\|end\)\>' || line =~ '^\s*}'
+ if line =~ '^\s*\%(then\|do\|else\|elif\|fi\|done\|end\)\>' || s:end_block(line)
let ind -= s:indent_value('default')
elseif line =~ '^\s*esac\>' && s:is_case_empty(getline(v:lnum - 1))
let ind -= s:indent_value('default')
@@ -112,14 +129,24 @@ function! GetShIndent()
" statements, executed within a here document. Keep the current indent
elseif match(map(synstack(v:lnum, 1), 'synIDattr(v:val, "name")'), '\c\mheredoc') > -1
return indent(v:lnum)
+ elseif s:is_comment(line) && s:is_empty(getline(v:lnum-1))
+ return indent(v:lnum)
endif
- return ind
+ return ind > 0 ? ind : 0
endfunction
function! s:is_continuation_line(line)
- return a:line =~ '\%(\%(^\|[^\\]\)\\\|&&\|||\||\)' .
+ " Comment, cannot be a line continuation
+ if a:line =~ '^\s*#'
+ return 0
+ else
+ " start-of-line
+ " \\ or && or || or |
+ " followed optionally by { or #
+ return a:line =~ '\%(\%(^\|[^\\]\)\\\|&&\|||\||\)' .
\ '\s*\({\s*\)\=\(#.*\)\=$'
+ endif
endfunction
function! s:find_continued_lnum(lnum)
@@ -130,6 +157,12 @@ function! s:find_continued_lnum(lnum)
return i
endfunction
+function! s:is_function_definition(line)
+ return a:line =~ '^\s*\<\k\+\>\s*()\s*{' ||
+ \ a:line =~ '^\s*{' ||
+ \ a:line =~ '^\s*function\s*\w\S\+\s*\%(()\)\?\s*{'
+endfunction
+
function! s:is_case_label(line, pnum)
if a:line !~ '^\s*(\=.*)'
return 0
@@ -195,5 +228,29 @@ function! s:escape(pattern)
return '\V'. escape(a:pattern, '\\')
endfunction
+function! s:is_empty(line)
+ return a:line =~ '^\s*$'
+endfunction
+
+function! s:end_block(line)
+ return a:line =~ '^\s*}'
+endfunction
+
+function! s:start_block(line)
+ return a:line =~ '{\s*\(#.*\)\?$'
+endfunction
+
+function! s:find_start_block(lnum)
+ let i = a:lnum
+ while i > 1 && !s:start_block(getline(i))
+ let i -= 1
+ endwhile
+ return i
+endfunction
+
+function! s:is_comment(line)
+ return a:line =~ '^\s*#'
+endfunction
+
let &cpo = s:cpo_save
unlet s:cpo_save
diff --git a/runtime/indent/tex.vim b/runtime/indent/tex.vim
index a748cfbb40..119a66c1b8 100644
--- a/runtime/indent/tex.vim
+++ b/runtime/indent/tex.vim
@@ -1,12 +1,16 @@
-" Vim indent file
-" Language: LaTeX
-" Maintainer: Yichao Zhou <broken.zhou AT gmail.com>
-" Created: Sat, 16 Feb 2002 16:50:19 +0100
-" Version: 1.0.0
+" Vim indent file for TeX
+" Language: TeX
+" Maintainer: Christian Brabandt <cb@256bit.org>
+" Previous Maintainer: YiChao Zhou <broken.zhou AT gmail.com>
+" Latest Revision: 2017-05-03
+" Version: 0.9.3
+" Repository: https://github.com/chrisbra/vim-tex-indent
+" Documention: :h ft-tex-indent
+" Created: Sat, 16 Feb 2002 16:50:19 +0100
" Please email me if you found something I can do. Comments, bug report and
" feature request are welcome.
-" Last Update: {{{
+" Last Update: {{{1
" 25th Sep 2002, by LH :
" (*) better support for the option
" (*) use some regex instead of several '||'.
@@ -15,122 +19,64 @@
" 2005/06/15, Moshe Kaminsky <kaminsky AT math.huji.ac.il>
" (*) New variables:
" g:tex_items, g:tex_itemize_env, g:tex_noindent_env
-" 2011/3/6, by Yichao Zhou <broken.zhou AT gmail.com>
+" 2011/3/6, by Zhou YiChao <broken.zhou AT gmail.com>
" (*) Don't change indentation of lines starting with '%'
" I don't see any code with '%' and it doesn't work properly
" so I add some code.
" (*) New features: Add smartindent-like indent for "{}" and "[]".
" (*) New variables: g:tex_indent_brace
-" 2011/9/25, by Yichao Zhou <broken.zhou AT gmail.com>
+" 2011/9/25, by Zhou Yichao <broken.zhou AT gmail.com>
" (*) Bug fix: smartindent-like indent for "[]"
" (*) New features: Align with "&".
" (*) New variable: g:tex_indent_and.
-" 2011/10/23 by Yichao Zhou <broken.zhou AT gmail.com>
+" 2011/10/23 by Zhou Yichao <broken.zhou AT gmail.com>
" (*) Bug fix: improve the smartindent-like indent for "{}" and
" "[]".
-" 2012/02/27 by Yichao Zhou <broken.zhou AT gmail.com>
+" 2012/02/27 by Zhou Yichao <broken.zhou AT gmail.com>
" (*) Bug fix: support default folding marker.
" (*) Indent with "&" is not very handy. Make it not enable by
" default.
-" 2012/03/06 by Yichao Zhou <broken.zhou AT gmail.com>
+" 2012/03/06 by Zhou Yichao <broken.zhou AT gmail.com>
" (*) Modify "&" behavior and make it default again. Now "&"
" won't align when there are more then one "&" in the previous
" line.
" (*) Add indent "\left(" and "\right)"
" (*) Trust user when in "verbatim" and "lstlisting"
-" 2012/03/11 by Yichao Zhou <broken.zhou AT gmail.com>
+" 2012/03/11 by Zhou Yichao <broken.zhou AT gmail.com>
" (*) Modify "&" so that only indent when current line start with
" "&".
-" 2012/03/12 by Yichao Zhou <broken.zhou AT gmail.com>
+" 2012/03/12 by Zhou Yichao <broken.zhou AT gmail.com>
" (*) Modify indentkeys.
-" 2012/03/18 by Yichao Zhou <broken.zhou AT gmail.com>
+" 2012/03/18 by Zhou Yichao <broken.zhou AT gmail.com>
" (*) Add &cpo
-" 2013/05/02 by Yichao Zhou <broken.zhou AT gmail.com>
+" 2013/05/02 by Zhou Yichao <broken.zhou AT gmail.com>
" (*) Fix problem about GetTeXIndent checker. Thank Albert Netymk
" for reporting this.
-" 2014/06/23 by Yichao Zhou <broken.zhou AT gmail.com>
+" 2014/06/23 by Zhou Yichao <broken.zhou AT gmail.com>
" (*) Remove the feature g:tex_indent_and because it is buggy.
" (*) If there is not any obvious indentation hints, we do not
" alert our user's current indentation.
" (*) g:tex_indent_brace now only works if the open brace is the
" last character of that line.
-" 2014/08/03 by Yichao Zhou <broken.zhou AT gmail.com>
+" 2014/08/03 by Zhou Yichao <broken.zhou AT gmail.com>
" (*) Indent current line if last line has larger indentation
-" 2016/11/08 by Yichao Zhou <broken.zhou AT gmail.com>
-" (*) Fix problems for \[ and \]. Thanks Bruno for reporting.
-" 2017/04/30 by Yichao Zhou <broken.zhou AT gmail.com>
-" (*) Fix a bug between g:tex_noindent_env and g:tex_indent_items
-" Now g:tex_noindent_env='document\|verbatim\|itemize' (Emacs
-" style) is supported. Thanks Miles Wheeler for reporting.
-" 2018/02/07 by Yichao Zhou <broken.zhou AT gmail.com>
-" (*) Make indentation more smart in the normal mode
+" 2014/08/09 by Zhou Yichao <broken.zhou AT gmail.com>
+" (*) Add missing return value for s:GetEndIndentation(...)
+" 2017/05/02: new maintainer Christian Brabandt
+" 2017/05/02: use shiftwidth() function
+" 2017/05/02: do not add indent when environment starts and ends
+" at previous line
+" 2017/05/03: release 0.9.3 submitted for inclusion with Vim
"
" }}}
-
-" Document: {{{
-"
-" To set the following options (ok, currently it's just one), add a line like
-" let g:tex_indent_items = 1
-" to your ~/.vimrc.
-"
-" * g:tex_indent_brace
-"
-" If this variable is unset or non-zero, it will use smartindent-like style
-" for "{}" and "[]". Now this only works if the open brace is the last
-" character of that line.
-"
-" % Example 1
-" \usetikzlibrary{
-" external
-" }
-"
-" % Example 2
-" \tikzexternalize[
-" prefix=tikz]
-"
-" * g:tex_indent_items
-"
-" If this variable is set, item-environments are indented like Emacs does
-" it, i.e., continuation lines are indented with a shiftwidth.
-"
-" set unset
-" ------------------------------------------------------
-" \begin{itemize} \begin{itemize}
-" \item blablabla \item blablabla
-" bla bla bla bla bla bla
-" \item blablabla \item blablabla
-" bla bla bla bla bla bla
-" \end{itemize} \end{itemize}
-"
-"
-" * g:tex_items
-"
-" A list of tokens to be considered as commands for the beginning of an item
-" command. The tokens should be separated with '\|'. The initial '\' should
-" be escaped. The default is '\\bibitem\|\\item'.
-"
-" * g:tex_itemize_env
-"
-" A list of environment names, separated with '\|', where the items (item
-" commands matching g:tex_items) may appear. The default is
-" 'itemize\|description\|enumerate\|thebibliography'.
-"
-" * g:tex_noindent_env
-"
-" A list of environment names. separated with '\|', where no indentation is
-" required. The default is 'document\|verbatim'.
-" }}}
-
-" Only define the function once
+" Only define the function once {{{1
if exists("b:did_indent")
finish
endif
let s:cpo_save = &cpo
set cpo&vim
-
-" Define global variable {{{
-
+" Define global variable {{{1
let b:did_indent = 1
if !exists("g:tex_indent_items")
@@ -147,7 +93,7 @@ if g:tex_indent_items
let g:tex_itemize_env = 'itemize\|description\|enumerate\|thebibliography'
endif
if !exists('g:tex_items')
- let g:tex_items = '\\bibitem\|\\item'
+ let g:tex_items = '\\bibitem\|\\item'
endif
else
let g:tex_items = ''
@@ -156,17 +102,17 @@ endif
if !exists("g:tex_noindent_env")
let g:tex_noindent_env = 'document\|verbatim\|lstlisting'
endif "}}}
-
-" VIM Setting " {{{
+" VIM Setting " {{{1
setlocal autoindent
setlocal nosmartindent
setlocal indentexpr=GetTeXIndent()
setlocal indentkeys&
exec 'setlocal indentkeys+=[,(,{,),},],\&' . substitute(g:tex_items, '^\|\(\\|\)', ',=', 'g')
let g:tex_items = '^\s*' . substitute(g:tex_items, '^\(\^\\s\*\)*', '', '')
-" }}}
-function! GetTeXIndent() " {{{
+let b:undo_indent = 'setlocal indentexpr< indentkeys< smartindent< autoindent<'
+" }}}
+function! GetTeXIndent() " {{{1
" Find a non-blank line above the current line.
let lnum = prevnonblank(v:lnum - 1)
let cnum = v:lnum
@@ -178,7 +124,7 @@ function! GetTeXIndent() " {{{
" At the start of the file use zero indent.
if lnum == 0
- return 0
+ return 0
endif
let line = substitute(getline(lnum), '\s*%.*', '','g') " last line
@@ -192,9 +138,9 @@ function! GetTeXIndent() " {{{
return indent(v:lnum)
end
endif
-
+
if lnum == 0
- return 0
+ return 0
endif
let ind = indent(lnum)
@@ -205,16 +151,12 @@ function! GetTeXIndent() " {{{
return indent(v:lnum)
endif
- " Add a 'shiftwidth' after beginning of environments.
- " Don't add it for \begin{document} and \begin{verbatim}
- " if line =~ '^\s*\\begin{\(.*\)}' && line !~ 'verbatim'
- " LH modification : \begin does not always start a line
- " ZYC modification : \end after \begin won't cause wrong indent anymore
- if line =~ '\\begin{.*}'
- if line !~ g:tex_noindent_env
- let ind = ind + shiftwidth()
- let stay = 0
- endif
+ " Add a 'shiftwidth' after beginning of environments
+ " But don't do it for g:tex_noindent_env or when it also ends at the
+ " previous line.
+ if line =~ '\\begin{.*}' && line !~ '\\end{.*}' && line !~ g:tex_noindent_env
+ let ind = ind + shiftwidth()
+ let stay = 0
if g:tex_indent_items
" Add another sw for item-environments
@@ -248,27 +190,29 @@ function! GetTeXIndent() " {{{
endif
if g:tex_indent_brace
- if line =~ '[[{]$'
+ let char = line[strlen(line)-1]
+ if char == '[' || char == '{'
let ind += shiftwidth()
let stay = 0
endif
- if cline =~ '^\s*\\\?[\]}]' && s:CheckPairedIsLastCharacter(v:lnum, indent(v:lnum))
+ let cind = indent(v:lnum)
+ let char = cline[cind]
+ if (char == ']' || char == '}') &&
+ \ s:CheckPairedIsLastCharacter(v:lnum, cind)
let ind -= shiftwidth()
let stay = 0
endif
- if line !~ '^\s*\\\?[\]}]'
- for i in range(indent(lnum)+1, strlen(line)-1)
- let char = line[i]
- if char == ']' || char == '}'
- if s:CheckPairedIsLastCharacter(lnum, i)
- let ind -= shiftwidth()
- let stay = 0
- endif
+ for i in range(indent(lnum)+1, strlen(line)-1)
+ let char = line[i]
+ if char == ']' || char == '}'
+ if s:CheckPairedIsLastCharacter(lnum, i)
+ let ind -= shiftwidth()
+ let stay = 0
endif
- endfor
- endif
+ endif
+ endfor
endif
" Special treatment for 'item'
@@ -287,9 +231,8 @@ function! GetTeXIndent() " {{{
endif
endif
- if stay && mode() == 'i'
- " If there is no obvious indentation hint, and indentation is triggered
- " in insert mode, we trust our user.
+ if stay
+ " If there is no obvious indentation hint, we trust our user.
if empty(cline)
return ind
else
@@ -299,8 +242,7 @@ function! GetTeXIndent() " {{{
return ind
endif
endfunction "}}}
-
-function! s:GetLastBeginIndentation(lnum) " {{{
+function! s:GetLastBeginIndentation(lnum) " {{{1
let matchend = 1
for lnum in range(a:lnum-1, max([a:lnum - g:tex_max_scan_line, 1]), -1)
let line = getline(lnum)
@@ -311,19 +253,19 @@ function! s:GetLastBeginIndentation(lnum) " {{{
let matchend -= 1
endif
if matchend == 0
- if line =~ g:tex_noindent_env
- return indent(lnum)
- endif
if line =~ g:tex_itemize_env
return indent(lnum) + 2 * shiftwidth()
endif
+ if line =~ g:tex_noindent_env
+ return indent(lnum)
+ endif
return indent(lnum) + shiftwidth()
endif
endfor
return -1
endfunction
-function! s:GetEndIndentation(lnum) " {{{
+function! s:GetEndIndentation(lnum) " {{{1
if getline(a:lnum) =~ '\\begin{.*}.*\\end{.*}'
return -1
endif
@@ -350,15 +292,12 @@ endfunction
" Most of the code is from matchparen.vim
function! s:CheckPairedIsLastCharacter(lnum, col) "{{{
+ " Get the character under the cursor and check if it's in 'matchpairs'.
let c_lnum = a:lnum
let c_col = a:col+1
- let line = getline(c_lnum)
- if line[c_col-1] == '\'
- let c_col = c_col + 1
- endif
- let c = line[c_col-1]
+ let c = getline(c_lnum)[c_col-1]
let plist = split(&matchpairs, '.\zs[:,]')
let i = index(plist, c)
if i < 0
@@ -407,8 +346,8 @@ function! s:CheckPairedIsLastCharacter(lnum, col) "{{{
endif
return 0
-endfunction "}}}
-
+endfunction
+" Reset cpo setting {{{1
let &cpo = s:cpo_save
unlet s:cpo_save
diff --git a/runtime/syntax/zsh.vim b/runtime/syntax/zsh.vim
index b4efcdcbdf..3eba438aa7 100644
--- a/runtime/syntax/zsh.vim
+++ b/runtime/syntax/zsh.vim
@@ -2,7 +2,7 @@
" Language: Zsh shell script
" Maintainer: Christian Brabandt <cb@256bit.org>
" Previous Maintainer: Nikolai Weibull <now@bitwi.se>
-" Latest Revision: 2017-11-22
+" Latest Revision: 2018-05-12
" License: Vim (see :h license)
" Repository: https://github.com/chrisbra/vim-zsh
@@ -67,15 +67,15 @@ syn match zshRedir '|&\='
syn region zshHereDoc matchgroup=zshRedir
\ start='<\@<!<<\s*\z([^<]\S*\)'
\ end='^\z1\>'
- \ contains=@zshSubst
+ \ contains=@zshSubst,@zshDerefs,zshQuoted,zshPOSIXString
syn region zshHereDoc matchgroup=zshRedir
\ start='<\@<!<<\s*\\\z(\S\+\)'
\ end='^\z1\>'
- \ contains=@zshSubst
+ \ contains=@zshSubst,@zshDerefs,zshQuoted,zshPOSIXString
syn region zshHereDoc matchgroup=zshRedir
\ start='<\@<!<<-\s*\\\=\z(\S\+\)'
\ end='^\s*\z1\>'
- \ contains=@zshSubst
+ \ contains=@zshSubst,@zshDerefs,zshQuoted,zshPOSIXString
syn region zshHereDoc matchgroup=zshRedir
\ start=+<\@<!<<\s*\(["']\)\z(\S\+\)\1+
\ end='^\z1\>'
@@ -118,8 +118,8 @@ syn keyword zshCommands alias autoload bg bindkey break bye cap cd
\ ttyctl type ulimit umask unalias unfunction
\ unhash unlimit unset vared wait
\ whence where which zcompile zformat zftp zle
- \ zmodload zparseopts zprof zpty zregexparse
- \ zsocket zstyle ztcp
+ \ zmodload zparseopts zprof zpty zrecompile
+ \ zregexparse zsocket zstyle ztcp
" Options, generated by: echo ${(j:\n:)options[(I)*]} | sort
" Create a list of option names from zsh source dir: