aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'runtime')
-rw-r--r--runtime/autoload/ada.vim6
-rw-r--r--runtime/autoload/adacomplete.vim2
-rw-r--r--runtime/autoload/csscomplete.vim8
-rw-r--r--runtime/autoload/decada.vim2
-rw-r--r--runtime/autoload/dist/ft.vim19
-rw-r--r--runtime/autoload/haskellcomplete.vim6
-rw-r--r--runtime/autoload/health/lsp.vim5
-rw-r--r--runtime/autoload/htmlcomplete.vim2
-rw-r--r--runtime/autoload/man.vim19
-rw-r--r--runtime/autoload/netrw.vim274
-rw-r--r--runtime/autoload/netrwSettings.vim8
-rw-r--r--runtime/autoload/phpcomplete.vim40
-rw-r--r--runtime/autoload/provider/clipboard.vim4
-rw-r--r--runtime/autoload/python3complete.vim2
-rw-r--r--runtime/autoload/pythoncomplete.vim2
-rw-r--r--runtime/autoload/remote/host.vim2
-rw-r--r--runtime/autoload/rubycomplete.vim11
-rw-r--r--runtime/autoload/sqlcomplete.vim10
-rw-r--r--runtime/autoload/tar.vim2
-rw-r--r--runtime/autoload/tohtml.vim2
-rw-r--r--runtime/autoload/vimexpect.vim2
-rw-r--r--runtime/autoload/xmlcomplete.vim2
-rw-r--r--runtime/autoload/zip.vim2
-rw-r--r--runtime/compiler/fpc.vim2
-rw-r--r--runtime/compiler/scdoc.vim16
-rw-r--r--runtime/compiler/spectral.vim17
-rw-r--r--runtime/compiler/tex.vim2
-rw-r--r--runtime/compiler/yamllint.vim16
-rw-r--r--runtime/doc/api.txt167
-rw-r--r--runtime/doc/arabic.txt7
-rw-r--r--runtime/doc/autocmd.txt17
-rw-r--r--runtime/doc/change.txt27
-rw-r--r--runtime/doc/cmdline.txt14
-rw-r--r--runtime/doc/deprecated.txt50
-rw-r--r--runtime/doc/dev_style.txt1159
-rw-r--r--runtime/doc/develop.txt55
-rw-r--r--runtime/doc/diagnostic.txt562
-rw-r--r--runtime/doc/diff.txt8
-rw-r--r--runtime/doc/digraph.txt8
-rw-r--r--runtime/doc/eval.txt1508
-rw-r--r--runtime/doc/filetype.txt11
-rw-r--r--runtime/doc/fold.txt2
-rw-r--r--runtime/doc/ft_ps1.txt2
-rw-r--r--runtime/doc/ft_raku.txt4
-rw-r--r--runtime/doc/ft_sql.txt2
-rw-r--r--runtime/doc/gui.txt6
-rw-r--r--runtime/doc/help.txt22
-rw-r--r--runtime/doc/helphelp.txt1
-rw-r--r--runtime/doc/if_perl.txt3
-rw-r--r--runtime/doc/if_ruby.txt4
-rw-r--r--runtime/doc/index.txt11
-rw-r--r--runtime/doc/insert.txt19
-rw-r--r--runtime/doc/intro.txt7
-rw-r--r--runtime/doc/job_control.txt4
-rw-r--r--runtime/doc/lsp.txt887
-rw-r--r--runtime/doc/lua.txt399
-rw-r--r--runtime/doc/map.txt1
-rw-r--r--runtime/doc/motion.txt11
-rw-r--r--runtime/doc/nvim_terminal_emulator.txt45
-rw-r--r--runtime/doc/options.txt158
-rw-r--r--runtime/doc/pattern.txt2
-rw-r--r--runtime/doc/pi_netrw.txt80
-rw-r--r--runtime/doc/print.txt11
-rw-r--r--runtime/doc/provider.txt1
-rw-r--r--runtime/doc/quickfix.txt3
-rw-r--r--runtime/doc/quickref.txt2
-rw-r--r--runtime/doc/remote.txt189
-rw-r--r--runtime/doc/repeat.txt95
-rw-r--r--runtime/doc/rileft.txt2
-rw-r--r--runtime/doc/russian.txt4
-rw-r--r--runtime/doc/sign.txt24
-rw-r--r--runtime/doc/spell.txt6
-rw-r--r--runtime/doc/starting.txt87
-rw-r--r--runtime/doc/syntax.txt120
-rw-r--r--runtime/doc/tagsrch.txt13
-rw-r--r--runtime/doc/testing.txt41
-rw-r--r--runtime/doc/treesitter.txt90
-rw-r--r--runtime/doc/usr_05.txt6
-rw-r--r--runtime/doc/usr_08.txt2
-rw-r--r--runtime/doc/usr_09.txt2
-rw-r--r--runtime/doc/usr_41.txt12
-rw-r--r--runtime/doc/usr_45.txt7
-rw-r--r--runtime/doc/various.txt32
-rw-r--r--runtime/doc/vim_diff.txt66
-rw-r--r--runtime/doc/visual.txt2
-rw-r--r--runtime/doc/windows.txt5
-rw-r--r--runtime/filetype.vim35
-rw-r--r--runtime/ftplugin/8th.vim10
-rw-r--r--runtime/ftplugin/c.vim10
-rw-r--r--runtime/ftplugin/chicken.vim1
-rw-r--r--runtime/ftplugin/dosini.vim2
-rw-r--r--runtime/ftplugin/eruby.vim4
-rw-r--r--runtime/ftplugin/gprof.vim22
-rw-r--r--runtime/ftplugin/jsonc.vim27
-rw-r--r--runtime/ftplugin/julia.vim92
-rw-r--r--runtime/ftplugin/man.vim14
-rw-r--r--runtime/ftplugin/matlab.vim7
-rw-r--r--runtime/ftplugin/ocaml.vim8
-rw-r--r--runtime/ftplugin/octave.vim63
-rw-r--r--runtime/ftplugin/ruby.vim4
-rw-r--r--runtime/ftplugin/scala.vim6
-rw-r--r--runtime/ftplugin/scdoc.vim26
-rw-r--r--runtime/ftplugin/scheme.vim5
-rw-r--r--runtime/ftplugin/systemverilog.vim2
-rw-r--r--runtime/ftplugin/tex.vim2
-rw-r--r--runtime/indent/ada.vim2
-rw-r--r--runtime/indent/bzl.vim41
-rw-r--r--runtime/indent/cdl.vim12
-rw-r--r--runtime/indent/config.vim4
-rw-r--r--runtime/indent/dtd.vim6
-rw-r--r--runtime/indent/erlang.vim8
-rw-r--r--runtime/indent/html.vim63
-rw-r--r--runtime/indent/json.vim2
-rw-r--r--runtime/indent/jsonc.vim189
-rw-r--r--runtime/indent/julia.vim491
-rw-r--r--runtime/indent/lifelines.vim2
-rw-r--r--runtime/indent/objc.vim2
-rw-r--r--runtime/indent/pascal.vim4
-rw-r--r--runtime/indent/pov.vim2
-rw-r--r--runtime/indent/python.vim4
-rw-r--r--runtime/indent/ruby.vim3
-rw-r--r--runtime/indent/scala.vim9
-rw-r--r--runtime/indent/sqlanywhere.vim2
-rw-r--r--runtime/indent/systemverilog.vim4
-rw-r--r--runtime/indent/testdir/xml.in2
-rw-r--r--runtime/indent/testdir/xml.ok2
-rw-r--r--runtime/indent/tex.vim2
-rw-r--r--runtime/indent/treetop.vim2
-rw-r--r--runtime/indent/typescript.vim2
-rw-r--r--runtime/indent/verilog.vim4
-rw-r--r--runtime/indent/yaml.vim2
-rw-r--r--runtime/keymap/kana.vim4
-rw-r--r--runtime/keymap/korean.vim2
-rw-r--r--runtime/keymap/russian-jcukenwintype.vim2
-rw-r--r--runtime/keymap/russian-typograph.vim4
-rw-r--r--runtime/lua/vim/F.lua13
-rw-r--r--runtime/lua/vim/_meta.lua1
-rw-r--r--runtime/lua/vim/diagnostic.lua1381
-rw-r--r--runtime/lua/vim/highlight.lua20
-rw-r--r--runtime/lua/vim/lsp.lua392
-rw-r--r--runtime/lua/vim/lsp/_snippet.lua399
-rw-r--r--runtime/lua/vim/lsp/buf.lua281
-rw-r--r--runtime/lua/vim/lsp/codelens.lua57
-rw-r--r--runtime/lua/vim/lsp/diagnostic.lua1448
-rw-r--r--runtime/lua/vim/lsp/handlers.lua287
-rw-r--r--runtime/lua/vim/lsp/health.lua27
-rw-r--r--runtime/lua/vim/lsp/log.lua46
-rw-r--r--runtime/lua/vim/lsp/protocol.lua24
-rw-r--r--runtime/lua/vim/lsp/rpc.lua168
-rw-r--r--runtime/lua/vim/lsp/util.lua674
-rw-r--r--runtime/lua/vim/shared.lua157
-rw-r--r--runtime/lua/vim/treesitter.lua23
-rw-r--r--runtime/lua/vim/treesitter/highlighter.lua20
-rw-r--r--runtime/lua/vim/treesitter/language.lua8
-rw-r--r--runtime/lua/vim/treesitter/languagetree.lua34
-rw-r--r--runtime/lua/vim/treesitter/query.lua71
-rw-r--r--runtime/lua/vim/ui.lua36
-rw-r--r--runtime/lua/vim/uri.lua32
-rw-r--r--runtime/nvim.appdata.xml1
-rw-r--r--runtime/optwin.vim3
-rw-r--r--runtime/pack/dist/opt/matchit/doc/matchit.txt4
-rw-r--r--runtime/pack/dist/opt/termdebug/plugin/termdebug.vim84
-rw-r--r--runtime/plugin/diagnostic.vim26
-rw-r--r--runtime/plugin/man.vim4
-rw-r--r--runtime/plugin/netrwPlugin.vim28
-rw-r--r--runtime/plugin/tohtml.vim2
-rw-r--r--runtime/syntax/2html.vim4
-rw-r--r--runtime/syntax/8th.vim2
-rw-r--r--runtime/syntax/abel.vim2
-rw-r--r--runtime/syntax/ada.vim2
-rw-r--r--runtime/syntax/ahdl.vim2
-rw-r--r--runtime/syntax/aptconf.vim13
-rw-r--r--runtime/syntax/aspvbs.vim6
-rw-r--r--runtime/syntax/c.vim5
-rw-r--r--runtime/syntax/cfg.vim2
-rw-r--r--runtime/syntax/chicken.vim21
-rw-r--r--runtime/syntax/cpp.vim57
-rw-r--r--runtime/syntax/csc.vim2
-rw-r--r--runtime/syntax/cupl.vim2
-rw-r--r--runtime/syntax/debchangelog.vim6
-rw-r--r--runtime/syntax/debsources.vim6
-rw-r--r--runtime/syntax/dosbatch.vim2
-rw-r--r--runtime/syntax/doxygen.vim8
-rw-r--r--runtime/syntax/focexec.vim2
-rw-r--r--runtime/syntax/forth.vim2
-rw-r--r--runtime/syntax/gemtext.vim24
-rw-r--r--runtime/syntax/go.vim444
-rw-r--r--runtime/syntax/gprof.vim5
-rw-r--r--runtime/syntax/gvpr.vim85
-rw-r--r--runtime/syntax/hamster.vim2
-rw-r--r--runtime/syntax/help.vim2
-rw-r--r--runtime/syntax/idl.vim2
-rw-r--r--runtime/syntax/iss.vim4
-rw-r--r--runtime/syntax/jsonc.vim44
-rw-r--r--runtime/syntax/julia.vim550
-rw-r--r--runtime/syntax/man.vim8
-rw-r--r--runtime/syntax/mma.vim4
-rw-r--r--runtime/syntax/objc.vim2
-rw-r--r--runtime/syntax/pascal.vim2
-rw-r--r--runtime/syntax/php.vim267
-rw-r--r--runtime/syntax/postscr.vim8
-rw-r--r--runtime/syntax/redif.vim2
-rw-r--r--runtime/syntax/ruby.vim20
-rw-r--r--runtime/syntax/scala.vim25
-rw-r--r--runtime/syntax/scdoc.vim52
-rw-r--r--runtime/syntax/scheme.vim13
-rw-r--r--runtime/syntax/sgml.vim6
-rw-r--r--runtime/syntax/sh.vim46
-rw-r--r--runtime/syntax/spup.vim4
-rw-r--r--runtime/syntax/st.vim4
-rw-r--r--runtime/syntax/structurizr.vim76
-rw-r--r--runtime/syntax/syncolor.vim87
-rw-r--r--runtime/syntax/synload.vim7
-rw-r--r--runtime/syntax/tmux.vim2
-rw-r--r--runtime/syntax/vim.vim17
-rw-r--r--runtime/tutor/en/vim-01-beginner.tutor222
-rw-r--r--runtime/tutor/en/vim-01-beginner.tutor.json70
217 files changed, 11071 insertions, 4720 deletions
diff --git a/runtime/autoload/ada.vim b/runtime/autoload/ada.vim
index d04feb9250..3f1b40398f 100644
--- a/runtime/autoload/ada.vim
+++ b/runtime/autoload/ada.vim
@@ -67,13 +67,13 @@ if exists ('g:ada_with_gnat_project_files')
endfor
endif
-" Section: add standart exception {{{2
+" Section: add standard exception {{{2
"
for Item in ['Constraint_Error', 'Program_Error', 'Storage_Error', 'Tasking_Error', 'Status_Error', 'Mode_Error', 'Name_Error', 'Use_Error', 'Device_Error', 'End_Error', 'Data_Error', 'Layout_Error', 'Length_Error', 'Pattern_Error', 'Index_Error', 'Translation_Error', 'Time_Error', 'Argument_Error', 'Tag_Error', 'Picture_Error', 'Terminator_Error', 'Conversion_Error', 'Pointer_Error', 'Dereference_Error', 'Update_Error']
let g:ada#Keywords += [{
\ 'word': Item,
\ 'menu': 'exception',
- \ 'info': 'Ada standart exception.',
+ \ 'info': 'Ada standard exception.',
\ 'kind': 'x',
\ 'icase': 1}]
endfor
@@ -210,7 +210,7 @@ function ada#Word (...)
let l:Line = substitute (getline (l:Line_Nr), g:ada#Comment, '', '' )
" Cope with tag searching for items in comments; if we are, don't loop
- " backards looking for previous lines
+ " backwards looking for previous lines
if l:Column_Nr > strlen(l:Line)
" We were in a comment
let l:Line = getline(l:Line_Nr)
diff --git a/runtime/autoload/adacomplete.vim b/runtime/autoload/adacomplete.vim
index 2659f51d5c..d7bba93d12 100644
--- a/runtime/autoload/adacomplete.vim
+++ b/runtime/autoload/adacomplete.vim
@@ -14,7 +14,7 @@
" 15.10.2006 MK Bram's suggestion for runtime integration
" 05.11.2006 MK Bram suggested not to use include protection for
" autoload
-" 05.11.2006 MK Bram suggested agaist using setlocal omnifunc
+" 05.11.2006 MK Bram suggested against using setlocal omnifunc
" 05.11.2006 MK Bram suggested to save on spaces
" Help Page: ft-ada-omni
"------------------------------------------------------------------------------
diff --git a/runtime/autoload/csscomplete.vim b/runtime/autoload/csscomplete.vim
index f6c5a6c391..4b673ac9b8 100644
--- a/runtime/autoload/csscomplete.vim
+++ b/runtime/autoload/csscomplete.vim
@@ -4,7 +4,7 @@
" plus CSS Speech Module <http://www.w3.org/TR/css3-speech/>
" Maintainer: Kao, Wei-Ko(othree) ( othree AT gmail DOT com )
" Original Author: Mikolaj Machowski ( mikmach AT wp DOT pl )
-" Last Change: 2018 Jul 02
+" Last Change: 2021 Sep 21
let s:values = split("all additive-symbols align-content align-items align-self animation animation-delay animation-direction animation-duration animation-fill-mode animation-iteration-count animation-name animation-play-state animation-timing-function backface-visibility background background-attachment background-blend-mode background-clip background-color background-image background-origin background-position background-repeat background-size block-size border border-block-end border-block-end-color border-block-end-style border-block-end-width border-block-start border-block-start-color border-block-start-style border-block-start-width border-bottom border-bottom-color border-bottom-left-radius border-bottom-right-radius border-bottom-style border-bottom-width border-collapse border-color border-image border-image-outset border-image-repeat border-image-slice border-image-source border-image-width border-inline-end border-inline-end-color border-inline-end-style border-inline-end-width border-inline-start border-inline-start-color border-inline-start-style border-inline-start-width border-left border-left-color border-left-style border-left-width border-radius border-right border-right-color border-right-style border-right-width border-spacing border-style border-top border-top-color border-top-left-radius border-top-right-radius border-top-style border-top-width border-width bottom box-decoration-break box-shadow box-sizing break-after break-before break-inside caption-side clear clip clip-path color columns column-count column-fill column-gap column-rule column-rule-color column-rule-style column-rule-width column-span column-width content counter-increment counter-reset cue cue-before cue-after cursor direction display empty-cells fallback filter flex flex-basis flex-direction flex-flow flex-grow flex-shrink flex-wrap float font font-family font-feature-settings font-kerning font-language-override font-size font-size-adjust font-stretch font-style font-synthesis font-variant font-variant-alternates font-variant-caps font-variant-east-asian font-variant-ligatures font-variant-numeric font-variant-position font-weight grid grid-area grid-auto-columns grid-auto-flow grid-auto-position grid-auto-rows grid-column grid-column-start grid-column-end grid-row grid-row-start grid-row-end grid-template grid-template-areas grid-template-rows grid-template-columns height hyphens image-rendering image-resolution image-orientation ime-mode inline-size isolation justify-content left letter-spacing line-break line-height list-style list-style-image list-style-position list-style-type margin margin-block-end margin-block-start margin-bottom margin-inline-end margin-inline-start margin-left margin-right margin-top marks mask mask-type max-block-size max-height max-inline-size max-width max-zoom min-block-size min-height min-inline-size min-width min-zoom mix-blend-mode negative object-fit object-position offset-block-end offset-block-start offset-inline-end offset-inline-start opacity order orientation orphans outline outline-color outline-offset outline-style outline-width overflow overflow-wrap overflow-x overflow-y pad padding padding-block-end padding-block-start padding-bottom padding-inline-end padding-inline-start padding-left padding-right padding-top page-break-after page-break-before page-break-inside pause-before pause-after pause perspective perspective-origin pointer-events position prefix quotes range resize rest rest-before rest-after right ruby-align ruby-merge ruby-position scroll-behavior scroll-snap-coordinate scroll-snap-destination scroll-snap-points-x scroll-snap-points-y scroll-snap-type scroll-snap-type-x scroll-snap-type-y shape-image-threshold shape-margin shape-outside speak speak-as suffix symbols system table-layout tab-size text-align text-align-last text-combine-upright text-decoration text-decoration-color text-decoration-line text-emphasis text-emphasis-color text-emphasis-position text-emphasis-style text-indent text-orientation text-overflow text-rendering text-shadow text-transform text-underline-position top touch-action transform transform-box transform-origin transform-style transition transition-delay transition-duration transition-property transition-timing-function unicode-bidi unicode-range user-zoom vertical-align visibility voice-balance voice-duration voice-family voice-pitch voice-rate voice-range voice-stress voice-volume white-space widows width will-change word-break word-spacing word-wrap writing-mode z-index zoom")
@@ -38,12 +38,12 @@ function! csscomplete#CompleteCSS(findstart, base)
if exists("b:compl_context")
let line = getline('.')
let compl_begin = col('.') - 2
- let after = line[compl_begin:]
+ let b:after = line[compl_begin:]
let line = b:compl_context
unlet! b:compl_context
else
let line = a:base
- let after = ''
+ let b:after = ''
endif
let res = []
@@ -311,7 +311,7 @@ function! csscomplete#CompleteCSS(findstart, base)
let values = ["normal", "italic", "oblique", "small-caps", "bold", "bolder", "lighter", "100", "200", "300", "400", "500", "600", "700", "800", "900", "xx-small", "x-small", "small", "medium", "large", "x-large", "xx-large", "larger", "smaller", "sans-serif", "serif", "monospace", "cursive", "fantasy", "caption", "icon", "menu", "message-box", "small-caption", "status-bar"]
elseif prop =~ '^\%(height\|width\)$'
let values = ["auto", "border-box", "content-box", "max-content", "min-content", "available", "fit-content"]
- elseif prop =~ '^\%(left\|rigth\)$'
+ elseif prop =~ '^\%(left\|right\)$'
let values = ["auto"]
elseif prop == 'image-rendering'
let values = ["auto", "crisp-edges", "pixelated"]
diff --git a/runtime/autoload/decada.vim b/runtime/autoload/decada.vim
index 5124429a75..fda2b76dac 100644
--- a/runtime/autoload/decada.vim
+++ b/runtime/autoload/decada.vim
@@ -23,7 +23,7 @@ endif
function decada#Unit_Name () dict " {{{1
" Convert filename into acs unit:
- " 1: remove the file extenstion.
+ " 1: remove the file extension.
" 2: replace all double '_' or '-' with an dot (which denotes a separate)
" 3: remove a trailing '_' (which denotes a specification)
return substitute (substitute (expand ("%:t:r"), '__\|-', ".", "g"), '_$', "", '')
diff --git a/runtime/autoload/dist/ft.vim b/runtime/autoload/dist/ft.vim
index ac80659113..7484149a26 100644
--- a/runtime/autoload/dist/ft.vim
+++ b/runtime/autoload/dist/ft.vim
@@ -264,6 +264,14 @@ func dist#ft#ProtoCheck(default)
endfunc
func dist#ft#FTm()
+ if exists("g:filetype_m")
+ exe "setf " . g:filetype_m
+ return
+ endif
+
+ " excluding end(for|function|if|switch|while) common to Murphi
+ let octave_block_terminators = '\<end\%(_try_catch\|classdef\|enumeration\|events\|methods\|parfor\|properties\)\>'
+
let n = 1
let saw_comment = 0 " Whether we've seen a multiline comment leader.
while n < 100
@@ -278,6 +286,12 @@ func dist#ft#FTm()
setf objc
return
endif
+ if line =~ '^\s*\%(#\|%!\)' || line =~ '^\s*unwind_protect\>' ||
+ \ line =~ '\%(^\|;\)\s*' .. octave_block_terminators
+ setf octave
+ return
+ endif
+ " TODO: could be Matlab or Octave
if line =~ '^\s*%'
setf matlab
return
@@ -298,11 +312,8 @@ func dist#ft#FTm()
" or Murphi based on the comment leader. Assume the former as it is more
" common.
setf objc
- elseif exists("g:filetype_m")
- " Use user specified default filetype for .m
- exe "setf " . g:filetype_m
else
- " Default is matlab
+ " Default is Matlab
setf matlab
endif
endfunc
diff --git a/runtime/autoload/haskellcomplete.vim b/runtime/autoload/haskellcomplete.vim
index 48fbac7f9f..759ff8741a 100644
--- a/runtime/autoload/haskellcomplete.vim
+++ b/runtime/autoload/haskellcomplete.vim
@@ -54,7 +54,7 @@ function! haskellcomplete#Complete(findstart, base)
if b:completingLangExtension
if a:base ==? ""
- " Return all posible Lang extensions
+ " Return all possible Lang extensions
return s:langExtensions
else
let l:matches = []
@@ -70,7 +70,7 @@ function! haskellcomplete#Complete(findstart, base)
elseif b:completingOptionsGHC
if a:base ==? ""
- " Return all posible GHC options
+ " Return all possible GHC options
return s:optionsGHC
else
let l:matches = []
@@ -86,7 +86,7 @@ function! haskellcomplete#Complete(findstart, base)
elseif b:completingModule
if a:base ==? ""
- " Return all posible modules
+ " Return all possible modules
return s:commonModules
else
let l:matches = []
diff --git a/runtime/autoload/health/lsp.vim b/runtime/autoload/health/lsp.vim
new file mode 100644
index 0000000000..2d2ba91cdf
--- /dev/null
+++ b/runtime/autoload/health/lsp.vim
@@ -0,0 +1,5 @@
+function! health#lsp#check() abort
+ call health#report_start('Checking language server client configuration')
+ lua require 'vim.lsp.health'.check_health()
+endfunction
+
diff --git a/runtime/autoload/htmlcomplete.vim b/runtime/autoload/htmlcomplete.vim
index 6b9d49a469..267889d97f 100644
--- a/runtime/autoload/htmlcomplete.vim
+++ b/runtime/autoload/htmlcomplete.vim
@@ -486,7 +486,7 @@ function! htmlcomplete#CompleteTags(findstart, base)
endif
endif
" Value of attribute completion {{{
- " If attr contains =\s*[\"'] we catched value of attribute
+ " If attr contains =\s*[\"'] we match value of attribute
if attr =~ "=\s*[\"']" || attr =~ "=\s*$"
" Let do attribute specific completion
let attrname = matchstr(attr, '.*\ze\s*=')
diff --git a/runtime/autoload/man.vim b/runtime/autoload/man.vim
index 4f556e6e87..4f132b6121 100644
--- a/runtime/autoload/man.vim
+++ b/runtime/autoload/man.vim
@@ -58,6 +58,7 @@ function! man#open_page(count, mods, ...) abort
else
execute 'silent keepalt' a:mods 'stag' l:target
endif
+ call s:set_options(v:false)
finally
call setbufvar(l:buf, '&tagfunc', l:save_tfu)
endtry
@@ -65,6 +66,7 @@ function! man#open_page(count, mods, ...) abort
let b:man_sect = sect
endfunction
+" Called when a man:// buffer is opened.
function! man#read_page(ref) abort
try
let [sect, name] = s:extract_sect_and_name_ref(a:ref)
@@ -121,6 +123,15 @@ function! s:system(cmd, ...) abort
return opts.stdout
endfunction
+function! s:set_options(pager) abort
+ setlocal filetype=man
+ setlocal noswapfile buftype=nofile bufhidden=hide
+ setlocal nomodified readonly nomodifiable
+ if a:pager
+ nnoremap <silent> <buffer> <nowait> q :lclose<CR>:q<CR>
+ endif
+endfunction
+
function! s:get_page(path) abort
" Disable hard-wrap by using a big $MANWIDTH (max 1000 on some systems #9065).
" Soft-wrap: ftplugin/man.vim sets wrap/breakindent/….
@@ -134,9 +145,7 @@ function! s:get_page(path) abort
endfunction
function! s:put_page(page) abort
- setlocal modifiable
- setlocal noreadonly
- setlocal noswapfile
+ setlocal modifiable noreadonly noswapfile
silent keepjumps %delete _
silent put =a:page
while getline(1) =~# '^\s*$'
@@ -148,7 +157,7 @@ function! s:put_page(page) abort
silent! keeppatterns keepjumps %s/\s\{199,}/\=repeat(' ', 10)/g
1
lua require("man").highlight_man_page()
- setlocal filetype=man
+ call s:set_options(v:false)
endfunction
function! man#show_toc() abort
@@ -397,6 +406,7 @@ function! s:format_candidate(path, psect) abort
endif
endfunction
+" Called when Nvim is invoked as $MANPAGER.
function! man#init_pager() abort
" https://github.com/neovim/neovim/issues/6828
let og_modifiable = &modifiable
@@ -420,6 +430,7 @@ function! man#init_pager() abort
execute 'silent file man://'.tolower(fnameescape(ref))
endif
+ call s:set_options(v:true)
let &l:modifiable = og_modifiable
endfunction
diff --git a/runtime/autoload/netrw.vim b/runtime/autoload/netrw.vim
index 74ceab35d4..b6edc4c4d8 100644
--- a/runtime/autoload/netrw.vim
+++ b/runtime/autoload/netrw.vim
@@ -1,7 +1,7 @@
" netrw.vim: Handles file transfer and remote directory listing across
" AUTOLOAD SECTION
-" Date: Sep 18, 2020
-" Version: 170
+" Date: Aug 16, 2021
+" Version: 171
" Maintainer: Charles E Campbell <NcampObell@SdrPchip.AorgM-NOSPAM>
" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
" Copyright: Copyright (C) 2016 Charles E. Campbell {{{1
@@ -43,7 +43,7 @@ if exists("s:needspatches")
endfor
endif
-let g:loaded_netrw = "v170"
+let g:loaded_netrw = "v171"
if !exists("s:NOTE")
let s:NOTE = 0
let s:WARNING = 1
@@ -93,7 +93,7 @@ fun! netrw#ErrorMsg(level,msg,errnum)
else
let msg= level.a:msg
endif
- let s:popuperr_id = popup_beval(msg,{})
+ let s:popuperr_id = popup_atcursor(msg,{})
let s:popuperr_text= ""
elseif g:netrw_use_errorwindow
" (default) netrw creates a one-line window to show error/warning
@@ -322,6 +322,7 @@ call s:NetrwInit("g:netrw_banner" , 1)
call s:NetrwInit("g:netrw_browse_split", 0)
call s:NetrwInit("g:netrw_bufsettings" , "noma nomod nonu nobl nowrap ro nornu")
call s:NetrwInit("g:netrw_chgwin" , -1)
+call s:NetrwInit("g:netrw_clipboard" , 1)
call s:NetrwInit("g:netrw_compress" , "gzip")
call s:NetrwInit("g:netrw_ctags" , "ctags")
if exists("g:netrw_cursorline") && !exists("g:netrw_cursor")
@@ -331,6 +332,7 @@ endif
call s:NetrwInit("g:netrw_cursor" , 2)
let s:netrw_usercul = &cursorline
let s:netrw_usercuc = &cursorcolumn
+"call Decho("(netrw) COMBAK: cuc=".&l:cuc." cul=".&l:cul." initialization of s:netrw_cu[cl]")
call s:NetrwInit("g:netrw_cygdrive","/cygdrive")
" Default values - d-g ---------- {{{3
call s:NetrwInit("s:didstarstar",0)
@@ -1606,7 +1608,8 @@ endfun
fun! s:NetrwOptionsSave(vt)
" call Dfunc("s:NetrwOptionsSave(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname(bufnr("%")).">"." winnr($)=".winnr("$")." mod=".&mod." ma=".&ma)
" call Decho(a:vt."netrw_optionsave".(exists("{a:vt}netrw_optionsave")? ("=".{a:vt}netrw_optionsave) : " doesn't exist"),'~'.expand("<slnum>"))
-" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))
+" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt." hid=".&hid,'~'.expand("<slnum>"))
+" call Decho("(s:NetrwOptionsSave) lines=".&lines)
if !exists("{a:vt}netrw_optionsave")
let {a:vt}netrw_optionsave= 1
@@ -1632,6 +1635,9 @@ fun! s:NetrwOptionsSave(vt)
let {a:vt}netrw_cinokeep = &l:cino
let {a:vt}netrw_comkeep = &l:com
let {a:vt}netrw_cpokeep = &l:cpo
+ let {a:vt}netrw_cuckeep = &l:cuc
+ let {a:vt}netrw_culkeep = &l:cul
+" call Decho("(s:NetrwOptionsSave) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
let {a:vt}netrw_diffkeep = &l:diff
let {a:vt}netrw_fenkeep = &l:fen
if !exists("g:netrw_ffkeep") || g:netrw_ffkeep
@@ -1639,9 +1645,11 @@ fun! s:NetrwOptionsSave(vt)
endif
let {a:vt}netrw_fokeep = &l:fo " formatoptions
let {a:vt}netrw_gdkeep = &l:gd " gdefault
+ let {a:vt}netrw_gokeep = &l:go " guioptions
let {a:vt}netrw_hidkeep = &l:hidden
let {a:vt}netrw_imkeep = &l:im
let {a:vt}netrw_iskkeep = &l:isk
+ let {a:vt}netrw_lines = &lines
let {a:vt}netrw_lskeep = &l:ls
let {a:vt}netrw_makeep = &l:ma
let {a:vt}netrw_magickeep = &l:magic
@@ -1693,12 +1701,17 @@ fun! s:NetrwOptionsSafe(islocal)
endif
call s:NetrwSetSafeSetting("&l:ci",0)
call s:NetrwSetSafeSetting("&l:cin",0)
- call s:NetrwSetSafeSetting("&l:bh","hide")
+ if g:netrw_fastbrowse > a:islocal
+ call s:NetrwSetSafeSetting("&l:bh","hide")
+ else
+ call s:NetrwSetSafeSetting("&l:bh","delete")
+ endif
call s:NetrwSetSafeSetting("&l:cino","")
call s:NetrwSetSafeSetting("&l:com","")
if &cpo =~ 'a' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'a','','g')) | endif
if &cpo =~ 'A' | call s:NetrwSetSafeSetting("&cpo",substitute(&cpo,'A','','g')) | endif
setl fo=nroql2
+ call s:NetrwSetSafeSetting("&go","begmr")
call s:NetrwSetSafeSetting("&l:hid",0)
call s:NetrwSetSafeSetting("&l:im",0)
setl isk+=@ isk+=* isk+=/
@@ -1712,7 +1725,10 @@ fun! s:NetrwOptionsSafe(islocal)
call s:NetrwSetSafeSetting("&l:tw",0)
call s:NetrwSetSafeSetting("&l:wig","")
setl cedit&
- call s:NetrwCursor()
+
+ " set up cuc and cul based on g:netrw_cursor and listing style
+ " COMBAK -- cuc cul related
+ call s:NetrwCursor(0)
" allow the user to override safe options
" call Decho("ft<".&ft."> ei=".&ei,'~'.expand("<slnum>"))
@@ -1730,11 +1746,14 @@ endfun
" s:NetrwOptionsRestore: restore options (based on prior s:NetrwOptionsSave) {{{2
fun! s:NetrwOptionsRestore(vt)
" call Dfunc("s:NetrwOptionsRestore(vt<".a:vt.">) win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> winnr($)=".winnr("$"))
+" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))
if !exists("{a:vt}netrw_optionsave")
" call Decho("case ".a:vt."netrw_optionsave : doesn't exist",'~'.expand("<slnum>"))
-" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))
-" call Decho("ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
+" call Decho("..doing filetype detect anyway")
+ filetype detect
+" call Decho("..settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))
+" call Decho("..ro=".&l:ro." ma=".&l:ma." mod=".&l:mod." wrap=".&l:wrap." (filename<".expand("%")."> win#".winnr()." ft<".&ft.">)",'~'.expand("<slnum>"))
" call Dret("s:NetrwOptionsRestore : ".a:vt."netrw_optionsave doesn't exist")
return
endif
@@ -1751,41 +1770,53 @@ fun! s:NetrwOptionsRestore(vt)
endif
endif
endif
+" call Decho("(s:NetrwOptionsRestore) #1 lines=".&lines)
call s:NetrwRestoreSetting(a:vt."netrw_aikeep","&l:ai")
call s:NetrwRestoreSetting(a:vt."netrw_awkeep","&l:aw")
call s:NetrwRestoreSetting(a:vt."netrw_blkeep","&l:bl")
call s:NetrwRestoreSetting(a:vt."netrw_btkeep","&l:bt")
call s:NetrwRestoreSetting(a:vt."netrw_bombkeep","&l:bomb")
+" call Decho("(s:NetrwOptionsRestore) #2 lines=".&lines)
call s:NetrwRestoreSetting(a:vt."netrw_cedit","&cedit")
call s:NetrwRestoreSetting(a:vt."netrw_cikeep","&l:ci")
call s:NetrwRestoreSetting(a:vt."netrw_cinkeep","&l:cin")
call s:NetrwRestoreSetting(a:vt."netrw_cinokeep","&l:cino")
call s:NetrwRestoreSetting(a:vt."netrw_comkeep","&l:com")
+" call Decho("(s:NetrwOptionsRestore) #3 lines=".&lines)
call s:NetrwRestoreSetting(a:vt."netrw_cpokeep","&l:cpo")
call s:NetrwRestoreSetting(a:vt."netrw_diffkeep","&l:diff")
call s:NetrwRestoreSetting(a:vt."netrw_fenkeep","&l:fen")
if exists("g:netrw_ffkeep") && g:netrw_ffkeep
call s:NetrwRestoreSetting(a:vt."netrw_ffkeep")","&l:ff")
endif
- call s:NetrwRestoreSetting(a:vt."netrw_fokeep","&l:fo")
- call s:NetrwRestoreSetting(a:vt."netrw_gdkeep","&l:gd")
- call s:NetrwRestoreSetting(a:vt."netrw_hidkeep","&l:hidden")
- call s:NetrwRestoreSetting(a:vt."netrw_imkeep","&l:im")
- call s:NetrwRestoreSetting(a:vt."netrw_iskkeep","&l:isk")
- call s:NetrwRestoreSetting(a:vt."netrw_lskeep","&l:ls")
- call s:NetrwRestoreSetting(a:vt."netrw_makeep","&l:ma")
+" call Decho("(s:NetrwOptionsRestore) #4 lines=".&lines)
+ call s:NetrwRestoreSetting(a:vt."netrw_fokeep" ,"&l:fo")
+ call s:NetrwRestoreSetting(a:vt."netrw_gdkeep" ,"&l:gd")
+ call s:NetrwRestoreSetting(a:vt."netrw_gokeep" ,"&l:go")
+ call s:NetrwRestoreSetting(a:vt."netrw_hidkeep" ,"&l:hidden")
+" call Decho("(s:NetrwOptionsRestore) #5 lines=".&lines)
+ call s:NetrwRestoreSetting(a:vt."netrw_imkeep" ,"&l:im")
+ call s:NetrwRestoreSetting(a:vt."netrw_iskkeep" ,"&l:isk")
+" call Decho("(s:NetrwOptionsRestore) #6 lines=".&lines)
+ call s:NetrwRestoreSetting(a:vt."netrw_lines" ,"&lines")
+" call Decho("(s:NetrwOptionsRestore) #7 lines=".&lines)
+ call s:NetrwRestoreSetting(a:vt."netrw_lskeep" ,"&l:ls")
+ call s:NetrwRestoreSetting(a:vt."netrw_makeep" ,"&l:ma")
call s:NetrwRestoreSetting(a:vt."netrw_magickeep","&l:magic")
- call s:NetrwRestoreSetting(a:vt."netrw_modkeep","&l:mod")
- call s:NetrwRestoreSetting(a:vt."netrw_nukeep","&l:nu")
- call s:NetrwRestoreSetting(a:vt."netrw_rnukeep","&l:rnu")
- call s:NetrwRestoreSetting(a:vt."netrw_repkeep","&l:report")
- call s:NetrwRestoreSetting(a:vt."netrw_rokeep","&l:ro")
- call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
+ call s:NetrwRestoreSetting(a:vt."netrw_modkeep" ,"&l:mod")
+ call s:NetrwRestoreSetting(a:vt."netrw_nukeep" ,"&l:nu")
+" call Decho("(s:NetrwOptionsRestore) #8 lines=".&lines)
+ call s:NetrwRestoreSetting(a:vt."netrw_rnukeep" ,"&l:rnu")
+ call s:NetrwRestoreSetting(a:vt."netrw_repkeep" ,"&l:report")
+ call s:NetrwRestoreSetting(a:vt."netrw_rokeep" ,"&l:ro")
+ call s:NetrwRestoreSetting(a:vt."netrw_selkeep" ,"&l:sel")
+" call Decho("(s:NetrwOptionsRestore) #9 lines=".&lines)
call s:NetrwRestoreSetting(a:vt."netrw_spellkeep","&l:spell")
- call s:NetrwRestoreSetting(a:vt."netrw_twkeep","&l:tw")
- call s:NetrwRestoreSetting(a:vt."netrw_wigkeep","&l:wig")
- call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep","&l:wrap")
+ call s:NetrwRestoreSetting(a:vt."netrw_twkeep" ,"&l:tw")
+ call s:NetrwRestoreSetting(a:vt."netrw_wigkeep" ,"&l:wig")
+ call s:NetrwRestoreSetting(a:vt."netrw_wrapkeep" ,"&l:wrap")
call s:NetrwRestoreSetting(a:vt."netrw_writekeep","&l:write")
+" call Decho("(s:NetrwOptionsRestore) #10 lines=".&lines)
call s:NetrwRestoreSetting("s:yykeep","@@")
" former problem: start with liststyle=0; press <i> : result, following line resets l:ts.
" Fixed; in s:PerformListing, when w:netrw_liststyle is s:LONGLIST, will use a printf to pad filename with spaces
@@ -1827,9 +1858,11 @@ fun! s:NetrwOptionsRestore(vt)
" were having their filetype detect-generated settings overwritten by
" NetrwOptionRestore.
if &ft != "netrw"
-" call Decho("filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
+" call Decho("before: filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
filetype detect
+" call Decho("after : filetype detect (ft=".&ft.")",'~'.expand("<slnum>"))
endif
+" call Decho("(s:NetrwOptionsRestore) lines=".&lines)
" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." a:vt=".a:vt,'~'.expand("<slnum>"))
" call Dret("s:NetrwOptionsRestore : tab#".tabpagenr()." win#".winnr()." buf#".bufnr("%")."<".bufname("%")."> modified=".&modified." modifiable=".&modifiable." readonly=".&readonly)
endfun
@@ -1879,7 +1912,7 @@ fun! s:NetrwRestoreSetting(keepvar,setting)
" typically called from s:NetrwOptionsRestore
" call s:NetrwRestoreSettings(keep-option-variable-name,'associated-option')
" ex. call s:NetrwRestoreSetting(a:vt."netrw_selkeep","&l:sel")
- " Restores option (if different) from a keepvar
+ " Restores option (but only if different) from a:keepvar
if exists(a:keepvar)
exe "let keepvarval= ".a:keepvar
exe "let setting= ".a:setting
@@ -2801,14 +2834,16 @@ fun! netrw#SetTreetop(iscmd,...)
" call Decho("inittreetop<".(exists("inittreetop")? inittreetop : "n/a").">")
if (a:iscmd == 0 || a:1 == "") && exists("inittreetop")
- let treedir= s:NetrwTreePath(inittreetop)
+ let treedir = s:NetrwTreePath(inittreetop)
" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
else
if isdirectory(s:NetrwFile(a:1))
" call Decho("a:1<".a:1."> is a directory",'~'.expand("<slnum>"))
- let treedir= a:1
+ let treedir = a:1
+ let s:netrw_treetop = treedir
elseif exists("b:netrw_curdir") && (isdirectory(s:NetrwFile(b:netrw_curdir."/".a:1)) || a:1 =~ '^\a\{3,}://')
- let treedir= b:netrw_curdir."/".a:1
+ let treedir = b:netrw_curdir."/".a:1
+ let s:netrw_treetop = treedir
" call Decho("a:1<".a:1."> is NOT a directory, using treedir<".treedir.">",'~'.expand("<slnum>"))
else
" normally the cursor is left in the message window.
@@ -2816,7 +2851,8 @@ fun! netrw#SetTreetop(iscmd,...)
let netrwbuf= bufnr("%")
call netrw#ErrorMsg(s:ERROR,"sorry, ".a:1." doesn't seem to be a directory!",95)
exe bufwinnr(netrwbuf)."wincmd w"
- let treedir= "."
+ let treedir = "."
+ let s:netrw_treetop = getcwd()
endif
endif
" call Decho("treedir<".treedir.">",'~'.expand("<slnum>"))
@@ -4071,6 +4107,7 @@ fun! s:NetrwFileInfo(islocal,fname)
elseif g:netrw_sizestyle =~# 'h'
let lsopt= "-lsadh --si"
endif
+" call Decho("(s:NetrwFileInfo) lsopt<".lsopt.">")
if (has("unix") || has("macunix")) && executable("/bin/ls")
if getline(".") == "../"
@@ -4132,9 +4169,10 @@ endfun
" s:NetrwGetBuffer: [get a new|find an old netrw] buffer for a netrw listing {{{2
" returns 0=cleared buffer
" 1=re-used buffer (buffer not cleared)
+" Nov 09, 2020: tst952 shows that when user does :set hidden that NetrwGetBuffer will come up with a [No Name] buffer (hid fix)
fun! s:NetrwGetBuffer(islocal,dirname)
" call Dfunc("s:NetrwGetBuffer(islocal=".a:islocal." dirname<".a:dirname.">) liststyle=".g:netrw_liststyle)
-" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo,'~'.expand("<slnum>"))
+" call Decho("settings buf#".bufnr("%")."<".bufname("%").">: ".((&l:ma == 0)? "no" : "")."ma ".((&l:mod == 0)? "no" : "")."mod ".((&l:bl == 0)? "no" : "")."bl ".((&l:ro == 0)? "no" : "")."ro fo=".&l:fo." hid=".&hid,'~'.expand("<slnum>"))
" call Decho("netrwbuf dictionary=".(exists("s:netrwbuf")? string(s:netrwbuf) : 'n/a'),'~'.expand("<slnum>"))
" call Dredir("ls!","s:NetrwGetBuffer")
let dirname= a:dirname
@@ -4184,17 +4222,26 @@ fun! s:NetrwGetBuffer(islocal,dirname)
endif
" call Decho(" bufnum#".bufnum,'~'.expand("<slnum>"))
- " highjack the current buffer if
- " it has the desired name
- " it is empty
-" call Decho("deciding if I can highjack the current buffer#".bufnr("%"),'~'.expand("<slnum>"))
-" call Decho("..dirname<".dirname.">",'~'.expand("<slnum>"))
-" call Decho("..bufname<".bufname("%").">",'~'.expand("<slnum>"))
-" call Decho("..getline($)<".getline("$").">",'~'.expand("<slnum>"))
- if dirname == bufname("%") && line("$") == 1 && getline("%") == ""
+ " hijack the current buffer
+ " IF the buffer already has the desired name
+ " AND it is empty
+ let curbuf = bufname("%")
+ if curbuf == '.'
+ let curbuf = getcwd()
+ endif
+" call Dredir("ls!","NetrwGetFile (renamed buffer back to remote filename<".rfile."> : expand(%)<".expand("%").">)")
+" call Decho("deciding if netrw may hijack the current buffer#".bufnr("%")."<".curbuf.">",'~'.expand("<slnum>"))
+" call Decho("..dirname<".dirname."> IF dirname == bufname",'~'.expand("<slnum>"))
+" call Decho("..curbuf<".curbuf.">",'~'.expand("<slnum>"))
+" call Decho("..line($)=".line("$")." AND this is 1",'~'.expand("<slnum>"))
+" call Decho("..getline(%)<".getline("%")."> AND this line is empty",'~'.expand("<slnum>"))
+ if dirname == curbuf && line("$") == 1 && getline("%") == ""
" call Dret("s:NetrwGetBuffer 0<cleared buffer> : highjacking buffer#".bufnr("%"))
return 0
+ else " DEBUG
+" call Decho("..did NOT hijack buffer",'~'.expand("<slnum>"))
endif
+ " Aug 14, 2021: was thinking about looking for a [No Name] buffer here and using it, but that might cause problems
" get enew buffer and name it -or- re-use buffer {{{3
if bufnum < 0 " get enew buffer and name it
@@ -4519,7 +4566,7 @@ fun! s:NetrwListStyle(islocal)
" refresh the listing
" call Decho("refresh the listing",'~'.expand("<slnum>"))
NetrwKeepj call s:NetrwRefresh(a:islocal,s:NetrwBrowseChgDir(a:islocal,'./'))
- NetrwKeepj call s:NetrwCursor()
+ NetrwKeepj call s:NetrwCursor(0)
" repoint t:netrw_lexbufnr if appropriate
if exists("repointlexbufnr")
@@ -4725,7 +4772,7 @@ fun! s:NetrwBrowseChgDir(islocal,newdir,...)
endif
" call Decho("b:netrw_curdir<".b:netrw_curdir.">")
- " NetrwBrowseChgDir: save options and initialize {{{3
+ " NetrwBrowseChgDir; save options and initialize {{{3
" call Decho("saving options",'~'.expand("<slnum>"))
call s:SavePosn(s:netrw_posn)
NetrwKeepj call s:NetrwOptionsSave("s:")
@@ -4793,6 +4840,8 @@ fun! s:NetrwBrowseChgDir(islocal,newdir,...)
if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST && exists("w:netrw_treedict") && newdir !~ '^\(/\|\a:\)'
" call Decho("edit-a-file: handle tree listing: w:netrw_treedict<".(exists("w:netrw_treedict")? string(w:netrw_treedict) : 'n/a').">",'~'.expand("<slnum>"))
" call Decho("edit-a-file: newdir<".newdir.">",'~'.expand("<slnum>"))
+" let newdir = s:NetrwTreePath(s:netrw_treetop)
+" call Decho("edit-a-file: COMBAK why doesn't this recognize file1's directory???")
let dirname= s:NetrwTreeDir(a:islocal)
"COMBAK : not working for a symlink -- but what about a regular file? a directory?
" call Decho("COMBAK : not working for a symlink -- but what about a regular file? a directory?")
@@ -4906,7 +4955,8 @@ fun! s:NetrwBrowseChgDir(islocal,newdir,...)
exe "NetrwKeepj e ".fnameescape(dirname)
endif
" call Decho("edit-a-file: after e! ".dirname.": hidden=".&hidden." bufhidden<".&bufhidden."> mod=".&mod,'~'.expand("<slnum>"))
- call s:NetrwCursor()
+ " COMBAK -- cuc cul related
+ call s:NetrwCursor(1)
if &hidden || &bufhidden == "hide"
" file came from vim's hidden storage. Don't "restore" options with it.
let dorestore= 0
@@ -4927,8 +4977,8 @@ fun! s:NetrwBrowseChgDir(islocal,newdir,...)
elseif type(g:Netrw_funcref) == 3
" call Decho("edit-a-file: handling a list of g:Netrw_funcrefs",'~'.expand("<slnum>"))
for Fncref in g:Netrw_funcref
- if type(FncRef) == 2
- NetrwKeepj call FncRef()
+ if type(Fncref) == 2
+ NetrwKeepj call Fncref()
endif
endfor
endif
@@ -5220,6 +5270,12 @@ fun! netrw#BrowseX(fname,remote)
endif
" call Decho("not a local file nor a webpage request",'~'.expand("<slnum>"))
+ if exists("g:netrw_browsex_viewer") && exists("g:netrw_browsex_support_remote") && !g:netrw_browsex_support_remote
+ let remote = a:remote
+ else
+ let remote = 0
+ endif
+
let ykeep = @@
let screenposn = winsaveview()
" call Decho("saving posn to screenposn<".string(screenposn).">",'~'.expand("<slnum>"))
@@ -5264,9 +5320,9 @@ fun! netrw#BrowseX(fname,remote)
endif
" call Decho("exten<".exten.">",'~'.expand("<slnum>"))
- if a:remote == 1
+ if remote == 1
" create a local copy
-" call Decho("remote: a:remote=".a:remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
+" call Decho("remote: remote=".remote.": create a local copy of <".a:fname.">",'~'.expand("<slnum>"))
setl bh=delete
call netrw#NetRead(3,a:fname)
" attempt to rename tempfile
@@ -5288,7 +5344,7 @@ fun! netrw#BrowseX(fname,remote)
let fname= s:netrw_tmpfile
endif
else
-" call Decho("local: a:remote=".a:remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
+" call Decho("local: remote=".remote.": handling local copy of <".a:fname.">",'~'.expand("<slnum>"))
let fname= a:fname
" special ~ handler for local
if fname =~ '^\~' && expand("$HOME") != ""
@@ -5382,8 +5438,8 @@ fun! netrw#BrowseX(fname,remote)
if a:fname =~ '^https\=://'
" atril does not appear to understand how to handle html -- so use gvim to edit the document
let use_ctrlo= 0
-" call Decho("(COMBAK) fname<".fname.">")
-" call Decho("(COMBAK) a:fname<".a:fname.">")
+" call Decho("fname<".fname.">")
+" call Decho("a:fname<".a:fname.">")
call s:NetrwExe("sil! !gvim ".fname.' -c "keepj keepalt file '.fnameescape(a:fname).'"')
else
@@ -5431,12 +5487,12 @@ fun! netrw#BrowseX(fname,remote)
" return to prior buffer (directory listing)
" Feb 12, 2008: had to de-activiate removal of
" temporary file because it wasn't getting seen.
-" if a:remote == 1 && fname != a:fname
+" if remote == 1 && fname != a:fname
"" call Decho("deleting temporary file<".fname.">",'~'.expand("<slnum>"))
" call s:NetrwDelete(fname)
" endif
- if a:remote == 1
+ if remote == 1
setl bh=delete bt=nofile
if g:netrw_use_noswf
setl noswf
@@ -5495,7 +5551,7 @@ fun! s:NetrwBufRename(newname)
let b:junk= 1
" call Decho("rename buffer: sil! keepj keepalt file ".fnameescape(a:newname),'~'.expand("<slnum>"))
exe 'sil! keepj keepalt file '.fnameescape(a:newname)
-" call Dredir("ls!","s:NetrwBufRename (before bwipe)")
+" call Dredir("ls!","s:NetrwBufRename (before bwipe)~".expand("<slnum>"))
let oldbufnr= bufnr(oldbufname)
" call Decho("oldbufname<".oldbufname."> oldbufnr#".oldbufnr,'~'.expand("<slnum>"))
" call Decho("bufnr(%)=".bufnr("%"),'~'.expand("<slnum>"))
@@ -5504,6 +5560,9 @@ fun! s:NetrwBufRename(newname)
exe "bwipe! ".oldbufnr
" else " Decho
" call Decho("did *not* bwipe buf#".oldbufnr,'~'.expand("<slnum>"))
+" call Decho("..reason: if oldbufname<".oldbufname."> is empty",'~'.expand("<slnum>"))"
+" call Decho("..reason: if oldbufnr#".oldbufnr." is -1",'~'.expand("<slnum>"))"
+" call Decho("..reason: if oldbufnr#".oldbufnr." != bufnr(%)#".bufnr("%"),'~'.expand("<slnum>"))"
endif
" call Dredir("ls!","s:NetrwBufRename (after rename)")
" else " Decho
@@ -6482,7 +6541,7 @@ fun! s:NetrwMaps(islocal)
if !hasmapto('<Plug>NetrwRefresh')
nmap <buffer> <unique> <c-l> <Plug>NetrwRefresh
endif
- nnoremap <buffer> <silent> <Plug>NetrwRefresh <c-l>:call <SID>NetrwRefresh(1,<SID>NetrwBrowseChgDir(1,(w:netrw_liststyle == 3)? w:netrw_treetop : './'))<cr>
+ nnoremap <buffer> <silent> <Plug>NetrwRefresh <c-l>:call <SID>NetrwRefresh(1,<SID>NetrwBrowseChgDir(1,(exists("w:netrw_liststyle") && exists("w:netrw_treetop") && w:netrw_liststyle == 3)? w:netrw_treetop : './'))<cr>
if s:didstarstar || !mapcheck("<s-down>","n")
nnoremap <buffer> <silent> <s-down> :Nexplore<cr>
endif
@@ -6731,7 +6790,7 @@ fun! s:NetrwMarkFile(islocal,fname)
" sanity check
if empty(a:fname)
-" call Dret("s:NetrwMarkFile : emtpy fname")
+" call Dret("s:NetrwMarkFile : empty fname")
return
endif
let curdir = s:NetrwGetCurdir(a:islocal)
@@ -8110,6 +8169,23 @@ fun! s:NetrwOpenFile(islocal)
call inputsave()
let fname= input("Enter filename: ")
call inputrestore()
+" call Decho("(s:NetrwOpenFile) fname<".fname.">",'~'.expand("<slnum>"))
+
+ " determine if Lexplore is in use
+ if exists("t:netrw_lexbufnr")
+ " check if t:netrw_lexbufnr refers to a netrw window
+" call Decho("(s:netrwOpenFile) ..t:netrw_lexbufnr=".t:netrw_lexbufnr,'~'.expand("<slnum>"))
+ let lexwinnr = bufwinnr(t:netrw_lexbufnr)
+ if lexwinnr != -1 && exists("g:netrw_chgwin") && g:netrw_chgwin != -1
+" call Decho("(s:netrwOpenFile) ..Lexplore in use",'~'.expand("<slnum>"))
+ exe "NetrwKeepj keepalt ".g:netrw_chgwin."wincmd w"
+ exe "NetrwKeepj e ".fnameescape(fname)
+ let @@= ykeep
+" call Dret("s:NetrwOpenFile : creating a file with Lexplore mode")
+ endif
+ endif
+
+ " Does the filename contain a path?
if fname !~ '[/\\]'
if exists("b:netrw_curdir")
if exists("g:netrw_quiet")
@@ -8448,6 +8524,7 @@ fun! s:NetrwPrevWinOpen(islocal)
let lastwinnr = winnr("$")
let curword = s:NetrwGetWord()
let choice = 0
+ let s:prevwinopen= 1 " lets s:NetrwTreeDir() know that NetrwPrevWinOpen called it
let s:treedir = s:NetrwTreeDir(a:islocal)
let curdir = s:treedir
" call Decho("winnr($)#".lastwinnr." curword<".curword.">",'~'.expand("<slnum>"))
@@ -8775,7 +8852,7 @@ fun! s:NetrwPreview(path) range
" 0 : 1: top -- preview window is horizontally split off and on the top
" 0 : 0: bot -- preview window is horizontally split off and on the bottom
"
- " Note that the file being previewed is already known to not be a directory, hence we can avoid doing a LocalBrowse() check via
+ " Note that the file being previewed is already known to not be a directory, hence we can avoid doing a LocalBrowseCheck() check via
" the BufEnter event set up in netrwPlugin.vim
" call Decho("exe ".(g:netrw_alto? "top " : "bot ").(g:netrw_preview? "vert " : "")."pedit ".fnameescape(a:path),'~'.expand("<slnum>"))
let eikeep = &ei
@@ -9210,14 +9287,20 @@ fun! s:NetrwTreeDir(islocal)
" call Decho("g:netrw_keepdir =".(exists("g:netrw_keepdir")? g:netrw_keepdir : 'n/a'),'~'.expand("<slnum>"))
" call Decho("w:netrw_liststyle=".(exists("w:netrw_liststyle")? w:netrw_liststyle : 'n/a'),'~'.expand("<slnum>"))
" call Decho("w:netrw_treetop =".(exists("w:netrw_treetop")? w:netrw_treetop : 'n/a'),'~'.expand("<slnum>"))
+" call Decho("current line<".getline(".").">")
- if exists("s:treedir")
+ if exists("s:treedir") && exists("s:prevwinopen")
" s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early
+" call Decho('s:NetrwPrevWinOpen opens a "previous" window -- and thus needs to and does call s:NetrwTreeDir early')
let treedir= s:treedir
unlet s:treedir
-" call Dret("s:NetrwTreeDir ".treedir)
+ unlet s:prevwinopen
+" call Dret("s:NetrwTreeDir ".treedir.": early return since s:treedir existed previously")
return treedir
endif
+ if exists("s:prevwinopen")
+ unlet s:prevwinopen
+ endif
if !exists("b:netrw_curdir") || b:netrw_curdir == ""
let b:netrw_curdir= getcwd()
@@ -9424,20 +9507,29 @@ endfun
" Called by s:PerformListing()
fun! s:NetrwTreeListing(dirname)
if exists("w:netrw_liststyle") && w:netrw_liststyle == s:TREELIST
-" call Dfunc("NetrwTreeListing() bufname<".expand("%").">")
+" call Dfunc("s:NetrwTreeListing() bufname<".expand("%").">")
" call Decho("curdir<".a:dirname.">",'~'.expand("<slnum>"))
" call Decho("win#".winnr().": w:netrw_treetop ".(exists("w:netrw_treetop")? "exists" : "doesn't exist")." w:netrw_treedict ".(exists("w:netrw_treedict")? "exists" : "doesn't exit"),'~'.expand("<slnum>"))
" call Decho("g:netrw_banner=".g:netrw_banner.": banner ".(g:netrw_banner? "enabled" : "suppressed").": (line($)=".line("$")." byte2line(1)=".byte2line(1)." bannercnt=".w:netrw_bannercnt.")",'~'.expand("<slnum>"))
" update the treetop
-" call Decho("update the treetop",'~'.expand("<slnum>"))
if !exists("w:netrw_treetop")
+" call Decho("update the treetop (w:netrw_treetop doesn't exist yet)",'~'.expand("<slnum>"))
let w:netrw_treetop= a:dirname
+ let s:netrw_treetop= w:netrw_treetop
" call Decho("w:netrw_treetop<".w:netrw_treetop."> (reusing)",'~'.expand("<slnum>"))
elseif (w:netrw_treetop =~ ('^'.a:dirname) && s:Strlen(a:dirname) < s:Strlen(w:netrw_treetop)) || a:dirname !~ ('^'.w:netrw_treetop)
+" call Decho("update the treetop (override w:netrw_treetop with a:dirname<".a:dirname.">)",'~'.expand("<slnum>"))
let w:netrw_treetop= a:dirname
+ let s:netrw_treetop= w:netrw_treetop
" call Decho("w:netrw_treetop<".w:netrw_treetop."> (went up)",'~'.expand("<slnum>"))
endif
+ if exists("w:netrw_treetop")
+ let s:netrw_treetop= w:netrw_treetop
+ else
+ let w:netrw_treetop= getcwd()
+ let s:netrw_treetop= w:netrw_treetop
+ endif
if !exists("w:netrw_treedict")
" insure that we have a treedict, albeit empty
@@ -9475,7 +9567,7 @@ fun! s:NetrwTreeListing(dirname)
exe "setl ".g:netrw_bufsettings
-" call Dret("NetrwTreeListing : bufname<".expand("%").">")
+" call Dret("s:NetrwTreeListing : bufname<".expand("%").">")
return
endif
endfun
@@ -10619,7 +10711,7 @@ endfun
" ---------------------------------------------------------------------
" netrw#LocalBrowseCheck: {{{2
fun! netrw#LocalBrowseCheck(dirname)
- " This function is called by netrwPlugin.vim's s:LocalBrowse(), s:NetrwRexplore(),
+ " This function is called by netrwPlugin.vim's s:LocalBrowseCheck(), s:NetrwRexplore(),
" and by <cr> when atop a listed file/directory (via a buffer-local map)
"
" unfortunate interaction -- split window debugging can't be used here, must use
@@ -10770,7 +10862,7 @@ endfun
" Hiding a buffer means that it will be re-used when examined, hence "fast".
" (re-using a buffer may not be as accurate)
"
-" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds whena med or fast browsing
+" s:netrw_events : doesn't exist, s:LocalFastBrowser() will install autocmds with medium-speed or fast browsing
" =1: autocmds installed, but ignore next FocusGained event to avoid initial double-refresh of listing.
" BufEnter may be first event, then a FocusGained event. Ignore the first FocusGained event.
" If :Explore used: it sets s:netrw_events to 2, so no FocusGained events are ignored.
@@ -10932,13 +11024,14 @@ fun! s:LocalListing()
let sz= s:NetrwHumanReadable(sz)
endif
let longfile= printf("%-".(g:netrw_maxfilenamelen+1)."s",pfile)
- let pfile = longfile.fsz." ".strftime(g:netrw_timefmt,getftime(filename))
+ let pfile = longfile.sz." ".strftime(g:netrw_timefmt,getftime(filename))
" call Decho("longlist support: sz=".sz." fsz=".fsz,'~'.expand("<slnum>"))
endif
if g:netrw_sort_by =~# "^t"
" sort by time (handles time up to 1 quintillion seconds, US)
" Decorate listing by prepending a timestamp/ . Sorting will then be done based on time.
+" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (time)")
" call Decho("getftime(".filename.")=".getftime(filename),'~'.expand("<slnum>"))
let t = getftime(filename)
let ft = strpart("000000000000000000",1,18-strlen(t)).t
@@ -10948,6 +11041,7 @@ fun! s:LocalListing()
elseif g:netrw_sort_by =~ "^s"
" sort by size (handles file sizes up to 1 quintillion bytes, US)
+" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (size)")
" call Decho("getfsize(".filename.")=".getfsize(filename),'~'.expand("<slnum>"))
let sz = getfsize(filename)
if g:netrw_sizestyle =~# "[hH]"
@@ -10960,6 +11054,7 @@ fun! s:LocalListing()
else
" sort by name
+" call Decho("implementing g:netrw_sort_by=".g:netrw_sort_by." (name)")
" call Decho("exe NetrwKeepj put ='".pfile."'",'~'.expand("<slnum>"))
sil! NetrwKeepj put=pfile
endif
@@ -11682,19 +11777,32 @@ endfun
" ---------------------------------------------------------------------
" s:NetrwCursor: responsible for setting cursorline/cursorcolumn based upon g:netrw_cursor {{{2
-fun! s:NetrwCursor()
+fun! s:NetrwCursor(editfile)
if !exists("w:netrw_liststyle")
let w:netrw_liststyle= g:netrw_liststyle
endif
" call Dfunc("s:NetrwCursor() ft<".&ft."> liststyle=".w:netrw_liststyle." g:netrw_cursor=".g:netrw_cursor." s:netrw_usercuc=".s:netrw_usercuc." s:netrw_usercul=".s:netrw_usercul)
+" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
+
if &ft != "netrw"
" if the current window isn't a netrw directory listing window, then use user cursorline/column
" settings. Affects when netrw is used to read/write a file using scp/ftp/etc.
" call Decho("case ft!=netrw: use user cul,cuc",'~'.expand("<slnum>"))
- let &l:cursorline = s:netrw_usercul
- let &l:cursorcolumn = s:netrw_usercuc
+ elseif g:netrw_cursor == 8
+ if w:netrw_liststyle == s:WIDELIST
+ setl cursorline
+ setl cursorcolumn
+ else
+ setl cursorline
+ endif
+ elseif g:netrw_cursor == 7
+ setl cursorline
+ elseif g:netrw_cursor == 6
+ if w:netrw_liststyle == s:WIDELIST
+ setl cursorline
+ endif
elseif g:netrw_cursor == 4
" all styles: cursorline, cursorcolumn
" call Decho("case g:netrw_cursor==4: setl cul cuc",'~'.expand("<slnum>"))
@@ -11711,26 +11819,22 @@ fun! s:NetrwCursor()
else
" call Decho("case g:netrw_cursor==3 and not wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
setl cursorline
- let &l:cursorcolumn = s:netrw_usercuc
endif
elseif g:netrw_cursor == 2
" thin-long-tree: cursorline, user's cursorcolumn
" wide : cursorline, user's cursorcolumn
" call Decho("case g:netrw_cursor==2: setl cuc (use user's cul)",'~'.expand("<slnum>"))
- let &l:cursorcolumn = s:netrw_usercuc
setl cursorline
elseif g:netrw_cursor == 1
" thin-long-tree: user's cursorline, user's cursorcolumn
" wide : cursorline, user's cursorcolumn
- let &l:cursorcolumn = s:netrw_usercuc
if w:netrw_liststyle == s:WIDELIST
" call Decho("case g:netrw_cursor==2 and wide: setl cul (use user's cuc)",'~'.expand("<slnum>"))
setl cursorline
else
" call Decho("case g:netrw_cursor==2 and not wide: (use user's cul,cuc)",'~'.expand("<slnum>"))
- let &l:cursorline = s:netrw_usercul
endif
else
@@ -11740,6 +11844,7 @@ fun! s:NetrwCursor()
let &l:cursorcolumn = s:netrw_usercuc
endif
+" call Decho("(s:NetrwCursor) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
" call Dret("s:NetrwCursor : l:cursorline=".&l:cursorline." l:cursorcolumn=".&l:cursorcolumn)
endfun
@@ -11753,6 +11858,7 @@ fun! s:RestoreCursorline()
if exists("s:netrw_usercuc")
let &l:cursorcolumn = s:netrw_usercuc
endif
+" call Decho("(s:RestoreCursorline) COMBAK: cuc=".&l:cuc." cul=".&l:cul)
" call Dret("s:RestoreCursorline : restored cul=".&l:cursorline." cuc=".&l:cursorcolumn)
endfun
@@ -11788,11 +11894,37 @@ fun! s:NetrwDelete(path)
endfun
" ---------------------------------------------------------------------
+" s:NetrwBufRemover: removes a buffer that: {{{2s
+" has buffer-id > 1
+" is unlisted
+" is unnamed
+" does not appear in any window
+fun! s:NetrwBufRemover(bufid)
+" call Dfunc("s:NetrwBufRemover(".a:bufid.")")
+" call Decho("buf#".a:bufid." ".((a:bufid > 1)? ">" : "≯")." must be >1 for removal","~".expand("<slnum>"))
+" call Decho("buf#".a:bufid." is ".(buflisted(a:bufid)? "listed" : "unlisted"),"~".expand("<slnum>"))
+" call Decho("buf#".a:bufid." has name <".bufname(a:bufid).">","~".expand("<slnum>"))
+" call Decho("buf#".a:bufid." has winid#".bufwinid(a:bufid),"~".expand("<slnum>"))
+
+ if a:bufid > 1 && !buflisted(a:bufid) && bufname(a:bufid) == "" && bufwinid(a:bufid) == -1
+" call Decho("(s:NetrwBufRemover) removing buffer#".a:bufid,"~".expand("<slnum>"))
+ exe "bd! ".a:bufid
+ endif
+
+" call Dret("s:NetrwBufRemover")
+endfun
+
+" ---------------------------------------------------------------------
" s:NetrwEnew: opens a new buffer, passes netrw buffer variables through {{{2
fun! s:NetrwEnew(...)
" call Dfunc("s:NetrwEnew() a:0=".a:0." win#".winnr()." winnr($)=".winnr("$")." bufnr($)=".bufnr("$")." expand(%)<".expand("%").">")
" call Decho("curdir<".((a:0>0)? a:1 : "")."> buf#".bufnr("%")."<".bufname("%").">",'~'.expand("<slnum>"))
+ " Clean out the last buffer:
+ " Check if the last buffer has # > 1, is unlisted, is unnamed, and does not appear in a window
+ " If so, delete it.
+ call s:NetrwBufRemover(bufnr("$"))
+
" grab a function-local-variable copy of buffer variables
" call Decho("make function-local copy of netrw variables",'~'.expand("<slnum>"))
if exists("b:netrw_bannercnt") |let netrw_bannercnt = b:netrw_bannercnt |endif
diff --git a/runtime/autoload/netrwSettings.vim b/runtime/autoload/netrwSettings.vim
index bed5cfc455..61c0ef739e 100644
--- a/runtime/autoload/netrwSettings.vim
+++ b/runtime/autoload/netrwSettings.vim
@@ -1,7 +1,7 @@
" netrwSettings.vim: makes netrw settings simpler
-" Date: Nov 09, 2016
+" Date: Aug 12, 2021
" Maintainer: Charles E Campbell <NcampObell@SdrPchip.AorgM-NOSPAM>
-" Version: 16
+" Version: 17 ASTRO-ONLY
" Copyright: Copyright (C) 1999-2007 Charles E. Campbell {{{1
" Permission is hereby granted to use and distribute this code,
" with or without modifications, provided that this copyright
@@ -19,7 +19,7 @@
if exists("g:loaded_netrwSettings") || &cp
finish
endif
-let g:loaded_netrwSettings = "v16"
+let g:loaded_netrwSettings = "v17"
if v:version < 700
echohl WarningMsg
echo "***warning*** this version of netrwSettings needs vim 7.0"
@@ -31,7 +31,7 @@ endif
" NetrwSettings: {{{1
fun! netrwSettings#NetrwSettings()
" this call is here largely just to insure that netrw has been loaded
- call netrw#SavePosn()
+ call netrw#WinPath("")
if !exists("g:loaded_netrw")
echohl WarningMsg | echomsg "***sorry*** netrw needs to be loaded prior to using NetrwSettings" | echohl None
return
diff --git a/runtime/autoload/phpcomplete.vim b/runtime/autoload/phpcomplete.vim
index 377baa8432..f9aa15c827 100644
--- a/runtime/autoload/phpcomplete.vim
+++ b/runtime/autoload/phpcomplete.vim
@@ -9,7 +9,7 @@
"
" let g:phpcomplete_relax_static_constraint = 1/0 [default 0]
" Enables completion for non-static methods when completing for static context (::).
-" This generates E_STRICT level warning, but php calls these methods nontheless.
+" This generates E_STRICT level warning, but php calls these methods nonetheless.
"
" let g:phpcomplete_complete_for_unknown_classes = 1/0 [default 0]
" Enables completion of variables and functions in "everything under the sun" fashion
@@ -28,7 +28,7 @@
" This option controls the number of characters the user needs to type before
" the tags will be searched for namespaces and classes in typed out namespaces in
" "use ..." context. Setting this to 0 is not recommended because that means the code
-" have to scan every tag, and vim's taglist() function runs extremly slow with a
+" have to scan every tag, and vim's taglist() function runs extremely slow with a
" "match everything" pattern.
"
" let g:phpcomplete_parse_docblock_comments = 1/0 [default 0]
@@ -268,7 +268,7 @@ function! phpcomplete#CompleteUse(base) " {{{
call add(no_namespace_matches, {'word': namespace_for_class.'\'.tag.name, 'kind': tag.kind, 'menu': tag.filename, 'info': tag.filename })
endif
endfor
- " if it seems that the tags file have namespace informations we can safely throw
+ " if it seems that the tags file have namespace information we can safely throw
" away namespaceless tag matches since we can be sure they are invalid
if patched_ctags_detected
no_namespace_matches = []
@@ -810,7 +810,7 @@ function! phpcomplete#CompleteClassName(base, kinds, current_namespace, imports)
endif
endfor
- " resolve the typed in part with namespaces (if theres a \ in it)
+ " resolve the typed in part with namespaces (if there's a \ in it)
let [tag_match_pattern, namespace_for_class] = phpcomplete#ExpandClassName(a:base, a:current_namespace, a:imports)
let tags = []
@@ -926,11 +926,11 @@ function! s:getNextCharWithPos(filelines, current_pos) " {{{
endfunction " }}}
function! phpcomplete#EvaluateModifiers(modifiers, required_modifiers, prohibited_modifiers) " {{{
- " if theres no modifier, and no modifier is allowed and no modifier is required
+ " if there's no modifier, and no modifier is allowed and no modifier is required
if len(a:modifiers) == 0 && len(a:required_modifiers) == 0
return 1
else
- " check if every requred modifier is present
+ " check if every required modifier is present
for required_modifier in a:required_modifiers
if index(a:modifiers, required_modifier) == -1
return 0
@@ -1258,7 +1258,7 @@ function! phpcomplete#GetCurrentInstruction(line_number, col_number, phpbegin) "
endif
endif
- " save the coma position for later use if theres a "naked" , possibly separating a parameter and it is not in a parented part
+ " save the coma position for later use if there's a "naked" , possibly separating a parameter and it is not in a parented part
if first_coma_break_pos == -1 && current_char == ','
let first_coma_break_pos = len(instruction)
endif
@@ -1304,7 +1304,7 @@ function! phpcomplete#GetCurrentInstruction(line_number, col_number, phpbegin) "
" there were a "naked" coma in the instruction
if first_coma_break_pos != -1
- if instruction !~? '^use' && instruction !~? '^class' " use ... statements and class delcarations should not be broken up by comas
+ if instruction !~? '^use' && instruction !~? '^class' " use ... statements and class declarations should not be broken up by comas
let pos = (-1 * first_coma_break_pos) + 1
let instruction = instruction[pos :]
endif
@@ -1316,7 +1316,7 @@ function! phpcomplete#GetCurrentInstruction(line_number, col_number, phpbegin) "
" clear everything up until the first (
let instruction = substitute(instruction, '^\(if\|while\|foreach\|for\)\s*(\s*', '', '')
- " lets iterate trough the instruction until we can find the pair for the opening (
+ " lets iterate through the instruction until we can find the pair for the opening (
let i = 0
let depth = 1
while i < len(instruction)
@@ -1424,7 +1424,7 @@ function! phpcomplete#GetCallChainReturnType(classname_candidate, class_candidat
let parts = split(substitute(type, '^\\', '', ''), '\')
let class_candidate_namespace = join(parts[0:-2], '\')
let classname_candidate = parts[-1]
- " check for renamed namepsace in imports
+ " check for renamed namespace in imports
if has_key(classstructure.imports, class_candidate_namespace)
let class_candidate_namespace = classstructure.imports[class_candidate_namespace].name
endif
@@ -2023,7 +2023,7 @@ function! phpcomplete#GetCachedClassContents(classlocation, class_name) " {{{
if getftime(classstructure.file) != classstructure.mtime
let valid = 0
" we could break here, but the time required for checking probably worth
- " the the memory we can free by checking every file in the cached hirearchy
+ " the memory we can free by checking every file in the cached hierarchy
call phpcomplete#ClearCachedClassContents(classstructure.file)
endif
endfor
@@ -2037,7 +2037,7 @@ function! phpcomplete#GetCachedClassContents(classlocation, class_name) " {{{
call remove(s:cache_classstructures, cache_key)
call phpcomplete#ClearCachedClassContents(full_file_path)
- " fall trough for the read from files path
+ " fall through for the read from files path
endif
else
call phpcomplete#ClearCachedClassContents(full_file_path)
@@ -2590,7 +2590,7 @@ function! phpcomplete#GetCurrentNameSpace(file_lines) " {{{
let search_line = line
let use_line = line
- " add lines from the file until theres no ';' in them
+ " add lines from the file until there's no ';' in them
while search_line !~? ';' && l > 0
" file lines are reversed so we need to go backwards
let l -= 1
@@ -2622,7 +2622,7 @@ function! phpcomplete#GetCurrentNameSpace(file_lines) " {{{
" find kind flags from tags or built in methods for the objects we extracted
" they can be either classes, interfaces or namespaces, no other thing is importable in php
for [key, import] in items(imports)
- " if theres a \ in the name we have it's definitely not a built in thing, look for tags
+ " if there's a \ in the name we have it's definitely not a built in thing, look for tags
if import.name =~ '\\'
let patched_ctags_detected = 0
let [classname, namespace_for_classes] = phpcomplete#ExpandClassName(import.name, '\', {})
@@ -2679,10 +2679,10 @@ function! phpcomplete#GetCurrentNameSpace(file_lines) " {{{
let import['kind'] = 'i'
let import['builtin'] = 1
else
- " or can be a tag with exactly matchign name
+ " or can be a tag with exactly matching name
let tags = phpcomplete#GetTaglist('^'.import['name'].'$')
for tag in tags
- " search for the first matchin namespace, class, interface with no namespace
+ " search for the first matching namespace, class, interface with no namespace
if !has_key(tag, 'namespace') && (tag.kind == 'n' || tag.kind == 'c' || tag.kind == 'i' || tag.kind == 't')
call extend(import, tag)
let import['builtin'] = 0
@@ -2900,7 +2900,7 @@ for [ext, data] in items(php_builtin['functions'])
call extend(g:php_builtin_functions, data)
endfor
-" Built in classs
+" Built in class
let g:php_builtin_classes = {}
for [ext, data] in items(php_builtin['classes'])
call extend(g:php_builtin_classes, data)
@@ -2918,10 +2918,10 @@ for [ext, data] in items(php_builtin['constants'])
call extend(g:php_constants, data)
endfor
-" When the classname not found or found but the tags dosen't contain that
-" class we will try to complate any method of any builtin class. To speed up
+" When the classname not found or found but the tags doesn't contain that
+" class we will try to complete any method of any builtin class. To speed up
" that lookup we compile a 'ClassName::MethodName':'info' dictionary from the
-" builtin class informations
+" builtin class information
let g:php_builtin_object_functions = {}
" When completing for 'everyting imaginable' (no class context, not a
diff --git a/runtime/autoload/provider/clipboard.vim b/runtime/autoload/provider/clipboard.vim
index dea79f21f0..991bed6bbd 100644
--- a/runtime/autoload/provider/clipboard.vim
+++ b/runtime/autoload/provider/clipboard.vim
@@ -158,7 +158,9 @@ function! s:clipboard.get(reg) abort
end
let clipboard_data = s:try_cmd(s:paste[a:reg])
- if match(&clipboard, '\v(unnamed|unnamedplus)') >= 0 && get(s:selections[a:reg].data, 0, []) == clipboard_data
+ if match(&clipboard, '\v(unnamed|unnamedplus)') >= 0
+ \ && type(clipboard_data) == v:t_list
+ \ && get(s:selections[a:reg].data, 0, []) ==# clipboard_data
" When system clipboard return is same as our cache return the cache
" as it contains regtype information
return s:selections[a:reg].data
diff --git a/runtime/autoload/python3complete.vim b/runtime/autoload/python3complete.vim
index 1d7f5d18f5..192e9e6df8 100644
--- a/runtime/autoload/python3complete.vim
+++ b/runtime/autoload/python3complete.vim
@@ -173,7 +173,7 @@ class Completer(object):
pass
if len(arg_text) == 0:
# The doc string sometimes contains the function signature
- # this works for alot of C modules that are part of the
+ # this works for a lot of C modules that are part of the
# standard library
doc = func_obj.__doc__
if doc:
diff --git a/runtime/autoload/pythoncomplete.vim b/runtime/autoload/pythoncomplete.vim
index 575c23e6d3..e9233e1d49 100644
--- a/runtime/autoload/pythoncomplete.vim
+++ b/runtime/autoload/pythoncomplete.vim
@@ -191,7 +191,7 @@ class Completer(object):
pass
if len(arg_text) == 0:
# The doc string sometimes contains the function signature
- # this works for alot of C modules that are part of the
+ # this works for a lot of C modules that are part of the
# standard library
doc = func_obj.__doc__
if doc:
diff --git a/runtime/autoload/remote/host.vim b/runtime/autoload/remote/host.vim
index c34ff4bee7..884b478f19 100644
--- a/runtime/autoload/remote/host.vim
+++ b/runtime/autoload/remote/host.vim
@@ -114,7 +114,7 @@ function! s:RegistrationCommands(host) abort
let host_id = a:host.'-registration-clone'
call remote#host#RegisterClone(host_id, a:host)
let pattern = s:plugin_patterns[a:host]
- let paths = globpath(&rtp, 'rplugin/'.a:host.'/'.pattern, 1, 1)
+ let paths = nvim_get_runtime_file('rplugin/'.a:host.'/'.pattern, 1)
let paths = map(paths, 'tr(resolve(v:val),"\\","/")') " Normalize slashes #4795
let paths = uniq(sort(paths))
if empty(paths)
diff --git a/runtime/autoload/rubycomplete.vim b/runtime/autoload/rubycomplete.vim
index e8a1879668..3677b25aeb 100644
--- a/runtime/autoload/rubycomplete.vim
+++ b/runtime/autoload/rubycomplete.vim
@@ -3,7 +3,7 @@
" Maintainer: Mark Guzman <segfault@hasno.info>
" URL: https://github.com/vim-ruby/vim-ruby
" Release Coordinator: Doug Kearns <dougkearns@gmail.com>
-" Last Change: 2019 Feb 25
+" Last Change: 2020 Apr 12
" ----------------------------------------------------------------------------
"
" Ruby IRB/Complete author: Keiju ISHITSUKA(keiju@ishitsuka.com)
@@ -501,13 +501,8 @@ class VimRubyCompletion
return if rails_base == nil
$:.push rails_base unless $:.index( rails_base )
- rails_config = rails_base + "config/"
- rails_lib = rails_base + "lib/"
- $:.push rails_config unless $:.index( rails_config )
- $:.push rails_lib unless $:.index( rails_lib )
-
- bootfile = rails_config + "boot.rb"
- envfile = rails_config + "environment.rb"
+ bootfile = rails_base + "config/boot.rb"
+ envfile = rails_base + "config/environment.rb"
if File.exists?( bootfile ) && File.exists?( envfile )
begin
require bootfile
diff --git a/runtime/autoload/sqlcomplete.vim b/runtime/autoload/sqlcomplete.vim
index ea0d8c2de9..adbdbab894 100644
--- a/runtime/autoload/sqlcomplete.vim
+++ b/runtime/autoload/sqlcomplete.vim
@@ -17,7 +17,7 @@
" and complete it.
"
" Version 16.0 (Dec 2015)
-" - NF: If reseting the cache and table, procedure or view completion
+" - NF: If resetting the cache and table, procedure or view completion
" had been used via dbext, have dbext delete or recreate the
" dictionary so that new objects are picked up for the
" next completion.
@@ -554,7 +554,7 @@ function! sqlcomplete#PreCacheSyntax(...)
let syn_group_arr = g:omni_sql_precache_syntax_groups
endif
" For each group specified in the list, precache all
- " the sytnax items.
+ " the syntax items.
if !empty(syn_group_arr)
for group_name in syn_group_arr
let syn_items = extend( syn_items, s:SQLCGetSyntaxList(group_name) )
@@ -577,7 +577,7 @@ function! sqlcomplete#ResetCacheSyntax(...)
let syn_group_arr = g:omni_sql_precache_syntax_groups
endif
" For each group specified in the list, precache all
- " the sytnax items.
+ " the syntax items.
if !empty(syn_group_arr)
for group_name in syn_group_arr
let list_idx = index(s:syn_list, group_name, 0, &ignorecase)
@@ -843,7 +843,7 @@ function! s:SQLCGetColumns(table_name, list_type)
let curline = line(".")
let curcol = col(".")
- " Do not let searchs wrap
+ " Do not let searches wrap
setlocal nowrapscan
" If . was entered, look at the word just before the .
" We are looking for something like this:
@@ -863,7 +863,7 @@ function! s:SQLCGetColumns(table_name, list_type)
" Search forward until one of the following:
" 1. Another select/update/delete statement
" 2. A ; at the end of a line (the delimiter)
- " 3. The end of the file (incase no delimiter)
+ " 3. The end of the file (in case no delimiter)
" Yank the visually selected text into the "y register.
exec 'silent! normal! vl/\c\(\<select\>\|\<update\>\|\<delete\>\|;\s*$\|\%$\)'."\n".'"yy'
diff --git a/runtime/autoload/tar.vim b/runtime/autoload/tar.vim
index b6c4c660b8..e495e8262a 100644
--- a/runtime/autoload/tar.vim
+++ b/runtime/autoload/tar.vim
@@ -778,7 +778,7 @@ fun! tar#Vimuntar(...)
elseif executable("gzip")
silent exe "!gzip -d ".shellescape(tartail)
else
- echoerr "unable to decompress<".tartail."> on this sytem"
+ echoerr "unable to decompress<".tartail."> on this system"
if simplify(curdir) != simplify(tarhome)
" remove decompressed tarball, restore directory
" call Decho("delete(".tartail.".tar)")
diff --git a/runtime/autoload/tohtml.vim b/runtime/autoload/tohtml.vim
index 76092f0f93..66f1cb46cb 100644
--- a/runtime/autoload/tohtml.vim
+++ b/runtime/autoload/tohtml.vim
@@ -693,7 +693,7 @@ func! tohtml#GetUserSettings() "{{{
let user_settings = {}
" Define the correct option if the old option name exists and we haven't
- " already defined the correct one. Maybe I'll put out a warnig message about
+ " already defined the correct one. Maybe I'll put out a warning message about
" this sometime and remove the old option entirely at some even later time,
" but for now just silently accept the old option.
if exists('g:use_xhtml') && !exists("g:html_use_xhtml")
diff --git a/runtime/autoload/vimexpect.vim b/runtime/autoload/vimexpect.vim
index 0ed888d2a4..04c742b894 100644
--- a/runtime/autoload/vimexpect.vim
+++ b/runtime/autoload/vimexpect.vim
@@ -39,7 +39,7 @@ let s:Parser.LINE_BUFFER_MAX_LEN = 100
" Create a new Parser instance with the initial state and a target. The target
" is a dictionary that will be the `self` of every State method call associated
" with the parser, and may contain options normally passed to
-" `jobstart`(on_stdout/on_stderr will be overriden). Returns the target so it
+" `jobstart`(on_stdout/on_stderr will be overridden). Returns the target so it
" can be called directly as the second argument of `jobstart`:
"
" call jobstart(prog_argv, vimexpect#Parser(initial_state, {'pty': 1}))
diff --git a/runtime/autoload/xmlcomplete.vim b/runtime/autoload/xmlcomplete.vim
index 4c1ac4f6b5..55fb031e68 100644
--- a/runtime/autoload/xmlcomplete.vim
+++ b/runtime/autoload/xmlcomplete.vim
@@ -199,7 +199,7 @@ function! xmlcomplete#CompleteTags(findstart, base)
" 1. Events attributes
if context =~ '\s'
- " If attr contains =\s*[\"'] we catched value of attribute
+ " If attr contains =\s*[\"'] we catch value of attribute
if attr =~ "=\s*[\"']" || attr =~ "=\s*$"
" Let do attribute specific completion
let attrname = matchstr(attr, '.*\ze\s*=')
diff --git a/runtime/autoload/zip.vim b/runtime/autoload/zip.vim
index f6b876df05..9588bbf4a2 100644
--- a/runtime/autoload/zip.vim
+++ b/runtime/autoload/zip.vim
@@ -81,7 +81,7 @@ fun! zip#Browse(zipfile)
" sanity checks
if !exists("*fnameescape")
if &verbose > 1
- echoerr "the zip plugin is not available (your vim doens't support fnameescape())"
+ echoerr "the zip plugin is not available (your vim doesn't support fnameescape())"
endif
return
endif
diff --git a/runtime/compiler/fpc.vim b/runtime/compiler/fpc.vim
index fb4f424986..de8e2fe3dc 100644
--- a/runtime/compiler/fpc.vim
+++ b/runtime/compiler/fpc.vim
@@ -12,6 +12,6 @@ if exists(":CompilerSet") != 2 " older Vim always used :setlocal
command -nargs=* CompilerSet setlocal <args>
endif
-" NOTE: compiler must be runned with -vb to write whole source path, not only file
+" NOTE: compiler must be run with -vb to write whole source path, not only file
" name.
CompilerSet errorformat=%f(%l\\,%c)\ %m
diff --git a/runtime/compiler/scdoc.vim b/runtime/compiler/scdoc.vim
new file mode 100644
index 0000000000..2f6edc6322
--- /dev/null
+++ b/runtime/compiler/scdoc.vim
@@ -0,0 +1,16 @@
+" scdoc compiler for Vim
+" Compiler: scdoc
+" Maintainer: Greg Anders <greg@gpanders.com>
+" Last Updated: 2019-10-24
+
+if exists('current_compiler')
+ finish
+endif
+let current_compiler = 'scdoc'
+
+if exists(':CompilerSet') != 2
+ command -nargs=* CompilerSet setlocal <args>
+endif
+
+CompilerSet makeprg=scdoc\ <\ %\ 2>&1
+CompilerSet errorformat=Error\ at\ %l:%c:\ %m,%-G%.%#
diff --git a/runtime/compiler/spectral.vim b/runtime/compiler/spectral.vim
new file mode 100644
index 0000000000..bd13c51f43
--- /dev/null
+++ b/runtime/compiler/spectral.vim
@@ -0,0 +1,17 @@
+" Vim compiler file
+" Compiler: Spectral for YAML
+" Maintainer: Romain Lafourcade <romainlafourcade@gmail.com>
+" Last Change: 2021 July 21
+
+if exists("current_compiler")
+ finish
+endif
+let current_compiler = "spectral"
+
+if exists(":CompilerSet") != 2
+ command -nargs=* CompilerSet setlocal <args>
+endif
+
+CompilerSet makeprg=spectral\ lint\ %\ -f\ text
+CompilerSet errorformat=%f:%l:%c\ %t%.%\\{-}\ %m
+
diff --git a/runtime/compiler/tex.vim b/runtime/compiler/tex.vim
index e43be8dbd6..65e15cf6e2 100644
--- a/runtime/compiler/tex.vim
+++ b/runtime/compiler/tex.vim
@@ -18,7 +18,7 @@ endif
if exists('b:tex_ignore_makefile') || exists('g:tex_ignore_makefile') ||
\(!filereadable('Makefile') && !filereadable('makefile'))
" If buffer-local variable 'tex_flavor' exists, it defines TeX flavor,
- " otherwize the same for global variable with same name, else it will be
+ " otherwise the same for global variable with same name, else it will be
" LaTeX
if exists("b:tex_flavor")
let current_compiler = b:tex_flavor
diff --git a/runtime/compiler/yamllint.vim b/runtime/compiler/yamllint.vim
new file mode 100644
index 0000000000..889b04b63c
--- /dev/null
+++ b/runtime/compiler/yamllint.vim
@@ -0,0 +1,16 @@
+" Vim compiler file
+" Compiler: Yamllint for YAML
+" Maintainer: Romain Lafourcade <romainlafourcade@gmail.com>
+" Last Change: 2021 July 21
+
+if exists("current_compiler")
+ finish
+endif
+let current_compiler = "yamllint"
+
+if exists(":CompilerSet") != 2
+ command -nargs=* CompilerSet setlocal <args>
+endif
+
+CompilerSet makeprg=yamllint\ -f\ parsable
+
diff --git a/runtime/doc/api.txt b/runtime/doc/api.txt
index 07c45c9298..df345e4981 100644
--- a/runtime/doc/api.txt
+++ b/runtime/doc/api.txt
@@ -134,6 +134,14 @@ lines, 0-based columns):
|nvim_win_get_cursor()|
|nvim_win_set_cursor()|
+Exception: the following API functions use |extmarks| indexing (0-based
+indices, end-inclusive):
+
+ |nvim_buf_del_extmark()|
+ |nvim_buf_get_extmark_by_id()|
+ |nvim_buf_get_extmarks()|
+ |nvim_buf_set_extmark()|
+
*api-fast*
Most API functions are "deferred": they are queued on the main loop and
processed sequentially with normal input. So if the editor is waiting for
@@ -436,36 +444,76 @@ Example: create a float with scratch buffer: >
>
==============================================================================
-Extended marks *api-extended-marks*
+Extended marks *api-extended-marks* *extmarks*
Extended marks (extmarks) represent buffer annotations that track text changes
-in the buffer. They could be used to represent cursors, folds, misspelled
-words, and anything else that needs to track a logical location in the buffer
-over time.
+in the buffer. They can represent cursors, folds, misspelled words, anything
+that needs to track a logical location in the buffer over time. |api-indexing|
+
+Extmark position works like "bar" cursor: it exists between characters. Thus
+the maximum extmark index on a line is 1 more than the character index: >
+
+ f o o b a r line contents
+ 0 1 2 3 4 5 character positions (0-based)
+ 0 1 2 3 4 5 6 extmark positions (0-based)
+
+Extmarks have "forward gravity": if you place the cursor directly on an
+extmark position and enter some text, the extmark migrates forward. >
+
+ f o o|b a r line (| = cursor)
+ 3 extmark
+
+ f o o z|b a r line (| = cursor)
+ 4 extmark (after typing "z")
+
+If an extmark is on the last index of a line and you inputsa newline at that
+point, the extmark will accordingly migrate to the next line: >
+
+ f o o z b a r| line (| = cursor)
+ 7 extmark
+
+ f o o z b a r first line
+ extmarks (none present)
+ | second line (| = cursor)
+ 0 extmark (after typing <CR>)
+
Example:
-We will set an extmark at the first row and third column. |api-indexing| is
-zero-indexed, so we use row=0 and column=2. Passing id=0 creates a new mark
-and returns the id: >
+Let's set an extmark at the first row (row=0) and third column (column=2).
+|api-indexing| Passing id=0 creates a new mark and returns the id: >
+ 01 2345678
+ 0 ex|ample..
+< ^ extmark position
+>
let g:mark_ns = nvim_create_namespace('myplugin')
- let g:mark_id = nvim_buf_set_extmark(0, g:mark_ns, 0, 0, 2, {})
-
-We can get a mark by its id: >
+ let g:mark_id = nvim_buf_set_extmark(0, g:mark_ns, 0, 2, {})
+<
+We can get the mark by its id: >
- echo nvim_buf_get_extmark_by_id(0, g:mark_ns, g:mark_id)
+ echo nvim_buf_get_extmark_by_id(0, g:mark_ns, g:mark_id, {})
=> [0, 2]
-We can get all marks in a buffer for our namespace (or by a range): >
+We can get all marks in a buffer by |namespace| (or by a range): >
echo nvim_buf_get_extmarks(0, g:mark_ns, 0, -1, {})
=> [[1, 0, 2]]
-Deleting all text surrounding an extmark does not remove the extmark. To
-remove an extmark use |nvim_buf_del_extmark()|.
+Deleting all surrounding text does NOT remove an extmark! To remove extmarks
+use |nvim_buf_del_extmark()|. Deleting "x" in our example: >
-Namespaces allow your plugin to manage only its own extmarks, ignoring those
+ 0 12345678
+ 0 e|ample..
+< ^ extmark position
+>
+ echo nvim_buf_get_extmark_by_id(0, g:mark_ns, g:mark_id, {})
+ => [0, 1]
+<
+ Note: Extmark "gravity" decides how it will shift after a text edit.
+ See |nvim_buf_set_extmark()|
+
+Namespaces allow any plugin to manage only its own extmarks, ignoring those
created by another plugin.
Extmark positions changed by an edit will be restored on undo/redo. Creating
@@ -661,8 +709,7 @@ nvim_create_namespace({name}) *nvim_create_namespace()*
Creates a new namespace, or gets an existing one.
Namespaces are used for buffer highlights and virtual text,
- see |nvim_buf_add_highlight()| and
- |nvim_buf_set_virtual_text()|.
+ see |nvim_buf_add_highlight()| and |nvim_buf_set_extmark()|.
Namespaces can be named or anonymous. If `name` matches an
existing namespace, the associated id is returned. If `name`
@@ -780,10 +827,9 @@ nvim_feedkeys({keys}, {mode}, {escape_csi}) *nvim_feedkeys()*
On execution error: does not fail, but updates v:errmsg.
- If you need to input sequences like <C-o> use
- |nvim_replace_termcodes| to replace the termcodes and then
- pass the resulting string to nvim_feedkeys. You'll also want
- to enable escape_csi.
+ To input sequences like <C-o> use |nvim_replace_termcodes()|
+ (typically with escape_csi=true) to replace the keycodes. Then
+ pass the result to nvim_feedkeys().
Example: >
:let key = nvim_replace_termcodes("<C-o>", v:true, v:false, v:true)
@@ -1104,7 +1150,7 @@ nvim_input_mouse({button}, {action}, {modifier}, {grid}, {row}, {col})
intermediate mouse positions will be ignored. It should be
used to implement real-time mouse input in a GUI. The
deprecated pseudokey form ("<LeftMouse><col,row>") of
- |nvim_input()| has the same limitiation.
+ |nvim_input()| has the same limitation.
Attributes: ~
{fast}
@@ -1183,7 +1229,7 @@ nvim_notify({msg}, {log_level}, {opts}) *nvim_notify()*
Notify the user with a message
Relays the call to vim.notify . By default forwards your
- message in the echo area but can be overriden to trigger
+ message in the echo area but can be overridden to trigger
desktop notifications.
Parameters: ~
@@ -1197,7 +1243,7 @@ nvim_open_term({buffer}, {opts}) *nvim_open_term()*
By default (and currently the only option) the terminal will
not be connected to an external process. Instead, input send
on the channel will be echoed directly by the terminal. This
- is useful to disply ANSI terminal sequences returned as part
+ is useful to display ANSI terminal sequences returned as part
of a rpc message, or similar.
Note: to directly initiate the terminal using the right size,
@@ -1419,8 +1465,9 @@ nvim_parse_expression({expr}, {flags}, {highlight})
• "len": Amount of bytes successfully parsed. With flags
equal to "" that should be equal to the length of expr
- string. (“Sucessfully parsed” here means “participated
- in AST creation”, not “till the first error”.)
+ string. (“Successfully parsed” here means
+ “participated in AST creation”, not “till the first
+ error”.)
• "ast": AST, either nil or a dictionary with these
keys:
• "type": node type, one of the value names from
@@ -1681,7 +1728,7 @@ nvim_set_decoration_provider({ns_id}, {opts})
Note: this function should not be called often. Rather, the
callbacks themselves can be used to throttle unneeded
callbacks. the `on_start` callback can return `false` to
- disable the provider until the next redraw. Similarily, return
+ disable the provider until the next redraw. Similarly, return
`false` in `on_win` will skip the `on_lines` calls for that
window (but any extmarks set in `on_win` will still be used).
A plugin managing multiple sources of decoration should
@@ -1721,7 +1768,7 @@ nvim_set_hl({ns_id}, {name}, {val}) *nvim_set_hl()*
Parameters: ~
{ns_id} number of namespace for this highlight
{name} highlight group name, like ErrorMsg
- {val} highlight definiton map, like
+ {val} highlight definition map, like
|nvim_get_hl_by_name|. in addition the following
keys are also recognized: `default` : don't
override existing definition, like `hi default`
@@ -2072,7 +2119,7 @@ nvim_buf_get_commands({buffer}, {opts}) *nvim_buf_get_commands()*
*nvim_buf_get_extmark_by_id()*
nvim_buf_get_extmark_by_id({buffer}, {ns_id}, {id}, {opts})
- Returns position for a given extmark id
+ Gets the position (0-indexed) of an extmark {id}.
Parameters: ~
{buffer} Buffer handle, or 0 for current buffer
@@ -2082,7 +2129,8 @@ nvim_buf_get_extmark_by_id({buffer}, {ns_id}, {id}, {opts})
• details: Whether to include the details dict
Return: ~
- (row, col) tuple or empty list () if extmark id was absent
+ 0-indexed (row, col) tuple or empty list () if extmark id
+ was absent
*nvim_buf_get_extmarks()*
nvim_buf_get_extmarks({buffer}, {ns_id}, {start}, {end}, {opts})
@@ -2122,10 +2170,12 @@ nvim_buf_get_extmarks({buffer}, {ns_id}, {start}, {end}, {opts})
Parameters: ~
{buffer} Buffer handle, or 0 for current buffer
{ns_id} Namespace id from |nvim_create_namespace()|
- {start} Start of range, given as (row, col) or valid
- extmark id (whose position defines the bound)
- {end} End of range, given as (row, col) or valid
- extmark id (whose position defines the bound)
+ {start} Start of range, given as 0-indexed (row, col) or
+ valid extmark id (whose position defines the
+ bound)
+ {end} End of range (inclusive), given as 0-indexed
+ (row, col) or valid extmark id (whose position
+ defines the bound)
{opts} Optional parameters. Keys:
• limit: Maximum number of marks to return
• details Whether to include the details dict
@@ -2289,7 +2339,16 @@ nvim_buf_set_extmark({buffer}, {ns_id}, {line}, {col}, {opts})
• hl_group : name of the highlight group used to
highlight this mark.
• virt_text : virtual text to link to this mark.
- • virt_text_pos : positioning of virtual text.
+ A list of [text, highlight] tuples, each
+ representing a text chunk with specified
+ highlight. `highlight` element can either be a
+ a single highlight group, or an array of
+ multiple highlight groups that will be stacked
+ (highest priority last). A highlight group can
+ be supplied either as a string or as an
+ integer, the latter which can be obtained
+ using |nvim_get_hl_id_by_name|.
+ • virt_text_pos : position of virtual text.
Possible values:
• "eol": right after eol character (default)
• "overlay": display over the specified
@@ -2426,44 +2485,6 @@ nvim_buf_set_var({buffer}, {name}, {value}) *nvim_buf_set_var()*
{name} Variable name
{value} Variable value
- *nvim_buf_set_virtual_text()*
-nvim_buf_set_virtual_text({buffer}, {src_id}, {line}, {chunks}, {opts})
- Set the virtual text (annotation) for a buffer line.
-
- By default (and currently the only option) the text will be
- placed after the buffer text. Virtual text will never cause
- reflow, rather virtual text will be truncated at the end of
- the screen line. The virtual text will begin one cell
- (|lcs-eol| or space) after the ordinary text.
-
- Namespaces are used to support batch deletion/updating of
- virtual text. To create a namespace, use
- |nvim_create_namespace()|. Virtual text is cleared using
- |nvim_buf_clear_namespace()|. The same `ns_id` can be used for
- both virtual text and highlights added by
- |nvim_buf_add_highlight()|, both can then be cleared with a
- single call to |nvim_buf_clear_namespace()|. If the virtual
- text never will be cleared by an API call, pass `ns_id = -1` .
-
- As a shorthand, `ns_id = 0` can be used to create a new
- namespace for the virtual text, the allocated id is then
- returned.
-
- Parameters: ~
- {buffer} Buffer handle, or 0 for current buffer
- {ns_id} Namespace to use or 0 to create a namespace, or
- -1 for a ungrouped annotation
- {line} Line to annotate with virtual text
- (zero-indexed)
- {chunks} A list of [text, hl_group] arrays, each
- representing a text chunk with specified
- highlight. `hl_group` element can be omitted for
- no highlight.
- {opts} Optional parameters. Currently not used.
-
- Return: ~
- The ns_id that was used
-
==============================================================================
Window Functions *api-window*
diff --git a/runtime/doc/arabic.txt b/runtime/doc/arabic.txt
index df91b8d065..5d3bf7a761 100644
--- a/runtime/doc/arabic.txt
+++ b/runtime/doc/arabic.txt
@@ -171,6 +171,13 @@ o Enable Arabic settings [short-cut]
and its support is preferred due to its level of offerings.
'arabic' when 'termbidi' is enabled only sets the keymap.
+ For vertical window isolation while setting 'termbidi' an LTR
+ vertical separator like "l" or "𝖨" may be used. It may also be
+ hidden by changing its color to the foreground color: >
+ :set fillchars=vert:l
+ :hi VertSplit ctermbg=White
+< Note that this is a workaround, not a proper solution.
+
If, on the other hand, you'd like to be verbose and explicit and
are opting not to use the 'arabic' short-cut command, here's what
is needed (i.e. if you use ':set arabic' you can skip this section) -
diff --git a/runtime/doc/autocmd.txt b/runtime/doc/autocmd.txt
index 9ee1954514..7a53f17a78 100644
--- a/runtime/doc/autocmd.txt
+++ b/runtime/doc/autocmd.txt
@@ -232,7 +232,7 @@ BufDelete Before deleting a buffer from the buffer list.
*BufEnter*
BufEnter After entering a buffer. Useful for setting
options for a file type. Also executed when
- starting to edit a buffer, after the
+ starting to edit a buffer.
After |BufAdd|.
After |BufReadPost|.
*BufFilePost*
@@ -499,8 +499,10 @@ CursorMoved After the cursor was moved in Normal or Visual
mode or to another window. Also when the text
of the cursor line has been changed, e.g. with
"x", "rx" or "p".
- Not triggered when there is typeahead or when
- an operator is pending.
+ Not triggered when there is typeahead, while
+ executing a script file, when an operator is
+ pending, or when moving to another window while
+ remaining at the same cursor position.
For an example see |match-parens|.
Note: Cannot be skipped with |:noautocmd|.
Careful: This is triggered very often, don't
@@ -798,9 +800,10 @@ QuickFixCmdPost Like QuickFixCmdPre, but after a quickfix
*QuitPre*
QuitPre When using `:quit`, `:wq` or `:qall`, before
deciding whether it closes the current window
- or quits Vim. Can be used to close any
- non-essential window if the current window is
- the last ordinary window.
+ or quits Vim. For `:wq` the buffer is written
+ before QuitPre is triggered. Can be used to
+ close any non-essential window if the current
+ window is the last ordinary window.
See also |ExitPre|, ||WinClosed|.
*RemoteReply*
RemoteReply When a reply from a Vim that functions as
@@ -914,6 +917,8 @@ TermLeave After leaving |Terminal-mode|.
After TermClose.
*TermClose*
TermClose When a |terminal| job ends.
+ Sets these |v:event| keys:
+ status
*TermResponse*
TermResponse After the response to t_RV is received from
the terminal. The value of |v:termresponse|
diff --git a/runtime/doc/change.txt b/runtime/doc/change.txt
index 7a63a89986..2b799e3e27 100644
--- a/runtime/doc/change.txt
+++ b/runtime/doc/change.txt
@@ -568,9 +568,7 @@ with ".". Vim does not recognize a comment (starting with '"') after the
option is empty (this is the default), use the
internal formatting function |C-indenting| and
|'lisp'|. But when 'indentexpr' is not empty, it will
- be used instead |indent-expression|. When Vim was
- compiled without internal formatting then the "indent"
- program is used as a last resort.
+ be used instead |indent-expression|.
*==*
== Filter [count] lines like with ={motion}.
@@ -749,12 +747,14 @@ For compatibility with Vi these two exceptions are allowed:
"\/{string}/" and "\?{string}?" do the same as "//{string}/r".
"\&{string}&" does the same as "//{string}/".
*pattern-delimiter* *E146*
-Instead of the '/' which surrounds the pattern and replacement string, you
-can use any other single-byte character, but not an alphanumeric character,
-'\', '"' or '|'. This is useful if you want to include a '/' in the search
-pattern or replacement string. Example: >
+Instead of the '/' which surrounds the pattern and replacement string, you can
+use another single-byte character. This is useful if you want to include a
+'/' in the search pattern or replacement string. Example: >
:s+/+//+
+You can use most characters, but not an alphanumeric character, '\', '"' or
+'|'.
+
For the definition of a pattern, see |pattern|. In Visual block mode, use
|/\%V| in the pattern to have the substitute work in the block only.
Otherwise it works on whole lines anyway.
@@ -988,9 +988,9 @@ inside of strings can change! Also see 'softtabstop' option. >
*Y*
["x]Y yank [count] lines [into register x] (synonym for
- yy, |linewise|). If you like "Y" to work from the
- cursor to the end of line (which is more logical,
- but not Vi-compatible) use ":map Y y$".
+ yy, |linewise|).
+ *Y-default*
+ Mapped to "y$" by default. |default-mappings|
*zy*
["x]zy{motion} Yank {motion} text [into register x]. Only differs
@@ -1011,9 +1011,7 @@ inside of strings can change! Also see 'softtabstop' option. >
with `zp`. (for {Visual} see |Visual-mode|)
*:y* *:yank* *E850*
-:[range]y[ank] [x] Yank [range] lines [into register x]. Yanking to the
- "* or "+ registers is possible only when the
- |+clipboard| feature is included.
+:[range]y[ank] [x] Yank [range] lines [into register x].
:[range]y[ank] [x] {count}
Yank {count} lines, starting with last line number
@@ -1802,8 +1800,7 @@ found here: |sort()|, |uniq()|.
With [f] sorting is done on the Float in the line.
The value of Float is determined similar to passing
the text (after or inside a {pattern} match) to
- str2float() function. This option is available only
- if Vim was compiled with Floating point support.
+ str2float() function.
With [x] sorting is done on the first hexadecimal
number in the line (after or inside a {pattern}
diff --git a/runtime/doc/cmdline.txt b/runtime/doc/cmdline.txt
index 2db694cf07..6b46ac9cf2 100644
--- a/runtime/doc/cmdline.txt
+++ b/runtime/doc/cmdline.txt
@@ -153,7 +153,12 @@ CTRL-R {register} *c_CTRL-R* *c_<C-R>*
too.
When the result is a Float it's automatically
converted to a String.
- See |registers| about registers.
+ Note that when you only want to move the
+ cursor and not insert anything, you must make
+ sure the expression evaluates to an empty
+ string. E.g.: >
+ <C-R><C-R>=setcmdpos(2)[-1]<CR>
+< See |registers| about registers.
Implementation detail: When using the |expression| register
and invoking setcmdpos(), this sets the position before
inserting the resulting string. Use CTRL-R CTRL-R to set the
@@ -1067,7 +1072,7 @@ in Normal mode and Insert mode.
It is possible to use ":", "/" and other commands that use the command-line,
but it's not possible to open another command-line window then. There is no
nesting.
- *E11*
+ *E11* *E1188*
The command-line window is not a normal window. It is not possible to move to
another window or edit another buffer. All commands that would do this are
disabled in the command-line window. Of course it _is_ possible to execute
@@ -1140,6 +1145,11 @@ Thus you can resize the command-line window, but not others.
The |getcmdwintype()| function returns the type of the command-line being
edited as described in |cmdwin-char|.
+Nvim defines this default CmdWinEnter autocmd in the "nvim_cmdwin" group: >
+ autocmd CmdWinEnter [:>] syntax sync minlines=1 maxlines=1
+<
+You can disable this in your config with "autocmd! nvim_cmdwin". |default-autocmds|
+
AUTOCOMMANDS
diff --git a/runtime/doc/deprecated.txt b/runtime/doc/deprecated.txt
index 3b5287ee44..a7ce4135af 100644
--- a/runtime/doc/deprecated.txt
+++ b/runtime/doc/deprecated.txt
@@ -14,6 +14,7 @@ updated.
API ~
*nvim_buf_clear_highlight()* Use |nvim_buf_clear_namespace()| instead.
+*nvim_buf_set_virtual_text()* Use |nvim_buf_set_extmark()| instead.
*nvim_command_output()* Use |nvim_exec()| instead.
*nvim_execute_lua()* Use |nvim_exec_lua()| instead.
@@ -54,6 +55,55 @@ Functions ~
without stopping the job. Use chanclose(id) to close
any socket.
+LSP Diagnostics ~
+
+For each of the functions below, use the corresponding function in
+|vim.diagnostic| instead (unless otherwise noted). For example, use
+|vim.diagnostic.get()| instead of |vim.lsp.diagnostic.get()|.
+
+*vim.lsp.diagnostic.clear()* Use |vim.diagnostic.hide()| instead.
+*vim.lsp.diagnostic.disable()*
+*vim.lsp.diagnostic.display()* Use |vim.diagnostic.show()| instead.
+*vim.lsp.diagnostic.enable()*
+*vim.lsp.diagnostic.get()*
+*vim.lsp.diagnostic.get_all()* Use |vim.diagnostic.get()| instead.
+*vim.lsp.diagnostic.get_count()* Use |vim.diagnostic.get()| instead.
+*vim.lsp.diagnostic.get_line_diagnostics()*
+ Use |vim.diagnostic.get()| instead.
+*vim.lsp.diagnostic.get_next()*
+*vim.lsp.diagnostic.get_next_pos()*
+*vim.lsp.diagnostic.get_prev()*
+*vim.lsp.diagnostic.get_prev_pos()*
+*vim.lsp.diagnostic.get_virtual_text_chunks_for_line()*
+ No replacement. Use options provided by
+ |vim.diagnostic.config()| to customize
+ virtual text.
+*vim.lsp.diagnostic.goto_next()*
+*vim.lsp.diagnostic.goto_prev()*
+*vim.lsp.diagnostic.redraw()* Use |vim.diagnostic.show()| instead.
+*vim.lsp.diagnostic.reset()*
+*vim.lsp.diagnostic.save()* Use |vim.diagnostic.set()| instead.
+*vim.lsp.diagnostic.set_loclist()* Use |vim.diagnostic.setloclist()| instead.
+*vim.lsp.diagnostic.set_qflist()* Use |vim.diagnostic.setqflist()| instead.
+*vim.lsp.diagnostic.show_line_diagnostics()*
+*vim.lsp.diagnostic.show_position_diagnostics()*
+
+The following are deprecated without replacement. These functions are moved
+internally and are no longer exposed as part of the API. Instead, use
+|vim.diagnostic.config()| and |vim.diagnostic.show()|.
+
+*vim.lsp.diagnostic.set_signs()*
+*vim.lsp.diagnostic.set_underline()*
+*vim.lsp.diagnostic.set_virtual_text()*
+
+LSP Utility Functions ~
+
+*vim.lsp.util.diagnostics_to_items()* Use |vim.diagnostic.toqflist()| instead.
+*vim.lsp.util.set_qflist()* Use |setqflist()| instead.
+*vim.lsp.util.set_loclist()* Use |setloclist()| instead.
+
+Lua ~
+*vim.register_keystroke_callback()* Use |vim.on_key()| instead.
Modifiers ~
*cpo-<*
diff --git a/runtime/doc/dev_style.txt b/runtime/doc/dev_style.txt
new file mode 100644
index 0000000000..82f279e781
--- /dev/null
+++ b/runtime/doc/dev_style.txt
@@ -0,0 +1,1159 @@
+*dev_style.txt* Nvim
+
+
+ NVIM REFERENCE MANUAL
+
+
+Nvim style guide *dev-style*
+
+This is style guide for developers working on Nvim's source code.
+
+License: CC-By 3.0 http://creativecommons.org/licenses/by/3.0/
+
+ Type |gO| to see the table of contents.
+
+==============================================================================
+Background
+
+One way in which we keep the code base manageable is by enforcing consistency.
+It is very important that any programmer be able to look at another's code and
+quickly understand it.
+
+Maintaining a uniform style and following conventions means that we can more
+easily use "pattern-matching" to infer what various symbols are and what
+invariants are true about them. Creating common, required idioms and patterns
+makes code much easier to understand.
+
+In some cases there might be good arguments for changing certain style rules,
+but we nonetheless keep things as they are in order to preserve consistency.
+
+
+==============================================================================
+Header Files *dev-style-header*
+
+
+The #define Guard ~
+
+All header files should have `#define` guards to prevent multiple inclusion.
+The format of the symbol name should be `NVIM_<DIRECTORY>_<FILE>_H`.
+
+ In foo/bar.h:
+>
+ #ifndef NVIM_FOO_BAR_H
+ #define NVIM_FOO_BAR_H
+
+ ...
+
+ #endif // NVIM_FOO_BAR_H
+<
+
+
+Names and Order of Includes ~
+
+Use standard order for readability and to avoid hidden dependencies: C
+library, other libraries' `.h`, your project's `.h`.
+
+ In foo.c order your includes as follows:
+
+ 1. C system files.
+ 2. Other libraries' `.h` files.
+ 3. Your project's `.h` files.
+
+ Exception: sometimes, system-specific code needs conditional includes.
+ Such code can put conditional includes after other includes. Of course,
+ keep your system-specific code small and localized.
+
+
+Constants ~
+
+Do not use macros to define constants in headers.
+
+Macro constants in header files cannot be used by unit tests.
+
+However, you are allowed to define a macro that holds the same value as a
+non-enum constant (defined in the same header) if the value of the constant
+represents the size of an array.
+
+
+==============================================================================
+Scoping *dev-style-scope*
+
+Local Variables ~
+
+Place a function's variables in the narrowest scope possible, and initialize
+variables in the declaration.
+
+C99 allows you to declare variables anywhere in a function. Declare them in as
+local a scope as possible, and as close to the first use as possible. This
+makes it easier for the reader to find the declaration and see what type the
+variable is and what it was initialized to. In particular, initialization
+should be used instead of declaration and assignment, e.g. >
+
+ int i;
+ i = f(); // BAD: initialization separate from declaration.
+
+ int j = g(); // GOOD: declaration has initialization.
+
+
+==============================================================================
+Nvim-Specific Magic
+
+clint ~
+
+Use `clint.py` to detect style errors.
+
+`src/clint.py` is a Python script that reads a source file and identifies
+style errors. It is not perfect, and has both false positives and false
+negatives, but it is still a valuable tool. False positives can be ignored by
+putting `// NOLINT` at the end of the line.
+
+uncrustify ~
+
+src/uncrustify.cfg is the authority for expected code formatting, for cases
+not covered by clint.py. We remove checks in clint.py if they are covered by
+uncrustify rules.
+
+==============================================================================
+Other C Features *dev-style-features*
+
+
+Variable-Length Arrays and alloca() ~
+
+We do not allow variable-length arrays or `alloca()`.
+
+Variable-length arrays can cause hard to detect stack overflows.
+
+
+Postincrement and Postdecrement ~
+
+Use postfix form (`i++`) in statements. >
+
+ for (int i = 0; i < 3; i++) { }
+ int j = ++i; // OK: ++i is used as an expression.
+
+ for (int i = 0; i < 3; ++i) { }
+ ++i; // BAD: ++i is used as a statement.
+
+
+Use of const ~
+
+Use `const` pointers whenever possible. Avoid `const` on non-pointer parameter definitions.
+
+ Where to put the const ~
+
+ Some people favor the form `int const *foo` to `const int *foo` . They
+ argue that this is more readable because it's more consistent: it keeps
+ the rule that `const` always follows the object it's describing. However,
+ this consistency argument doesn't apply in codebases with few
+ deeply-nested pointer expressions since most `const` expressions have only
+ one `const`, and it applies to the underlying value. In such cases, there's
+ no consistency to maintain. Putting the `const` first is arguably more
+ readable, since it follows English in putting the "adjective" (`const`)
+ before the "noun" (`int`).
+
+ That said, while we encourage putting `const` first, we do not require it.
+ But be consistent with the code around you! >
+
+ void foo(const char *p, int i);
+ }
+
+ int foo(const int a, const bool b) {
+ }
+
+ int foo(int *const p) {
+ }
+
+
+Integer Types ~
+
+Of the built-in integer types only use `char`, `int`, `uint8_t`, `int8_t`,
+`uint16_t`, `int16_t`, `uint32_t`, `int32_t`, `uint64_t`, `int64_t`,
+`uintmax_t`, `intmax_t`, `size_t`, `ssize_t`, `uintptr_t`, `intptr_t`, and
+`ptrdiff_t`.
+
+Use `int` for error codes and local, trivial variables only.
+
+Use care when converting integer types. Integer conversions and promotions can
+cause non-intuitive behavior. Note that the signedness of `char` is
+implementation defined.
+
+Public facing types must have fixed width (`uint8_t`, etc.)
+
+There are no convenient `printf` format placeholders for fixed width types.
+Cast to `uintmax_t` or `intmax_t` if you have to format fixed width integers.
+
+Type unsigned signed
+`char` `%hhu` `%hhd`
+`int` n/a `%d`
+`(u)intmax_t` `%ju` `%jd`
+`(s)size_t` `%zu` `%zd`
+`ptrdiff_t` `%tu` `%td`
+
+
+Booleans ~
+
+Use `bool` to represent boolean values. >
+
+ int loaded = 1; // BAD: loaded should have type bool.
+
+
+Variable declarations ~
+
+Declare only one variable per line. >
+
+ int i, j = 1
+
+
+Conditions ~
+
+Don't use "yoda-conditions". Use at most one assignment per condition. >
+
+ if (1 == x) {
+
+ if (x == 1) { //use this order
+
+ if ((x = f()) && (y = g())) {
+
+
+Function declarations ~
+
+Every function must not have a separate declaration.
+
+Function declarations are created by the gendeclarations.lua script. >
+
+ static void f(void);
+
+ static void f(void)
+ {
+ ...
+ }
+
+
+General translation unit layout ~
+
+The definitions of public functions precede the definitions of static
+functions. >
+
+ <HEADER>
+
+ <PUBLIC FUNCTION DEFINITIONS>
+
+ <STATIC FUNCTION DEFINITIONS>
+
+
+Integration with declarations generator ~
+
+Every C file must contain #include of the generated header file, guarded by
+#ifdef INCLUDE_GENERATED_DECLARATIONS.
+
+Include must go after other #includes and typedefs in .c files and after
+everything else in header files. It is allowed to omit #include in a .c file
+if .c file does not contain any static functions.
+
+Included file name consists of the .c file name without extension, preceded by
+the directory name relative to src/nvim. Name of the file containing static
+functions declarations ends with `.c.generated.h`, `*.h.generated.h` files
+contain only non-static function declarations. >
+
+ // src/nvim/foo.c file
+ #include <stddef.h>
+
+ typedef int FooType;
+
+ #ifdef INCLUDE_GENERATED_DECLARATIONS
+ # include "foo.c.generated.h"
+ #endif
+
+ …
+
+
+ // src/nvim/foo.h file
+ #ifndef NVIM_FOO_H
+ #define NVIM_FOO_H
+
+ …
+
+ #ifdef INCLUDE_GENERATED_DECLARATIONS
+ # include "foo.h.generated.h"
+ #endif
+ #endif // NVIM_FOO_H
+
+
+64-bit Portability ~
+
+Code should be 64-bit and 32-bit friendly. Bear in mind problems of printing,
+comparisons, and structure alignment.
+
+- Remember that `sizeof(void *)` != `sizeof(int)`. Use `intptr_t` if you want
+ a pointer-sized integer.
+
+- You may need to be careful with structure alignments, particularly for
+ structures being stored on disk. Any class/structure with a
+ `int64_t`/`uint64_t` member will by default end up being 8-byte aligned on a
+ 64-bit system. If you have such structures being shared on disk between
+ 32-bit and 64-bit code, you will need to ensure that they are packed the
+ same on both architectures. Most compilers offer a way to alter structure
+ alignment. For gcc, you can use `__attribute__((packed))`. MSVC offers
+ `#pragma pack()` and `__declspec(align())`.
+
+- Use the `LL` or `ULL` suffixes as needed to create 64-bit constants. For
+ example: >
+
+ int64_t my_value = 0x123456789LL;
+ uint64_t my_mask = 3ULL << 48;
+
+
+sizeof ~
+
+Prefer `sizeof(varname)` to `sizeof(type)`.
+
+Use `sizeof(varname)` when you take the size of a particular variable.
+`sizeof(varname)` will update appropriately if someone changes the variable
+type either now or later. You may use `sizeof(type)` for code unrelated to any
+particular variable, such as code that manages an external or internal data
+format where a variable of an appropriate C type is not convenient. >
+
+ Struct data;
+ memset(&data, 0, sizeof(data));
+
+ memset(&data, 0, sizeof(Struct));
+
+ if (raw_size < sizeof(int)) {
+ fprintf(stderr, "compressed record not big enough for count: %ju", raw_size);
+ return false;
+ }
+
+
+==============================================================================
+Naming *dev-style-naming*
+
+The most important consistency rules are those that govern naming. The style
+of a name immediately informs us what sort of thing the named entity is: a
+type, a variable, a function, a constant, a macro, etc., without requiring us
+to search for the declaration of that entity. The pattern-matching engine in
+our brains relies a great deal on these naming rules.
+
+Naming rules are pretty arbitrary, but we feel that consistency is more
+important than individual preferences in this area, so regardless of whether
+you find them sensible or not, the rules are the rules.
+
+
+General Naming Rules ~
+
+Function names, variable names, and filenames should be descriptive; eschew
+abbreviation.
+
+Give as descriptive a name as possible, within reason. Do not worry about
+saving horizontal space as it is far more important to make your code
+immediately understandable by a new reader. Do not use abbreviations that are
+ambiguous or unfamiliar to readers outside your project, and do not abbreviate
+by deleting letters within a word. >
+
+ int price_count_reader; // No abbreviation.
+ int num_errors; // "num" is a widespread convention.
+ int num_dns_connections; // Most people know what "DNS" stands for.
+
+ int n; // Meaningless.
+ int nerr; // Ambiguous abbreviation.
+ int n_comp_conns; // Ambiguous abbreviation.
+ int wgc_connections; // Only your group knows what this stands for.
+ int pc_reader; // Lots of things can be abbreviated "pc".
+ int cstmr_id; // Deletes internal letters.
+
+
+File Names ~
+
+Filenames should be all lowercase and can include underscores (`_`).
+
+Use underscores to separate words. Examples of acceptable file names: >
+
+ my_useful_file.c
+ getline_fix.c // OK: getline refers to the glibc function.
+
+C files should end in `.c` and header files should end in `.h`.
+
+Do not use filenames that already exist in `/usr/include`, such as `db.h`.
+
+In general, make your filenames very specific. For example, use
+`http_server_logs.h` rather than `logs.h`.
+
+
+Type Names ~
+
+Typedef-ed structs and enums start with a capital letter and have a capital
+letter for each new word, with no underscores: `MyExcitingStruct`.
+
+Non-Typedef-ed structs and enums are all lowercase with underscores between
+words: `struct my_exciting_struct` . >
+
+ struct my_struct {
+ ...
+ };
+ typedef struct my_struct MyAwesomeStruct;
+
+
+Variable Names ~
+
+Variable names are all lowercase, with underscores between words. For
+instance: `my_exciting_local_variable`.
+
+ Common Variable names ~
+
+ For example: >
+
+ string table_name; // OK: uses underscore.
+ string tablename; // OK: all lowercase.
+
+ string tableName; // BAD: mixed case.
+<
+
+ Struct Variables ~
+
+ Data members in structs should be named like regular variables. >
+
+ struct url_table_properties {
+ string name;
+ int num_entries;
+ }
+<
+
+ Global Variables ~
+
+ Don't use global variables unless absolutely necessary. Prefix global
+ variables with `g_`.
+
+
+Constant Names ~
+
+Use a `k` followed by mixed case: `kDaysInAWeek`.
+
+All compile-time constants, whether they are declared locally or globally,
+follow a slightly different naming convention from other variables. Use a `k`
+followed by words with uppercase first letters: >
+
+ const int kDaysInAWeek = 7;
+
+Function Names ~
+
+Function names are all lowercase, with underscores between words. For
+instance: `my_exceptional_function()`. All functions in the same header file
+should have a common prefix.
+
+In `os_unix.h`: >
+
+ void unix_open(const char *path);
+ void unix_user_id(void);
+
+If your function crashes upon an error, you should append `or_die` to the
+function name. This only applies to functions which could be used by
+production code and to errors that are reasonably likely to occur during
+normal operation.
+
+
+Enumerator Names ~
+
+Enumerators should be named like constants: `kEnumName`. >
+
+ enum url_table_errors {
+ kOK = 0,
+ kErrorOutOfMemory,
+ kErrorMalformedInput,
+ };
+
+
+Macro Names ~
+
+They're like this: `MY_MACRO_THAT_SCARES_CPP_DEVELOPERS`. >
+
+ #define ROUND(x) ...
+ #define PI_ROUNDED 5.0
+
+
+==============================================================================
+Comments *dev-style-comments*
+
+Comments are vital to keeping our code readable. The following rules describe
+what you should comment and where. But remember: while comments are very
+important, the best code is self-documenting.
+
+When writing your comments, write for your audience: the next contributor who
+will need to understand your code. Be generous — the next one may be you!
+
+Nvim uses Doxygen comments.
+
+
+Comment Style ~
+
+Use the `//`-style syntax only. >
+
+ // This is a comment spanning
+ // multiple lines
+ f();
+
+
+File Comments ~
+
+Start each file with a description of its contents.
+
+ Legal Notice ~
+
+ We have no such thing. These things are in LICENSE and only there.
+
+ File Contents ~
+
+ Every file should have a comment at the top describing its contents.
+
+ Generally a `.h` file will describe the variables and functions that are
+ declared in the file with an overview of what they are for and how they
+ are used. A `.c` file should contain more information about implementation
+ details or discussions of tricky algorithms. If you feel the
+ implementation details or a discussion of the algorithms would be useful
+ for someone reading the `.h`, feel free to put it there instead, but
+ mention in the `.c` that the documentation is in the `.h` file.
+
+ Do not duplicate comments in both the `.h` and the `.c`. Duplicated
+ comments diverge. >
+
+ /// A brief description of this file.
+ ///
+ /// A longer description of this file.
+ /// Be very generous here.
+
+
+Struct Comments ~
+
+Every struct definition should have accompanying comments that describes what
+it is for and how it should be used. >
+
+ /// Window info stored with a buffer.
+ ///
+ /// Two types of info are kept for a buffer which are associated with a
+ /// specific window:
+ /// 1. Each window can have a different line number associated with a
+ /// buffer.
+ /// 2. The window-local options for a buffer work in a similar way.
+ /// The window-info is kept in a list at g_wininfo. It is kept in
+ /// most-recently-used order.
+ struct win_info {
+ /// Next entry or NULL for last entry.
+ WinInfo *wi_next;
+ /// Previous entry or NULL for first entry.
+ WinInfo *wi_prev;
+ /// Pointer to window that did the wi_fpos.
+ Win *wi_win;
+ ...
+ };
+
+If the field comments are short, you can also put them next to the field. But
+be consistent within one struct. >
+
+ struct wininfo_S {
+ WinInfo *wi_next; /// Next entry or NULL for last entry.
+ WinInfo *wi_prev; /// Previous entry or NULL for first entry.
+ Win *wi_win; /// Pointer to window that did the wi_fpos.
+ ...
+ };
+
+If you have already described a struct in detail in the comments at the top of
+your file feel free to simply state "See comment at top of file for a complete
+description", but be sure to have some sort of comment.
+
+Document the synchronization assumptions the struct makes, if any. If an
+instance of the struct can be accessed by multiple threads, take extra care to
+document the rules and invariants surrounding multithreaded use.
+
+
+Function Comments ~
+
+Declaration comments describe use of the function; comments at the definition
+of a function describe operation.
+
+ Function Declarations ~
+
+ Every function declaration should have comments immediately preceding it
+ that describe what the function does and how to use it. These comments
+ should be descriptive ("Opens the file") rather than imperative ("Open the
+ file"); the comment describes the function, it does not tell the function
+ what to do. In general, these comments do not describe how the function
+ performs its task. Instead, that should be left to comments in the
+ function definition.
+
+ Types of things to mention in comments at the function declaration:
+
+ - If the function allocates memory that the caller must free.
+ - Whether any of the arguments can be a null pointer.
+ - If there are any performance implications of how a function is used.
+ - If the function is re-entrant. What are its synchronization assumptions?
+ >
+ /// Brief description of the function.
+ ///
+ /// Detailed description.
+ /// May span multiple paragraphs.
+ ///
+ /// @param arg1 Description of arg1
+ /// @param arg2 Description of arg2. May span
+ /// multiple lines.
+ ///
+ /// @return Description of the return value.
+ Iterator *get_iterator(void *arg1, void *arg2);
+<
+
+ Function Definitions ~
+
+ If there is anything tricky about how a function does its job, the
+ function definition should have an explanatory comment. For example, in
+ the definition comment you might describe any coding tricks you use, give
+ an overview of the steps you go through, or explain why you chose to
+ implement the function in the way you did rather than using a viable
+ alternative. For instance, you might mention why it must acquire a lock
+ for the first half of the function but why it is not needed for the second
+ half.
+
+ Note you should not just repeat the comments given with the function
+ declaration, in the `.h` file or wherever. It's okay to recapitulate
+ briefly what the function does, but the focus of the comments should be on
+ how it does it. >
+
+ // Note that we don't use Doxygen comments here.
+ Iterator *get_iterator(void *arg1, void *arg2)
+ {
+ ...
+ }
+
+
+Variable Comments ~
+
+In general the actual name of the variable should be descriptive enough to
+give a good idea of what the variable is used for. In certain cases, more
+comments are required.
+
+ Global Variables ~
+
+ All global variables should have a comment describing what they are and
+ what they are used for. For example: >
+
+ /// The total number of tests cases that we run
+ /// through in this regression test.
+ const int kNumTestCases = 6;
+
+
+Implementation Comments ~
+
+In your implementation you should have comments in tricky, non-obvious,
+interesting, or important parts of your code.
+
+ Line Comments ~
+
+ Also, lines that are non-obvious should get a comment at the end of the
+ line. These end-of-line comments should be separated from the code by 2
+ spaces. Example: >
+
+ // If we have enough memory, mmap the data portion too.
+ mmap_budget = max<int64>(0, mmap_budget - index_->length());
+ if (mmap_budget >= data_size_ && !MmapData(mmap_chunk_bytes, mlock)) {
+ return; // Error already logged.
+ }
+<
+ Note that there are both comments that describe what the code is doing,
+ and comments that mention that an error has already been logged when the
+ function returns.
+
+ If you have several comments on subsequent lines, it can often be more
+ readable to line them up: >
+
+ do_something(); // Comment here so the comments line up.
+ do_something_else_that_is_longer(); // Comment here so there are two spaces between
+ // the code and the comment.
+ { // One space before comment when opening a new scope is allowed,
+ // thus the comment lines up with the following comments and code.
+ do_something_else(); // Two spaces before line comments normally.
+ }
+<
+
+ NULL, true/false, 1, 2, 3... ~
+
+ When you pass in a null pointer, boolean, or literal integer values to
+ functions, you should consider adding a comment about what they are, or
+ make your code self-documenting by using constants. For example, compare:
+ >
+
+ bool success = calculate_something(interesting_value,
+ 10,
+ false,
+ NULL); // What are these arguments??
+<
+
+ versus: >
+
+ bool success = calculate_something(interesting_value,
+ 10, // Default base value.
+ false, // Not the first time we're calling this.
+ NULL); // No callback.
+<
+
+ Or alternatively, constants or self-describing variables: >
+
+ const int kDefaultBaseValue = 10;
+ const bool kFirstTimeCalling = false;
+ Callback *null_callback = NULL;
+ bool success = calculate_something(interesting_value,
+ kDefaultBaseValue,
+ kFirstTimeCalling,
+ null_callback);
+<
+
+ Don'ts ~
+
+ Note that you should never describe the code itself. Assume that the
+ person reading the code knows C better than you do, even though he or she
+ does not know what you are trying to do: >
+
+ // Now go through the b array and make sure that if i occurs,
+ // the next element is i+1.
+ ... // Geez. What a useless comment.
+
+
+Punctuation, Spelling and Grammar ~
+
+Pay attention to punctuation, spelling, and grammar; it is easier to read
+well-written comments than badly written ones.
+
+Comments should be as readable as narrative text, with proper capitalization
+and punctuation. In many cases, complete sentences are more readable than
+sentence fragments. Shorter comments, such as comments at the end of a line of
+code, can sometimes be less formal, but you should be consistent with your
+style.
+
+Although it can be frustrating to have a code reviewer point out that you are
+using a comma when you should be using a semicolon, it is very important that
+source code maintain a high level of clarity and readability. Proper
+punctuation, spelling, and grammar help with that goal.
+
+
+TODO Comments ~
+
+Use `TODO` comments for code that is temporary, a short-term solution, or
+good-enough but not perfect.
+
+`TODO`s should include the string `TODO` in all caps, followed by the name,
+email address, or other identifier of the person who can best provide context
+about the problem referenced by the `TODO`. The main purpose is to have a
+consistent `TODO` format that can be searched to find the person who can
+provide more details upon request. A `TODO` is not a commitment that the
+person referenced will fix the problem. Thus when you create a `TODO`, it is
+almost always your name that is given. >
+
+ // TODO(kl@gmail.com): Use a "*" here for concatenation operator.
+ // TODO(Zeke): change this to use relations.
+
+If your `TODO` is of the form "At a future date do something" make sure that
+you either include a very specific date ("Fix by November 2005") or a very
+specific event ("Remove this code when all clients can handle XML
+responses.").
+
+
+Deprecation Comments ~
+
+Mark deprecated interface points with `@deprecated` docstring token.
+
+You can mark an interface as deprecated by writing a comment containing the
+word `@deprecated` in all caps. The comment goes either before the declaration
+of the interface or on the same line as the declaration.
+
+After `@deprecated`, write your name, email, or other identifier in
+parentheses.
+
+A deprecation comment must include simple, clear directions for people to fix
+their callsites. In C, you can implement a deprecated function as an inline
+function that calls the new interface point.
+
+Marking an interface point `DEPRECATED` will not magically cause any callsites
+to change. If you want people to actually stop using the deprecated facility,
+you will have to fix the callsites yourself or recruit a crew to help you.
+
+New code should not contain calls to deprecated interface points. Use the new
+interface point instead. If you cannot understand the directions, find the
+person who created the deprecation and ask them for help using the new
+interface point.
+
+
+==============================================================================
+Formatting *dev-style-format*
+
+Coding style and formatting are pretty arbitrary, but a project is much easier
+to follow if everyone uses the same style. Individuals may not agree with
+every aspect of the formatting rules, and some of the rules may take some
+getting used to, but it is important that all project contributors follow the
+style rules so that they can all read and understand everyone's code easily.
+
+
+Line Length ~
+
+Each line of text in your code should be at most 100 characters long.
+
+Exception: if a comment line contains an example command or a literal URL
+longer than 100 characters, that line may be longer than 100 characters for ease
+of cut and paste.
+
+
+Non-ASCII Characters ~
+
+Non-ASCII characters should be rare, and must use UTF-8 formatting.
+
+You shouldn't hard-code user-facing text in source (OR SHOULD YOU?), even
+English, so use of non-ASCII characters should be rare. However, in certain
+cases it is appropriate to include such words in your code. For example, if
+your code parses data files from foreign sources, it may be appropriate to
+hard-code the non-ASCII string(s) used in those data files as delimiters. More
+commonly, unittest code (which does not need to be localized) might contain
+non-ASCII strings. In such cases, you should use UTF-8, since that is an
+encoding understood by most tools able to handle more than just ASCII.
+
+Hex encoding is also OK, and encouraged where it enhances readability — for
+example, `"\uFEFF"`, is the Unicode zero-width no-break space character, which
+would be invisible if included in the source as straight UTF-8.
+
+
+Spaces vs. Tabs ~
+
+Use only spaces, and indent 2 spaces at a time. Do not use tabs in your code.
+
+
+Function Declarations and Definitions ~
+
+Return type on the same line as function name, parameters on the same line if
+they fit.
+
+Functions look like this: >
+
+ ReturnType function_name(Type par_name1, Type par_name2)
+ {
+ do_something();
+ ...
+ }
+
+If you have too much text to fit on one line: >
+
+ ReturnType really_long_function_name(Type par_name1, Type par_name2,
+ Type par_name3)
+ {
+ do_something();
+ ...
+ }
+
+or if you cannot fit even the first parameter (but only then): >
+
+ ReturnType really_really_really_long_function_name(
+ Type par_name1, // 4 space indent
+ Type par_name2,
+ Type par_name3)
+ {
+ do_something(); // 2 space indent
+ ...
+ }
+
+Some points to note:
+
+- The open parenthesis is always on the same line as the function name.
+- There is never a space between the function name and the open parenthesis.
+- There is never a space between the parentheses and the parameters.
+- The open curly brace is always on the next line.
+- The close curly brace is always on the last line by itself.
+- There should be a space between the close parenthesis and the open curly
+ brace.
+- All parameters should be named, with identical names in the declaration and
+ implementation.
+- All parameters should be aligned if possible.
+- Default indentation is 2 spaces.
+- Wrapped parameters have a 4 space indent.
+
+
+Function Calls ~
+
+On one line if it fits; otherwise, wrap arguments at the parenthesis.
+
+Function calls have the following format: >
+
+ bool retval = do_something(argument1, argument2, argument3);
+
+If the arguments do not all fit on one line, they should be broken up onto
+multiple lines, with each subsequent line aligned with the first argument. Do
+not add spaces after the open paren or before the close paren: >
+
+ bool retval = do_something(averyveryveryverylongargument1,
+ argument2, argument3);
+
+If the function has many arguments, consider having one per line if this makes
+the code more readable: >
+
+ bool retval = do_something(argument1,
+ argument2,
+ argument3,
+ argument4);
+
+Arguments may optionally all be placed on subsequent lines, with one line per
+argument: >
+
+ if (...) {
+ ...
+ ...
+ if (...) {
+ do_something(
+ argument1, // 4 space indent
+ argument2,
+ argument3,
+ argument4);
+ }
+
+In particular, this should be done if the function signature is so long that
+it cannot fit within the maximum line length.
+
+
+Braced Initializer Lists ~
+
+Format a braced list exactly like you would format a function call in its
+place but with one space after the `{` and one space before the `}`
+
+If the braced list follows a name (e.g. a type or variable name), format as if
+the `{}` were the parentheses of a function call with that name. If there is
+no name, assume a zero-length name. >
+
+ struct my_struct m = { // Here, you could also break before {.
+ superlongvariablename1,
+ superlongvariablename2,
+ { short, interior, list },
+ { interiorwrappinglist,
+ interiorwrappinglist2 } };
+
+
+Conditionals ~
+
+Don't use spaces inside parentheses. Always use curly braces. >
+
+ if (condition) { // no spaces inside parentheses
+ ... // 2 space indent.
+ } else if (...) { // The else goes on the same line as the closing brace.
+ ...
+ } else {
+ ...
+ }
+
+You must have a space between the `if` and the open parenthesis. You must also
+have a space between the close parenthesis and the curly brace, if you're
+using one. >
+
+ if(condition) { // BAD: space missing after IF.
+ if (condition){ // BAD: space missing before {.
+ if (condition) { // GOOD: proper space after IF and before {.
+
+
+Loops and Switch Statements ~
+
+Annotate non-trivial fall-through between cases. Empty loop bodies should use
+`{}` or `continue`.
+
+If not conditional on an enumerated value, switch statements should always
+have a `default` case (in the case of an enumerated value, the compiler will
+warn you if any values are not handled). If the default case should never
+execute, simply `assert`: >
+
+ switch (var) {
+ case 0: // 2 space indent
+ ... // 4 space indent
+ break;
+ case 1:
+ ...
+ break;
+ default:
+ assert(false);
+ }
+
+Empty loop bodies should use `{}` or `continue`, but not a single semicolon. >
+
+ while (condition) {
+ // Repeat test until it returns false.
+ }
+ for (int i = 0; i < kSomeNumber; i++) {} // GOOD: empty body.
+ while (condition) continue; // GOOD: continue indicates no logic.
+
+ while (condition); // BAD: looks like part of do/while loop.
+
+Pointer Expressions ~
+
+No spaces around period or arrow. Pointer operators do not have trailing
+spaces.
+
+The following are examples of correctly-formatted pointer and reference
+expressions: >
+
+ x = *p;
+ p = &x;
+ x = r.y;
+ x = r->y;
+
+Note that:
+
+ - There are no spaces around the period or arrow when accessing a member.
+ - Pointer operators have no space after the * or &.
+
+When declaring a pointer variable or argument, place the asterisk adjacent to
+the variable name: >
+
+ char *c;
+
+ char * c; // BAD: spaces on both sides of *
+ char* c; // BAD
+
+
+Boolean Expressions ~
+
+When you have a boolean expression that is longer than the standard line
+length, keep operators at the start of the line. >
+
+ if (this_one_thing > this_other_thing
+ && a_third_thing == a_fourth_thing
+ && yet_another && last_one) {
+ ...
+ }
+
+Also note that you should always use the punctuation operators, such as `&&`
+and `~`, rather than the word operators, such as `and` and `compl`.
+
+
+Return Values ~
+
+Do not needlessly surround the `return` expression with parentheses.
+
+Use parentheses in `return expr`; only where you would use them in `x =
+expr;`. >
+
+ return result;
+ return (some_long_condition && another_condition);
+
+ return (value); // You wouldn't write var = (value);
+ return(result); // return is not a function!
+
+
+Preprocessor Directives ~
+
+The hash mark that starts a preprocessor directive should always be at the
+beginning of the line.
+
+Even when preprocessor directives are within the body of indented code, the
+directives should start at the beginning of the line.
+
+Nested directives should add one spaces after the hash mark for each level of
+indentation.
+
+ // GOOD: directives at beginning of line >
+ if (lopsided_score) {
+ #if DISASTER_PENDING // Correct -- Starts at beginning of line
+ drop_everything();
+ # if NOTIFY // One space after #
+ notify_client();
+ # endif
+ #endif
+ BackToNormal();
+ }
+
+< // BAD: indented directives >
+ if (lopsided_score) {
+ #if DISASTER_PENDING // Wrong! The "#if" should be at beginning of line
+ drop_everything();
+ #endif // Wrong! Do not indent "#endif"
+ back_to_normal();
+ }
+
+
+Horizontal Whitespace ~
+
+Use of horizontal whitespace depends on location. Never put trailing
+whitespace at the end of a line.
+
+ General ~
+>
+ if (x) { // Open braces should always have a space before them.
+ ...
+ }
+ int i = 0; // Semicolons usually have no space before them.
+ int x[] = { 0 }; // Spaces inside braces for braced-init-list.
+<
+
+ Variables ~
+>
+ int long_variable = 0; // Don't align assignments.
+ int i = 1;
+
+ struct my_struct { // Exception: struct arrays.
+ const char *boy;
+ const char *girl;
+ int pos;
+ } my_variable[] = {
+ { "Mia", "Michael", 8 },
+ { "Elizabeth", "Aiden", 10 },
+ { "Emma", "Mason", 2 },
+ };
+<
+
+ Macros ~
+>
+ #define FI(x) \ // Don't align \'s in macro definitions.
+ foo(); \
+ bar(); \
+ ...
+<
+
+ Loops and Conditionals ~
+>
+ if (b) { // Space after the keyword in condition.
+ } else { // Spaces around else.
+ }
+ while (test) {} // There is usually no space inside parentheses.
+ for (; i < 5; i++) { // For loops always have a space after the
+ ... // semicolon and no a space before the
+ ... // semicolon.
+ }
+ switch (i) {
+ case 1: // No space before colon in a switch case.
+ ...
+ case 2: break; // Space after a colon if there's code after it.
+<
+
+ Operators ~
+>
+ x = 0; // Assignment operators always have spaces around
+ // them.
+ x = -5; // No spaces separating unary operators and their
+ x++; // arguments.
+ if (x && !y)
+ ...
+ v = w*x + y/z; // Use spaces to indicate operator precedence.
+ v = w * (x + z); // Parentheses should have no spaces inside them.
+ i = (int)d; // No spaces after a cast operator.
+<
+
+Vertical Whitespace ~
+
+Minimize use of vertical whitespace.
+
+This is more a principle than a rule: don't use blank lines when you don't
+have to. In particular, don't put more than one or two blank lines between
+functions, resist starting functions with a blank line, don't end functions
+with a blank line, and be discriminating with your use of blank lines inside
+functions.
+
+The basic principle is: The more code that fits on one screen, the easier it
+is to follow and understand the control flow of the program. Of course,
+readability can suffer from code being too dense as well as too spread out, so
+use your judgment. But in general, minimize use of vertical whitespace.
+
+
+==============================================================================
+Parting Words
+
+The style guide is intended to make the code more readable. If you think you
+must violate its rules for the sake of clarity, do it! But please add a note
+to your pull request explaining your reasoning.
+
+
+ vim:tw=78:ts=8:et:ft=help:norl:
diff --git a/runtime/doc/develop.txt b/runtime/doc/develop.txt
index aec0178da2..14f35acce3 100644
--- a/runtime/doc/develop.txt
+++ b/runtime/doc/develop.txt
@@ -46,7 +46,7 @@ NVIM IS... WELL DOCUMENTED *design-documented*
item is easier to find.
-NVIM IS... HIGH SPEED AND SMALL IN SIZE *design-speed-size*
+NVIM IS... FAST AND SMALL *design-speed-size*
Keep Nvim small and fast.
- Computers are becoming faster and bigger each year. Vim can grow too, but
@@ -127,14 +127,20 @@ Sometimes a GUI or other application may want to force a provider to
DOCUMENTATION *dev-doc*
-- Do not prefix help tags with "nvim-". Use |vim_diff.txt| to document
- differences from Vim; no other distinction is necessary.
-- If a Vim feature is removed, delete its help section and move its tag to
- |vim_diff.txt|.
-- Move deprecated features to |deprecated.txt|.
+- "Just say it". Avoid mushy, colloquial phrasing in all documentation
+ (docstrings, user manual, website materials, newsletters, …). Don't mince
+ words. Personality and flavor, used sparingly, are welcome--but in general,
+ optimize for the reader's time and energy: be "precise yet concise".
+ - Prefer the active voice: "Foo does X", not "X is done by Foo".
+- Vim differences:
+ - Do not prefix help tags with "nvim-". Use |vim_diff.txt| to catalog
+ differences from Vim; no other distinction is necessary.
+ - If a Vim feature is removed, delete its help section and move its tag to
+ |vim_diff.txt|.
+- Mention deprecated features in |deprecated.txt| and delete their old doc.
- Use consistent language.
- - "terminal" in a help tag always means "the embedded terminal emulator", not
- "the user host terminal".
+ - "terminal" in a help tag always means "the embedded terminal emulator",
+ not "the user host terminal".
- Use "tui-" to prefix help tags related to the host terminal, and "TUI"
in prose if possible.
- Docstrings: do not start parameter descriptions with "The" or "A" unless it
@@ -191,8 +197,8 @@ definitions. The |lua-vim| :help is generated from the docstrings.
Docstring format:
- Lines in the main description start with `---`
-- Special tokens start with `--@` followed by the token name:
- `--@see`, `--@param`, `--@returns`
+- Special tokens start with `---@` followed by the token name:
+ `---@see`, `---@param`, `---@returns`
- Limited markdown is supported.
- List-items start with `-` (useful to nest or "indent")
- Use `<pre>` for code samples.
@@ -211,24 +217,24 @@ vim.paste in src/nvim/lua/vim.lua like this: >
--- end)()
--- </pre>
---
- --@see |paste|
+ ---@see |paste|
---
- --@param lines ...
- --@param phase ...
- --@returns false if client should cancel the paste.
+ ---@param lines ...
+ ---@param phase ...
+ ---@returns false if client should cancel the paste.
LUA *dev-lua*
- Keep the core Lua modules |lua-stdlib| simple. Avoid elaborate OOP or
pseudo-OOP designs. Plugin authors just want functions to call, they don't
- want to learn a big, fancy inheritance hierarchy. So we should avoid complex
- objects: tables are usually better.
+ want to learn a big, fancy inheritance hierarchy. Thus avoid specialized
+ objects; tables or values are usually better.
API *dev-api*
-Use this template to name new API functions:
+Use this template to name new RPC |API| functions:
nvim_{thing}_{action}_{arbitrary-qualifiers}
If the function acts on an object then {thing} is the name of that object
@@ -356,4 +362,19 @@ External UIs are expected to implement these common features:
published in this event. See also "mouse_on", "mouse_off".
+NAMING *dev-naming*
+
+Naming is important. Consistent naming in the API and UI helps both users and
+developers discover and intuitively understand related concepts ("families"),
+and reduces cognitive burden. Discoverability encourages code re-use and
+likewise avoids redundant, overlapping mechanisms, which reduces code
+surface-area, and thereby minimizes bugs...
+
+Naming conventions ~
+
+Use the "on_" prefix to name event handlers and also the interface for
+"registering" such handlers (on_key). The dual nature is acceptable to avoid
+a confused collection of naming conventions for these related concepts.
+
+
vim:tw=78:ts=8:noet:ft=help:norl:
diff --git a/runtime/doc/diagnostic.txt b/runtime/doc/diagnostic.txt
new file mode 100644
index 0000000000..679bb2f7ff
--- /dev/null
+++ b/runtime/doc/diagnostic.txt
@@ -0,0 +1,562 @@
+*diagnostic.txt* Diagnostics
+
+
+ NVIM REFERENCE MANUAL
+
+
+Diagnostic framework *vim.diagnostic*
+
+Nvim provides a framework for displaying errors or warnings from external
+tools, otherwise known as "diagnostics". These diagnostics can come from a
+variety of sources, such as linters or LSP servers. The diagnostic framework
+is an extension to existing error handling functionality such as the
+|quickfix| list.
+
+ Type |gO| to see the table of contents.
+
+==============================================================================
+QUICKSTART *diagnostic-quickstart*
+
+Anything that reports diagnostics is referred to below as a "diagnostic
+producer". Diagnostic producers need only follow a few simple steps to
+report diagnostics:
+
+1. Create a namespace |nvim_create_namespace()|. Note that the namespace must
+ have a name. Anonymous namespaces WILL NOT WORK.
+2. (Optional) Configure options for the diagnostic namespace
+ |vim.diagnostic.config()|.
+3. Generate diagnostics.
+4. Set the diagnostics for the buffer |vim.diagnostic.set()|.
+5. Repeat from step 3.
+
+Generally speaking, the API is split between functions meant to be used by
+diagnostic producers and those meant for diagnostic consumers (i.e. end users
+who want to read and view the diagnostics for a buffer). The APIs for
+producers require a {namespace} as their first argument, while those for
+consumers generally do not require a namespace (though often one may be
+optionally supplied). A good rule of thumb is that if a method is meant to
+modify the diagnostics for a buffer (e.g. |vim.diagnostic.set()|) then it
+requires a namespace.
+
+ *diagnostic-structure*
+A diagnostic is a Lua table with the following keys:
+
+ lnum: The starting line of the diagnostic
+ end_lnum: The final line of the diagnostic
+ col: The starting column of the diagnostic
+ end_col: The final column of the diagnostic
+ severity: The severity of the diagnostic |vim.diagnostic.severity|
+ message: The diagnostic text
+ source: The source of the diagnostic
+
+Diagnostics use the same indexing as the rest of the Nvim API (i.e. 0-based
+rows and columns). |api-indexing|
+
+ *vim.diagnostic.severity* *diagnostic-severity*
+The "severity" key in a diagnostic is one of the values defined in
+`vim.diagnostic.severity`:
+
+ vim.diagnostic.severity.ERROR
+ vim.diagnostic.severity.WARN
+ vim.diagnostic.severity.INFO
+ vim.diagnostic.severity.HINT
+
+Functions that take a severity as an optional parameter (e.g.
+|vim.diagnostic.get()|) accept one of two forms:
+
+1. A single |vim.diagnostic.severity| value: >
+
+ vim.diagnostic.get(0, { severity = vim.diagnostic.severity.WARN })
+
+2. A table with a "min" or "max" key (or both): >
+
+ vim.diagnostic.get(0, { severity = {min=vim.diagnostic.severity.WARN})
+
+The latter form allows users to specify a range of severities.
+
+==============================================================================
+HIGHLIGHTS *diagnostic-highlights*
+
+All highlights defined for diagnostics begin with `Diagnostic` followed by
+the type of highlight (e.g., `Sign`, `Underline`, etc.) and the severity (e.g.
+`Error`, `Warn`, etc.)
+
+Sign, underline and virtual text highlights (by default) are linked to their
+corresponding default highlight.
+
+For example, the default highlighting for |hl-DiagnosticSignError| is linked
+to |hl-DiagnosticError|. To change the default (and therefore the linked
+highlights), use the |:highlight| command: >
+
+ highlight DiagnosticError guifg="BrightRed"
+<
+ *hl-DiagnosticError*
+DiagnosticError
+ Used as the base highlight group.
+ Other Diagnostic highlights link to this by default (except Underline)
+
+ *hl-DiagnosticWarn*
+DiagnosticWarn
+ Used as the base highlight group.
+ Other Diagnostic highlights link to this by default (except Underline)
+
+ *hl-DiagnosticInfo*
+DiagnosticInfo
+ Used as the base highlight group.
+ Other Diagnostic highlights link to this by default (except Underline)
+
+ *hl-DiagnosticHint*
+DiagnosticHint
+ Used as the base highlight group.
+ Other Diagnostic highlights link to this by default (except Underline)
+
+ *hl-DiagnosticVirtualTextError*
+DiagnosticVirtualTextError
+ Used for "Error" diagnostic virtual text.
+
+ *hl-DiagnosticVirtualTextWarn*
+DiagnosticVirtualTextWarn
+ Used for "Warn" diagnostic virtual text.
+
+ *hl-DiagnosticVirtualTextInfo*
+DiagnosticVirtualTextInfo
+ Used for "Info" diagnostic virtual text.
+
+ *hl-DiagnosticVirtualTextHint*
+DiagnosticVirtualTextHint
+ Used for "Hint" diagnostic virtual text.
+
+ *hl-DiagnosticUnderlineError*
+DiagnosticUnderlineError
+ Used to underline "Error" diagnostics.
+
+ *hl-DiagnosticUnderlineWarn*
+DiagnosticUnderlineWarn
+ Used to underline "Warn" diagnostics.
+
+ *hl-DiagnosticUnderlineInfo*
+DiagnosticUnderlineInfo
+ Used to underline "Info" diagnostics.
+
+ *hl-DiagnosticUnderlineHint*
+DiagnosticUnderlineHint
+ Used to underline "Hint" diagnostics.
+
+ *hl-DiagnosticFloatingError*
+DiagnosticFloatingError
+ Used to color "Error" diagnostic messages in diagnostics float.
+ See |vim.diagnostic.show_line_diagnostics()|
+
+ *hl-DiagnosticFloatingWarn*
+DiagnosticFloatingWarn
+ Used to color "Warn" diagnostic messages in diagnostics float.
+
+ *hl-DiagnosticFloatingInfo*
+DiagnosticFloatingInfo
+ Used to color "Info" diagnostic messages in diagnostics float.
+
+ *hl-DiagnosticFloatingHint*
+DiagnosticFloatingHint
+ Used to color "Hint" diagnostic messages in diagnostics float.
+
+ *hl-DiagnosticSignError*
+DiagnosticSignError
+ Used for "Error" signs in sign column.
+
+ *hl-DiagnosticSignWarn*
+DiagnosticSignWarn
+ Used for "Warn" signs in sign column.
+
+ *hl-DiagnosticSignInfo*
+DiagnosticSignInfo
+ Used for "Info" signs in sign column.
+
+ *hl-DiagnosticSignHint*
+DiagnosticSignHint
+ Used for "Hint" signs in sign column.
+
+==============================================================================
+SIGNS *diagnostic-signs*
+
+Signs are defined for each diagnostic severity. The default text for each sign
+is the first letter of the severity name (for example, "E" for ERROR). Signs
+can be customized using the following: >
+
+ sign define DiagnosticSignError text=E texthl=DiagnosticSignError linehl= numhl=
+ sign define DiagnosticSignWarn text=W texthl=DiagnosticSignWarn linehl= numhl=
+ sign define DiagnosticSignInfo text=I texthl=DiagnosticSignInfo linehl= numhl=
+ sign define DiagnosticSignHint text=H texthl=DiagnosticSignHint linehl= numhl=
+
+When the "severity_sort" option is set (see |vim.diagnostic.config()|) the
+priority of each sign depends on the severity of the associated diagnostic.
+Otherwise, all signs have the same priority (the value of the "priority"
+option in the "signs" table of |vim.diagnostic.config()| or 10 if unset).
+
+==============================================================================
+EVENTS *diagnostic-events*
+
+ *DiagnosticsChanged*
+DiagnosticsChanged After diagnostics have changed.
+
+Example: >
+ autocmd User DiagnosticsChanged lua vim.diagnostic.setqflist({open = false })
+<
+
+==============================================================================
+Lua module: vim.diagnostic *diagnostic-api*
+
+config({opts}, {namespace}) *vim.diagnostic.config()*
+ Configure diagnostic options globally or for a specific
+ diagnostic namespace.
+
+ Note:
+ Each of the configuration options below accepts one of the
+ following:
+ • `false` : Disable this feature
+ • `true` : Enable this feature, use default settings.
+ • `table` : Enable this feature with overrides.
+ • `function` : Function with signature (namespace, bufnr)
+ that returns any of the above.
+
+ Parameters: ~
+ {opts} table Configuration table with the following
+ keys:
+ • underline: (default true) Use underline for
+ diagnostics. Options:
+ • severity: Only underline diagnostics
+ matching the given severity
+ |diagnostic-severity|
+
+ • virtual_text: (default true) Use virtual
+ text for diagnostics. Options:
+ • severity: Only show virtual text for
+ diagnostics matching the given severity
+ |diagnostic-severity|
+ • source: (string) Include the diagnostic
+ source in virtual text. One of "always"
+ or "if_many".
+ • format: (function) A function that takes
+ a diagnostic as input and returns a
+ string. The return value is the text used
+ to display the diagnostic. Example:>
+
+ function(diagnostic)
+ if diagnostic.severity == vim.diagnostic.severity.ERROR then
+ return string.format("E: %s", diagnostic.message)
+ end
+ return diagnostic.message
+ end
+<
+
+ • signs: (default true) Use signs for
+ diagnostics. Options:
+ • severity: Only show signs for diagnostics
+ matching the given severity
+ |diagnostic-severity|
+
+ • update_in_insert: (default false) Update
+ diagnostics in Insert mode (if false,
+ diagnostics are updated on InsertLeave)
+ • severity_sort: (default false) Sort
+ diagnostics by severity. This affects the
+ order in which signs and virtual text are
+ displayed. When true, higher severities are
+ displayed before lower severities (e.g.
+ ERROR is displayed before WARN). Options:
+ • reverse: (boolean) Reverse sort order
+ {namespace} number|nil Update the options for the given
+ namespace. When omitted, update the global
+ diagnostic options.
+
+disable({bufnr}, {namespace}) *vim.diagnostic.disable()*
+ Disable diagnostics in the given buffer.
+
+ Parameters: ~
+ {bufnr} number|nil Buffer number. Defaults to the
+ current buffer.
+ {namespace} number|nil Only disable diagnostics for the
+ given namespace.
+
+enable({bufnr}, {namespace}) *vim.diagnostic.enable()*
+ Enable diagnostics in the given buffer.
+
+ Parameters: ~
+ {bufnr} number|nil Buffer number. Defaults to the
+ current buffer.
+ {namespace} number|nil Only enable diagnostics for the
+ given namespace.
+
+fromqflist({list}) *vim.diagnostic.fromqflist()*
+ Convert a list of quickfix items to a list of diagnostics.
+
+ Parameters: ~
+ {list} table A list of quickfix items from |getqflist()|
+ or |getloclist()|.
+
+ Return: ~
+ array of diagnostics |diagnostic-structure|
+
+get({bufnr}, {opts}) *vim.diagnostic.get()*
+ Get current diagnostics.
+
+ Parameters: ~
+ {bufnr} number|nil Buffer number to get diagnostics from.
+ Use 0 for current buffer or nil for all buffers.
+ {opts} table|nil A table with the following keys:
+ • namespace: (number) Limit diagnostics to the
+ given namespace.
+ • lnum: (number) Limit diagnostics to the given
+ line number.
+ • severity: See |diagnostic-severity|.
+
+ Return: ~
+ table A list of diagnostic items |diagnostic-structure|.
+
+get_next({opts}) *vim.diagnostic.get_next()*
+ Get the next diagnostic closest to the cursor position.
+
+ Parameters: ~
+ {opts} table See |vim.diagnostic.goto_next()|
+
+ Return: ~
+ table Next diagnostic
+
+get_next_pos({opts}) *vim.diagnostic.get_next_pos()*
+ Return the position of the next diagnostic in the current
+ buffer.
+
+ Parameters: ~
+ {opts} table See |vim.diagnostic.goto_next()|
+
+ Return: ~
+ table Next diagnostic position as a (row, col) tuple.
+
+get_prev({opts}) *vim.diagnostic.get_prev()*
+ Get the previous diagnostic closest to the cursor position.
+
+ Parameters: ~
+ {opts} table See |vim.diagnostic.goto_next()|
+
+ Return: ~
+ table Previous diagnostic
+
+get_prev_pos({opts}) *vim.diagnostic.get_prev_pos()*
+ Return the position of the previous diagnostic in the current
+ buffer.
+
+ Parameters: ~
+ {opts} table See |vim.diagnostic.goto_next()|
+
+ Return: ~
+ table Previous diagnostic position as a (row, col) tuple.
+
+goto_next({opts}) *vim.diagnostic.goto_next()*
+ Move to the next diagnostic.
+
+ Parameters: ~
+ {opts} table|nil Configuration table with the following
+ keys:
+ • namespace: (number) Only consider diagnostics
+ from the given namespace.
+ • cursor_position: (cursor position) Cursor
+ position as a (row, col) tuple. See
+ |nvim_win_get_cursor()|. Defaults to the current
+ cursor position.
+ • wrap: (boolean, default true) Whether to loop
+ around file or not. Similar to 'wrapscan'.
+ • severity: See |diagnostic-severity|.
+ • enable_popup: (boolean, default true) Call
+ |vim.diagnostic.show_line_diagnostics()| on
+ jump.
+ • popup_opts: (table) Table to pass as {opts}
+ parameter to
+ |vim.diagnostic.show_line_diagnostics()|
+ • win_id: (number, default 0) Window ID
+
+goto_prev({opts}) *vim.diagnostic.goto_prev()*
+ Move to the previous diagnostic in the current buffer.
+
+ Parameters: ~
+ {opts} table See |vim.diagnostic.goto_next()|
+
+hide({namespace}, {bufnr}) *vim.diagnostic.hide()*
+ Hide currently displayed diagnostics.
+
+ This only clears the decorations displayed in the buffer.
+ Diagnostics can be redisplayed with |vim.diagnostic.show()|.
+ To completely remove diagnostics, use
+ |vim.diagnostic.reset()|.
+
+ To hide diagnostics and prevent them from re-displaying, use
+ |vim.diagnostic.disable()|.
+
+ Parameters: ~
+ {namespace} number The diagnostic namespace
+ {bufnr} number|nil Buffer number. Defaults to the
+ current buffer.
+
+ *vim.diagnostic.match()*
+match({str}, {pat}, {groups}, {severity_map}, {defaults})
+ Parse a diagnostic from a string.
+
+ For example, consider a line of output from a linter: >
+
+ WARNING filename:27:3: Variable 'foo' does not exist
+
+ < This can be parsed into a diagnostic |diagnostic-structure|
+ with: >
+
+ local s = "WARNING filename:27:3: Variable 'foo' does not exist"
+ local pattern = "^(%w+) %w+:(%d+):(%d+): (.+)$"
+ local groups = {"severity", "lnum", "col", "message"}
+ vim.diagnostic.match(s, pattern, groups, {WARNING = vim.diagnostic.WARN})
+<
+
+ Parameters: ~
+ {str} string String to parse diagnostics from.
+ {pat} string Lua pattern with capture groups.
+ {groups} table List of fields in a
+ |diagnostic-structure| to associate with
+ captures from {pat}.
+ {severity_map} table A table mapping the severity field
+ from {groups} with an item from
+ |vim.diagnostic.severity|.
+ {defaults} table|nil Table of default values for any
+ fields not listed in {groups}. When
+ omitted, numeric values default to 0 and
+ "severity" defaults to ERROR.
+
+ Return: ~
+ diagnostic |diagnostic-structure| or `nil` if {pat} fails
+ to match {str}.
+
+reset({namespace}, {bufnr}) *vim.diagnostic.reset()*
+ Remove all diagnostics from the given namespace.
+
+ Unlike |vim.diagnostic.hide()|, this function removes all
+ saved diagnostics. They cannot be redisplayed using
+ |vim.diagnostic.show()|. To simply remove diagnostic
+ decorations in a way that they can be re-displayed, use
+ |vim.diagnostic.hide()|.
+
+ Parameters: ~
+ {namespace} number
+ {bufnr} number|nil Remove diagnostics for the given
+ buffer. When omitted, diagnostics are removed
+ for all buffers.
+
+set({namespace}, {bufnr}, {diagnostics}, {opts}) *vim.diagnostic.set()*
+ Set diagnostics for the given namespace and buffer.
+
+ Parameters: ~
+ {namespace} number The diagnostic namespace
+ {bufnr} number Buffer number
+ {diagnostics} table A list of diagnostic items
+ |diagnostic-structure|
+ {opts} table|nil Display options to pass to
+ |vim.diagnostic.show()|
+
+setloclist({opts}) *vim.diagnostic.setloclist()*
+ Add buffer diagnostics to the location list.
+
+ Parameters: ~
+ {opts} table|nil Configuration table with the following
+ keys:
+ • namespace: (number) Only add diagnostics from
+ the given namespace.
+ • winnr: (number, default 0) Window number to set
+ location list for.
+ • open: (boolean, default true) Open the location
+ list after setting.
+ • title: (string) Title of the location list.
+ Defaults to "Diagnostics".
+ • severity: See |diagnostic-severity|.
+
+setqflist({opts}) *vim.diagnostic.setqflist()*
+ Add all diagnostics to the quickfix list.
+
+ Parameters: ~
+ {opts} table|nil Configuration table with the following
+ keys:
+ • namespace: (number) Only add diagnostics from
+ the given namespace.
+ • open: (boolean, default true) Open quickfix list
+ after setting.
+ • title: (string) Title of quickfix list. Defaults
+ to "Diagnostics".
+ • severity: See |diagnostic-severity|.
+
+ *vim.diagnostic.show()*
+show({namespace}, {bufnr}, {diagnostics}, {opts})
+ Display diagnostics for the given namespace and buffer.
+
+ Parameters: ~
+ {namespace} number Diagnostic namespace
+ {bufnr} number|nil Buffer number. Defaults to the
+ current buffer.
+ {diagnostics} table|nil The diagnostics to display. When
+ omitted, use the saved diagnostics for the
+ given namespace and buffer. This can be
+ used to display a list of diagnostics
+ without saving them or to display only a
+ subset of diagnostics.
+ {opts} table|nil Display options. See
+ |vim.diagnostic.config()|.
+
+ *vim.diagnostic.show_line_diagnostics()*
+show_line_diagnostics({opts}, {bufnr}, {lnum})
+ Open a floating window with the diagnostics from the given
+ line.
+
+ Parameters: ~
+ {opts} table Configuration table. See
+ |vim.diagnostic.show_position_diagnostics()|.
+ {bufnr} number|nil Buffer number. Defaults to the current
+ buffer.
+ {lnum} number|nil Line number. Defaults to line number
+ of cursor.
+
+ Return: ~
+ tuple ({popup_bufnr}, {win_id})
+
+ *vim.diagnostic.show_position_diagnostics()*
+show_position_diagnostics({opts}, {bufnr}, {position})
+ Open a floating window with the diagnostics at the given
+ position.
+
+ Parameters: ~
+ {opts} table|nil Configuration table with the same
+ keys as |vim.lsp.util.open_floating_preview()|
+ in addition to the following:
+ • namespace: (number) Limit diagnostics to the
+ given namespace
+ • severity: See |diagnostic-severity|.
+ • show_header: (boolean, default true) Show
+ "Diagnostics:" header
+ • source: (string) Include the diagnostic
+ source in the message. One of "always" or
+ "if_many".
+ • format: (function) A function that takes a
+ diagnostic as input and returns a string.
+ The return value is the text used to display
+ the diagnostic.
+ {bufnr} number|nil Buffer number. Defaults to the
+ current buffer.
+ {position} table|nil The (0,0)-indexed position. Defaults
+ to the current cursor position.
+
+ Return: ~
+ tuple ({popup_bufnr}, {win_id})
+
+toqflist({diagnostics}) *vim.diagnostic.toqflist()*
+ Convert a list of diagnostics to a list of quickfix items that
+ can be passed to |setqflist()| or |setloclist()|.
+
+ Parameters: ~
+ {diagnostics} table List of diagnostics
+ |diagnostic-structure|.
+
+ Return: ~
+ array of quickfix list items |setqflist-what|
+
+ vim:tw=78:ts=8:ft=help:norl:
diff --git a/runtime/doc/diff.txt b/runtime/doc/diff.txt
index a9e2a0d522..6115a5d235 100644
--- a/runtime/doc/diff.txt
+++ b/runtime/doc/diff.txt
@@ -334,9 +334,11 @@ between file1 and file2: >
The ">" is replaced with the value of 'shellredir'.
-The output of "diff" must be a normal "ed" style diff or a unified diff. Do
-NOT use a context diff. This example explains the format that Vim expects for
-the "ed" style diff: >
+The output of "diff" must be a normal "ed" style diff or a unified diff. A
+context diff will NOT work. For a unified diff no context lines can be used.
+Using "diff -u" will NOT work, use "diff -U0".
+
+This example explains the format that Vim expects for the "ed" style diff: >
1a2
> bbb
diff --git a/runtime/doc/digraph.txt b/runtime/doc/digraph.txt
index b7dc16341d..dd7e9a331a 100644
--- a/runtime/doc/digraph.txt
+++ b/runtime/doc/digraph.txt
@@ -165,7 +165,7 @@ ROUBLE
The rouble sign was added in 2014 as 0x20bd. Vim supports the digraphs =R and
=P for this. Note that R= and P= are other characters.
- *digraph-table*
+ *digraph-table* *digraph-table-mbyte*
char digraph hex dec official name ~
^@ NU 0x00 0 NULL (NUL)
^A SH 0x01 1 START OF HEADING (SOH)
@@ -341,12 +341,6 @@ $ DO 0x24 36 DOLLAR SIGN
ý y' 0xfd 253 LATIN SMALL LETTER Y WITH ACUTE
þ th 0xfe 254 LATIN SMALL LETTER THORN (Icelandic)
ÿ y: 0xff 255 LATIN SMALL LETTER Y WITH DIAERESIS
-
-If your Vim is compiled with |multibyte| support and you are using a multibyte
-'encoding', Vim provides this enhanced set of additional digraphs:
-
- *digraph-table-mbyte*
-char digraph hex dec official name ~
Ā A- 0100 0256 LATIN CAPITAL LETTER A WITH MACRON
ā a- 0101 0257 LATIN SMALL LETTER A WITH MACRON
Ă A( 0102 0258 LATIN CAPITAL LETTER A WITH BREVE
diff --git a/runtime/doc/eval.txt b/runtime/doc/eval.txt
index bf7f2b21de..d6f72b68f7 100644
--- a/runtime/doc/eval.txt
+++ b/runtime/doc/eval.txt
@@ -14,18 +14,17 @@ Using expressions is introduced in chapter 41 of the user manual |usr_41.txt|.
1. Variables *variables*
1.1 Variable types ~
- *E712*
-There are six types of variables:
+ *E712* *E896* *E897* *E899*
+There are seven types of variables:
*Number* *Integer*
Number A 32 or 64 bit signed number. |expr-number|
The number of bits is available in |v:numbersize|.
- Examples: -123 0x10 0177 0b1011
+ Examples: -123 0x10 0177 0o177 0b1011
Float A floating point number. |floating-point-format| *Float*
Examples: 123.456 1.15e-6 -1.1e3
- *E928*
String A NUL terminated string of 8-bit unsigned characters (bytes).
|expr-string| Examples: "ab\txx\"--" 'x-z''a,c'
@@ -35,7 +34,7 @@ Funcref A reference to a function |Funcref|.
like a Partial.
Example: function("Callback", [arg], myDict)
-List An ordered sequence of items |List|.
+List An ordered sequence of items, see |List| for details.
Example: [1, 2, ['a', 'b']]
Dictionary An associative, unordered array: Each entry has a key and a
@@ -44,6 +43,11 @@ Dictionary An associative, unordered array: Each entry has a key and a
{'blue': "#0000ff", 'red': "#ff0000"}
#{blue: "#0000ff", red: "#ff0000"}
+Blob Binary Large Object. Stores any sequence of bytes. See |Blob|
+ for details.
+ Example: 0zFF00ED015DAF
+ 0z is an empty Blob.
+
The Number and String types are converted automatically, depending on how they
are used.
@@ -54,14 +58,15 @@ the Number. Examples:
Number -1 --> String "-1" ~
*octal*
Conversion from a String to a Number is done by converting the first digits to
-a number. Hexadecimal "0xf9", Octal "017", and Binary "0b10" numbers are
-recognized. If the String doesn't start with digits, the result is zero.
-Examples:
+a number. Hexadecimal "0xf9", Octal "017" or "0o17", and Binary "0b10"
+numbers are recognized. If the String doesn't start with digits, the result
+is zero. Examples:
String "456" --> Number 456 ~
String "6bar" --> Number 6 ~
String "foo" --> Number 0 ~
String "0xf1" --> Number 241 ~
String "0100" --> Number 64 ~
+ String "0o100" --> Number 64 ~
String "0b101" --> Number 5 ~
String "-8" --> Number -8 ~
String "+8" --> Number 0 ~
@@ -97,6 +102,7 @@ Note that " " and "0" are also non-empty strings, thus considered to be TRUE.
A List, Dictionary or Float is not a Number or String, thus evaluate to FALSE.
*E745* *E728* *E703* *E729* *E730* *E731*
+ *E974* *E975* *E976*
|List|, |Dictionary|, |Funcref|, and |Blob| types are not automatically
converted.
@@ -366,8 +372,8 @@ Changing the order of items in a list: >
For loop ~
-The |:for| loop executes commands for each item in a list. A variable is set
-to each item in the list in sequence. Example: >
+The |:for| loop executes commands for each item in a |List| or |Blob|.
+A variable is set to each item in the sequence. Example with a List: >
:for item in mylist
: call Doit(item)
:endfor
@@ -400,6 +406,8 @@ It is also possible to put remaining items in a List variable: >
: endif
:endfor
+For a Blob one byte at a time is used.
+
List functions ~
*E714*
@@ -578,7 +586,7 @@ It is not necessary to use the "dict" attribute for a numbered function.
If you get an error for a numbered function, you can find out what it is with
a trick. Assuming the function is 42, the command is: >
- :function {42}
+ :function g:42
Functions for Dictionaries ~
@@ -594,7 +602,137 @@ Functions that can be used with a Dictionary: >
:call map(dict, '">> " . v:val') " prepend ">> " to each item
-1.5 More about variables ~
+1.5 Blobs ~
+ *blob* *Blob* *Blobs* *E978*
+A Blob is a binary object. It can be used to read an image from a file and
+send it over a channel, for example.
+
+A Blob mostly behaves like a |List| of numbers, where each number has the
+value of an 8-bit byte, from 0 to 255.
+
+
+Blob creation ~
+
+A Blob can be created with a |blob-literal|: >
+ :let b = 0zFF00ED015DAF
+Dots can be inserted between bytes (pair of hex characters) for readability,
+they don't change the value: >
+ :let b = 0zFF00.ED01.5DAF
+
+A blob can be read from a file with |readfile()| passing the {type} argument
+set to "B", for example: >
+ :let b = readfile('image.png', 'B')
+
+
+Blob index ~
+ *blob-index* *E979*
+A byte in the Blob can be accessed by putting the index in square brackets
+after the Blob. Indexes are zero-based, thus the first byte has index zero. >
+ :let myblob = 0z00112233
+ :let byte = myblob[0] " get the first byte: 0x00
+ :let byte = myblob[2] " get the third byte: 0x22
+
+A negative index is counted from the end. Index -1 refers to the last byte in
+the Blob, -2 to the last but one byte, etc. >
+ :let last = myblob[-1] " get the last byte: 0x33
+
+To avoid an error for an invalid index use the |get()| function. When an item
+is not available it returns -1 or the default value you specify: >
+ :echo get(myblob, idx)
+ :echo get(myblob, idx, 999)
+
+
+Blob iteration ~
+
+The |:for| loop executes commands for each byte of a Blob. The loop variable is
+set to each byte in the Blob. Example: >
+ :for byte in 0z112233
+ : call Doit(byte)
+ :endfor
+This calls Doit() with 0x11, 0x22 and 0x33.
+
+
+Blob concatenation ~
+
+Two blobs can be concatenated with the "+" operator: >
+ :let longblob = myblob + 0z4455
+ :let myblob += 0z6677
+
+To change a blob in-place see |blob-modification| below.
+
+
+Part of a blob ~
+
+A part of the Blob can be obtained by specifying the first and last index,
+separated by a colon in square brackets: >
+ :let myblob = 0z00112233
+ :let shortblob = myblob[1:2] " get 0z1122
+ :let shortblob = myblob[2:-1] " get 0z2233
+
+Omitting the first index is similar to zero. Omitting the last index is
+similar to -1. >
+ :let endblob = myblob[2:] " from item 2 to the end: 0z2233
+ :let shortblob = myblob[2:2] " Blob with one byte: 0z22
+ :let otherblob = myblob[:] " make a copy of the Blob
+
+If the first index is beyond the last byte of the Blob or the second byte is
+before the first byte, the result is an empty Blob. There is no error
+message.
+
+If the second index is equal to or greater than the length of the Blob the
+length minus one is used: >
+ :echo myblob[2:8] " result: 0z2233
+
+
+Blob modification ~
+ *blob-modification*
+To change a specific byte of a blob use |:let| this way: >
+ :let blob[4] = 0x44
+
+When the index is just one beyond the end of the Blob, it is appended. Any
+higher index is an error.
+
+To change a sequence of bytes the [:] notation can be used: >
+ let blob[1:3] = 0z445566
+The length of the replaced bytes must be exactly the same as the value
+provided. *E972*
+
+To change part of a blob you can specify the first and last byte to be
+modified. The value must at least have the number of bytes in the range: >
+ :let blob[3:5] = [3, 4, 5]
+
+You can also use the functions |add()|, |remove()| and |insert()|.
+
+
+Blob identity ~
+
+Blobs can be compared for equality: >
+ if blob == 0z001122
+And for equal identity: >
+ if blob is otherblob
+< *blob-identity* *E977*
+When variable "aa" is a Blob and you assign it to another variable "bb", both
+variables refer to the same Blob. Then the "is" operator returns true.
+
+When making a copy using [:] or |copy()| the values are the same, but the
+identity is different: >
+ :let blob = 0z112233
+ :let blob2 = blob
+ :echo blob == blob2
+< 1 >
+ :echo blob is blob2
+< 1 >
+ :let blob3 = blob[:]
+ :echo blob == blob3
+< 1 >
+ :echo blob is blob3
+< 0
+
+Making a copy of a Blob is done with the |copy()| function. Using [:] also
+works, as explained above.
+
+
+1.6 More about variables ~
*more-variables*
If you need to know the type of a variable or expression, use the |type()|
function.
@@ -645,8 +783,9 @@ Expression syntax summary, from least to most significant:
etc. As above, append ? for ignoring case, # for
matching case
- expr5 is expr5 same |List| instance
- expr5 isnot expr5 different |List| instance
+ expr5 is expr5 same |List|, |Dictionary| or |Blob| instance
+ expr5 isnot expr5 different |List|, |Dictionary| or |Blob|
+ instance
|expr5| expr6
expr6 + expr6 ... number addition, list or blob concatenation
@@ -669,12 +808,14 @@ Expression syntax summary, from least to most significant:
expr8[expr1 : expr1] substring of a String or sublist of a |List|
expr8.name entry in a |Dictionary|
expr8(expr1, ...) function call with |Funcref| variable
+ expr8->name(expr1, ...) |method| call
|expr9| number number constant
"string" string constant, backslash is special
'string' string constant, ' is doubled
[expr1, ...] |List|
{expr1: expr1, ...} |Dictionary|
+ #{key: expr1, ...} |Dictionary|
&option option value
(expr1) nested expression
variable internal variable
@@ -815,12 +956,12 @@ Dictionary and arguments, use |get()| to get the function name: >
if get(Part1, 'name') == get(Part2, 'name')
" Part1 and Part2 refer to the same function
-When using "is" or "isnot" with a |List| or a |Dictionary| this checks if the
-expressions are referring to the same |List| or |Dictionary| instance. A copy
-of a |List| is different from the original |List|. When using "is" without
-a |List| or a |Dictionary| it is equivalent to using "equal", using "isnot"
-equivalent to using "not equal". Except that a different type means the
-values are different: >
+Using "is" or "isnot" with a |List|, |Dictionary| or |Blob| checks whether
+the expressions are referring to the same |List|, |Dictionary| or |Blob|
+instance. A copy of a |List| is different from the original |List|. When
+using "is" without a |List|, |Dictionary| or |Blob|, it is equivalent to
+using "equal", using "isnot" is equivalent to using "not equal". Except that
+a different type means the values are different: >
echo 4 == '4'
1
echo 4 is '4'
@@ -939,9 +1080,11 @@ expr8 *expr8*
-----
This expression is either |expr9| or a sequence of the alternatives below,
in any order. E.g., these are all possible:
- expr9[expr1].name
- expr9.name[expr1]
- expr9(expr1, ...)[expr1].name
+ expr8[expr1].name
+ expr8.name[expr1]
+ expr8(expr1, ...)[expr1].name
+ expr8->(expr1, ...)[expr1]
+Evaluation is always from left to right.
expr8[expr1] item of String or |List| *expr-[]* *E111*
@@ -1008,6 +1151,12 @@ just above. Also see |sublist| below. Examples: >
:let l = mylist[4:4] " List with one item
:let l = mylist[:] " shallow copy of a List
+If expr8 is a |Blob| this results in a new |Blob| with the bytes in the
+indexes expr1a and expr1b, inclusive. Examples: >
+ :let b = 0zDEADBEEF
+ :let bs = b[1:2] " 0zADBE
+ :let bs = b[] " copy of 0zDEADBEEF
+
Using expr8[expr1] or expr8[expr1a : expr1b] on a |Funcref| results in an
error.
@@ -1043,6 +1192,36 @@ expr8(expr1, ...) |Funcref| function call
When expr8 is a |Funcref| type variable, invoke the function it refers to.
+expr8->name([args]) method call *method* *->*
+expr8->{lambda}([args])
+
+For methods that are also available as global functions this is the same as: >
+ name(expr8 [, args])
+There can also be methods specifically for the type of "expr8".
+
+This allows for chaining, passing the value that one method returns to the
+next method: >
+ mylist->filter(filterexpr)->map(mapexpr)->sort()->join()
+<
+Example of using a lambda: >
+ GetPercentage->{x -> x * 100}()->printf('%d%%')
+<
+When using -> the |expr7| operators will be applied first, thus: >
+ -1.234->string()
+Is equivalent to: >
+ (-1.234)->string()
+And NOT: >
+ -(1.234->string())
+<
+ *E274*
+"->name(" must not contain white space. There can be white space before the
+"->" and after the "(", thus you can split the lines like this: >
+ mylist
+ \ ->filter(filterexpr)
+ \ ->map(mapexpr)
+ \ ->sort()
+ \ ->join()
+<
*expr9*
number
@@ -1051,7 +1230,7 @@ number number constant *expr-number*
*hex-number* *octal-number* *binary-number*
Decimal, Hexadecimal (starting with 0x or 0X), Binary (starting with 0b or 0B)
-and Octal (starting with 0).
+and Octal (starting with 0, 0o or 0O).
*floating-point-format*
Floating point numbers can be written in two forms:
@@ -1146,6 +1325,14 @@ encodings. Use "\u00ff" to store character 255 correctly as UTF-8.
Note that "\000" and "\x00" force the end of the string.
+blob-literal *blob-literal* *E973*
+------------
+
+Hexadecimal starting with 0z or 0Z, with an arbitrary number of bytes.
+The sequence must be an even number of hex characters. Example: >
+ :let b = 0zFF00ED015DAF
+
+
literal-string *literal-string* *E115*
---------------
'string' string constant *expr-'*
@@ -1283,7 +1470,17 @@ The lambda expression is also useful for jobs and timers: >
Handler called
Handler called
-Note how execute() is used to execute an Ex command. That's ugly though.
+Note that it is possible to cause memory to be used and not freed if the
+closure is referenced by the context it depends on: >
+ function Function()
+ let x = 0
+ let F = {-> x}
+ endfunction
+The closure uses "x" from the function scope, and "F" in that same scope
+refers to the closure. This cycle results in the memory not being freed.
+Recommendation: don't do this.
+
+Notice how execute() is used to execute an Ex command. That's ugly though.
Lambda expressions have internal names like '<lambda>42'. If you get an error
@@ -1641,6 +1838,7 @@ v:event Dictionary of event data for the current |autocommand|. Valid
|v:false| if not.
changed_window Is |v:true| if the the event fired
while changing window (or tab) on |DirChanged|.
+ status Job status or exit code, -1 means "unknown". |TermClose|
*v:exception* *exception-variable*
v:exception The value of the exception most recently caught and not
@@ -1687,7 +1885,8 @@ v:fcs_choice What should happen after a |FileChangedShell| event was
Vim behaves like it is empty, there is no warning message.
*v:fname* *fname-variable*
-v:fname The file name set by 'includeexpr'. Empty otherwise.
+v:fname When evaluating 'includeexpr': the file name that was
+ detected. Empty otherwise.
*v:fname_in* *fname_in-variable*
v:fname_in The name of the input file. Valid while evaluating:
@@ -1821,7 +2020,7 @@ v:null Special value used to put "null" in JSON and NIL in msgpack.
v:numbermax Maximum value of a number.
*v:numbermin* *numbermin-variable*
-v:numbermin Minimum value of a number (negative)
+v:numbermin Minimum value of a number (negative).
*v:numbersize* *numbersize-variable*
v:numbersize Number of bits in a Number. This is normally 64, but on some
@@ -1961,19 +2160,21 @@ v:swapcommand Normal mode command to be executed after a file has been
For ":edit +cmd file" the value is ":cmd\r".
*v:t_TYPE* *v:t_bool* *t_bool-variable*
-v:t_bool Value of Boolean type. Read-only. See: |type()|
+v:t_bool Value of |Boolean| type. Read-only. See: |type()|
*v:t_dict* *t_dict-variable*
-v:t_dict Value of Dictionary type. Read-only. See: |type()|
+v:t_dict Value of |Dictionary| type. Read-only. See: |type()|
*v:t_float* *t_float-variable*
-v:t_float Value of Float type. Read-only. See: |type()|
+v:t_float Value of |Float| type. Read-only. See: |type()|
*v:t_func* *t_func-variable*
-v:t_func Value of Funcref type. Read-only. See: |type()|
+v:t_func Value of |Funcref| type. Read-only. See: |type()|
*v:t_list* *t_list-variable*
-v:t_list Value of List type. Read-only. See: |type()|
+v:t_list Value of |List| type. Read-only. See: |type()|
*v:t_number* *t_number-variable*
-v:t_number Value of Number type. Read-only. See: |type()|
+v:t_number Value of |Number| type. Read-only. See: |type()|
*v:t_string* *t_string-variable*
-v:t_string Value of String type. Read-only. See: |type()|
+v:t_string Value of |String| type. Read-only. See: |type()|
+ *v:t_blob* *t_blob-variable*
+v:t_blob Value of |Blob| type. Read-only. See: |type()|
*v:termresponse* *termresponse-variable*
v:termresponse The escape sequence returned by the terminal for the DA
@@ -2057,7 +2258,7 @@ USAGE RESULT DESCRIPTION ~
abs({expr}) Float or Number absolute value of {expr}
acos({expr}) Float arc cosine of {expr}
-add({list}, {item}) List append {item} to |List| {list}
+add({object}, {item}) List/Blob append {item} to {object}
and({expr}, {expr}) Number bitwise AND
api_info() Dict api metadata
append({lnum}, {string}) Number append {string} below line {lnum}
@@ -2114,7 +2315,7 @@ chanclose({id}[, {stream}]) Number Closes a channel or one of its streams
chansend({id}, {data}) Number Writes {data} to channel
char2nr({expr}[, {utf8}]) Number ASCII/UTF8 value of first char in {expr}
charidx({string}, {idx} [, {countcc}])
- Number char index of byte {idx} in {string}
+ Number char index of byte {idx} in {string}
cindent({lnum}) Number C indent for line {lnum}
clearmatches([{win}]) none clear all matches
col({expr}) Number column nr of cursor or mark
@@ -2144,8 +2345,8 @@ cursor({list}) Number move cursor to position in {list}
debugbreak({pid}) Number interrupt process being debugged
deepcopy({expr} [, {noref}]) any make a full copy of {expr}
delete({fname} [, {flags}]) Number delete the file or directory {fname}
-deletebufline({expr}, {first}[, {last}])
- Number delete lines from buffer {expr}
+deletebufline({buf}, {first}[, {last}])
+ Number delete lines from buffer {buf}
dictwatcheradd({dict}, {pattern}, {callback})
Start watching a dictionary
dictwatcherdel({dict}, {pattern}, {callback})
@@ -2197,15 +2398,17 @@ garbagecollect([{atexit}]) none free memory, breaking cyclic references
get({list}, {idx} [, {def}]) any get item {idx} from {list} or {def}
get({dict}, {key} [, {def}]) any get item {key} from {dict} or {def}
get({func}, {what}) any get property of funcref/partial {func}
-getbufinfo([{expr}]) List information about buffers
-getbufline({expr}, {lnum} [, {end}])
- List lines {lnum} to {end} of buffer {expr}
-getbufvar({expr}, {varname} [, {def}])
- any variable {varname} in buffer {expr}
-getchangelist({expr}) List list of change list items
-getchar([expr]) Number get one character from the user
+getbufinfo([{buf}]) List information about buffers
+getbufline({buf}, {lnum} [, {end}])
+ List lines {lnum} to {end} of buffer {buf}
+getbufvar({buf}, {varname} [, {def}])
+ any variable {varname} in buffer {buf}
+getchangelist([{buf}]) List list of change list items
+getchar([expr]) Number or String
+ get one character from the user
getcharmod() Number modifiers for the last typed character
getcharsearch() Dict last character search
+getcharstr([expr]) String get one character from the user
getcmdline() String return the current command-line
getcmdpos() Number return cursor position in command-line
getcmdtype() String return current command-line type
@@ -2226,15 +2429,17 @@ getline({lnum}) String line {lnum} of current buffer
getline({lnum}, {end}) List lines {lnum} to {end} of current buffer
getloclist({nr}) List list of location list items
getloclist({nr}, {what}) Dict get specific location list properties
-getmarklist([{expr}]) List list of global/local marks
+getmarklist([{buf}]) List list of global/local marks
getmatches([{win}]) List list of current matches
+getmousepos() Dict last known mouse position
getpid() Number process ID of Vim
getpos({expr}) List position of cursor, mark, etc.
getqflist() List list of quickfix items
getqflist({what}) Dict get specific quickfix list properties
getreg([{regname} [, 1 [, {list}]]])
- String or List contents of register
-getregtype([{regname}]) String type of register
+ String or List contents of a register
+getreginfo([{regname}]) Dict information about a register
+getregtype([{regname}]) String type of a register
gettabinfo([{expr}]) List list of tab pages
gettabvar({nr}, {varname} [, {def}])
any variable {varname} in tab {nr} or {def}
@@ -2267,8 +2472,8 @@ hlID({name}) Number syntax ID of highlight group {name}
hostname() String name of the machine Vim is running on
iconv({expr}, {from}, {to}) String convert encoding of {expr}
indent({lnum}) Number indent of line {lnum}
-index({list}, {expr} [, {start} [, {ic}]])
- Number index in {list} where {expr} appears
+index({object}, {expr} [, {start} [, {ic}]])
+ Number index in {object} where {expr} appears
input({prompt} [, {text} [, {completion}]])
String get input from the user
inputlist({textlist}) Number let the user pick from a choice list
@@ -2276,8 +2481,8 @@ inputrestore() Number restore typeahead
inputsave() Number save and clear typeahead
inputsecret({prompt} [, {text}])
String like input() but hiding the text
-insert({list}, {item} [, {idx}])
- List insert {item} in {list} [before {idx}]
+insert({object}, {item} [, {idx}])
+ List insert {item} in {object} [before {idx}]
interrupt() none interrupt script execution
invert({expr}) Number bitwise invert
isdirectory({directory}) Number |TRUE| if {directory} is a directory
@@ -2331,12 +2536,13 @@ matchstr({expr}, {pat}[, {start}[, {count}]])
matchstrpos({expr}, {pat}[, {start}[, {count}]])
List {count}'th match of {pat} in {expr}
max({expr}) Number maximum value of items in {expr}
+menu_get({path} [, {modes}]) List description of |menus| matched by {path}
min({expr}) Number minimum value of items in {expr}
mkdir({name} [, {path} [, {prot}]])
Number create directory {name}
mode([expr]) String current editing mode
-msgpackdump({list}) List dump a list of objects to msgpack
-msgpackparse({list}) List parse msgpack to a list of objects
+msgpackdump({list} [, {type}]) List/Blob dump objects to msgpack
+msgpackparse({data}) List parse msgpack to a list of objects
nextnonblank({lnum}) Number line nr of non-blank line >= {lnum}
nr2char({expr}[, {utf8}]) String single char with ASCII/UTF8 value {expr}
nvim_...({args}...) any call nvim |api| functions
@@ -2358,7 +2564,7 @@ pyxeval({expr}) any evaluate |python_x| expression
range({expr} [, {max} [, {stride}]])
List items from {expr} to {max}
readdir({dir} [, {expr}]) List file names in {dir} selected by {expr}
-readfile({fname} [, {binary} [, {max}]])
+readfile({fname} [, {type} [, {max}]])
List get list of lines from file {fname}
reg_executing() String get the executing register name
reg_recording() String get the recording register name
@@ -2375,7 +2581,10 @@ remote_read({serverid} [, {timeout}])
remote_send({server}, {string} [, {idvar}])
String send key sequence
remote_startserver({name}) none become server {name}
-remove({list}, {idx} [, {end}]) any remove items {idx}-{end} from {list}
+remove({list}, {idx} [, {end}]) any/List
+ remove items {idx}-{end} from {list}
+remove({blob}, {idx} [, {end}]) Number/Blob
+ remove bytes {idx}-{end} from {blob}
remove({dict}, {key}) any remove entry {key} from {dict}
rename({from}, {to}) Number rename (move) file from {from} to {to}
repeat({expr}, {count}) String repeat {expr} {count} times
@@ -2389,9 +2598,11 @@ rpcrequest({channel}, {method}[, {args}...])
Sends an |RPC| request to {channel}
screenattr({row}, {col}) Number attribute at screen position
screenchar({row}, {col}) Number character at screen position
+screenchars({row}, {col}) List List of characters at screen position
screencol() Number current cursor column
screenpos({winid}, {lnum}, {col}) Dict screen row and col of a text character
screenrow() Number current cursor row
+screenstring({row}, {col}) String characters at screen position
search({pattern} [, {flags} [, {stopline} [, {timeout}]]])
Number search for {pattern}
searchcount([{options}]) Dict Get or update the last search count
@@ -2409,7 +2620,7 @@ serverlist() String get a list of available servers
setbufline( {expr}, {lnum}, {line})
Number set line {lnum} to {line} in buffer
{expr}
-setbufvar({expr}, {varname}, {val}) set {varname} in buffer {expr} to {val}
+setbufvar({buf}, {varname}, {val}) set {varname} in buffer {buf} to {val}
setcharsearch({dict}) Dict set character search from {dict}
setcmdpos({pos}) Number set cursor position in command-line
setenv({name}, {val}) none set environment variable
@@ -2439,11 +2650,11 @@ shiftwidth([{col}]) Number effective value of 'shiftwidth'
sign_define({name} [, {dict}]) Number define or update a sign
sign_define({list}) List define or update a list of signs
sign_getdefined([{name}]) List get a list of defined signs
-sign_getplaced([{expr} [, {dict}]])
+sign_getplaced([{buf} [, {dict}]])
List get a list of placed signs
-sign_jump({id}, {group}, {expr})
+sign_jump({id}, {group}, {buf})
Number jump to a sign
-sign_place({id}, {group}, {name}, {expr} [, {dict}])
+sign_place({id}, {group}, {name}, {buf} [, {dict}])
Number place a sign
sign_placelist({list}) List place a list of signs
sign_undefine([{name}]) Number undefine a sign
@@ -2467,10 +2678,11 @@ split({expr} [, {pat} [, {keepempty}]])
sqrt({expr}) Float square root of {expr}
stdioopen({dict}) Number open stdio in a headless instance.
stdpath({what}) String/List returns the standard path(s) for {what}
-str2float({expr}) Float convert String to Float
+str2float({expr} [, {quoted}]) Float convert String to Float
str2list({expr} [, {utf8}]) List convert each character of {expr} to
ASCII/UTF8 value
-str2nr({expr} [, {base}]) Number convert String to Number
+str2nr({expr} [, {base} [, {quoted}]])
+ Number convert String to Number
strchars({expr} [, {skipcc}]) Number character length of the String {expr}
strcharpart({str}, {start} [, {len}])
String {len} characters of {str} at
@@ -2496,7 +2708,7 @@ submatch({nr} [, {list}]) String or List
substitute({expr}, {pat}, {sub}, {flags})
String all {pat} in {expr} replaced with {sub}
swapinfo({fname}) Dict information about swap file {fname}
-swapname({expr}) String swap file of buffer {expr}
+swapname({buf}) String swap file of buffer {buf}
synID({lnum}, {col}, {trans}) Number syntax ID at {lnum} and {col}
synIDattr({synID}, {what} [, {mode}])
String attribute {what} of syntax ID {synID}
@@ -2562,8 +2774,8 @@ winrestview({dict}) none restore view of current window
winsaveview() Dict save view of current window
winwidth({nr}) Number width of window {nr}
wordcount() Dict get byte/char/word statistics
-writefile({list}, {fname} [, {flags}])
- Number write list of lines to file {fname}
+writefile({object}, {fname} [, {flags}])
+ Number write |Blob| or |List| of lines to file
xor({expr}, {expr}) Number bitwise XOR
@@ -2580,6 +2792,8 @@ abs({expr}) *abs()*
echo abs(-4)
< 4
+ Can also be used as a |method|: >
+ Compute()->abs()
acos({expr}) *acos()*
Return the arc cosine of {expr} measured in radians, as a
@@ -2592,22 +2806,29 @@ acos({expr}) *acos()*
:echo acos(-0.5)
< 2.094395
+ Can also be used as a |method|: >
+ Compute()->acos()
-add({list}, {expr}) *add()*
- Append the item {expr} to |List| {list}. Returns the
- resulting |List|. Examples: >
+add({object}, {expr}) *add()*
+ Append the item {expr} to |List| or |Blob| {object}. Returns
+ the resulting |List| or |Blob|. Examples: >
:let alist = add([1, 2, 3], item)
:call add(mylist, "woodstock")
< Note that when {expr} is a |List| it is appended as a single
item. Use |extend()| to concatenate |Lists|.
+ When {object} is a |Blob| then {expr} must be a number.
Use |insert()| to add an item at another position.
+ Can also be used as a |method|: >
+ mylist->add(val1)->add(val2)
and({expr}, {expr}) *and()*
Bitwise AND on the two arguments. The arguments are converted
to a number. A List, Dict or Float argument causes an error.
Example: >
:let flag = and(bits, 0x80)
+< Can also be used as a |method|: >
+ :let flag = bits->and(0x80)
api_info() *api_info()*
Returns Dictionary of |api-metadata|.
@@ -2621,18 +2842,22 @@ append({lnum}, {text}) *append()*
Otherwise append {text} as one text line below line {lnum} in
the current buffer.
{lnum} can be zero to insert a line before the first one.
+ {lnum} is used like with |getline()|.
Returns 1 for failure ({lnum} out of range or out of memory),
0 for success. Example: >
:let failed = append(line('$'), "# THE END")
:let failed = append(0, ["Chapter 1", "the beginning"])
-appendbufline({expr}, {lnum}, {text}) *appendbufline()*
+< Can also be used as a |method| after a List: >
+ mylist->append(lnum)
+
+appendbufline({buf}, {lnum}, {text}) *appendbufline()*
Like |append()| but append the text in buffer {expr}.
This function works only for loaded buffers. First call
|bufload()| if needed.
- For the use of {expr}, see |bufname()|.
+ For the use of {buf}, see |bufname()|.
{lnum} is used like with |append()|. Note that using |line()|
would use the current buffer, not the one appending to.
@@ -2640,12 +2865,14 @@ appendbufline({expr}, {lnum}, {text}) *appendbufline()*
On success 0 is returned, on failure 1 is returned.
- If {expr} is not a valid buffer or {lnum} is not valid, an
+ If {buf} is not a valid buffer or {lnum} is not valid, an
error message is given. Example: >
:let failed = appendbufline(13, 0, "# THE START")
<
- *argc()*
-argc([{winid}])
+ Can also be used as a |method| after a List: >
+ mylist->appendbufline(buf, lnum)
+
+argc([{winid}]) *argc()*
The result is the number of files in the argument list. See
|arglist|.
If {winid} is not supplied, the argument list of the current
@@ -2699,6 +2926,9 @@ asin({expr}) *asin()*
:echo asin(-0.5)
< -0.523599
+ Can also be used as a |method|: >
+ Compute()->asin()
+
assert_ functions are documented here: |assert-functions-details|
@@ -2713,6 +2943,8 @@ atan({expr}) *atan()*
:echo atan(-4.01)
< -1.326405
+ Can also be used as a |method|: >
+ Compute()->atan()
atan2({expr1}, {expr2}) *atan2()*
Return the arc tangent of {expr1} / {expr2}, measured in
@@ -2724,6 +2956,8 @@ atan2({expr1}, {expr2}) *atan2()*
:echo atan2(1, -1)
< 2.356194
+ Can also be used as a |method|: >
+ Compute()->atan2(1)
*browse()*
browse({save}, {title}, {initdir}, {default})
@@ -2734,8 +2968,8 @@ browse({save}, {title}, {initdir}, {default})
{title} title for the requester
{initdir} directory to start browsing in
{default} default file name
- When the "Cancel" button is hit, something went wrong, or
- browsing is not possible, an empty string is returned.
+ An empty string is returned when the "Cancel" button is hit,
+ something went wrong, or browsing is not possible.
*browsedir()*
browsedir({title}, {initdir})
@@ -2751,20 +2985,22 @@ browsedir({title}, {initdir})
browsing is not possible, an empty string is returned.
bufadd({name}) *bufadd()*
- Add a buffer to the buffer list with {name}.
+ Add a buffer to the buffer list with String {name}.
If a buffer for file {name} already exists, return that buffer
number. Otherwise return the buffer number of the newly
created buffer. When {name} is an empty string then a new
buffer is always created.
The buffer will not have' 'buflisted' set.
+< Can also be used as a |method|: >
+ let bufnr = 'somename'->bufadd()
-bufexists({expr}) *bufexists()*
+bufexists({buf}) *bufexists()*
The result is a Number, which is |TRUE| if a buffer called
- {expr} exists.
- If the {expr} argument is a number, buffer numbers are used.
+ {buf} exists.
+ If the {buf} argument is a number, buffer numbers are used.
Number zero is the alternate buffer for the current window.
- If the {expr} argument is a string it must match a buffer name
+ If the {buf} argument is a string it must match a buffer name
exactly. The name can be:
- Relative to the current directory.
- A full path.
@@ -2780,32 +3016,45 @@ bufexists({expr}) *bufexists()*
Use "bufexists(0)" to test for the existence of an alternate
file name.
-buflisted({expr}) *buflisted()*
+ Can also be used as a |method|: >
+ let exists = 'somename'->bufexists()
+
+buflisted({buf}) *buflisted()*
The result is a Number, which is |TRUE| if a buffer called
- {expr} exists and is listed (has the 'buflisted' option set).
- The {expr} argument is used like with |bufexists()|.
+ {buf} exists and is listed (has the 'buflisted' option set).
+ The {buf} argument is used like with |bufexists()|.
+
+ Can also be used as a |method|: >
+ let listed = 'somename'->buflisted()
-bufload({expr}) *bufload()*
- Ensure the buffer {expr} is loaded. When the buffer name
+bufload({buf}) *bufload()*
+ Ensure the buffer {buf} is loaded. When the buffer name
refers to an existing file then the file is read. Otherwise
the buffer will be empty. If the buffer was already loaded
then there is no change.
If there is an existing swap file for the file of the buffer,
there will be no dialog, the buffer will be loaded anyway.
- The {expr} argument is used like with |bufexists()|.
+ The {buf} argument is used like with |bufexists()|.
+
+ Can also be used as a |method|: >
+ eval 'somename'->bufload()
-bufloaded({expr}) *bufloaded()*
+bufloaded({buf}) *bufloaded()*
The result is a Number, which is |TRUE| if a buffer called
- {expr} exists and is loaded (shown in a window or hidden).
- The {expr} argument is used like with |bufexists()|.
-
-bufname([{expr}]) *bufname()*
- The result is the name of a buffer, as it is displayed by the
- ":ls" command.
-+ If {expr} is omitted the current buffer is used.
- If {expr} is a Number, that buffer number's name is given.
+ {buf} exists and is loaded (shown in a window or hidden).
+ The {buf} argument is used like with |bufexists()|.
+
+ Can also be used as a |method|: >
+ let loaded = 'somename'->bufloaded()
+
+bufname([{buf}]) *bufname()*
+ The result is the name of a buffer. Mostly as it is displayed
+ by the `:ls` command, but not using special names such as
+ "[No Name]".
+ If {buf} is omitted the current buffer is used.
+ If {buf} is a Number, that buffer number's name is given.
Number zero is the alternate buffer for the current window.
- If {expr} is a String, it is used as a |file-pattern| to match
+ If {buf} is a String, it is used as a |file-pattern| to match
with the buffer names. This is always done like 'magic' is
set and 'cpoptions' is empty. When there is more than one
match an empty string is returned.
@@ -2818,9 +3067,12 @@ bufname([{expr}]) *bufname()*
Listed buffers are found first. If there is a single match
with a listed buffer, that one is returned. Next unlisted
buffers are searched for.
- If the {expr} is a String, but you want to use it as a buffer
+ If the {buf} is a String, but you want to use it as a buffer
number, force it to be a Number by adding zero to it: >
:echo bufname("3" + 0)
+< Can also be used as a |method|: >
+ echo bufnr->bufname()
+
< If the buffer doesn't exist, or doesn't have a name, an empty
string is returned. >
bufname("#") alternate buffer name
@@ -2829,9 +3081,9 @@ bufname([{expr}]) *bufname()*
bufname("file2") name of buffer where "file2" matches.
*bufnr()*
-bufnr([{expr} [, {create}]])
+bufnr([{buf} [, {create}]])
The result is the number of a buffer, as it is displayed by
- the ":ls" command. For the use of {expr}, see |bufname()|
+ the `:ls` command. For the use of {buf}, see |bufname()|
above.
If the buffer doesn't exist, -1 is returned. Or, if the
{create} argument is present and TRUE, a new, unlisted,
@@ -2843,28 +3095,35 @@ bufnr([{expr} [, {create}]])
number necessarily exist, because ":bwipeout" may have removed
them. Use bufexists() to test for the existence of a buffer.
-bufwinid({expr}) *bufwinid()*
+ Can also be used as a |method|: >
+ echo bufref->bufnr()
+
+bufwinid({buf}) *bufwinid()*
The result is a Number, which is the |window-ID| of the first
- window associated with buffer {expr}. For the use of {expr},
- see |bufname()| above. If buffer {expr} doesn't exist or
+ window associated with buffer {buf}. For the use of {buf},
+ see |bufname()| above. If buffer {buf} doesn't exist or
there is no such window, -1 is returned. Example: >
echo "A window containing buffer 1 is " . (bufwinid(1))
<
Only deals with the current tab page.
-bufwinnr({expr}) *bufwinnr()*
- The result is a Number, which is the number of the first
- window associated with buffer {expr}. For the use of {expr},
- see |bufname()| above. If buffer {expr} doesn't exist or
- there is no such window, -1 is returned. Example: >
+ Can also be used as a |method|: >
+ FindBuffer()->bufwinid()
+
+bufwinnr({buf}) *bufwinnr()*
+ Like |bufwinid()| but return the window number instead of the
+ |window-ID|.
+ If buffer {buf} doesn't exist or there is no such window, -1
+ is returned. Example: >
echo "A window containing buffer 1 is " . (bufwinnr(1))
< The number can be used with |CTRL-W_w| and ":wincmd w"
|:wincmd|.
- Only deals with the current tab page.
+ Can also be used as a |method|: >
+ FindBuffer()->bufwinnr()
byte2line({byte}) *byte2line()*
Return the line number that contains the character at byte
@@ -2874,8 +3133,11 @@ byte2line({byte}) *byte2line()*
one.
Also see |line2byte()|, |go| and |:goto|.
+ Can also be used as a |method|: >
+ GetOffset()->byte2line()
+
byteidx({expr}, {nr}) *byteidx()*
- Return byte index of the {nr}'th character in the string
+ Return byte index of the {nr}'th character in the String
{expr}. Use zero for the first character, it then returns
zero.
If there are no multibyte characters the returned value is
@@ -2896,6 +3158,9 @@ byteidx({expr}, {nr}) *byteidx()*
If there are exactly {nr} characters the length of the string
in bytes is returned.
+ Can also be used as a |method|: >
+ GetName()->byteidx(idx)
+
byteidxcomp({expr}, {nr}) *byteidxcomp()*
Like byteidx(), except that a composing character is counted
as a separate character. Example: >
@@ -2909,6 +3174,9 @@ byteidxcomp({expr}, {nr}) *byteidxcomp()*
Only works differently from byteidx() when 'encoding' is set to
a Unicode encoding.
+ Can also be used as a |method|: >
+ GetName()->byteidxcomp(idx)
+
call({func}, {arglist} [, {dict}]) *call()* *E699*
Call function {func} with the items in |List| {arglist} as
arguments.
@@ -2918,6 +3186,9 @@ call({func}, {arglist} [, {dict}]) *call()* *E699*
{dict} is for functions with the "dict" attribute. It will be
used to set the local variable "self". |Dictionary-function|
+ Can also be used as a |method|: >
+ GetFunc()->call([arg, arg], dict)
+
ceil({expr}) *ceil()*
Return the smallest integral value greater than or equal to
{expr} as a |Float| (round up).
@@ -2930,6 +3201,9 @@ ceil({expr}) *ceil()*
echo ceil(4.0)
< 4.0
+ Can also be used as a |method|: >
+ Compute()->ceil()
+
changenr() *changenr()*
Return the number of the most recent change. This is the same
number as what is displayed with |:undolist| and can be used
@@ -2955,8 +3229,8 @@ chansend({id}, {data}) *chansend()*
written if the write succeeded, 0 otherwise.
See |channel-bytes| for more information.
- {data} may be a string, string convertible, or a list. If
- {data} is a list, the items will be joined by newlines; any
+ {data} may be a string, string convertible, |Blob|, or a list.
+ If {data} is a list, the items will be joined by newlines; any
newlines in an item will be sent as NUL. To send a final
newline, include a final empty string. Example: >
:call chansend(id, ["abc", "123\n456", ""])
@@ -2967,8 +3241,9 @@ chansend({id}, {data}) *chansend()*
messages, use |rpcnotify()| and |rpcrequest()| instead.
-char2nr({expr} [, {utf8}]) *char2nr()*
- Return number value of the first char in {expr}. Examples: >
+char2nr({string} [, {utf8}]) *char2nr()*
+ Return number value of the first char in {string}.
+ Examples: >
char2nr(" ") returns 32
char2nr("ABC") returns 65
char2nr("á") returns 225
@@ -2979,16 +3254,19 @@ char2nr({expr} [, {utf8}]) *char2nr()*
A combining character is a separate character.
|nr2char()| does the opposite.
+ Can also be used as a |method|: >
+ GetChar()->char2nr()
+
*charidx()*
charidx({string}, {idx} [, {countcc}])
Return the character index of the byte at {idx} in {string}.
The index of the first character is zero.
If there are no multibyte characters the returned value is
equal to {idx}.
- When {countcc} is omitted or zero, then composing characters
- are not counted separately, their byte length is added to the
- preceding base character.
- When {countcc} is set to 1, then composing characters are
+ When {countcc} is omitted or |FALSE|, then composing characters
+ are not counted separately, their byte length is
+ added to the preceding base character.
+ When {countcc} is |TRUE|, then composing characters are
counted as separate characters.
Returns -1 if the arguments are invalid or if {idx} is greater
than the index of the last byte in {string}. An error is
@@ -3010,12 +3288,18 @@ cindent({lnum}) *cindent()*
When {lnum} is invalid -1 is returned.
See |C-indenting|.
+ Can also be used as a |method|: >
+ GetLnum()->cindent()
+
clearmatches([{win}]) *clearmatches()*
Clears all matches previously defined for the current window
by |matchadd()| and the |:match| commands.
If {win} is specified, use the window with this number or
window ID instead of the current window.
+ Can also be used as a |method|: >
+ GetWin()->clearmatches()
+<
*col()*
col({expr}) The result is a Number, which is the byte index of the column
position given with {expr}. The accepted positions are:
@@ -3051,6 +3335,9 @@ col({expr}) The result is a Number, which is the byte index of the column
\<C-O>:set ve=all<CR>
\<C-O>:echo col(".") . "\n" <Bar>
\let &ve = save_ve<CR>
+
+< Can also be used as a |method|: >
+ GetPos()->col()
<
complete({startcol}, {matches}) *complete()* *E785*
@@ -3065,6 +3352,7 @@ complete({startcol}, {matches}) *complete()* *E785*
match.
{matches} must be a |List|. Each |List| item is one match.
See |complete-items| for the kind of items that are possible.
+ "longest" in 'completeopt' is ignored.
Note that the after calling this function you need to avoid
inserting anything that would cause completion to stop.
The match can be selected with CTRL-N and CTRL-P as usual with
@@ -3082,6 +3370,10 @@ complete({startcol}, {matches}) *complete()* *E785*
< This isn't very useful, but it shows how it works. Note that
an empty string is returned to avoid a zero being inserted.
+ Can also be used as a |method|, the second argument is passed
+ in: >
+ GetMatches()->complete(col('.'))
+
complete_add({expr}) *complete_add()*
Add {expr} to the list of matches. Only to be used by the
function specified with the 'completefunc' option.
@@ -3091,6 +3383,9 @@ complete_add({expr}) *complete_add()*
See |complete-functions| for an explanation of {expr}. It is
the same as one item in the list that 'omnifunc' would return.
+ Can also be used as a |method|: >
+ GetMoreMatches()->complete_add()
+
complete_check() *complete_check()*
Check for a key typed while looking for completion matches.
This is to be used when looking for matches takes some time.
@@ -3099,8 +3394,8 @@ complete_check() *complete_check()*
Only to be used by the function specified with the
'completefunc' option.
- *complete_info()*
-complete_info([{what}])
+
+complete_info([{what}]) *complete_info()*
Returns a |Dictionary| with information about Insert mode
completion. See |ins-completion|.
The items are:
@@ -3114,7 +3409,9 @@ complete_info([{what}])
See |complete-items|.
selected Selected item index. First index is zero.
Index is -1 if no item is selected (showing
- typed text only)
+ typed text only, or the last completion after
+ no item is selected when using the <Up> or
+ <Down> keys)
inserted Inserted string. [NOT IMPLEMENT YET]
*complete_info_mode*
@@ -3151,6 +3448,9 @@ complete_info([{what}])
call complete_info(['mode'])
" Get only 'mode' and 'pum_visible'
call complete_info(['mode', 'pum_visible'])
+
+< Can also be used as a |method|: >
+ GetItems()->complete_info()
<
*confirm()*
confirm({msg} [, {choices} [, {default} [, {type}]]])
@@ -3174,10 +3474,10 @@ confirm({msg} [, {choices} [, {default} [, {type}]]])
< For the console, the first letter of each choice is used as
the default shortcut key. Case is ignored.
- The optional {default} argument is the number of the choice
- that is made if the user hits <CR>. Use 1 to make the first
- choice the default one. Use 0 to not set a default. If
- {default} is omitted, 1 is used.
+ The optional {type} String argument gives the type of dialog.
+ It can be one of these values: "Error", "Question", "Info",
+ "Warning" or "Generic". Only the first character is relevant.
+ When {type} is omitted, "Generic" is used.
The optional {type} argument gives the type of dialog. This
is only used for the icon of the Win32 GUI. It can be one of
@@ -3204,6 +3504,9 @@ confirm({msg} [, {choices} [, {default} [, {type}]]])
don't fit, a vertical layout is used anyway. For some systems
the horizontal layout is always used.
+ Can also be used as a |method|in: >
+ BuildMessage()->confirm("&Yes\n&No")
+
*copy()*
copy({expr}) Make a copy of {expr}. For Numbers and Strings this isn't
different from using {expr} directly.
@@ -3213,6 +3516,8 @@ copy({expr}) Make a copy of {expr}. For Numbers and Strings this isn't
changing an item changes the contents of both |Lists|.
A |Dictionary| is copied in a similar way as a |List|.
Also see |deepcopy()|.
+ Can also be used as a |method|: >
+ mylist->copy()
cos({expr}) *cos()*
Return the cosine of {expr}, measured in radians, as a |Float|.
@@ -3223,6 +3528,8 @@ cos({expr}) *cos()*
:echo cos(-4.01)
< -0.646043
+ Can also be used as a |method|: >
+ Compute()->cos()
cosh({expr}) *cosh()*
Return the hyperbolic cosine of {expr} as a |Float| in the range
@@ -3234,6 +3541,8 @@ cosh({expr}) *cosh()*
:echo cosh(-0.5)
< -1.127626
+ Can also be used as a |method|: >
+ Compute()->cosh()
count({comp}, {expr} [, {ic} [, {start}]]) *count()*
Return the number of times an item with value {expr} appears
@@ -3248,12 +3557,14 @@ count({comp}, {expr} [, {ic} [, {start}]]) *count()*
occurrences of {expr} is returned. Zero is returned when
{expr} is an empty string.
+ Can also be used as a |method|: >
+ mylist->count(val)
+
*cscope_connection()*
cscope_connection([{num} , {dbpath} [, {prepend}]])
Checks for the existence of a |cscope| connection. If no
parameters are specified, then the function returns:
- 0, if cscope was not available (not compiled in), or
- if there are no cscope connections;
+ 0, if there are no cscope connections;
1, if there is at least one cscope connection.
If parameters are specified, then the value of {num}
@@ -3344,6 +3655,8 @@ cursor({list})
position within a <Tab> or after the last character.
Returns 0 when the position could be set, -1 otherwise.
+ Can also be used as a |method|: >
+ GetCursorPos()->cursor()
deepcopy({expr}[, {noref}]) *deepcopy()* *E698*
Make a copy of {expr}. For Numbers and Strings this isn't
@@ -3365,7 +3678,10 @@ deepcopy({expr}[, {noref}]) *deepcopy()* *E698*
{noref} set to 1 will fail.
Also see |copy()|.
-delete({fname} [, {flags}]) *delete()*
+ Can also be used as a |method|: >
+ GetObject()->deepcopy()
+
+delete({fname} [, {flags}]) *delete()*
Without {flags} or with {flags} empty: Deletes the file by the
name {fname}. This also works when {fname} is a symbolic link.
A symbolic link itself is deleted, not what it points to.
@@ -3382,19 +3698,25 @@ delete({fname} [, {flags}]) *delete()*
operation was successful and -1/true when the deletion failed
or partly failed.
-deletebufline({expr}, {first}[, {last}]) *deletebufline()*
- Delete lines {first} to {last} (inclusive) from buffer {expr}.
+ Can also be used as a |method|: >
+ GetName()->delete()
+
+deletebufline({buf}, {first}[, {last}]) *deletebufline()*
+ Delete lines {first} to {last} (inclusive) from buffer {buf}.
If {last} is omitted then delete line {first} only.
On success 0 is returned, on failure 1 is returned.
This function works only for loaded buffers. First call
|bufload()| if needed.
- For the use of {expr}, see |bufname()| above.
+ For the use of {buf}, see |bufname()| above.
{first} and {last} are used like with |setline()|. Note that
when using |line()| this refers to the current buffer. Use "$"
- to refer to the last line in buffer {expr}.
+ to refer to the last line in buffer {buf}.
+
+ Can also be used as a |method|: >
+ GetBuffer()->deletebufline(1)
dictwatcheradd({dict}, {pattern}, {callback}) *dictwatcheradd()*
Adds a watcher to a dictionary. A dictionary watcher is
@@ -3462,6 +3784,9 @@ diff_filler({lnum}) *diff_filler()*
line, "'m" mark m, etc.
Returns 0 if the current window is not in diff mode.
+ Can also be used as a |method|: >
+ GetLnum()->diff_filler()
+
diff_hlID({lnum}, {col}) *diff_hlID()*
Returns the highlight ID for diff mode at line {lnum} column
{col} (byte index). When the current line does not have a
@@ -3473,11 +3798,20 @@ diff_hlID({lnum}, {col}) *diff_hlID()*
The highlight ID can be used with |synIDattr()| to obtain
syntax information about the highlighting.
+ Can also be used as a |method|: >
+ GetLnum()->diff_hlID(col)
+
empty({expr}) *empty()*
Return the Number 1 if {expr} is empty, zero otherwise.
- A |List| or |Dictionary| is empty when it does not have any
- items. A Number is empty when its value is zero. Special
- variable is empty when it is |v:false| or |v:null|.
+ - A |List| or |Dictionary| is empty when it does not have any
+ items.
+ - A |String| is empty when its length is zero.
+ - A |Number| and |Float| are empty when their value is zero.
+ - |v:false| and |v:null| are empty, |v:true| is not.
+ - A |Blob| is empty when its length is zero.
+
+ Can also be used as a |method|: >
+ mylist->empty()
environ() *environ()*
Return all of environment variables as dictionary. You can
@@ -3498,10 +3832,13 @@ escape({string}, {chars}) *escape()*
*eval()*
eval({string}) Evaluate {string} and return the result. Especially useful to
turn the result of |string()| back into the original value.
- This works for Numbers, Floats, Strings and composites of
- them. Also works for |Funcref|s that refer to existing
+ This works for Numbers, Floats, Strings, Blobs and composites
+ of them. Also works for |Funcref|s that refer to existing
functions.
+ Can also be used as a |method|: >
+ argv->join()->eval()
+
eventhandler() *eventhandler()*
Returns 1 when inside an event handler. That is that Vim got
interrupted while waiting for the user to type a character,
@@ -3659,27 +3996,33 @@ exp({expr}) *exp()*
:echo exp(-1)
< 0.367879
+ Can also be used as a |method|: >
+ Compute()->exp()
+
debugbreak({pid}) *debugbreak()*
Specifically used to interrupt a program being debugged. It
will cause process {pid} to get a SIGTRAP. Behavior for other
processes is undefined. See |terminal-debugger|.
{Sends a SIGINT to a process {pid} other than MS-Windows}
-expand({expr} [, {nosuf} [, {list}]]) *expand()*
- Expand wildcards and the following special keywords in {expr}.
- 'wildignorecase' applies.
+ Can also be used as a |method|: >
+ GetPid()->debugbreak()
+
+expand({string} [, {nosuf} [, {list}]]) *expand()*
+ Expand wildcards and the following special keywords in
+ {string}. 'wildignorecase' applies.
If {list} is given and it is |TRUE|, a List will be returned.
Otherwise the result is a String and when there are several
matches, they are separated by <NL> characters.
If the expansion fails, the result is an empty string. A name
- for a non-existing file is not included, unless {expr} does
+ for a non-existing file is not included, unless {string} does
not start with '%', '#' or '<', see below.
- When {expr} starts with '%', '#' or '<', the expansion is done
- like for the |cmdline-special| variables with their associated
- modifiers. Here is a short overview:
+ When {string} starts with '%', '#' or '<', the expansion is
+ done like for the |cmdline-special| variables with their
+ associated modifiers. Here is a short overview:
% current file name
# alternate file name
@@ -3728,7 +4071,7 @@ expand({expr} [, {nosuf} [, {list}]]) *expand()*
buffer with no name, results in the current directory, with a
'/' added.
- When {expr} does not start with '%', '#' or '<', it is
+ When {string} does not start with '%', '#' or '<', it is
expanded like a file name is expanded on the command line.
'suffixes' and 'wildignore' are used, unless the optional
{nosuf} argument is given and it is |TRUE|.
@@ -3793,6 +4136,8 @@ extend({expr1}, {expr2} [, {expr3}]) *extend()*
fails.
Returns {expr1}.
+ Can also be used as a |method|: >
+ mylist->extend(otherlist)
feedkeys({string} [, {mode}]) *feedkeys()*
Characters in {string} are queued for processing as if they
@@ -3846,7 +4191,11 @@ filereadable({file}) *filereadable()*
expression, which is used as a String.
If you don't care about the file being readable you can use
|glob()|.
-
+ {file} is used as-is, you may want to expand wildcards first: >
+ echo filereadable('~/.vimrc')
+ 0
+ echo filereadable(expand('~/.vimrc'))
+ 1
filewritable({file}) *filewritable()*
The result is a Number, which is 1 when a file with the
@@ -3856,16 +4205,19 @@ filewritable({file}) *filewritable()*
filter({expr1}, {expr2}) *filter()*
- {expr1} must be a |List| or a |Dictionary|.
+ {expr1} must be a |List|, |Blob|, or a |Dictionary|.
For each item in {expr1} evaluate {expr2} and when the result
- is zero remove the item from the |List| or |Dictionary|.
+ is zero remove the item from the |List| or |Dictionary|. For a
+ |Blob| each byte is removed.
+
{expr2} must be a |string| or |Funcref|.
If {expr2} is a |string|, inside {expr2} |v:val| has the value
of the current item. For a |Dictionary| |v:key| has the key
of the current item and for a |List| |v:key| has the index of
- the current item.
- For a |Dictionary| |v:key| has the key of the current item.
+ the current item. For a |Blob| |v:key| has the index of the
+ current byte.
+
Examples: >
call filter(mylist, 'v:val !~ "OLD"')
< Removes the items where "OLD" appears. >
@@ -3896,25 +4248,30 @@ filter({expr1}, {expr2}) *filter()*
|Dictionary| to remain unmodified make a copy first: >
:let l = filter(copy(mylist), 'v:val =~ "KEEP"')
-< Returns {expr1}, the |List| or |Dictionary| that was filtered.
- When an error is encountered while evaluating {expr2} no
- further items in {expr1} are processed. When {expr2} is a
- Funcref errors inside a function are ignored, unless it was
- defined with the "abort" flag.
+< Returns {expr1}, the |List|, |Blob| or |Dictionary| that was
+ filtered. When an error is encountered while evaluating
+ {expr2} no further items in {expr1} are processed. When
+ {expr2} is a Funcref errors inside a function are ignored,
+ unless it was defined with the "abort" flag.
+ Can also be used as a |method|: >
+ mylist->filter(expr2)
finddir({name} [, {path} [, {count}]]) *finddir()*
Find directory {name} in {path}. Supports both downwards and
upwards recursive directory searches. See |file-searching|
for the syntax of {path}.
+
Returns the path of the first found match. When the found
directory is below the current directory a relative path is
returned. Otherwise a full path is returned.
If {path} is omitted or empty then 'path' is used.
+
If the optional {count} is given, find {count}'s occurrence of
{name} in {path} instead of the first one.
When {count} is negative return all the matches in a |List|.
- This is quite similar to the ex-command |:find|.
+
+ This is quite similar to the ex-command `:find`.
findfile({name} [, {path} [, {count}]]) *findfile()*
Just like |finddir()|, but find a file instead of a directory.
@@ -3964,6 +4321,8 @@ float2nr({expr}) *float2nr()*
echo float2nr(1.0e-100)
< 0
+ Can also be used as a |method|: >
+ Compute()->float2nr()
floor({expr}) *floor()*
Return the largest integral value less than or equal to
@@ -3977,6 +4336,8 @@ floor({expr}) *floor()*
echo floor(4.0)
< 4.0
+ Can also be used as a |method|: >
+ Compute()->floor()
fmod({expr1}, {expr2}) *fmod()*
Return the remainder of {expr1} / {expr2}, even if the
@@ -3992,6 +4353,8 @@ fmod({expr1}, {expr2}) *fmod()*
:echo fmod(-12.33, 1.22)
< -0.13
+ Can also be used as a |method|: >
+ Compute()->fmod(1.22)
fnameescape({string}) *fnameescape()*
Escape {string} for use as file name command argument. All
@@ -4024,11 +4387,15 @@ foldclosed({lnum}) *foldclosed()*
The result is a Number. If the line {lnum} is in a closed
fold, the result is the number of the first line in that fold.
If the line {lnum} is not in a closed fold, -1 is returned.
+ {lnum} is used like with |getline()|. Thus "." is the current
+ line, "'m" mark m, etc.
foldclosedend({lnum}) *foldclosedend()*
The result is a Number. If the line {lnum} is in a closed
fold, the result is the number of the last line in that fold.
If the line {lnum} is not in a closed fold, -1 is returned.
+ {lnum} is used like with |getline()|. Thus "." is the current
+ line, "'m" mark m, etc.
foldlevel({lnum}) *foldlevel()*
The result is a Number, which is the foldlevel of line {lnum}
@@ -4039,6 +4406,8 @@ foldlevel({lnum}) *foldlevel()*
returned for lines where folds are still to be updated and the
foldlevel is unknown. As a special case the level of the
previous line is usually available.
+ {lnum} is used like with |getline()|. Thus "." is the current
+ line, "'m" mark m, etc.
*foldtext()*
foldtext() Returns a String, to be displayed for a closed fold. This is
@@ -4158,6 +4527,12 @@ get({list}, {idx} [, {default}]) *get()*
Get item {idx} from |List| {list}. When this item is not
available return {default}. Return zero when {default} is
omitted.
+ Can also be used as a |method|: >
+ mylist->get(idx)
+get({blob}, {idx} [, {default}])
+ Get byte {idx} from |Blob| {blob}. When this byte is not
+ available return {default}. Return -1 when {default} is
+ omitted.
get({dict}, {key} [, {default}])
Get item with key {key} from |Dictionary| {dict}. When this
item is not available return {default}. Return zero when
@@ -4174,7 +4549,7 @@ get({func}, {what})
"args" The list with arguments
*getbufinfo()*
-getbufinfo([{expr}])
+getbufinfo([{buf}])
getbufinfo([{dict}])
Get information about buffers as a List of Dictionaries.
@@ -4188,8 +4563,8 @@ getbufinfo([{dict}])
bufloaded include only loaded buffers.
bufmodified include only modified buffers.
- Otherwise, {expr} specifies a particular buffer to return
- information for. For the use of {expr}, see |bufname()|
+ Otherwise, {buf} specifies a particular buffer to return
+ information for. For the use of {buf}, see |bufname()|
above. If the buffer is found the returned List has one item.
Otherwise the result is an empty list.
@@ -4242,12 +4617,12 @@ getbufinfo([{dict}])
<
*getbufline()*
-getbufline({expr}, {lnum} [, {end}])
+getbufline({buf}, {lnum} [, {end}])
Return a |List| with the lines starting from {lnum} to {end}
- (inclusive) in the buffer {expr}. If {end} is omitted, a
+ (inclusive) in the buffer {buf}. If {end} is omitted, a
|List| with only the line {lnum} is returned.
- For the use of {expr}, see |bufname()| above.
+ For the use of {buf}, see |bufname()| above.
For {lnum} and {end} "$" can be used for the last line of the
buffer. Otherwise a number must be used.
@@ -4266,10 +4641,11 @@ getbufline({expr}, {lnum} [, {end}])
Example: >
:let lines = getbufline(bufnr("myfile"), 1, "$")
-getbufvar({expr}, {varname} [, {def}]) *getbufvar()*
+getbufvar({buf}, {varname} [, {def}]) *getbufvar()*
The result is the value of option or local buffer variable
- {varname} in buffer {expr}. Note that the name without "b:"
+ {varname} in buffer {buf}. Note that the name without "b:"
must be used.
+ The {varname} argument is a string.
When {varname} is empty returns a |Dictionary| with all the
buffer-local variables.
When {varname} is equal to "&" returns a |Dictionary| with all
@@ -4279,16 +4655,16 @@ getbufvar({expr}, {varname} [, {def}]) *getbufvar()*
This also works for a global or buffer-local option, but it
doesn't work for a global variable, window-local variable or
window-local option.
- For the use of {expr}, see |bufname()| above.
+ For the use of {buf}, see |bufname()| above.
When the buffer or variable doesn't exist {def} or an empty
string is returned, there is no error message.
Examples: >
:let bufmodified = getbufvar(1, "&mod")
:echo "todo myvar = " . getbufvar("todo", "myvar")
<
-getchangelist({expr}) *getchangelist()*
- Returns the |changelist| for the buffer {expr}. For the use
- of {expr}, see |bufname()| above. If buffer {expr} doesn't
+getchangelist({buf}) *getchangelist()*
+ Returns the |changelist| for the buffer {buf}. For the use
+ of {buf}, see |bufname()| above. If buffer {buf} doesn't
exist, an empty list is returned.
The returned list contains two entries: a list with the change
@@ -4298,7 +4674,7 @@ getchangelist({expr}) *getchangelist()*
col column number
coladd column offset for 'virtualedit'
lnum line number
- If buffer {expr} is the current buffer, then the current
+ If buffer {buf} is the current buffer, then the current
position refers to the position in the list. For other
buffers, it is set to the length of the list.
@@ -4309,6 +4685,7 @@ getchar([expr]) *getchar()*
Return zero otherwise.
If [expr] is 1, only check if a character is available, it is
not consumed. Return zero if no character available.
+ If you prefer always getting a string use |getcharstr()|.
Without [expr] and when [expr] is 0 a whole character or
special key is returned. If it is a single character, the
@@ -4333,7 +4710,8 @@ getchar([expr]) *getchar()*
When the user clicks a mouse button, the mouse event will be
returned. The position can then be found in |v:mouse_col|,
|v:mouse_lnum|, |v:mouse_winid| and |v:mouse_win|.
- Mouse move events will be ignored.
+ |getmousepos()| can also be used. Mouse move events will be
+ ignored.
This example positions the mouse as it would normally happen: >
let c = getchar()
if c == "\<LeftMouse>" && v:mouse_win > 0
@@ -4400,6 +4778,20 @@ getcharsearch() *getcharsearch()*
:nnoremap <expr> , getcharsearch().forward ? ',' : ';'
< Also see |setcharsearch()|.
+
+getcharstr([expr]) *getcharstr()*
+ Get a single character from the user or input stream as a
+ string.
+ If [expr] is omitted, wait until a character is available.
+ If [expr] is 0 or false, only get a character when one is
+ available. Return an empty string otherwise.
+ If [expr] is 1 or true, only check if a character is
+ available, it is not consumed. Return an empty string
+ if no character is available.
+ Otherwise this works like |getchar()|, except that a number
+ result is converted to a string.
+
+
getcmdline() *getcmdline()*
Return the current command-line. Only works when the command
line is being edited, thus requires use of |c_CTRL-\_e| or
@@ -4439,9 +4831,9 @@ getcmdwintype() *getcmdwintype()*
when not in the command-line window.
getcompletion({pat}, {type} [, {filtered}]) *getcompletion()*
- Return a list of command-line completion matches. {type}
- specifies what for. The following completion types are
- supported:
+ Return a list of command-line completion matches. The String
+ {type} argument specifies what for. The following completion
+ types are supported:
arglist file names in argument list
augroup autocmd groups
@@ -4512,9 +4904,9 @@ getcurpos() Get the position of the cursor. This is like getpos('.'), but
|winrestview()| for restoring more state.
getcwd([{winnr}[, {tabnr}]]) *getcwd()*
- With no arguments the result is a String, which is the name of
- the current effective working directory. With {winnr} or
- {tabnr} the working directory of that scope is returned.
+ With no arguments, returns the name of the effective
+ |current-directory|. With {winnr} or {tabnr} the working
+ directory of that scope is returned.
Tabs and windows are identified by their respective numbers,
0 means current tab or window. Missing argument implies 0.
Thus the following are equivalent: >
@@ -4525,8 +4917,11 @@ getcwd([{winnr}[, {tabnr}]]) *getcwd()*
{winnr} can be the window number or the |window-ID|.
getenv({name}) *getenv()*
- Return the value of environment variable {name}.
- When the variable does not exist |v:null| is returned. That
+ Return the value of environment variable {name}. The {name}
+ argument is a string, without a leading '$'. Example: >
+ myHome = getenv('HOME')
+
+< When the variable does not exist |v:null| is returned. That
is different from a variable set to an empty string.
See also |expr-env|.
@@ -4534,8 +4929,8 @@ getfontname([{name}]) *getfontname()*
Without an argument returns the name of the normal font being
used. Like what is used for the Normal highlight group
|hl-Normal|.
- With an argument a check is done whether {name} is a valid
- font name. If not then an empty string is returned.
+ With an argument a check is done whether String {name} is a
+ valid font name. If not then an empty string is returned.
Otherwise the actual font name is returned, or {name} if the
GUI does not support obtaining the real name.
Only works when the GUI is running, thus not in your vimrc or
@@ -4664,20 +5059,20 @@ getloclist({nr},[, {what}]) *getloclist()*
:echo getloclist(5, {'filewinid': 0})
-getmarklist([{expr}]) *getmarklist()*
- Without the {expr} argument returns a |List| with information
+getmarklist([{buf}]) *getmarklist()*
+ Without the {buf} argument returns a |List| with information
about all the global marks. |mark|
- If the optional {expr} argument is specified, returns the
- local marks defined in buffer {expr}. For the use of {expr},
+ If the optional {buf} argument is specified, returns the
+ local marks defined in buffer {buf}. For the use of {buf},
see |bufname()|.
Each item in the returned List is a |Dict| with the following:
- name - name of the mark prefixed by "'"
- pos - a |List| with the position of the mark:
+ mark name of the mark prefixed by "'"
+ pos a |List| with the position of the mark:
[bufnum, lnum, col, off]
- Refer to |getpos()| for more information.
- file - file name
+ Refer to |getpos()| for more information.
+ file file name
Refer to |getpos()| for getting information about a specific
mark.
@@ -4688,6 +5083,8 @@ getmatches([{win}]) *getmatches()*
|getmatches()| is useful in combination with |setmatches()|,
as |setmatches()| can restore a list of matches saved by
|getmatches()|.
+ If {win} is specified, use the window with this number or
+ window ID instead of the current window.
Example: >
:echo getmatches()
< [{'group': 'MyGroup1', 'pattern': 'TODO',
@@ -4704,13 +5101,42 @@ getmatches([{win}]) *getmatches()*
'pattern': 'FIXME', 'priority': 10, 'id': 2}] >
:unlet m
<
+getmousepos() *getmousepos()*
+ Returns a Dictionary with the last known position of the
+ mouse. This can be used in a mapping for a mouse click. The
+ items are:
+ screenrow screen row
+ screencol screen column
+ winid Window ID of the click
+ winrow row inside "winid"
+ wincol column inside "winid"
+ line text line inside "winid"
+ column text column inside "winid"
+ All numbers are 1-based.
+
+ If not over a window, e.g. when in the command line, then only
+ "screenrow" and "screencol" are valid, the others are zero.
+
+ When on the status line below a window or the vertical
+ separater right of a window, the "line" and "column" values
+ are zero.
+
+ When the position is after the text then "column" is the
+ length of the text in bytes plus one.
+
+ If the mouse is over a focusable floating window then that
+ window is used.
+
+ When using |getchar()| the Vim variables |v:mouse_lnum|,
+ |v:mouse_col| and |v:mouse_winid| also provide these values.
+
*getpid()*
getpid() Return a Number which is the process ID of the Vim process.
This is a unique number, until Vim exits.
*getpos()*
-getpos({expr}) Get the position for {expr}. For possible values of {expr}
- see |line()|. For getting the cursor position see
+getpos({expr}) Get the position for String {expr}. For possible values of
+ {expr} see |line()|. For getting the cursor position see
|getcurpos()|.
The result is a |List| with four numbers:
[bufnum, lnum, col, off]
@@ -4743,7 +5169,10 @@ getqflist([{what}]) *getqflist()*
bufname() to get the name
module module name
lnum line number in the buffer (first line is 1)
+ end_lnum
+ end of line number if the item is multiline
col column number (first column is 1)
+ end_col end of column number if the item has range
vcol |TRUE|: "col" is visual column
|FALSE|: "col" is byte index
nr error number
@@ -4753,8 +5182,10 @@ getqflist([{what}]) *getqflist()*
valid |TRUE|: recognized error message
When there is no error list or it's empty, an empty list is
- returned. Quickfix list entries with non-existing buffer
- number are returned with "bufnr" set to zero.
+ returned. Quickfix list entries with a non-existing buffer
+ number are returned with "bufnr" set to zero (Note: some
+ functions accept buffer number zero for the alternate buffer,
+ you may need to explicitly check for zero).
Useful application: Find pattern matches in multiple files and
do something with them: >
@@ -4831,6 +5262,7 @@ getreg([{regname} [, 1 [, {list}]]]) *getreg()*
{regname}. Example: >
:let cliptext = getreg('*')
< When {regname} was not set the result is an empty string.
+ The {regname} argument is a string.
getreg('=') returns the last evaluated value of the expression
register. (For use in maps.)
@@ -4847,6 +5279,32 @@ getreg([{regname} [, 1 [, {list}]]]) *getreg()*
If {regname} is not specified, |v:register| is used.
+getreginfo([{regname}]) *getreginfo()*
+ Returns detailed information about register {regname} as a
+ Dictionary with the following entries:
+ regcontents List of lines contained in register
+ {regname}, like
+ |getreg|({regname}, 1, 1).
+ regtype the type of register {regname}, as in
+ |getregtype()|.
+ isunnamed Boolean flag, v:true if this register
+ is currently pointed to by the unnamed
+ register.
+ points_to for the unnamed register, gives the
+ single letter name of the register
+ currently pointed to (see |quotequote|).
+ For example, after deleting a line
+ with `dd`, this field will be "1",
+ which is the register that got the
+ deleted text.
+
+ The {regname} argument is a string. If {regname} is invalid
+ or not set, an empty Dictionary will be returned.
+ If {regname} is not specified, |v:register| is used.
+ The returned Dictionary can be passed to |setreg()|.
+
+ Can also be used as a |method|: >
+ GetRegname()->getreginfo()
getregtype([{regname}]) *getregtype()*
The result is a String, which is type of register {regname}.
@@ -4856,14 +5314,15 @@ getregtype([{regname}]) *getregtype()*
"<CTRL-V>{width}" for |blockwise-visual| text
"" for an empty or unknown register
<CTRL-V> is one character with value 0x16.
- If {regname} is not specified, |v:register| is used.
+ The {regname} argument is a string. If {regname} is not
+ specified, |v:register| is used.
-gettabinfo([{arg}]) *gettabinfo()*
- If {arg} is not specified, then information about all the tab
- pages is returned as a |List|. Each List item is a |Dictionary|.
- Otherwise, {arg} specifies the tab page number and information
- about that one is returned. If the tab page does not exist an
- empty List is returned.
+gettabinfo([{tabnr}]) *gettabinfo()*
+ If {tabnr} is not specified, then information about all the
+ tab pages is returned as a |List|. Each List item is a
+ |Dictionary|. Otherwise, {tabnr} specifies the tab page
+ number and information about that one is returned. If the tab
+ page does not exist an empty List is returned.
Each List item is a |Dictionary| with the following entries:
tabnr tab page number.
@@ -4875,8 +5334,8 @@ gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
Get the value of a tab-local variable {varname} in tab page
{tabnr}. |t:var|
Tabs are numbered starting with one.
- When {varname} is empty a dictionary with all tab-local
- variables is returned.
+ The {varname} argument is a string. When {varname} is empty a
+ dictionary with all tab-local variables is returned.
Note that the name without "t:" must be used.
When the tab or variable doesn't exist {def} or an empty
string is returned, there is no error message.
@@ -4884,8 +5343,8 @@ gettabvar({tabnr}, {varname} [, {def}]) *gettabvar()*
gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
Get the value of window-local variable {varname} in window
{winnr} in tab page {tabnr}.
- When {varname} is empty a dictionary with all window-local
- variables is returned.
+ The {varname} argument is a string. When {varname} is empty a
+ dictionary with all window-local variables is returned.
When {varname} is equal to "&" get the values of all
window-local options in a |Dictionary|.
Otherwise, when {varname} starts with "&" get the value of a
@@ -4907,11 +5366,11 @@ gettabwinvar({tabnr}, {winnr}, {varname} [, {def}]) *gettabwinvar()*
To obtain all window-local variables use: >
gettabwinvar({tabnr}, {winnr}, '&')
-gettagstack([{nr}]) *gettagstack()*
- The result is a Dict, which is the tag stack of window {nr}.
- {nr} can be the window number or the |window-ID|.
- When {nr} is not specified, the current window is used.
- When window {nr} doesn't exist, an empty Dict is returned.
+gettagstack([{winnr}]) *gettagstack()*
+ The result is a Dict, which is the tag stack of window {winnr}.
+ {winnr} can be the window number or the |window-ID|.
+ When {winnr} is not specified, the current window is used.
+ When window {winnr} doesn't exist, an empty Dict is returned.
The returned dictionary contains the following entries:
curidx Current index in the stack. When at
@@ -5040,22 +5499,22 @@ glob({expr} [, {nosuf} [, {list} [, {alllinks}]]]) *glob()*
See |expand()| for expanding special Vim variables. See
|system()| for getting the raw output of an external command.
-glob2regpat({expr}) *glob2regpat()*
+glob2regpat({string}) *glob2regpat()*
Convert a file pattern, as used by glob(), into a search
pattern. The result can be used to match with a string that
is a file name. E.g. >
if filename =~ glob2regpat('Make*.mak')
< This is equivalent to: >
if filename =~ '^Make.*\.mak$'
-< When {expr} is an empty string the result is "^$", match an
+< When {string} is an empty string the result is "^$", match an
empty string.
Note that the result depends on the system. On MS-Windows
a backslash usually means a path separator.
*globpath()*
globpath({path}, {expr} [, {nosuf} [, {list} [, {allinks}]]])
- Perform glob() on all directories in {path} and concatenate
- the results. Example: >
+ Perform glob() for String {expr} on all directories in {path}
+ and concatenate the results. Example: >
:echo globpath(&rtp, "syntax/c.vim")
<
{path} is a comma-separated list of directory names. Each
@@ -5149,7 +5608,11 @@ has({feature}) Returns 1 if {feature} is supported, 0 otherwise. The
has_key({dict}, {key}) *has_key()*
The result is a Number, which is TRUE if |Dictionary| {dict}
- has an entry with key {key}. FALSE otherwise.
+ has an entry with key {key}. FALSE otherwise. The {key}
+ argument is a string.
+
+ Can also be used as a |method|: >
+ mydict->has_key(key)
haslocaldir([{winnr}[, {tabnr}]]) *haslocaldir()*
The result is a Number, which is 1 when the tabpage or window
@@ -5171,6 +5634,7 @@ hasmapto({what} [, {mode} [, {abbr}]]) *hasmapto()*
that contains {what} in somewhere in the rhs (what it is
mapped to) and this mapping exists in one of the modes
indicated by {mode}.
+ The arguments {what} and {mode} are strings.
When {abbr} is there and it is |TRUE| use abbreviations
instead of mappings. Don't forget to specify Insert and/or
Command-line mode.
@@ -5291,17 +5755,14 @@ hostname() *hostname()*
which Vim is currently running. Machine names greater than
256 characters long are truncated.
-iconv({expr}, {from}, {to}) *iconv()*
- The result is a String, which is the text {expr} converted
+iconv({string}, {from}, {to}) *iconv()*
+ The result is a String, which is the text {string} converted
from encoding {from} to encoding {to}.
When the conversion completely fails an empty string is
returned. When some characters could not be converted they
are replaced with "?".
The encoding names are whatever the iconv() library function
can accept, see ":!man 3 iconv".
- Most conversions require Vim to be compiled with the |+iconv|
- feature. Otherwise only UTF-8 to latin1 conversion and back
- can be done.
Note that Vim uses UTF-8 for all Unicode encodings, conversion
from/to UCS-2 is automatically changed to use UTF-8. You
cannot use UCS-2 in a string anyway, because of the NUL bytes.
@@ -5314,17 +5775,21 @@ indent({lnum}) The result is a Number, which is indent of line {lnum} in the
When {lnum} is invalid -1 is returned.
-index({list}, {expr} [, {start} [, {ic}]]) *index()*
- Return the lowest index in |List| {list} where the item has a
- value equal to {expr}. There is no automatic conversion, so
- the String "4" is different from the Number 4. And the number
- 4 is different from the Float 4.0. The value of 'ignorecase'
- is not used here, case always matters.
+index({object}, {expr} [, {start} [, {ic}]]) *index()*
+ If {object} is a |List| return the lowest index where the item
+ has a value equal to {expr}. There is no automatic
+ conversion, so the String "4" is different from the Number 4.
+ And the Number 4 is different from the Float 4.0. The value
+ of 'ignorecase' is not used here, case always matters.
+
+ If {object} is a |Blob| return the lowest index where the byte
+ value is equal to {expr}.
+
If {start} is given then start looking at the item with index
{start} (may be negative for an item relative to the end).
When {ic} is given and it is |TRUE|, ignore case. Otherwise
case must match.
- -1 is returned when {expr} is not found in {list}.
+ -1 is returned when {expr} is not found in {object}.
Example: >
:let idx = index(words, "the")
:if index(numbers, 123) >= 0
@@ -5483,13 +5948,16 @@ inputsecret({prompt} [, {text}]) *inputsecret()*
typed on the command-line in response to the issued prompt.
NOTE: Command-line completion is not supported.
-insert({list}, {item} [, {idx}]) *insert()*
- Insert {item} at the start of |List| {list}.
+insert({object}, {item} [, {idx}]) *insert()*
+ When {object} is a |List| or a |Blob| insert {item} at the start
+ of it.
+
If {idx} is specified insert {item} before the item with index
{idx}. If {idx} is zero it goes before the first item, just
like omitting {idx}. A negative {idx} is also possible, see
|list-index|. -1 inserts just before the last item.
- Returns the resulting |List|. Examples: >
+
+ Returns the resulting |List| or |Blob|. Examples: >
:let mylist = insert([2, 3, 5], 1)
:call insert(mylist, 4, -1)
:call insert(mylist, 6, len(mylist))
@@ -5497,6 +5965,9 @@ insert({list}, {item} [, {idx}]) *insert()*
Note that when {item} is a |List| it is inserted as a single
item. Use |extend()| to concatenate |Lists|.
+ Can also be used as a |method|: >
+ mylist->insert(item)
+
interrupt() *interrupt()*
Interrupt script execution. It works more or less like the
user typing CTRL-C, most commands won't execute and control
@@ -5514,6 +5985,8 @@ invert({expr}) *invert()*
Bitwise invert. The argument is converted to a number. A
List, Dict or Float argument causes an error. Example: >
:let bits = invert(bits)
+< Can also be used as a |method|: >
+ :let bits = bits->invert()
isdirectory({directory}) *isdirectory()*
The result is a Number, which is |TRUE| when a directory
@@ -5529,11 +6002,15 @@ isinf({expr}) *isinf()*
:echo isinf(-1.0 / 0.0)
< -1
+ Can also be used as a |method|: >
+ Compute()->isinf()
+
islocked({expr}) *islocked()* *E786*
The result is a Number, which is |TRUE| when {expr} is the
name of a locked variable.
- {expr} must be the name of a variable, |List| item or
- |Dictionary| entry, not the variable itself! Example: >
+ The string argument {expr} must be the name of a variable,
+ |List| item or |Dictionary| entry, not the variable itself!
+ Example: >
:let alist = [0, ['a', 'b'], 2, 3]
:lockvar 1 alist
:echo islocked('alist') " 1
@@ -5544,16 +6021,16 @@ islocked({expr}) *islocked()* *E786*
id({expr}) *id()*
Returns a |String| which is a unique identifier of the
- container type (|List|, |Dict| and |Partial|). It is
+ container type (|List|, |Dict|, |Blob| and |Partial|). It is
guaranteed that for the mentioned types `id(v1) ==# id(v2)`
returns true iff `type(v1) == type(v2) && v1 is v2`.
- Note that |v:_null_string|, |v:_null_list|, and |v:_null_dict|
- have the same `id()` with different types because they are
- internally represented as a NULL pointers. `id()` returns a
- hexadecimal representanion of the pointers to the containers
- (i.e. like `0x994a40`), same as `printf("%p", {expr})`,
- but it is advised against counting on the exact format of
- return value.
+ Note that |v:_null_string|, |v:_null_list|, |v:_null_dict| and
+ |v:_null_blob| have the same `id()` with different types
+ because they are internally represented as NULL pointers.
+ `id()` returns a hexadecimal representanion of the pointers to
+ the containers (i.e. like `0x994a40`), same as `printf("%p",
+ {expr})`, but it is advised against counting on the exact
+ format of the return value.
It is not guaranteed that `id(no_longer_existing_container)`
will not be equal to some other `id()`: new containers may
@@ -5563,13 +6040,23 @@ items({dict}) *items()*
Return a |List| with all the key-value pairs of {dict}. Each
|List| item is a list with two items: the key of a {dict}
entry and the value of this entry. The |List| is in arbitrary
- order.
+ order. Also see |keys()| and |values()|.
+ Example: >
+ for [key, value] in items(mydict)
+ echo key . ': ' . value
+ endfor
+
+< Can also be used as a |method|: >
+ mydict->items()
isnan({expr}) *isnan()*
Return |TRUE| if {expr} is a float with value NaN. >
echo isnan(0.0 / 0.0)
< 1
+ Can also be used as a |method|: >
+ Compute()->isnan()
+
jobpid({job}) *jobpid()*
Return the PID (process id) of |job-id| {job}.
@@ -5641,6 +6128,9 @@ jobstart({cmd}[, {opts}]) *jobstart()*
before invoking `on_stderr`. |channel-buffered|
stdout_buffered: (boolean) Collect data until EOF (stream
closed) before invoking `on_stdout`. |channel-buffered|
+ stdin: (string) Either "pipe" (default) to connect the
+ job's stdin to a channel or "null" to disconnect
+ stdin.
width: (number) Width of the `pty` terminal.
{opts} is passed as |self| dictionary to the callback; the
@@ -5666,8 +6156,8 @@ jobwait({jobs}[, {timeout}]) *jobwait()*
Waits for jobs and their |on_exit| handlers to complete.
{jobs} is a List of |job-id|s to wait for.
- {timeout} is the maximum waiting time in milliseconds, -1
- means forever.
+ {timeout} is the maximum waiting time in milliseconds. If
+ omitted or -1, wait forever.
Timeout of 0 can be used to check the status of a job: >
let running = jobwait([{job-id}], 0)[0] == -1
@@ -5694,6 +6184,9 @@ join({list} [, {sep}]) *join()*
converted into a string like with |string()|.
The opposite function is |split()|.
+ Can also be used as a |method|: >
+ mylist->join()
+
json_decode({expr}) *json_decode()*
Convert {expr} from JSON object. Accepts |readfile()|-style
list as the input, as well as regular string. May output any
@@ -5720,12 +6213,16 @@ json_encode({expr}) *json_encode()*
surrogate pairs (such strings are not valid UTF-8 strings).
Non-printable characters are converted into "\u1234" escapes
or special escapes like "\t", other are dumped as-is.
+ |Blob|s are converted to arrays of the individual bytes.
keys({dict}) *keys()*
Return a |List| with all the keys of {dict}. The |List| is in
- arbitrary order.
+ arbitrary order. Also see |items()| and |values()|.
+
+ Can also be used as a |method|: >
+ mydict->keys()
- *len()* *E701*
+< *len()* *E701*
len({expr}) The result is a Number, which is the length of the argument.
When {expr} is a String or a Number the length in bytes is
used, as with |strlen()|.
@@ -5736,7 +6233,10 @@ len({expr}) The result is a Number, which is the length of the argument.
|Dictionary| is returned.
Otherwise an error is given.
- *libcall()* *E364* *E368*
+ Can also be used as a |method|: >
+ mylist->len()
+
+< *libcall()* *E364* *E368*
libcall({libname}, {funcname}, {argument})
Call function {funcname} in the run-time library {libname}
with single argument {argument}.
@@ -5790,7 +6290,8 @@ libcallnr({libname}, {funcname}, {argument})
<
*line()*
line({expr}) The result is a Number, which is the line number of the file
- position given with {expr}. The accepted positions are:
+ position given with {expr}. The {expr} argument is a string.
+ The accepted positions are:
. the cursor position
$ the last line in the current buffer
'x position of mark x (if the mark is not set, 0 is
@@ -5821,8 +6322,8 @@ line2byte({lnum}) *line2byte()*
line just below the last line: >
line2byte(line("$") + 1)
< This is the buffer size plus one. If 'fileencoding' is empty
- it is the file size plus one.
- When {lnum} is invalid -1 is returned.
+ it is the file size plus one. {lnum} is used like with
+ |getline()|. When {lnum} is invalid -1 is returned.
Also see |byte2line()|, |go| and |:goto|.
lispindent({lnum}) *lispindent()*
@@ -5830,8 +6331,7 @@ lispindent({lnum}) *lispindent()*
indenting rules, as with 'lisp'.
The indent is counted in spaces, the value of 'tabstop' is
relevant. {lnum} is used just like in |getline()|.
- When {lnum} is invalid or Vim was not compiled the
- |+lispindent| feature, -1 is returned.
+ When {lnum} is invalid, -1 is returned.
list2str({list} [, {utf8}]) *list2str()*
Convert each number in {list} to a character string can
@@ -5862,6 +6362,8 @@ log({expr}) *log()*
:echo log(exp(5))
< 5.0
+ Can also be used as a |method|: >
+ Compute()->log()
log10({expr}) *log10()*
Return the logarithm of Float {expr} to base 10 as a |Float|.
@@ -5872,19 +6374,25 @@ log10({expr}) *log10()*
:echo log10(0.01)
< -2.0
+ Can also be used as a |method|: >
+ Compute()->log10()
+
luaeval({expr}[, {expr}])
Evaluate Lua expression {expr} and return its result converted
to Vim data structures. See |lua-eval| for more details.
map({expr1}, {expr2}) *map()*
- {expr1} must be a |List| or a |Dictionary|.
+ {expr1} must be a |List|, |Blob| or |Dictionary|.
Replace each item in {expr1} with the result of evaluating
- {expr2}. {expr2} must be a |string| or |Funcref|.
+ {expr2}. For a |Blob| each byte is replaced.
+
+ {expr2} must be a |string| or |Funcref|.
If {expr2} is a |string|, inside {expr2} |v:val| has the value
- of the current item. For a |Dictionary| |v:key| has the key
+ of the current item. For a |Dictionary| |v:key| has the key
of the current item and for a |List| |v:key| has the index of
- the current item.
+ the current item. For a |Blob| |v:key| has the index of the
+ current byte.
Example: >
:call map(mylist, '"> " . v:val . " <"')
< This puts "> " before and " <" after each item in "mylist".
@@ -5914,12 +6422,14 @@ map({expr1}, {expr2}) *map()*
|Dictionary| to remain unmodified make a copy first: >
:let tlist = map(copy(mylist), ' v:val . "\t"')
-< Returns {expr1}, the |List| or |Dictionary| that was filtered.
- When an error is encountered while evaluating {expr2} no
- further items in {expr1} are processed. When {expr2} is a
- Funcref errors inside a function are ignored, unless it was
- defined with the "abort" flag.
+< Returns {expr1}, the |List|, |Blob| or |Dictionary| that was
+ filtered. When an error is encountered while evaluating
+ {expr2} no further items in {expr1} are processed. When
+ {expr2} is a Funcref errors inside a function are ignored,
+ unless it was defined with the "abort" flag.
+ Can also be used as a |method|: >
+ mylist->map(expr2)
maparg({name} [, {mode} [, {abbr} [, {dict}]]]) *maparg()*
When {dict} is omitted or zero: Return the rhs of mapping
@@ -6179,7 +6689,7 @@ matcharg({nr}) *matcharg()*
Highlighting matches using the |:match| commands are limited
to three matches. |matchadd()| does not have this limitation.
-matchdelete({id} [, {win}) *matchdelete()* *E802* *E803*
+matchdelete({id} [, {win}]) *matchdelete()* *E802* *E803*
Deletes a match with ID {id} previously defined by |matchadd()|
or one of the |:match| commands. Returns 0 if successful,
otherwise -1. See example for |matchadd()|. All matches can
@@ -6255,7 +6765,10 @@ max({expr}) Return the maximum value of all items in {expr}.
items in {expr} cannot be used as a Number this results in
an error. An empty |List| or |Dictionary| results in zero.
-menu_get({path}, {modes}) *menu_get()*
+ Can also be used as a |method|: >
+ mylist->max()
+
+menu_get({path} [, {modes}]) *menu_get()*
Returns a |List| of |Dictionaries| describing |menus| (defined
by |:menu|, |:amenu|, …), including |hidden-menus|.
@@ -6309,15 +6822,18 @@ min({expr}) Return the minimum value of all items in {expr}.
items in {expr} cannot be used as a Number this results in
an error. An empty |List| or |Dictionary| results in zero.
- *mkdir()* *E739*
+ Can also be used as a |method|: >
+ mylist->min()
+
+< *mkdir()* *E739*
mkdir({name} [, {path} [, {prot}]])
Create directory {name}.
If {path} is "p" then intermediate directories are created as
necessary. Otherwise it must be "".
If {prot} is given it is used to set the protection bits of
- the new directory. The default is 0755 (rwxr-xr-x: r/w for
- the user readable for others). Use 0700 to make it unreadable
- for others.
+ the new directory. The default is 0o755 (rwxr-xr-x: r/w for
+ the user, readable for others). Use 0o700 to make it
+ unreadable for others.
{prot} is applied for all parts of {name}. Thus if you create
/tmp/foo/bar then /tmp/foo will be created with 0700. Example: >
@@ -6352,6 +6868,10 @@ mode([expr]) Return a string that indicates the current mode.
s Select by character
S Select by line
CTRL-S Select blockwise
+ vs Visual by character using |v_CTRL-O| from
+ Select mode
+ Vs Visual by line using |v_CTRL-O| from Select mode
+ CTRL-Vs Visual blockwise using |v_CTRL-O| from Select mode
i Insert
ic Insert mode completion |compl-generic|
ix Insert mode |i_CTRL-X| completion
@@ -6360,8 +6880,7 @@ mode([expr]) Return a string that indicates the current mode.
Rv Virtual Replace |gR|
Rx Replace mode |i_CTRL-X| completion
c Command-line editing
- cv Vim Ex mode |gQ|
- ce Normal Ex mode |Q|
+ cv Vim Ex mode |Q| or |gQ|
r Hit-enter prompt
rm The -- more -- prompt
r? |:confirm| query of some sort
@@ -6375,11 +6894,15 @@ mode([expr]) Return a string that indicates the current mode.
the leading character(s).
Also see |visualmode()|.
-msgpackdump({list}) *msgpackdump()*
- Convert a list of VimL objects to msgpack. Returned value is
- |readfile()|-style list. Example: >
+msgpackdump({list} [, {type}]) *msgpackdump()*
+ Convert a list of VimL objects to msgpack. Returned value is a
+ |readfile()|-style list. When {type} contains "B", a |Blob| is
+ returned instead. Example: >
call writefile(msgpackdump([{}]), 'fname.mpack', 'b')
-< This will write the single 0x80 byte to `fname.mpack` file
+< or, using a |Blob|: >
+ call writefile(msgpackdump([{}], 'B'), 'fname.mpack')
+<
+ This will write the single 0x80 byte to a `fname.mpack` file
(dictionary with zero items is represented by 0x80 byte in
messagepack).
@@ -6387,11 +6910,12 @@ msgpackdump({list}) *msgpackdump()*
1. |Funcref|s cannot be dumped.
2. Containers that reference themselves cannot be dumped.
3. Dictionary keys are always dumped as STR strings.
- 4. Other strings are always dumped as BIN strings.
+ 4. Other strings and |Blob|s are always dumped as BIN strings.
5. Points 3. and 4. do not apply to |msgpack-special-dict|s.
-msgpackparse({list}) *msgpackparse()*
- Convert a |readfile()|-style list to a list of VimL objects.
+msgpackparse({data}) *msgpackparse()*
+ Convert a |readfile()|-style list or a |Blob| to a list of
+ VimL objects.
Example: >
let fname = expand('~/.config/nvim/shada/main.shada')
let mpack = readfile(fname, 'b')
@@ -6401,7 +6925,7 @@ msgpackparse({list}) *msgpackparse()*
Limitations:
1. Mapping ordering is not preserved unless messagepack
- mapping is dumped using generic mapping
+ mapping is dumped using generic mapping
(|msgpack-special-map|).
2. Since the parser aims to preserve all data untouched
(except for 1.) some strings are parsed to
@@ -6445,9 +6969,9 @@ msgpackparse({list}) *msgpackparse()*
zero byte or if string is a mapping key and mapping is
being represented as special dictionary for other
reasons.
- binary |readfile()|-style list of strings. This value will
- appear in |msgpackparse()| output if binary string
- contains zero byte.
+ binary |String|, or |Blob| if binary string contains zero
+ byte. This value cannot appear in |msgpackparse()|
+ output since blobs were introduced.
array |List|. This value cannot appear in |msgpackparse()|
output.
*msgpack-special-map*
@@ -6469,6 +6993,7 @@ nextnonblank({lnum}) *nextnonblank()*
if getline(nextnonblank(1)) =~ "Java"
< When {lnum} is invalid or there is no non-blank line at or
below it, zero is returned.
+ {lnum} is used like with |getline()|.
See also |prevnonblank()|.
nr2char({expr} [, {utf8}]) *nr2char()*
@@ -6501,10 +7026,11 @@ or({expr}, {expr}) *or()*
to a number. A List, Dict or Float argument causes an error.
Example: >
:let bits = or(bits, 0x80)
+< Can also be used as a |method|: >
+ :let bits = bits->or(0x80)
-
-pathshorten({expr}) *pathshorten()*
- Shorten directory names in the path {expr} and return the
+pathshorten({path}) *pathshorten()*
+ Shorten directory names in the path {path} and return the
result. The tail, the file name, is kept as-is. The other
components in the path are reduced to single letters. Leading
'~' and '.' characters are kept. Example: >
@@ -6538,12 +7064,16 @@ pow({x}, {y}) *pow()*
:echo pow(32, 0.20)
< 2.0
+ Can also be used as a |method|: >
+ Compute()->pow(3)
+
prevnonblank({lnum}) *prevnonblank()*
Return the line number of the first line at or above {lnum}
that is not blank. Example: >
let ind = indent(prevnonblank(v:lnum - 1))
< When {lnum} is invalid or there is no non-blank line at or
above it, zero is returned.
+ {lnum} is used like with |getline()|.
Also see |nextnonblank()|.
@@ -6554,7 +7084,11 @@ printf({fmt}, {expr1} ...) *printf()*
< May result in:
" 99: E42 asdfasdfasdfasdfasdfasdfasdfas" ~
- Often used items are:
+ When used as a |method| the base is passed as the second
+ argument: >
+ Compute()->printf("result: %d")
+
+< Often used items are:
%s string
%6S string right-aligned in 6 display cells
%6s string right-aligned in 6 bytes
@@ -6882,16 +7416,18 @@ readdir({directory} [, {expr}])
echo s:tree(".")
<
*readfile()*
-readfile({fname} [, {binary} [, {max}]])
+readfile({fname} [, {type} [, {max}]])
Read file {fname} and return a |List|, each line of the file
as an item. Lines are broken at NL characters. Macintosh
files separated with CR will result in a single long line
(unless a NL appears somewhere).
All NUL characters are replaced with a NL character.
- When {binary} contains "b" binary mode is used:
+ When {type} contains "b" binary mode is used:
- When the last line ends in a NL an extra empty list item is
added.
- No CR characters are removed.
+ When {type} contains "B" a |Blob| is returned with the binary
+ data of the file unmodified.
Otherwise:
- CR characters that appear before a NL are removed.
- Whether the last line ends in a NL or not does not matter.
@@ -6949,7 +7485,8 @@ reltimefloat({time}) *reltimefloat()*
call MyFunction()
let seconds = reltimefloat(reltime(start))
See the note of reltimestr() about overhead.
- Also see |profiling|.
+ Also see |profiling|.
+ If there is an error an empty string is returned
reltimestr({time}) *reltimestr()*
Return a String that represents the time value of {time}.
@@ -6963,6 +7500,7 @@ reltimestr({time}) *reltimestr()*
can use split() to remove it. >
echo split(reltimestr(reltime(start)))[0]
< Also see |profiling|.
+ If there is an error an empty string is returned
*remote_expr()* *E449*
remote_expr({server}, {string} [, {idvar} [, {timeout}]])
@@ -6993,6 +7531,7 @@ remote_expr({server}, {string} [, {idvar} [, {timeout}]])
remote_foreground({server}) *remote_foreground()*
Move the Vim server with the name {server} to the foreground.
+ The {server} argument is a string.
This works like: >
remote_expr({server}, "foreground()")
< Except that on Win32 systems the client does the work, to work
@@ -7064,6 +7603,21 @@ remove({list}, {idx} [, {end}]) *remove()*
Example: >
:echo "last item: " . remove(mylist, -1)
:call remove(mylist, 0, 9)
+
+< Can also be used as a |method|: >
+ mylist->remove(idx)
+
+remove({blob}, {idx} [, {end}])
+ Without {end}: Remove the byte at {idx} from |Blob| {blob} and
+ return the byte.
+ With {end}: Remove bytes from {idx} to {end} (inclusive) and
+ return a |Blob| with these bytes. When {idx} points to the same
+ byte as {end} a |Blob| with one byte is returned. When {end}
+ points to a byte before {idx} this is an error.
+ Example: >
+ :echo "last byte: " . remove(myblob, -1)
+ :call remove(mylist, 0, 9)
+
remove({dict}, {key})
Remove the entry from {dict} with key {key} and return it.
Example: >
@@ -7090,6 +7644,8 @@ repeat({expr}, {count}) *repeat()*
:let longlist = repeat(['a', 'b'], 3)
< Results in ['a', 'b', 'a', 'b', 'a', 'b'].
+ Can also be used as a |method|: >
+ mylist->repeat(count)
resolve({filename}) *resolve()* *E655*
On MS-Windows, when {filename} is a shortcut (a .lnk file),
@@ -7105,10 +7661,14 @@ resolve({filename}) *resolve()* *E655*
path name) and also keeps a trailing path separator.
*reverse()*
-reverse({list}) Reverse the order of items in {list} in-place. Returns
- {list}.
- If you want a list to remain unmodified make a copy first: >
+reverse({object})
+ Reverse the order of items in {object} in-place.
+ {object} can be a |List| or a |Blob|.
+ Returns {object}.
+ If you want an object to remain unmodified make a copy first: >
:let revlist = reverse(copy(mylist))
+< Can also be used as a |method|: >
+ mylist->reverse()
round({expr}) *round()*
Round off {expr} to the nearest integral value and return it
@@ -7123,6 +7683,9 @@ round({expr}) *round()*
echo round(-4.5)
< -5.0
+ Can also be used as a |method|: >
+ Compute()->round()
+
rpcnotify({channel}, {event}[, {args}...]) *rpcnotify()*
Sends {event} to {channel} via |RPC| and returns immediately.
If {channel} is 0, the event is broadcast to all channels.
@@ -7150,7 +7713,6 @@ rubyeval({expr}) *rubyeval()*
Hashes are represented as Vim |Dictionary| type.
Other objects are represented as strings resulted from their
"Object#to_s" method.
- {only available when compiled with the |+ruby| feature}
screenattr({row}, {col}) *screenattr()*
Like |screenchar()|, but return the attribute. This is a rather
@@ -7167,6 +7729,13 @@ screenchar({row}, {col}) *screenchar()*
This is mainly to be used for testing.
Returns -1 when row or col is out of range.
+screenchars({row}, {col}) *screenchars()*
+ The result is a List of Numbers. The first number is the same
+ as what |screenchar()| returns. Further numbers are
+ composing characters on top of the base character.
+ This is mainly to be used for testing.
+ Returns an empty List when row or col is out of range.
+
screencol() *screencol()*
The result is a Number, which is the current screen column of
the cursor. The leftmost column has number 1.
@@ -7197,6 +7766,10 @@ screenpos({winid}, {lnum}, {col}) *screenpos()*
The "curscol" value is where the cursor would be placed. For
a Tab it would be the same as "endcol", while for a double
width character it would be the same as "col".
+ The |conceal| feature is ignored here, the column numbers are
+ as if 'conceallevel' is zero. You can set the cursor to the
+ right position and use |screencol()| to get the value with
+ |conceal| taken into account.
screenrow() *screenrow()*
The result is a Number, which is the current screen row of the
@@ -7206,6 +7779,14 @@ screenrow() *screenrow()*
Note: Same restrictions as with |screencol()|.
+screenstring({row}, {col}) *screenstring()*
+ The result is a String that contains the base character and
+ any composing characters at position [row, col] on the screen.
+ This is like |screenchars()| but returning a String with the
+ characters.
+ This is mainly to be used for testing.
+ Returns an empty String when row or col is out of range.
+
search({pattern} [, {flags} [, {stopline} [, {timeout}]]]) *search()*
Search for regexp pattern {pattern}. The search starts at the
cursor position (you can use |cursor()| to set it).
@@ -7601,8 +8182,8 @@ serverstop({address}) *serverstop()*
If |v:servername| is stopped it is set to the next available
address returned by |serverlist()|.
-setbufline({expr}, {lnum}, {text}) *setbufline()*
- Set line {lnum} to {text} in buffer {expr}. This works like
+setbufline({buf}, {lnum}, {text}) *setbufline()*
+ Set line {lnum} to {text} in buffer {buf}. This works like
|setline()| for the specified buffer.
This function works only for loaded buffers. First call
@@ -7615,23 +8196,24 @@ setbufline({expr}, {lnum}, {text}) *setbufline()*
to set multiple lines. If the list extends below the last
line then those lines are added.
- For the use of {expr}, see |bufname()| above.
+ For the use of {buf}, see |bufname()| above.
{lnum} is used like with |setline()|.
When {lnum} is just below the last line the {text} will be
added below the last line.
On success 0 is returned, on failure 1 is returned.
- If {expr} is not a valid buffer or {lnum} is not valid, an
+ If {buf} is not a valid buffer or {lnum} is not valid, an
error message is given.
-setbufvar({expr}, {varname}, {val}) *setbufvar()*
- Set option or local variable {varname} in buffer {expr} to
+setbufvar({buf}, {varname}, {val}) *setbufvar()*
+ Set option or local variable {varname} in buffer {buf} to
{val}.
This also works for a global or local window option, but it
doesn't work for a global or local window variable.
For a local window option the global value is unchanged.
- For the use of {expr}, see |bufname()| above.
+ For the use of {buf}, see |bufname()| above.
+ The {varname} argument is a string.
Note that the variable name without "b:" must be used.
Examples: >
:call setbufvar(1, "&mod", 1)
@@ -7674,8 +8256,10 @@ setcmdpos({pos}) *setcmdpos()*
command line.
setenv({name}, {val}) *setenv()*
- Set environment variable {name} to {val}.
- When {val} is |v:null| the environment variable is deleted.
+ Set environment variable {name} to {val}. Example: >
+ call setenv('HOME', '/home/myhome')
+
+< When {val} is |v:null| the environment variable is deleted.
See also |expr-env|.
setfperm({fname}, {mode}) *setfperm()* *chmod*
@@ -7746,7 +8330,7 @@ setmatches({list} [, {win}]) *setmatches()*
*setpos()*
setpos({expr}, {list})
- Set the position for {expr}. Possible values:
+ Set the position for String {expr}. Possible values:
. the cursor
'x mark x
@@ -7907,9 +8491,10 @@ setqflist({list} [, {action}[, {what}]]) *setqflist()*
*setreg()*
setreg({regname}, {value} [, {options}])
Set the register {regname} to {value}.
+ The {regname} argument is a string.
- {value} may be any value returned by |getreg()|, including
- a |List|.
+ {value} may be any value returned by |getreg()| or
+ |getreginfo()|, including a |List| or |Dict|.
If {options} contains "a" or {regname} is upper case,
then the value is appended.
@@ -7939,9 +8524,13 @@ setreg({regname}, {value} [, {options}])
:call setreg(v:register, @*)
:call setreg('*', @%, 'ac')
:call setreg('a', "1\n2\n3", 'b5')
+ :call setreg('"', { 'points_to': 'a'})
< This example shows using the functions to save and restore a
register: >
+ :let var_a = getreginfo()
+ :call setreg('a', var_a)
+< or: >
:let var_a = getreg('a', 1, 1)
:let var_amode = getregtype('a')
....
@@ -7958,6 +8547,7 @@ setreg({regname}, {value} [, {options}])
settabvar({tabnr}, {varname}, {val}) *settabvar()*
Set tab-local variable {varname} to {val} in tab page {tabnr}.
|t:var|
+ The {varname} argument is a string.
Note that the variable name without "t:" must be used.
Tabs are numbered starting with one.
This function is not available in the |sandbox|.
@@ -8042,6 +8632,10 @@ shellescape({string} [, {special}]) *shellescape()*
- The <NL> character is escaped (twice if {special} is
a ||non-zero-arg|).
+ If 'shell' contains "fish" in the tail, the "\" character will
+ be escaped because in fish it is used as an escape character
+ inside single quotes.
+
Example of use with a |:!| command: >
:exe '!dir ' . shellescape(expand('<cfile>'), 1)
< This results in a directory listing for the file under the
@@ -8100,6 +8694,8 @@ sin({expr}) *sin()*
:echo sin(-4.01)
< 0.763301
+ Can also be used as a |method|: >
+ Compute()->sin()
sinh({expr}) *sinh()*
Return the hyperbolic sine of {expr} as a |Float| in the range
@@ -8111,7 +8707,10 @@ sinh({expr}) *sinh()*
:echo sinh(-0.9)
< -1.026517
-sockconnect({mode}, {address}, {opts}) *sockconnect()*
+ Can also be used as a |method|: >
+ Compute()->sinh()
+
+sockconnect({mode}, {address} [, {opts}]) *sockconnect()*
Connect a socket to an address. If {mode} is "pipe" then
{address} should be the path of a named pipe. If {mode} is
"tcp" then {address} should be of the form "host:port" where
@@ -8123,7 +8722,7 @@ sockconnect({mode}, {address}, {opts}) *sockconnect()*
|rpcrequest()| and |rpcnotify()| to communicate with a RPC
socket.
- {opts} is a dictionary with these keys:
+ {opts} is an optional dictionary with these keys:
|on_data| : callback invoked when data was read from socket
data_buffered : read socket data in |channel-buffered| mode.
rpc : If set, |msgpack-rpc| will be used to communicate
@@ -8189,18 +8788,23 @@ sort({list} [, {func} [, {dict}]]) *sort()* *E702*
on numbers, text strings will sort next to each other, in the
same order as they were originally.
- Also see |uniq()|.
+ Can also be used as a |method|: >
+ mylist->sort()
+
+< Also see |uniq()|.
Example: >
func MyCompare(i1, i2)
return a:i1 == a:i2 ? 0 : a:i1 > a:i2 ? 1 : -1
endfunc
- let sortedlist = sort(mylist, "MyCompare")
+ eval mylist->sort("MyCompare")
< A shorter compare version for this specific simple case, which
ignores overflow: >
func MyCompare(i1, i2)
return a:i1 - a:i2
endfunc
+< For a simple expression you can use a lambda: >
+ eval mylist->sort({i1, i2 -> i1 - i2})
<
*soundfold()*
soundfold({word})
@@ -8259,8 +8863,8 @@ spellsuggest({word} [, {max} [, {capital}]])
values of 'spelllang' and 'spellsuggest' are used.
-split({expr} [, {pattern} [, {keepempty}]]) *split()*
- Make a |List| out of {expr}. When {pattern} is omitted or
+split({string} [, {pattern} [, {keepempty}]]) *split()*
+ Make a |List| out of {string}. When {pattern} is omitted or
empty each white-separated sequence of characters becomes an
item.
Otherwise the string is split where {pattern} matches,
@@ -8282,6 +8886,8 @@ split({expr} [, {pattern} [, {keepempty}]]) *split()*
:let items = split(line, ':', 1)
< The opposite function is |join()|.
+ Can also be used as a |method|: >
+ GetString()->split()
sqrt({expr}) *sqrt()*
Return the non-negative square root of Float {expr} as a
@@ -8295,6 +8901,8 @@ sqrt({expr}) *sqrt()*
< nan
"nan" may be different, it depends on system libraries.
+ Can also be used as a |method|: >
+ Compute()->sqrt()
stdioopen({opts}) *stdioopen()*
With |--headless| this opens stdin and stdout as a |channel|.
@@ -8333,23 +8941,29 @@ stdpath({what}) *stdpath()* *E6100*
:echo stdpath("config")
-str2float({expr}) *str2float()*
- Convert String {expr} to a Float. This mostly works the same
- as when using a floating point number in an expression, see
- |floating-point-format|. But it's a bit more permissive.
- E.g., "1e40" is accepted, while in an expression you need to
- write "1.0e40". The hexadecimal form "0x123" is also
- accepted, but not others, like binary or octal.
+str2float({string} [, {quoted}]) *str2float()*
+ Convert String {string} to a Float. This mostly works the
+ same as when using a floating point number in an expression,
+ see |floating-point-format|. But it's a bit more permissive.
+ E.g., "1e40" is accepted, while in an expression you need to
+ write "1.0e40". The hexadecimal form "0x123" is also
+ accepted, but not others, like binary or octal.
+ When {quoted} is present and non-zero then embedded single
+ quotes before the dot are ignored, thus "1'000.0" is a
+ thousand.
Text after the number is silently ignored.
The decimal point is always '.', no matter what the locale is
set to. A comma ends the number: "12,345.67" is converted to
12.0. You can strip out thousands separators with
|substitute()|: >
let f = str2float(substitute(text, ',', '', 'g'))
+<
+ Can also be used as a |method|: >
+ let f = text->substitute(',', '', 'g')->str2float()
-str2list({expr} [, {utf8}]) *str2list()*
+str2list({string} [, {utf8}]) *str2list()*
Return a list containing the number values which represent
- each character in String {expr}. Examples: >
+ each character in String {string}. Examples: >
str2list(" ") returns [32]
str2list("ABC") returns [65, 66, 67]
< |list2str()| does the opposite.
@@ -8360,22 +8974,30 @@ str2list({expr} [, {utf8}]) *str2list()*
properly: >
str2list("á") returns [97, 769]
-str2nr({expr} [, {base}]) *str2nr()*
- Convert string {expr} to a number.
+< Can also be used as a |method|: >
+ GetString()->str2list()
+
+str2nr({string} [, {base}]) *str2nr()*
+ Convert string {string} to a number.
{base} is the conversion base, it can be 2, 8, 10 or 16.
+ When {quoted} is present and non-zero then embedded single
+ quotes are ignored, thus "1'000'000" is a million.
+
When {base} is omitted base 10 is used. This also means that
a leading zero doesn't cause octal conversion to be used, as
- with the default String to Number conversion.
+ with the default String to Number conversion. Example: >
+ let nr = str2nr('123')
+<
When {base} is 16 a leading "0x" or "0X" is ignored. With a
- different base the result will be zero. Similarly, when {base}
- is 8 a leading "0" is ignored, and when {base} is 2 a leading
- "0b" or "0B" is ignored.
+ different base the result will be zero. Similarly, when
+ {base} is 8 a leading "0", "0o" or "0O" is ignored, and when
+ {base} is 2 a leading "0b" or "0B" is ignored.
Text after the number is silently ignored.
-strchars({expr} [, {skipcc}]) *strchars()*
+strchars({string} [, {skipcc}]) *strchars()*
The result is a Number, which is the number of characters
- in String {expr}.
+ in String {string}.
When {skipcc} is omitted or zero, composing characters are
counted separately.
When {skipcc} set to 1, Composing characters are ignored.
@@ -8406,16 +9028,16 @@ strcharpart({src}, {start} [, {len}]) *strcharpart()*
strcharpart('abc', -1, 2)
< results in 'a'.
-strdisplaywidth({expr} [, {col}]) *strdisplaywidth()*
+strdisplaywidth({string} [, {col}]) *strdisplaywidth()*
The result is a Number, which is the number of display cells
- String {expr} occupies on the screen when it starts at {col}
+ String {string} occupies on the screen when it starts at {col}
(first column is zero). When {col} is omitted zero is used.
Otherwise it is the screen column where to start. This
matters for Tab characters.
The option settings of the current window are used. This
matters for anything that's displayed differently, such as
'tabstop' and 'display'.
- When {expr} contains characters with East Asian Width Class
+ When {string} contains characters with East Asian Width Class
Ambiguous, this function's return value depends on 'ambiwidth'.
Also see |strlen()|, |strwidth()| and |strchars()|.
@@ -8463,14 +9085,15 @@ stridx({haystack}, {needle} [, {start}]) *stridx()*
*string()*
string({expr}) Return {expr} converted to a String. If {expr} is a Number,
- Float, String or a composition of them, then the result can be
- parsed back with |eval()|.
+ Float, String, Blob or a composition of them, then the result
+ can be parsed back with |eval()|.
{expr} type result ~
String 'string'
Number 123
Float 123.123456 or 1.123456e8 or
`str2float('inf')`
Funcref `function('name')`
+ Blob 0z00112233.44556677.8899
List [item, item]
Dictionary {key: value, key: value}
Note that in String values the ' character is doubled.
@@ -8484,15 +9107,21 @@ string({expr}) Return {expr} converted to a String. If {expr} is a Number,
method, use |msgpackdump()| or |json_encode()| if you need to
share data with other application.
- *strlen()*
-strlen({expr}) The result is a Number, which is the length of the String
- {expr} in bytes.
+ Can also be used as a |method|: >
+ mylist->string()
+
+strlen({string}) *strlen()*
+ The result is a Number, which is the length of the String
+ {string} in bytes.
If the argument is a Number it is first converted to a String.
For other types an error is given.
If you want to count the number of multibyte characters use
|strchars()|.
Also see |len()|, |strdisplaywidth()| and |strwidth()|.
+ Can also be used as a |method|: >
+ GetString()->strlen()
+
strpart({src}, {start} [, {len} [, {chars}]]) *strpart()*
The result is a String, which is part of {src}, starting from
byte {start}, with the byte length {len}.
@@ -8559,22 +9188,28 @@ strridx({haystack}, {needle} [, {start}]) *strridx()*
When used with a single character it works similar to the C
function strrchr().
-strtrans({expr}) *strtrans()*
- The result is a String, which is {expr} with all unprintable
+strtrans({string}) *strtrans()*
+ The result is a String, which is {string} with all unprintable
characters translated into printable characters |'isprint'|.
Like they are shown in a window. Example: >
echo strtrans(@a)
< This displays a newline in register a as "^@" instead of
starting a new line.
-strwidth({expr}) *strwidth()*
+ Can also be used as a |method|: >
+ GetString()->strtrans()
+
+strwidth({string}) *strwidth()*
The result is a Number, which is the number of display cells
- String {expr} occupies. A Tab character is counted as one
+ String {string} occupies. A Tab character is counted as one
cell, alternatively use |strdisplaywidth()|.
- When {expr} contains characters with East Asian Width Class
+ When {string} contains characters with East Asian Width Class
Ambiguous, this function's return value depends on 'ambiwidth'.
Also see |strlen()|, |strdisplaywidth()| and |strchars()|.
+ Can also be used as a |method|: >
+ GetString()->strwidth()
+
submatch({nr} [, {list}]) *submatch()* *E935*
Only for an expression in a |:substitute| command or
substitute() function.
@@ -8601,10 +9236,10 @@ submatch({nr} [, {list}]) *submatch()* *E935*
< This finds the first number in the line and adds one to it.
A line break is included as a newline character.
-substitute({expr}, {pat}, {sub}, {flags}) *substitute()*
- The result is a String, which is a copy of {expr}, in which
+substitute({string}, {pat}, {sub}, {flags}) *substitute()*
+ The result is a String, which is a copy of {string}, in which
the first match of {pat} is replaced with {sub}.
- When {flags} is "g", all matches of {pat} in {expr} are
+ When {flags} is "g", all matches of {pat} in {string} are
replaced. Otherwise {flags} should be "".
This works like the ":substitute" command (without any flags).
@@ -8620,7 +9255,7 @@ substitute({expr}, {pat}, {sub}, {flags}) *substitute()*
|sub-replace-special|. For example, to replace something with
"\n" (two characters), use "\\\\n" or '\\n'.
- When {pat} does not match in {expr}, {expr} is returned
+ When {pat} does not match in {string}, {string} is returned
unmodified.
Example: >
@@ -8642,6 +9277,9 @@ substitute({expr}, {pat}, {sub}, {flags}) *substitute()*
|submatch()| returns. Example: >
:echo substitute(s, '%\(\x\x\)', {m -> '0x' . m[1]}, 'g')
+< Can also be used as a |method|: >
+ GetString()->substitute(pat, sub, flags)
+
swapinfo({fname}) *swapinfo()*
The result is a dictionary, which holds information about the
swapfile {fname}. The available fields are:
@@ -8660,12 +9298,12 @@ swapinfo({fname}) *swapinfo()*
Not a swap file: does not contain correct block ID
Magic number mismatch: Info in first block is invalid
-swapname({expr}) *swapname()*
- The result is the swap file path of the buffer {expr}.
- For the use of {expr}, see |bufname()| above.
- If buffer {expr} is the current buffer, the result is equal to
+swapname({buf}) *swapname()*
+ The result is the swap file path of the buffer {buf}.
+ For the use of {buf}, see |bufname()| above.
+ If buffer {buf} is the current buffer, the result is equal to
|:swapname| (unless there is no swap file).
- If buffer {expr} has no swap file, returns an empty string.
+ If buffer {buf} has no swap file, returns an empty string.
synID({lnum}, {col}, {trans}) *synID()*
The result is a Number, which is the syntax ID at the position
@@ -8677,7 +9315,7 @@ synID({lnum}, {col}, {trans}) *synID()*
line. 'synmaxcol' applies, in a longer line zero is returned.
Note that when the position is after the last character,
that's where the cursor can be in Insert mode, synID() returns
- zero.
+ zero. {lnum} is used like with |getline()|.
When {trans} is |TRUE|, transparent items are reduced to the
item that they reveal. This is useful when wanting to know
@@ -8726,17 +9364,23 @@ synIDattr({synID}, {what} [, {mode}]) *synIDattr()*
cursor): >
:echo synIDattr(synIDtrans(synID(line("."), col("."), 1)), "fg")
<
+ Can also be used as a |method|: >
+ :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
+
synIDtrans({synID}) *synIDtrans()*
The result is a Number, which is the translated syntax ID of
{synID}. This is the syntax group ID of what is being used to
highlight the character. Highlight links given with
":highlight link" are followed.
+ Can also be used as a |method|: >
+ :echo synID(line("."), col("."), 1)->synIDtrans()->synIDattr("fg")
+
synconcealed({lnum}, {col}) *synconcealed()*
The result is a |List| with currently three items:
1. The first item in the list is 0 if the character at the
position {lnum} and {col} is not part of a concealable
- region, 1 if it is.
+ region, 1 if it is. {lnum} is used like with |getline()|.
2. The second item in the list is a string. If the first item
is 1, the second item contains the text which will be
displayed in place of the concealed text, depending on the
@@ -8760,8 +9404,9 @@ synconcealed({lnum}, {col}) *synconcealed()*
synstack({lnum}, {col}) *synstack()*
Return a |List|, which is the stack of syntax items at the
- position {lnum} and {col} in the current window. Each item in
- the List is an ID like what |synID()| returns.
+ position {lnum} and {col} in the current window. {lnum} is
+ used like with |getline()|. Each item in the List is an ID
+ like what |synID()| returns.
The first item in the List is the outer region, following are
items contained in that one. The last one is what |synID()|
returns, unless not the whole item is highlighted or it is a
@@ -8777,11 +9422,23 @@ synstack({lnum}, {col}) *synstack()*
valid positions.
system({cmd} [, {input}]) *system()* *E677*
- Get the output of {cmd} as a |string| (use |systemlist()| to
- get a |List|). {cmd} is treated exactly as in |jobstart()|.
- Not to be used for interactive commands.
+ Gets the output of {cmd} as a |string| (|systemlist()| returns
+ a |List|) and sets |v:shell_error| to the error code.
+ {cmd} is treated as in |jobstart()|:
+ If {cmd} is a List it runs directly (no 'shell').
+ If {cmd} is a String it runs in the 'shell', like this: >
+ :call jobstart(split(&shell) + split(&shellcmdflag) + ['{cmd}'])
+
+< Not to be used for interactive commands.
+
+ Result is a String, filtered to avoid platform-specific quirks:
+ - <CR><NL> is replaced with <NL>
+ - NUL characters are replaced with SOH (0x01)
+
+ Example: >
+ :echo system(['ls', expand('%:h')])
- If {input} is a string it is written to a pipe and passed as
+< If {input} is a string it is written to a pipe and passed as
stdin to the command. The string is written as-is, line
separators are not changed.
If {input} is a |List| it is written to the pipe as
@@ -8794,7 +9451,7 @@ system({cmd} [, {input}]) *system()* *E677*
*E5677*
Note: system() cannot write to or read from backgrounded ("&")
shell commands, e.g.: >
- :echo system("cat - &", "foo"))
+ :echo system("cat - &", "foo")
< which is equivalent to: >
$ echo foo | bash -c 'cat - &'
< The pipes are disconnected (unless overridden by shell
@@ -8803,31 +9460,16 @@ system({cmd} [, {input}]) *system()* *E677*
Note: Use |shellescape()| or |::S| with |expand()| or
|fnamemodify()| to escape special characters in a command
- argument. Newlines in {cmd} may cause the command to fail.
- The characters in 'shellquote' and 'shellxquote' may also
- cause trouble.
+ argument. 'shellquote' and 'shellxquote' must be properly
+ configured. Example: >
+ :echo system('ls '..shellescape(expand('%:h')))
+ :echo system('ls '..expand('%:h:S'))
- Result is a String. Example: >
- :let files = system("ls " . shellescape(expand('%:h')))
- :let files = system('ls ' . expand('%:h:S'))
-
-< To make the result more system-independent, the shell output
- is filtered to replace <CR> with <NL> for Macintosh, and
- <CR><NL> with <NL> for DOS-like systems.
- To avoid the string being truncated at a NUL, all NUL
- characters are replaced with SOH (0x01).
-
- The command executed is constructed using several options when
- {cmd} is a string: 'shell' 'shellcmdflag' {cmd}
-
- The resulting error code can be found in |v:shell_error|.
-
- Note that any wrong value in the options mentioned above may
- make the function fail. It has also been reported to fail
- when using a security agent application.
- Unlike ":!cmd" there is no automatic check for changed files.
+< Unlike ":!cmd" there is no automatic check for changed files.
Use |:checktime| to force a check.
+ Can also be used as a |method|: >
+ :echo GetCmd()->system()
systemlist({cmd} [, {input} [, {keepempty}]]) *systemlist()*
Same as |system()|, but returns a |List| with lines (parts of
@@ -8843,6 +9485,8 @@ systemlist({cmd} [, {input} [, {keepempty}]]) *systemlist()*
<
Returns an empty string on error.
+ Can also be used as a |method|: >
+ :echo GetCmd()->systemlist()
tabpagebuflist([{arg}]) *tabpagebuflist()*
The result is a |List|, where each item is the number of the
@@ -8966,6 +9610,8 @@ tan({expr}) *tan()*
:echo tan(-4.01)
< -1.181502
+ Can also be used as a |method|: >
+ Compute()->tan()
tanh({expr}) *tanh()*
Return the hyperbolic tangent of {expr} as a |Float| in the
@@ -8977,7 +9623,9 @@ tanh({expr}) *tanh()*
:echo tanh(-1)
< -0.761594
-
+ Can also be used as a |method|: >
+ Compute()->tanh()
+<
*timer_info()*
timer_info([{id}])
Return a list with information about timers.
@@ -9103,6 +9751,9 @@ trunc({expr}) *trunc()*
echo trunc(4.0)
< 4.0
+ Can also be used as a |method|: >
+ Compute()->trunc()
+
type({expr}) *type()*
The result is a Number representing the type of {expr}.
Instead of using the number directly, it is better to use the
@@ -9115,6 +9766,7 @@ type({expr}) *type()*
Float: 5 (|v:t_float|)
Boolean: 6 (|v:true| and |v:false|)
Null: 7 (|v:null|)
+ Blob: 10 (|v:t_blob|)
For backward compatibility, this method can be used: >
:if type(myvar) == type(0)
:if type(myvar) == type("")
@@ -9129,6 +9781,9 @@ type({expr}) *type()*
< To check if the v:t_ variables exist use this: >
:if exists('v:t_number')
+< Can also be used as a |method|: >
+ mylist->type()
+
undofile({name}) *undofile()*
Return the name of the undo file that would be used for a file
with name {name} when writing. This uses the 'undodir'
@@ -9139,8 +9794,6 @@ undofile({name}) *undofile()*
If {name} is empty undofile() returns an empty string, since a
buffer without a file name will not write an undo file.
Useful in combination with |:wundo| and |:rundo|.
- When compiled without the |+persistent_undo| option this always
- returns an empty string.
undotree() *undotree()*
Return the current state of the undo tree in a dictionary with
@@ -9193,10 +9846,15 @@ uniq({list} [, {func} [, {dict}]]) *uniq()* *E882*
< The default compare function uses the string representation of
each item. For the use of {func} and {dict} see |sort()|.
+ Can also be used as a |method|: >
+ mylist->uniq()
+
values({dict}) *values()*
Return a |List| with all the values of {dict}. The |List| is
- in arbitrary order.
+ in arbitrary order. Also see |items()| and |keys()|.
+ Can also be used as a |method|: >
+ mydict->values()
virtcol({expr}) *virtcol()*
The result is a Number, which is the screen column of the file
@@ -9305,10 +9963,12 @@ win_gettype([{nr}]) *win_gettype()*
Return the type of the window:
"autocmd" autocommand window. Temporary window
used to execute autocommands.
- "popup" popup window |popup|
- "preview" preview window |preview-window|
"command" command-line window |cmdwin|
(empty) normal window
+ "loclist" |location-list-window|
+ "popup" popup window |popup|
+ "preview" preview window |preview-window|
+ "quickfix" |quickfix-window|
"unknown" window {nr} not found
When {nr} is omitted return the type of the current window.
@@ -9339,7 +9999,7 @@ win_screenpos({nr}) *win_screenpos()*
[1, 1], unless there is a tabline, then it is [2, 1].
{nr} can be the window number or the |window-ID|. Use zero
for the current window.
- Return [0, 0] if the window cannot be found in the current
+ Returns [0, 0] if the window cannot be found in the current
tabpage.
win_splitmove({nr}, {target} [, {options}]) *win_splitmove()*
@@ -9372,6 +10032,9 @@ winbufnr({nr}) The result is a Number, which is the number of the buffer
Example: >
:echo "The file in the current window is " . bufname(winbufnr(0))
<
+ Can also be used as a |method|: >
+ FindWindow()->winbufnr()->bufname()
+<
*wincol()*
wincol() The result is a Number, which is the virtual column of the
cursor in the window. This is counting screen cells from the
@@ -9548,14 +10211,17 @@ wordcount() *wordcount()*
*writefile()*
-writefile({list}, {fname} [, {flags}])
- Write |List| {list} to file {fname}. Each list item is
- separated with a NL. Each list item must be a String or
- Number.
+writefile({object}, {fname} [, {flags}])
+ When {object} is a |List| write it to file {fname}. Each list
+ item is separated with a NL. Each list item must be a String
+ or Number.
When {flags} contains "b" then binary mode is used: There will
not be a NL after the last list item. An empty item at the
end does cause the last line in the file to end in a NL.
+ When {object} is a |Blob| write the bytes to file {fname}
+ unmodified.
+
When {flags} contains "a" then append mode is used, lines are
appended to the file: >
:call writefile(["foo"], "event.log", "a")
@@ -9585,6 +10251,8 @@ xor({expr}, {expr}) *xor()*
to a number. A List, Dict or Float argument causes an error.
Example: >
:let bits = xor(bits, 0x80)
+< Can also be used as a |method|: >
+ :let bits = bits->xor(0x80)
<
@@ -9922,7 +10590,9 @@ This function can then be called with: >
The recursiveness of user functions is restricted with the |'maxfuncdepth'|
option.
-It is also possible to use `:eval`. It does not support a range.
+It is also possible to use `:eval`. It does not support a range, but does
+allow for method chaining, e.g.: >
+ eval GetList()->Filter()->append('$')
AUTOMATICALLY LOADING FUNCTIONS ~
@@ -10067,7 +10737,10 @@ This does NOT work: >
This cannot be used to set a byte in a String. You
can do that like this: >
:let var = var[0:2] . 'X' . var[4:]
-<
+< When {var-name} is a |Blob| then {idx} can be the
+ length of the blob, in which case one byte is
+ appended.
+
*E711* *E719*
:let {var-name}[{idx1}:{idx2}] = {expr1} *E708* *E709* *E710*
Set a sequence of items in a |List| to the result of
@@ -10078,14 +10751,15 @@ This does NOT work: >
When the selected range of items is partly past the
end of the list, items will be added.
- *:let+=* *:let-=* *:letstar=*
- *:let/=* *:let%=* *:let.=* *E734*
+ *:let+=* *:let-=* *:letstar=*
+ *:let/=* *:let%=* *:let.=* *:let..=* *E734*
:let {var} += {expr1} Like ":let {var} = {var} + {expr1}".
:let {var} -= {expr1} Like ":let {var} = {var} - {expr1}".
:let {var} *= {expr1} Like ":let {var} = {var} * {expr1}".
:let {var} /= {expr1} Like ":let {var} = {var} / {expr1}".
:let {var} %= {expr1} Like ":let {var} = {var} % {expr1}".
:let {var} .= {expr1} Like ":let {var} = {var} . {expr1}".
+:let {var} ..= {expr1} Like ":let {var} = {var} .. {expr1}".
These fail if {var} was not set yet and when the type
of {var} and {expr1} don't fit the operator.
@@ -10303,10 +10977,18 @@ text...
:const x = 1
< is equivalent to: >
:let x = 1
- :lockvar 1 x
+ :lockvar! x
< This is useful if you want to make sure the variable
- is not modified.
- *E995*
+ is not modified. If the value is a List or Dictionary
+ literal then the items also cannot be changed: >
+ const ll = [1, 2, 3]
+ let ll[1] = 5 " Error!
+< Nested references are not locked: >
+ let lvar = ['a']
+ const lconst = [0, lvar]
+ let lconst[0] = 2 " Error!
+ let lconst[1][0] = 'b' " OK
+< *E995*
|:const| does not allow to for changing a variable. >
:let x = 1
:const x = 2 " Error!
@@ -10423,28 +11105,34 @@ text...
NOTE: The ":append" and ":insert" commands don't work
properly inside a ":while" and ":for" loop.
-:for {var} in {list} *:for* *E690* *E732*
+:for {var} in {object} *:for* *E690* *E732*
:endfo[r] *:endfo* *:endfor*
Repeat the commands between ":for" and ":endfor" for
- each item in {list}. Variable {var} is set to the
- value of each item.
- When an error is detected for a command inside the
- loop, execution continues after the "endfor".
- Changing {list} inside the loop affects what items are
- used. Make a copy if this is unwanted: >
+ each item in {object}. {object} can be a |List| or
+ a |Blob|. Variable {var} is set to the value of each
+ item. When an error is detected for a command inside
+ the loop, execution continues after the "endfor".
+ Changing {object} inside the loop affects what items
+ are used. Make a copy if this is unwanted: >
:for item in copy(mylist)
-< When not making a copy, Vim stores a reference to the
- next item in the list, before executing the commands
- with the current item. Thus the current item can be
- removed without effect. Removing any later item means
- it will not be found. Thus the following example
- works (an inefficient way to make a list empty): >
+<
+ When {object} is a |List| and not making a copy, Vim
+ stores a reference to the next item in the |List|
+ before executing the commands with the current item.
+ Thus the current item can be removed without effect.
+ Removing any later item means it will not be found.
+ Thus the following example works (an inefficient way
+ to make a |List| empty): >
for item in mylist
call remove(mylist, 0)
endfor
-< Note that reordering the list (e.g., with sort() or
+< Note that reordering the |List| (e.g., with sort() or
reverse()) may have unexpected effects.
+ When {object} is a |Blob|, Vim always makes a copy to
+ iterate over. Unlike with |List|, modifying the
+ |Blob| does not affect the iteration.
+
:for [{var1}, {var2}, ...] in {listlist}
:endfo[r]
Like ":for" above, but each item in {listlist} must be
@@ -10665,7 +11353,7 @@ text...
<
*:eval*
:eval {expr} Evaluate {expr} and discard the result. Example: >
- :eval append(Filter(Getlist()), '$')
+ :eval Getlist()->Filter()->append('$')
< The expression is supposed to have a side effect,
since the resulting value is not used. In the example
@@ -11704,7 +12392,7 @@ displayed.
*except-several-errors*
When several errors appear in a single command, the first error message is
-usually the most specific one and therefor converted to the error exception.
+usually the most specific one and therefore converted to the error exception.
Example: >
echo novar
causes >
@@ -11886,7 +12574,7 @@ Command-line expressions highlighting *expr-highlight*
Expressions entered by the user in |i_CTRL-R_=|, |c_CTRL-\_e|, |quote=| are
highlighted by the built-in expressions parser. It uses highlight groups
-described in the table below, which may be overriden by colorschemes.
+described in the table below, which may be overridden by colorschemes.
*hl-NvimInvalid*
Besides the "Nvim"-prefixed highlight groups described below, there are
"NvimInvalid"-prefixed highlight groups which have the same meaning but
diff --git a/runtime/doc/filetype.txt b/runtime/doc/filetype.txt
index 36ed6bbac1..a23ae3fb76 100644
--- a/runtime/doc/filetype.txt
+++ b/runtime/doc/filetype.txt
@@ -135,6 +135,7 @@ can be used to overrule the filetype used for certain extensions:
*.inc g:filetype_inc
*.w g:filetype_w |ft-cweb-syntax|
*.i g:filetype_i |ft-progress-syntax|
+ *.m g:filetype_m |ft-mathematica-syntax|
*.p g:filetype_p |ft-pascal-syntax|
*.pp g:filetype_pp |ft-pascal-syntax|
*.sh g:bash_is_sh |ft-sh-syntax|
@@ -500,6 +501,14 @@ One command, :DiffGitCached, is provided to show a diff of the current commit
in the preview window. It is equivalent to calling "git diff --cached" plus
any arguments given to the command.
+GPROF
+
+The gprof filetype plugin defines a mapping <C-]> to jump from a function
+entry in the gprof flat profile or from a function entry in the call graph
+to the details of that function in the call graph.
+
+The mapping can be disabled with: >
+ let g:no_gprof_maps = 1
MAIL *ft-mail-plugin*
@@ -580,7 +589,7 @@ To disable bold highlighting: >
MARKDOWN *ft-markdown-plugin*
To enable folding use this: >
- let g:markdown_folding = 1
+ let g:markdown_folding = 1
<
PDF *ft-pdf-plugin*
diff --git a/runtime/doc/fold.txt b/runtime/doc/fold.txt
index 8e2cb2f728..80c934d13b 100644
--- a/runtime/doc/fold.txt
+++ b/runtime/doc/fold.txt
@@ -535,6 +535,8 @@ nest, the nested fold is one character right of the fold it's contained in.
A closed fold is indicated with a '+'.
+These characters can be changed with the 'fillchars' option.
+
Where the fold column is too narrow to display all nested folds, digits are
shown to indicate the nesting level.
diff --git a/runtime/doc/ft_ps1.txt b/runtime/doc/ft_ps1.txt
index df1480b929..3eb89a4c24 100644
--- a/runtime/doc/ft_ps1.txt
+++ b/runtime/doc/ft_ps1.txt
@@ -1,4 +1,4 @@
-*ps1.txt* A Windows PowerShell syntax plugin for Vim
+*ft_ps1.txt* A Windows PowerShell syntax plugin for Vim
Author: Peter Provost <https://www.github.com/PProvost>
License: Apache 2.0
diff --git a/runtime/doc/ft_raku.txt b/runtime/doc/ft_raku.txt
index 26ada8a140..00b140ee9c 100644
--- a/runtime/doc/ft_raku.txt
+++ b/runtime/doc/ft_raku.txt
@@ -1,4 +1,4 @@
-*vim-raku.txt* The Raku programming language filetype
+*ft_raku.txt* The Raku programming language filetype
*vim-raku*
@@ -45,7 +45,7 @@ Numbers, subscripts and superscripts are available with 's' and 'S':
1s ₁ 1S ¹ ~
2s ₂ 9S ⁹ ~
-But some don´t come defined by default. Those are digraph definitions you can
+But some don't come defined by default. Those are digraph definitions you can
add in your ~/.vimrc file. >
exec 'digraph \\ '.char2nr('∖')
exec 'digraph \< '.char2nr('≼')
diff --git a/runtime/doc/ft_sql.txt b/runtime/doc/ft_sql.txt
index f38c8edbf3..53a99a9e1d 100644
--- a/runtime/doc/ft_sql.txt
+++ b/runtime/doc/ft_sql.txt
@@ -436,7 +436,7 @@ the space bar):
replace the column list with the list of tables.
- This allows you to quickly drill down into a
table to view its columns and back again.
- - <Right> and <Left> can be also be chosen via
+ - <Right> and <Left> can also be chosen via
your |init.vim| >
let g:ftplugin_sql_omni_key_right = '<Right>'
let g:ftplugin_sql_omni_key_left = '<Left>'
diff --git a/runtime/doc/gui.txt b/runtime/doc/gui.txt
index 0f1fa2b7a7..812259741f 100644
--- a/runtime/doc/gui.txt
+++ b/runtime/doc/gui.txt
@@ -175,7 +175,6 @@ system. To do this, put these commands in your vimrc file: >
:map <F4> :emenu <C-Z>
Pressing <F4> will start the menu. You can now use the cursor keys to select
a menu entry. Hit <Enter> to execute it. Hit <Esc> if you want to cancel.
-This does require the |+menu| feature enabled at compile time.
Creating New Menus *creating-menus*
@@ -473,9 +472,8 @@ Executing Menus *execute-menus*
insert-mode menu Eg: >
:emenu File.Exit
-If the console-mode vim has been compiled with WANT_MENU defined, you can
-use :emenu to access useful menu items you may have got used to from GUI
-mode. See 'wildmenu' for an option that works well with this. See
+You can use :emenu to access useful menu items you may have got used to from
+GUI mode. See 'wildmenu' for an option that works well with this. See
|console-menus| for an example.
When using a range, if the lines match with '<,'>, then the menu is executed
diff --git a/runtime/doc/help.txt b/runtime/doc/help.txt
index 8b096ff28b..6416f49061 100644
--- a/runtime/doc/help.txt
+++ b/runtime/doc/help.txt
@@ -125,11 +125,12 @@ Advanced editing ~
|windows.txt| commands for using multiple windows and buffers
|tabpage.txt| commands for using multiple tab pages
|spell.txt| spell checking
-|diff.txt| working with two to four versions of the same file
+|diff.txt| working with two to eight versions of the same file
|autocmd.txt| automatically executing commands on an event
|eval.txt| expression evaluation, conditional commands
|fold.txt| hide (fold) ranges of lines
|lua.txt| Lua API
+|api.txt| Nvim API via RPC, Lua and VimL
Special issues ~
|testing.txt| testing Vim and Vim scripts
@@ -137,14 +138,17 @@ Special issues ~
|remote.txt| using Vim as a server or client
Programming language support ~
-|indent.txt| automatic indenting for C and other languages
-|lsp.txt| Language Server Protocol (LSP)
-|syntax.txt| syntax highlighting
-|filetype.txt| settings done specifically for a type of file
-|quickfix.txt| commands for a quick edit-compile-fix cycle
-|ft_ada.txt| Ada (the programming language) support
-|ft_rust.txt| Filetype plugin for Rust
-|ft_sql.txt| about the SQL filetype plugin
+|indent.txt| automatic indenting for C and other languages
+|lsp.txt| Language Server Protocol (LSP)
+|treesitter.txt| tree-sitter library for incremental parsing of buffers
+|syntax.txt| syntax highlighting
+|filetype.txt| settings done specifically for a type of file
+|quickfix.txt| commands for a quick edit-compile-fix cycle
+|ft_ada.txt| Ada (the programming language) support
+|ft_ps1.txt| Filetype plugin for Windows PowerShell
+|ft_raku.txt| Filetype plugin for Raku
+|ft_rust.txt| Filetype plugin for Rust
+|ft_sql.txt| about the SQL filetype plugin
Language support ~
|digraph.txt| list of available digraphs
diff --git a/runtime/doc/helphelp.txt b/runtime/doc/helphelp.txt
index 7643d84017..4a94701b2e 100644
--- a/runtime/doc/helphelp.txt
+++ b/runtime/doc/helphelp.txt
@@ -249,7 +249,6 @@ command: >
It is possible to add translated help files, next to the original English help
files. Vim will search for all help in "doc" directories in 'runtimepath'.
-This is only available when compiled with the |+multi_lang| feature.
At this moment translations are available for:
Chinese - multiple authors
diff --git a/runtime/doc/if_perl.txt b/runtime/doc/if_perl.txt
index ddcf220844..3787ca69ba 100644
--- a/runtime/doc/if_perl.txt
+++ b/runtime/doc/if_perl.txt
@@ -189,6 +189,9 @@ VIM::Eval({expr}) Evaluates {expr} and returns (success, value) in list
A |List| is turned into a string by joining the items
and inserting line breaks.
+ *perl-Blob*
+VIM::Blob({expr}) Return Blob literal string 0zXXXX from scalar value.
+
==============================================================================
3. VIM::Buffer objects *perl-buffer*
diff --git a/runtime/doc/if_ruby.txt b/runtime/doc/if_ruby.txt
index 02edd50ae8..47305c65fb 100644
--- a/runtime/doc/if_ruby.txt
+++ b/runtime/doc/if_ruby.txt
@@ -32,10 +32,6 @@ downloading Ruby there.
This form of the |:ruby| command is mainly useful for
including ruby code in vim scripts.
- Note: This command doesn't work when the Ruby feature
- wasn't compiled in. To avoid errors, see
- |script-here|.
-
Example Vim script: >
function! RedGem()
diff --git a/runtime/doc/index.txt b/runtime/doc/index.txt
index 2aafc075a6..baa7bc1992 100644
--- a/runtime/doc/index.txt
+++ b/runtime/doc/index.txt
@@ -155,6 +155,7 @@ commands in CTRL-X submode *i_CTRL-X_index*
|i_CTRL-X_CTRL-Y| CTRL-X CTRL-Y scroll down
|i_CTRL-X_CTRL-U| CTRL-X CTRL-U complete with 'completefunc'
|i_CTRL-X_CTRL-V| CTRL-X CTRL-V complete like in : command line
+|i_CTRL-X_CTRL-Z| CTRL-X CTRL-Z stop completion, keeping the text as-is
|i_CTRL-X_CTRL-]| CTRL-X CTRL-] complete tags
|i_CTRL-X_s| CTRL-X s spelling suggestions
@@ -699,8 +700,7 @@ tag char note action in Normal mode ~
tag char note action in Normal mode ~
------------------------------------------------------------------------------
-|g_CTRL-A| g CTRL-A only when compiled with MEM_PROFILE
- defined: dump a memory profile
+|g_CTRL-A| g CTRL-A dump a memory profile
|g_CTRL-G| g CTRL-G show information about current cursor
position
|g_CTRL-H| g CTRL-H start Select block mode
@@ -1097,8 +1097,9 @@ tag command action in Command-line editing mode ~
==============================================================================
5. Terminal mode *terminal-mode-index*
-In a |terminal| buffer all keys except |CTRL-\_CTRL-N| are forwarded to the
-terminal job. Use CTRL-\_CTRL-N to go to Normal mode.
+In a |terminal| buffer all keys except CTRL-\ are forwarded to the terminal
+job. If CTRL-\ is pressed, the next key is forwarded unless it is CTRL-N.
+Use |CTRL-\_CTRL-N| to go to Normal mode.
You found it, Arthur! *holy-grail*
@@ -1609,7 +1610,7 @@ tag command action ~
|:tab| :tab create new tab when opening new window
|:tag| :ta[g] jump to tag
|:tags| :tags show the contents of the tag stack
-|:tcd| :tcd change directory for tab page
+|:tcd| :tc[d] change directory for tab page
|:tchdir| :tch[dir] change directory for tab page
|:terminal| :te[rminal] open a terminal buffer
|:tfirst| :tf[irst] jump to first matching tag
diff --git a/runtime/doc/insert.txt b/runtime/doc/insert.txt
index c8a4168ab2..bfc1c235ea 100644
--- a/runtime/doc/insert.txt
+++ b/runtime/doc/insert.txt
@@ -68,12 +68,18 @@ CTRL-A Insert previously inserted text.
CTRL-W Delete the word before the cursor (see |i_backspacing| about
joining lines). See the section "word motions",
|word-motions|, for the definition of a word.
+ *i_CTRL-W-default*
+ By default, sets a new undo point before deleting.
+ |default-mappings|
*i_CTRL-U*
CTRL-U Delete all entered characters before the cursor in the current
line. If there are no newly entered characters and
'backspace' is not empty, delete all characters before the
cursor in the current line.
See |i_backspacing| about joining lines.
+ *i_CTRL-U-default*
+ By default, sets a new undo point before deleting.
+ |default-mappings|
*i_CTRL-I* *i_<Tab>* *i_Tab*
<Tab> or CTRL-I Insert a tab. If the 'expandtab' option is on, the
equivalent number of spaces is inserted (use CTRL-V <Tab> to
@@ -616,6 +622,8 @@ Completion can be done for:
12. Spelling suggestions |i_CTRL-X_s|
13. keywords in 'complete' |i_CTRL-N| |i_CTRL-P|
+Additionally, |i_CTRL-X_CTRL-Z| stops completion without changing the text.
+
All these, except CTRL-N and CTRL-P, are done in CTRL-X mode. This is a
sub-mode of Insert and Replace modes. You enter CTRL-X mode by typing CTRL-X
and one of the CTRL-X commands. You exit CTRL-X mode by typing a key that is
@@ -1016,6 +1024,12 @@ CTRL-P Find previous match for words that start with the
other contexts unless a double CTRL-X is used.
+Stop completion *compl-stop*
+
+ *i_CTRL-X_CTRL-Z*
+CTRL-X CTRL-Z Stop completion without changing the text.
+
+
FUNCTIONS FOR FINDING COMPLETIONS *complete-functions*
This applies to 'completefunc' and 'omnifunc'.
@@ -1047,7 +1061,8 @@ On the second invocation the arguments are:
The function must return a List with the matching words. These matches
usually include the "a:base" text. When there are no matches return an empty
-List.
+List. Note that the cursor may have moved since the first invocation, the
+text may have been changed.
In order to return more information than the matching words, return a Dict
that contains the List. The Dict can have these items:
@@ -1118,7 +1133,7 @@ match to the total list. These matches should then not appear in the returned
list! Call |complete_check()| now and then to allow the user to press a key
while still searching for matches. Stop searching when it returns non-zero.
- *E839* *E840*
+ *E840*
The function is allowed to move the cursor, it is restored afterwards.
The function is not allowed to move to another window or delete text.
diff --git a/runtime/doc/intro.txt b/runtime/doc/intro.txt
index f739e2e88b..2baf3a247f 100644
--- a/runtime/doc/intro.txt
+++ b/runtime/doc/intro.txt
@@ -454,9 +454,10 @@ Ex mode Like Command-line mode, but after entering a command
command line. |Ex-mode|
*Terminal-mode*
-Terminal mode In Terminal mode all input (except |c_CTRL-\_CTRL-N|)
- is sent to the process running in the current
- |terminal| buffer.
+Terminal mode In Terminal mode all input (except CTRL-\) is sent to
+ the process running in the current |terminal| buffer.
+ If CTRL-\ is pressed, the next key is sent unless it
+ is CTRL-N (|CTRL-\_CTRL-N|).
If the 'showmode' option is on "-- TERMINAL --" is shown
at the bottom of the window.
diff --git a/runtime/doc/job_control.txt b/runtime/doc/job_control.txt
index bf01e8e266..6a9d865c40 100644
--- a/runtime/doc/job_control.txt
+++ b/runtime/doc/job_control.txt
@@ -19,7 +19,7 @@ Job Id *job-id*
Each job is identified by an integer id, unique for the life of the current
Nvim session. Each job-id is a valid |channel-id|: they share the same "key
space". Functions like |jobstart()| return job ids; functions like
-|jobsend()|, |jobstop()|, |rpcnotify()|, and |rpcrequest()| take job ids.
+|jobstop()|, |chansend()|, |rpcnotify()|, and |rpcrequest()| take job ids.
Job stdio streams form a |channel| which can send and receive raw bytes or
|msgpack-rpc| messages.
@@ -28,7 +28,7 @@ Job stdio streams form a |channel| which can send and receive raw bytes or
Usage *job-control-usage*
To control jobs, use the "job…" family of functions: |jobstart()|,
-|jobsend()|, |jobstop()|.
+|jobstop()|, etc.
Example: >
diff --git a/runtime/doc/lsp.txt b/runtime/doc/lsp.txt
index d6ef761bcb..5b2a8d68b4 100644
--- a/runtime/doc/lsp.txt
+++ b/runtime/doc/lsp.txt
@@ -202,23 +202,33 @@ responses and notifications from LSP servers.
For |lsp-request|, each |lsp-handler| has this signature: >
- function(err, method, result, client_id, bufnr, config)
+ function(err, result, ctx, config)
<
Parameters: ~
{err} (table|nil)
When the language server is unable to complete a
request, a table with information about the error
is sent. Otherwise, it is `nil`. See |lsp-response|.
- {method} (string)
- The |lsp-method| name.
{result} (Result | Params | nil)
When the language server is able to succesfully
complete a request, this contains the `result` key
of the response. See |lsp-response|.
- {client_id} (number)
- The ID of the |vim.lsp.client|.
- {bufnr} (Buffer)
- Buffer handle, or 0 for current.
+ {ctx} (table)
+ Context describes additional calling state
+ associated with the handler. It consists of the
+ following key, value pairs:
+
+ {method} (string)
+ The |lsp-method| name.
+ {client_id} (number)
+ The ID of the |vim.lsp.client|.
+ {bufnr} (Buffer)
+ Buffer handle, or 0 for current.
+
+ {params} (table|nil)
+ The parameters used in the original request
+ which resulted in this handler
+ call.
{config} (table)
Configuration for the handler.
@@ -229,6 +239,7 @@ For |lsp-request|, each |lsp-handler| has this signature: >
To configure a particular |lsp-handler|, see:
|lsp-handler-configuration|
+
Returns: ~
The |lsp-handler| can respond by returning two values: `result, err`
Where `err` must be shaped like an RPC error:
@@ -238,21 +249,24 @@ For |lsp-request|, each |lsp-handler| has this signature: >
For |lsp-notification|, each |lsp-handler| has this signature: >
- function(err, method, params, client_id, bufnr, config)
+ function(err, result, ctx, config)
<
Parameters: ~
{err} (nil)
This is always `nil`.
See |lsp-notification|
- {method} (string)
- The |lsp-method| name.
- {params} (Params)
+ {result} (Result)
This contains the `params` key of the notification.
See |lsp-notification|
- {client_id} (number)
- The ID of the |vim.lsp.client|
- {bufnr} (nil)
- `nil`, as the server doesn't have an associated buffer.
+ {ctx} (table)
+ Context describes additional calling state
+ associated with the handler. It consists of the
+ following key, value pairs:
+
+ {method} (string)
+ The |lsp-method| name.
+ {client_id} (number)
+ The ID of the |vim.lsp.client|.
{config} (table)
Configuration for the handler.
@@ -322,6 +336,18 @@ To configure the behavior of a builtin |lsp-handler|, the convenient method
}
}
<
+ Some handlers do not have an explicitly named handler function (such as
+ |on_publish_diagnostics()|). To override these, first create a reference
+ to the existing handler: >
+
+ local on_references = vim.lsp.handlers["textDocument/references"]
+ vim.lsp.handlers["textDocument/references"] = vim.lsp.with(
+ on_references, {
+ -- Use location list instead of quickfix list
+ loclist = true,
+ }
+ )
+<
*lsp-handler-resolution*
Handlers can be set by:
@@ -404,121 +430,6 @@ LspReferenceRead used for highlighting "read" references
LspReferenceWrite used for highlighting "write" references
- *lsp-highlight-diagnostics*
-All highlights defined for diagnostics begin with `LspDiagnostics` followed by
-the type of highlight (e.g., `Sign`, `Underline`, etc.) and then the Severity
-of the highlight (e.g. `Error`, `Warning`, etc.)
-
-Sign, underline and virtual text highlights (by default) are linked to their
-corresponding LspDiagnosticsDefault highlight.
-
-For example, the default highlighting for |hl-LspDiagnosticsSignError| is
-linked to |hl-LspDiagnosticsDefaultError|. To change the default (and
-therefore the linked highlights), use the |:highlight| command: >
-
- highlight LspDiagnosticsDefaultError guifg="BrightRed"
-<
-
- *hl-LspDiagnosticsDefaultError*
-LspDiagnosticsDefaultError
- Used as the base highlight group.
- Other LspDiagnostic highlights link to this by default (except Underline)
-
- *hl-LspDiagnosticsDefaultWarning*
-LspDiagnosticsDefaultWarning
- Used as the base highlight group.
- Other LspDiagnostic highlights link to this by default (except Underline)
-
- *hl-LspDiagnosticsDefaultInformation*
-LspDiagnosticsDefaultInformation
- Used as the base highlight group.
- Other LspDiagnostic highlights link to this by default (except Underline)
-
- *hl-LspDiagnosticsDefaultHint*
-LspDiagnosticsDefaultHint
- Used as the base highlight group.
- Other LspDiagnostic highlights link to this by default (except Underline)
-
- *hl-LspDiagnosticsVirtualTextError*
-LspDiagnosticsVirtualTextError
- Used for "Error" diagnostic virtual text.
- See |vim.lsp.diagnostic.set_virtual_text()|
-
- *hl-LspDiagnosticsVirtualTextWarning*
-LspDiagnosticsVirtualTextWarning
- Used for "Warning" diagnostic virtual text.
- See |vim.lsp.diagnostic.set_virtual_text()|
-
- *hl-LspDiagnosticsVirtualTextInformation*
-LspDiagnosticsVirtualTextInformation
- Used for "Information" diagnostic virtual text.
- See |vim.lsp.diagnostic.set_virtual_text()|
-
- *hl-LspDiagnosticsVirtualTextHint*
-LspDiagnosticsVirtualTextHint
- Used for "Hint" diagnostic virtual text.
- See |vim.lsp.diagnostic.set_virtual_text()|
-
- *hl-LspDiagnosticsUnderlineError*
-LspDiagnosticsUnderlineError
- Used to underline "Error" diagnostics.
- See |vim.lsp.diagnostic.set_underline()|
-
- *hl-LspDiagnosticsUnderlineWarning*
-LspDiagnosticsUnderlineWarning
- Used to underline "Warning" diagnostics.
- See |vim.lsp.diagnostic.set_underline()|
-
- *hl-LspDiagnosticsUnderlineInformation*
-LspDiagnosticsUnderlineInformation
- Used to underline "Information" diagnostics.
- See |vim.lsp.diagnostic.set_underline()|
-
- *hl-LspDiagnosticsUnderlineHint*
-LspDiagnosticsUnderlineHint
- Used to underline "Hint" diagnostics.
- See |vim.lsp.diagnostic.set_underline()|
-
- *hl-LspDiagnosticsFloatingError*
-LspDiagnosticsFloatingError
- Used to color "Error" diagnostic messages in diagnostics float.
- See |vim.lsp.diagnostic.show_line_diagnostics()|
-
- *hl-LspDiagnosticsFloatingWarning*
-LspDiagnosticsFloatingWarning
- Used to color "Warning" diagnostic messages in diagnostics float.
- See |vim.lsp.diagnostic.show_line_diagnostics()|
-
- *hl-LspDiagnosticsFloatingInformation*
-LspDiagnosticsFloatingInformation
- Used to color "Information" diagnostic messages in diagnostics float.
- See |vim.lsp.diagnostic.show_line_diagnostics()|
-
- *hl-LspDiagnosticsFloatingHint*
-LspDiagnosticsFloatingHint
- Used to color "Hint" diagnostic messages in diagnostics float.
- See |vim.lsp.diagnostic.show_line_diagnostics()|
-
- *hl-LspDiagnosticsSignError*
-LspDiagnosticsSignError
- Used for "Error" signs in sign column.
- See |vim.lsp.diagnostic.set_signs()|
-
- *hl-LspDiagnosticsSignWarning*
-LspDiagnosticsSignWarning
- Used for "Warning" signs in sign column.
- See |vim.lsp.diagnostic.set_signs()|
-
- *hl-LspDiagnosticsSignInformation*
-LspDiagnosticsSignInformation
- Used for "Information" signs in sign column.
- See |vim.lsp.diagnostic.set_signs()|
-
- *hl-LspDiagnosticsSignHint*
-LspDiagnosticsSignHint
- Used for "Hint" signs in sign column.
- See |vim.lsp.diagnostic.set_signs()|
-
*lsp-highlight-codelens*
Highlight groups related to |lsp-codelens| functionality.
@@ -526,14 +437,19 @@ Highlight groups related to |lsp-codelens| functionality.
*hl-LspCodeLens*
LspCodeLens
Used to color the virtual text of the codelens. See
- |nvim_buf_set_virtual_text()|.
+ |nvim_buf_set_extmark()|.
-==============================================================================
-AUTOCOMMANDS *lsp-autocommands*
+LspCodeLensSeparator *hl-LspCodeLensSeparator*
+ Used to color the seperator between two or more code lens.
- *LspDiagnosticsChanged*
-LspDiagnosticsChanged After receiving publishDiagnostics server response
+ *lsp-highlight-signature*
+Highlight groups related to |vim.lsp.handlers.signature_help()|.
+
+ *hl-LspSignatureActiveParameter*
+LspSignatureActiveParameter
+ Used to highlight the active parameter in the signature help. See
+ |vim.lsp.handlers.signature_help()|.
==============================================================================
Lua module: vim.lsp *lsp-core*
@@ -742,15 +658,6 @@ get_log_path() *vim.lsp.get_log_path()*
Return: ~
(String) Path to logfile.
-init({client}, {bufnr}) *vim.lsp.init()*
- client_id → state
-
- state pending_change?: function that the timer starts to
- trigger didChange pending_changes: list of tables with the
- pending changesets; for incremental_sync only
- use_incremental_sync: bool buffers?: table (bufnr → lines);
- for incremental sync only timer?: uv_timer
-
omnifunc({findstart}, {base}) *vim.lsp.omnifunc()*
Implements 'omnifunc' compatible LSP completion.
@@ -804,109 +711,117 @@ start_client({config}) *vim.lsp.start_client()*
table.
Parameters: ~
- {root_dir} (required, string) Directory where the
- LSP server will base its rootUri on
- initialization.
- {cmd} (required, string or list treated like
- |jobstart()|) Base command that
- initiates the LSP client.
- {cmd_cwd} (string, default=|getcwd()|) Directory
- to launch the `cmd` process. Not
- related to `root_dir` .
- {cmd_env} (table) Environment flags to pass to
- the LSP on spawn. Can be specified
- using keys like a map or as a list with `k=v` pairs or both. Non-string values are
- coerced to string. Example: >
+ {root_dir} (string) Directory where the LSP
+ server will base its rootUri on
+ initialization.
+ {cmd} (required, string or list treated
+ like |jobstart()|) Base command that
+ initiates the LSP client.
+ {cmd_cwd} (string, default=|getcwd()|)
+ Directory to launch the `cmd`
+ process. Not related to `root_dir` .
+ {cmd_env} (table) Environment flags to pass to
+ the LSP on spawn. Can be specified
+ using keys like a map or as a list
+ with `k=v` pairs or both. Non-string values are
+ coerced to string. Example: >
{ "PRODUCTION=true"; "TEST=123"; PORT = 8080; HOST = "0.0.0.0"; }
<
- {capabilities} Map overriding the default capabilities
- defined by
- |vim.lsp.protocol.make_client_capabilities()|,
- passed to the language server on
- initialization. Hint: use
- make_client_capabilities() and modify
- its result.
- • Note: To send an empty dictionary use
- `{[vim.type_idx]=vim.types.dictionary}`
- , else it will be encoded as an
- array.
- {handlers} Map of language server method names to
- |lsp-handler|
- {settings} Map with language server specific
- settings. These are returned to the
- language server if requested via
- `workspace/configuration` . Keys are
- case-sensitive.
- {init_options} Values to pass in the initialization
- request as `initializationOptions` .
- See `initialize` in the LSP spec.
- {name} (string, default=client-id) Name in log
- messages.
- {get_language_id} function(bufnr, filetype) -> language
- ID as string. Defaults to the filetype.
- {offset_encoding} (default="utf-16") One of "utf-8",
- "utf-16", or "utf-32" which is the
- encoding that the LSP server expects.
- Client does not verify this is correct.
- {on_error} Callback with parameters (code, ...),
- invoked when the client operation
- throws an error. `code` is a number
- describing the error. Other arguments
- may be passed depending on the error
- kind. See |vim.lsp.client_errors| for
- possible errors. Use
- `vim.lsp.client_errors[code]` to get
- human-friendly name.
- {before_init} Callback with parameters
- (initialize_params, config) invoked
- before the LSP "initialize" phase,
- where `params` contains the parameters
- being sent to the server and `config`
- is the config that was passed to
- |vim.lsp.start_client()|. You can use
- this to modify parameters before they
- are sent.
- {on_init} Callback (client, initialize_result)
- invoked after LSP "initialize", where
- `result` is a table of `capabilities`
- and anything else the server may send.
- For example, clangd sends
- `initialize_result.offsetEncoding` if
- `capabilities.offsetEncoding` was sent
- to it. You can only modify the
- `client.offset_encoding` here before
- any notifications are sent. Most
- language servers expect to be sent
- client specified settings after
- initialization. Neovim does not make
- this assumption. A
- `workspace/didChangeConfiguration`
- notification should be sent to the
- server during on_init.
- {on_exit} Callback (code, signal, client_id)
- invoked on client exit.
- • code: exit code of the process
- • signal: number describing the signal
- used to terminate (if any)
- • client_id: client handle
- {on_attach} Callback (client, bufnr) invoked when
- client attaches to a buffer.
- {trace} "off" | "messages" | "verbose" | nil
- passed directly to the language server
- in the initialize request.
- Invalid/empty values will default to
- "off"
- {flags} A table with flags for the client. The
- current (experimental) flags are:
- • allow_incremental_sync (bool, default
- true): Allow using incremental sync
- for buffer edits
- • debounce_text_changes (number,
- default nil): Debounce didChange
- notifications to the server by the
- given number in milliseconds. No
- debounce occurs if nil
+ {capabilities} Map overriding the default
+ capabilities defined by
+ |vim.lsp.protocol.make_client_capabilities()|,
+ passed to the language server on
+ initialization. Hint: use
+ make_client_capabilities() and modify
+ its result.
+ • Note: To send an empty dictionary
+ use
+ `{[vim.type_idx]=vim.types.dictionary}`
+ , else it will be encoded as an
+ array.
+ {handlers} Map of language server method names
+ to |lsp-handler|
+ {settings} Map with language server specific
+ settings. These are returned to the
+ language server if requested via
+ `workspace/configuration` . Keys are
+ case-sensitive.
+ {init_options} Values to pass in the initialization
+ request as `initializationOptions` .
+ See `initialize` in the LSP spec.
+ {name} (string, default=client-id) Name in
+ log messages.
+ {workspace_folders} (table) List of workspace folders
+ passed to the language server.
+ Defaults to root_dir if not set. See
+ `workspaceFolders` in the LSP spec
+ {get_language_id} function(bufnr, filetype) -> language
+ ID as string. Defaults to the
+ filetype.
+ {offset_encoding} (default="utf-16") One of "utf-8",
+ "utf-16", or "utf-32" which is the
+ encoding that the LSP server expects.
+ Client does not verify this is
+ correct.
+ {on_error} Callback with parameters (code, ...),
+ invoked when the client operation
+ throws an error. `code` is a number
+ describing the error. Other arguments
+ may be passed depending on the error
+ kind. See |vim.lsp.client_errors| for
+ possible errors. Use
+ `vim.lsp.client_errors[code]` to get
+ human-friendly name.
+ {before_init} Callback with parameters
+ (initialize_params, config) invoked
+ before the LSP "initialize" phase,
+ where `params` contains the
+ parameters being sent to the server
+ and `config` is the config that was
+ passed to |vim.lsp.start_client()|.
+ You can use this to modify parameters
+ before they are sent.
+ {on_init} Callback (client, initialize_result)
+ invoked after LSP "initialize", where
+ `result` is a table of `capabilities`
+ and anything else the server may
+ send. For example, clangd sends
+ `initialize_result.offsetEncoding` if
+ `capabilities.offsetEncoding` was
+ sent to it. You can only modify the
+ `client.offset_encoding` here before
+ any notifications are sent. Most
+ language servers expect to be sent
+ client specified settings after
+ initialization. Neovim does not make
+ this assumption. A
+ `workspace/didChangeConfiguration`
+ notification should be sent to the
+ server during on_init.
+ {on_exit} Callback (code, signal, client_id)
+ invoked on client exit.
+ • code: exit code of the process
+ • signal: number describing the
+ signal used to terminate (if any)
+ • client_id: client handle
+ {on_attach} Callback (client, bufnr) invoked when
+ client attaches to a buffer.
+ {trace} "off" | "messages" | "verbose" | nil
+ passed directly to the language
+ server in the initialize request.
+ Invalid/empty values will default to
+ "off"
+ {flags} A table with flags for the client.
+ The current (experimental) flags are:
+ • allow_incremental_sync (bool,
+ default true): Allow using
+ incremental sync for buffer edits
+ • debounce_text_changes (number,
+ default nil): Debounce didChange
+ notifications to the server by the
+ given number in milliseconds. No
+ debounce occurs if nil
Return: ~
Client id. |vim.lsp.get_client_by_id()| Note: client may
@@ -954,12 +869,17 @@ clear_references() *vim.lsp.buf.clear_references()*
Removes document highlights from current buffer.
code_action({context}) *vim.lsp.buf.code_action()*
- Selects a code action from the input list that is available at
- the current cursor position.
+ Selects a code action available at the current cursor
+ position.
Parameters: ~
- {context} (table, optional) Valid `CodeActionContext`
- object
+ {context} table|nil `CodeActionContext` of the LSP specification:
+ • diagnostics: (table|nil) LSP`Diagnostic[]` . Inferred from the current position if not
+ provided.
+ • only: (string|nil) LSP `CodeActionKind` used
+ to filter the code actions. Most language
+ servers support values like `refactor` or
+ `quickfix` .
See also: ~
https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_codeAction
@@ -1100,8 +1020,13 @@ range_code_action({context}, {start_pos}, {end_pos})
Performs |vim.lsp.buf.code_action()| for a given range.
Parameters: ~
- {context} (table, optional) Valid `CodeActionContext`
- object
+ {context} table|nil `CodeActionContext` of the LSP specification:
+ • diagnostics: (table|nil) LSP`Diagnostic[]` . Inferred from the current position if not
+ provided.
+ • only: (string|nil) LSP `CodeActionKind`
+ used to filter the code actions. Most
+ language servers support values like
+ `refactor` or `quickfix` .
{start_pos} ({number, number}, optional) mark-indexed
position. Defaults to the start of the last
visual selection.
@@ -1176,195 +1101,20 @@ workspace_symbol({query}) *vim.lsp.buf.workspace_symbol()*
==============================================================================
Lua module: vim.lsp.diagnostic *lsp-diagnostic*
- *vim.lsp.diagnostic.clear()*
-clear({bufnr}, {client_id}, {diagnostic_ns}, {sign_ns})
- Clears the currently displayed diagnostics
-
- Parameters: ~
- {bufnr} number The buffer number
- {client_id} number the client id
- {diagnostic_ns} number|nil Associated diagnostic
- namespace
- {sign_ns} number|nil Associated sign namespace
-
-get({bufnr}, {client_id}) *vim.lsp.diagnostic.get()*
- Return associated diagnostics for bufnr
-
- Parameters: ~
- {bufnr} number
- {client_id} number|nil If nil, then return all of the
- diagnostics. Else, return just the
- diagnostics associated with the client_id.
-
-get_all({client_id}) *vim.lsp.diagnostic.get_all()*
- Get all diagnostics for clients
-
- Parameters: ~
- {client_id} number Restrict included diagnostics to the
- client If nil, diagnostics of all clients are
- included.
-
- Return: ~
- table with diagnostics grouped by bufnr (bufnr:Diagnostic[])
-
- *vim.lsp.diagnostic.get_count()*
-get_count({bufnr}, {severity}, {client_id})
- Get the counts for a particular severity
-
- Useful for showing diagnostic counts in statusline. eg:
->
-
- function! LspStatus() abort
- let sl = ''
- if luaeval('not vim.tbl_isempty(vim.lsp.buf_get_clients(0))')
- let sl.='%#MyStatuslineLSP#E:'
- let sl.='%#MyStatuslineLSPErrors#%{luaeval("vim.lsp.diagnostic.get_count(0, [[Error]])")}'
- let sl.='%#MyStatuslineLSP# W:'
- let sl.='%#MyStatuslineLSPWarnings#%{luaeval("vim.lsp.diagnostic.get_count(0, [[Warning]])")}'
- else
- let sl.='%#MyStatuslineLSPErrors#off'
- endif
- return sl
- endfunction
- let &l:statusline = '%#MyStatuslineLSP#LSP '.LspStatus()
-<
-
- Parameters: ~
- {bufnr} number The buffer number
- {severity} DiagnosticSeverity
- {client_id} number the client id
-
- *vim.lsp.diagnostic.get_line_diagnostics()*
-get_line_diagnostics({bufnr}, {line_nr}, {opts}, {client_id})
- Get the diagnostics by line
-
- Parameters: ~
- {bufnr} number The buffer number
- {line_nr} number The line number
- {opts} table|nil Configuration keys
- • severity: (DiagnosticSeverity, default nil)
- • Only return diagnostics with this
- severity. Overrides severity_limit
-
- • severity_limit: (DiagnosticSeverity, default nil)
- • Limit severity of diagnostics found. E.g.
- "Warning" means { "Error", "Warning" }
- will be valid.
- {client_id} number the client id
-
- Return: ~
- table Table with map of line number to list of
- diagnostics.
-
-get_next({opts}) *vim.lsp.diagnostic.get_next()*
- Get the next diagnostic closest to the cursor_position
-
- Parameters: ~
- {opts} table See |vim.lsp.diagnostic.goto_next()|
-
- Return: ~
- table Next diagnostic
-
-get_next_pos({opts}) *vim.lsp.diagnostic.get_next_pos()*
- Return the pos, {row, col}, for the next diagnostic in the
- current buffer.
-
- Parameters: ~
- {opts} table See |vim.lsp.diagnostic.goto_next()|
-
- Return: ~
- table Next diagnostic position
-
-get_prev({opts}) *vim.lsp.diagnostic.get_prev()*
- Get the previous diagnostic closest to the cursor_position
-
- Parameters: ~
- {opts} table See |vim.lsp.diagnostic.goto_next()|
-
- Return: ~
- table Previous diagnostic
-
-get_prev_pos({opts}) *vim.lsp.diagnostic.get_prev_pos()*
- Return the pos, {row, col}, for the prev diagnostic in the
- current buffer.
-
- Parameters: ~
- {opts} table See |vim.lsp.diagnostic.goto_next()|
-
- Return: ~
- table Previous diagnostic position
-
- *vim.lsp.diagnostic.get_virtual_text_chunks_for_line()*
-get_virtual_text_chunks_for_line({bufnr}, {line}, {line_diags}, {opts})
- Default function to get text chunks to display using `nvim_buf_set_virtual_text` .
-
- Parameters: ~
- {bufnr} number The buffer to display the virtual
- text in
- {line} number The line number to display the
- virtual text on
- {line_diags} Diagnostic [] The diagnostics associated with the line
- {opts} table See {opts} from
- |vim.lsp.diagnostic.set_virtual_text()|
-
- Return: ~
- table chunks, as defined by |nvim_buf_set_virtual_text()|
-
-goto_next({opts}) *vim.lsp.diagnostic.goto_next()*
- Move to the next diagnostic
+get_namespace({client_id}) *vim.lsp.diagnostic.get_namespace()*
+ Get the diagnostic namespace associated with an LSP client
+ |vim.diagnostic|.
Parameters: ~
- {opts} table|nil Configuration table. Keys:
- • {client_id}: (number)
- • If nil, will consider all clients attached to
- buffer.
-
- • {cursor_position}: (Position, default current
- position)
- • See |nvim_win_get_cursor()|
-
- • {wrap}: (boolean, default true)
- • Whether to loop around file or not. Similar to
- 'wrapscan'
-
- • {severity}: (DiagnosticSeverity)
- • Exclusive severity to consider. Overrides
- {severity_limit}
-
- • {severity_limit}: (DiagnosticSeverity)
- • Limit severity of diagnostics found. E.g.
- "Warning" means { "Error", "Warning" } will be
- valid.
-
- • {enable_popup}: (boolean, default true)
- • Call
- |vim.lsp.diagnostic.show_line_diagnostics()|
- on jump
-
- • {popup_opts}: (table)
- • Table to pass as {opts} parameter to
- |vim.lsp.diagnostic.show_line_diagnostics()|
-
- • {win_id}: (number, default 0)
- • Window ID
-
-goto_prev({opts}) *vim.lsp.diagnostic.goto_prev()*
- Move to the previous diagnostic
-
- Parameters: ~
- {opts} table See |vim.lsp.diagnostic.goto_next()|
+ {client_id} number The id of the LSP client
*vim.lsp.diagnostic.on_publish_diagnostics()*
-on_publish_diagnostics({_}, {_}, {params}, {client_id}, {_}, {config})
+on_publish_diagnostics({_}, {result}, {ctx}, {config})
|lsp-handler| for the method "textDocument/publishDiagnostics"
- Note:
- Each of the configuration options accepts:
- • `false` : Disable this feature
- • `true` : Enable this feature, use default settings.
- • `table` : Enable this feature, use overrides.
- • `function`: Function with signature (bufnr, client_id) that
- returns any of the above.>
+ See |vim.diagnostic.config()| for configuration options.
+ Handler-specific configuration can be set using
+ |vim.lsp.with()|: >
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
vim.lsp.diagnostic.on_publish_diagnostics, {
@@ -1386,180 +1136,8 @@ on_publish_diagnostics({_}, {_}, {params}, {client_id}, {_}, {config})
<
Parameters: ~
- {config} table Configuration table.
- • underline: (default=true)
- • Apply underlines to diagnostics.
- • See |vim.lsp.diagnostic.set_underline()|
-
- • virtual_text: (default=true)
- • Apply virtual text to line endings.
- • See |vim.lsp.diagnostic.set_virtual_text()|
-
- • signs: (default=true)
- • Apply signs for diagnostics.
- • See |vim.lsp.diagnostic.set_signs()|
-
- • update_in_insert: (default=false)
- • Update diagnostics in InsertMode or wait
- until InsertLeave
-
- • severity_sort: (default=false)
- • Sort diagnostics (and thus signs and virtual
- text)
-
-reset({client_id}, {buffer_client_map}) *vim.lsp.diagnostic.reset()*
- Clear diagnotics and diagnostic cache
-
- Handles saving diagnostics from multiple clients in the same
- buffer.
-
- Parameters: ~
- {client_id} number
- {buffer_client_map} table map of buffers to active
- clients
-
-save({diagnostics}, {bufnr}, {client_id}) *vim.lsp.diagnostic.save()*
- Save diagnostics to the current buffer.
-
- Handles saving diagnostics from multiple clients in the same
- buffer.
-
- Parameters: ~
- {diagnostics} Diagnostic []
- {bufnr} number
- {client_id} number
-
-set_loclist({opts}) *vim.lsp.diagnostic.set_loclist()*
- Sets the location list
-
- Parameters: ~
- {opts} table|nil Configuration table. Keys:
- • {open_loclist}: (boolean, default true)
- • Open loclist after set
-
- • {client_id}: (number)
- • If nil, will consider all clients attached to
- buffer.
-
- • {severity}: (DiagnosticSeverity)
- • Exclusive severity to consider. Overrides
- {severity_limit}
-
- • {severity_limit}: (DiagnosticSeverity)
- • Limit severity of diagnostics found. E.g.
- "Warning" means { "Error", "Warning" } will be
- valid.
-
- • {workspace}: (boolean, default false)
- • Set the list with workspace diagnostics
-
- *vim.lsp.diagnostic.set_signs()*
-set_signs({diagnostics}, {bufnr}, {client_id}, {sign_ns}, {opts})
- Set signs for given diagnostics
-
- Sign characters can be customized with the following commands:
->
-
- sign define LspDiagnosticsSignError text=E texthl=LspDiagnosticsSignError linehl= numhl=
- sign define LspDiagnosticsSignWarning text=W texthl=LspDiagnosticsSignWarning linehl= numhl=
- sign define LspDiagnosticsSignInformation text=I texthl=LspDiagnosticsSignInformation linehl= numhl=
- sign define LspDiagnosticsSignHint text=H texthl=LspDiagnosticsSignHint linehl= numhl=
-<
-
- Parameters: ~
- {diagnostics} Diagnostic []
- {bufnr} number The buffer number
- {client_id} number the client id
- {sign_ns} number|nil
- {opts} table Configuration for signs. Keys:
- • priority: Set the priority of the signs.
- • severity_limit (DiagnosticSeverity):
- • Limit severity of diagnostics found.
- E.g. "Warning" means { "Error",
- "Warning" } will be valid.
-
- *vim.lsp.diagnostic.set_underline()*
-set_underline({diagnostics}, {bufnr}, {client_id}, {diagnostic_ns}, {opts})
- Set underline for given diagnostics
-
- Underline highlights can be customized by changing the
- following |:highlight| groups.
->
-
- LspDiagnosticsUnderlineError
- LspDiagnosticsUnderlineWarning
- LspDiagnosticsUnderlineInformation
- LspDiagnosticsUnderlineHint
-<
-
- Parameters: ~
- {diagnostics} Diagnostic []
- {bufnr} number: The buffer number
- {client_id} number: The client id
- {diagnostic_ns} number|nil: The namespace
- {opts} table: Configuration table:
- • severity_limit (DiagnosticSeverity):
- • Limit severity of diagnostics found.
- E.g. "Warning" means { "Error",
- "Warning" } will be valid.
-
- *vim.lsp.diagnostic.set_virtual_text()*
-set_virtual_text({diagnostics}, {bufnr}, {client_id}, {diagnostic_ns}, {opts})
- Set virtual text given diagnostics
-
- Virtual text highlights can be customized by changing the
- following |:highlight| groups.
->
-
- LspDiagnosticsVirtualTextError
- LspDiagnosticsVirtualTextWarning
- LspDiagnosticsVirtualTextInformation
- LspDiagnosticsVirtualTextHint
-<
-
- Parameters: ~
- {diagnostics} Diagnostic []
- {bufnr} number
- {client_id} number
- {diagnostic_ns} number
- {opts} table Options on how to display virtual
- text. Keys:
- • prefix (string): Prefix to display
- before virtual text on line
- • spacing (number): Number of spaces to
- insert before virtual text
- • severity_limit (DiagnosticSeverity):
- • Limit severity of diagnostics found.
- E.g. "Warning" means { "Error",
- "Warning" } will be valid.
-
- *vim.lsp.diagnostic.show_line_diagnostics()*
-show_line_diagnostics({opts}, {bufnr}, {line_nr}, {client_id})
- Open a floating window with the diagnostics from {line_nr}
-
- The floating window can be customized with the following
- highlight groups: >
-
- LspDiagnosticsFloatingError
- LspDiagnosticsFloatingWarning
- LspDiagnosticsFloatingInformation
- LspDiagnosticsFloatingHint
-<
-
- Parameters: ~
- {opts} table Configuration table
- • show_header (boolean, default true): Show
- "Diagnostics:" header.
- • Plus all the opts for
- |vim.lsp.diagnostic.get_line_diagnostics()|
- and |vim.lsp.util.open_floating_preview()|
- can be used here.
- {bufnr} number The buffer number
- {line_nr} number The line number
- {client_id} number|nil the client id
-
- Return: ~
- table {popup_bufnr, win_id}
+ {config} table Configuration table (see
+ |vim.diagnostic.config()|).
==============================================================================
@@ -1577,11 +1155,15 @@ display({lenses}, {bufnr}, {client_id}) *vim.lsp.codelens.display()*
get({bufnr}) *vim.lsp.codelens.get()*
Return all lenses for the given buffer
+ Parameters: ~
+ {bufnr} number Buffer number. 0 can be used for the
+ current buffer.
+
Return: ~
table ( `CodeLens[]` )
*vim.lsp.codelens.on_codelens()*
-on_codelens({err}, {_}, {result}, {client_id}, {bufnr})
+on_codelens({err}, {result}, {ctx}, {_})
|lsp-handler| for the method `textDocument/codeLens`
refresh() *vim.lsp.codelens.refresh()*
@@ -1609,21 +1191,28 @@ save({lenses}, {bufnr}, {client_id}) *vim.lsp.codelens.save()*
==============================================================================
Lua module: vim.lsp.handlers *lsp-handlers*
- *vim.lsp.handlers.progress_handler()*
-progress_handler({_}, {_}, {params}, {client_id})
- See also: ~
- https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_executeCommand
+hover({_}, {result}, {ctx}, {config}) *vim.lsp.handlers.hover()*
+ |lsp-handler| for the method "textDocument/hover" >
+
+ vim.lsp.handlers["textDocument/hover"] = vim.lsp.with(
+ vim.lsp.handlers.hover, {
+ -- Use a sharp border with `FloatBorder` highlights
+ border = "single"
+ }
+ )
+<
- *vim.lsp.handlers.signature_help()*
-signature_help({_}, {method}, {result}, {_}, {bufnr}, {config})
Parameters: ~
{config} table Configuration table.
• border: (default=nil)
• Add borders to the floating window
• See |vim.api.nvim_open_win()|
- See also: ~
- https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_declaration@seehttps://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_definition@seehttps://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_typeDefinition@seehttps://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_implementation|lsp-handler| for the method "textDocument/signatureHelp">
+ *vim.lsp.handlers.signature_help()*
+signature_help({_}, {result}, {ctx}, {config})
+ |lsp-handler| for the method "textDocument/signatureHelp". The
+ active parameter is highlighted with
+ |hl-LspSignatureActiveParameter|. >
vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(
vim.lsp.handlers.signature_help, {
@@ -1633,6 +1222,12 @@ signature_help({_}, {method}, {result}, {_}, {bufnr}, {config})
)
<
+ Parameters: ~
+ {config} table Configuration table.
+ • border: (default=nil)
+ • Add borders to the floating window
+ • See |vim.api.nvim_open_win()|
+
==============================================================================
Lua module: vim.lsp.util *lsp-util*
@@ -1659,6 +1254,9 @@ apply_text_edits({text_edits}, {bufnr})
{text_edits} (table) list of `TextEdit` objects
{buf_nr} (number) Buffer id
+ See also: ~
+ https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textEdit
+
*vim.lsp.util.apply_workspace_edit()*
apply_workspace_edit({workspace_edit})
Applies a `WorkspaceEdit` .
@@ -1666,12 +1264,6 @@ apply_workspace_edit({workspace_edit})
Parameters: ~
{workspace_edit} (table) `WorkspaceEdit`
-border_height({id}) *vim.lsp.util.border_height()*
- TODO: Documentation
-
-border_width({id}) *vim.lsp.util.border_width()*
- TODO: Documentation
-
buf_clear_references({bufnr}) *vim.lsp.util.buf_clear_references()*
Removes document highlights from a buffer.
@@ -1687,6 +1279,9 @@ buf_highlight_references({bufnr}, {references})
{references} List of `DocumentHighlight` objects to
highlight
+ See also: ~
+ https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/#documentHighlight
+
buf_lines({bufnr}) *vim.lsp.util.buf_lines()*
TODO: Documentation
@@ -1756,7 +1351,7 @@ convert_input_to_markdown_lines({input}, {contents})
https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_hover
*vim.lsp.util.convert_signature_help_to_markdown_lines()*
-convert_signature_help_to_markdown_lines({signature_help}, {ft})
+convert_signature_help_to_markdown_lines({signature_help}, {ft}, {triggers})
Converts `textDocument/SignatureHelp` response to markdown
lines.
@@ -1765,6 +1360,9 @@ convert_signature_help_to_markdown_lines({signature_help}, {ft})
{ft} optional filetype that will be use as
the `lang` for the label markdown code
block
+ {triggers} optional list of trigger characters from
+ the lsp server. used to better determine
+ parameter offsets
Return: ~
list of lines of converted markdown.
@@ -1778,19 +1376,6 @@ create_file({change}) *vim.lsp.util.create_file()*
delete_file({change}) *vim.lsp.util.delete_file()*
TODO: Documentation
- *vim.lsp.util.diagnostics_to_items()*
-diagnostics_to_items({diagnostics_by_bufnr}, {predicate})
- Convert diagnostics grouped by bufnr to a list of items for
- use in the quickfix or location list.
-
- Parameters: ~
- {diagnostics_by_bufnr} table bufnr -> Diagnostic []
- {predicate} an optional function to filter the
- diagnostics.
-
- Return: ~
- table (A list of items)
-
*vim.lsp.util.extract_completion_items()*
extract_completion_items({result})
Can be used to extract the completion items from a `textDocument/completion` request, which may return one of `CompletionItem[]` , `CompletionList` or null.
@@ -1819,6 +1404,8 @@ get_effective_tabstop({bufnr}) *vim.lsp.util.get_effective_tabstop()*
|softtabstop|
get_line({uri}, {row}) *vim.lsp.util.get_line()*
+ Gets the zero-indexed line from the given uri.
+
Parameters: ~
{uri} string uri of the resource to get the line from
{row} number zero-indexed line number
@@ -1827,6 +1414,8 @@ get_line({uri}, {row}) *vim.lsp.util.get_line()*
string the line at row in filename
get_lines({uri}, {rows}) *vim.lsp.util.get_lines()*
+ Gets the zero-indexed lines from the given uri.
+
Parameters: ~
{uri} string uri of the resource to get the lines from
{rows} number[] zero-indexed line numbers
@@ -1851,6 +1440,9 @@ locations_to_items({locations}) *vim.lsp.util.locations_to_items()*
and in sorted order, for display in quickfix and location
lists.
+ The result can be passed to the {list} argument of
+ |setqflist()| or |setloclist()|.
+
Parameters: ~
{locations} (table) list of `Location` s or
`LocationLink` s
@@ -1886,14 +1478,14 @@ make_floating_popup_options({width}, {height}, {opts})
*vim.lsp.util.make_formatting_params()*
make_formatting_params({options})
- Creates a `FormattingOptions` object for the current buffer
- and cursor position.
+ Creates a `DocumentFormattingParams` object for the current
+ buffer and cursor position.
Parameters: ~
{options} Table with valid `FormattingOptions` entries
Return: ~
- `FormattingOptions object
+ `DocumentFormattingParams` object
See also: ~
https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_formatting
@@ -2014,6 +1606,8 @@ preview_location({location}, {opts}) *vim.lsp.util.preview_location()*
or nil
rename({old_fname}, {new_fname}, {opts}) *vim.lsp.util.rename()*
+ Rename old_fname to new_fname
+
Parameters: ~
{opts} (table)
@@ -2033,21 +1627,6 @@ set_lines({lines}, {A}, {B}, {new_lines}) *vim.lsp.util.set_lines()*
Return: ~
(table) The modified {lines} object
-set_loclist({items}, {win_id}) *vim.lsp.util.set_loclist()*
- Fills target window's location list with given list of items.
- Can be obtained with e.g. |vim.lsp.util.locations_to_items()|.
- Defaults to current window.
-
- Parameters: ~
- {items} (table) list of items
-
-set_qflist({items}) *vim.lsp.util.set_qflist()*
- Fills quickfix list with given list of items. Can be obtained
- with e.g. |vim.lsp.util.locations_to_items()|.
-
- Parameters: ~
- {items} (table) list of items
-
*vim.lsp.util.stylize_markdown()*
stylize_markdown({bufnr}, {contents}, {opts})
Converts markdown into syntax highlighted regions by stripping
diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt
index fd1bedd8ef..22e323baa7 100644
--- a/runtime/doc/lua.txt
+++ b/runtime/doc/lua.txt
@@ -1,15 +1,15 @@
*lua.txt* Nvim
- NVIM REFERENCE MANUAL
+ NVIM REFERENCE MANUAL
-Lua engine *lua* *Lua*
+Lua engine *lua* *Lua*
Type |gO| to see the table of contents.
==============================================================================
-INTRODUCTION *lua-intro*
+INTRODUCTION *lua-intro*
The Lua 5.1 language is builtin and always available. Try this command to get
an idea of what lurks beneath: >
@@ -27,11 +27,12 @@ are on 'runtimepath':
~/.config/nvim/lua/foo.lua
then `require('foo')` loads "~/.config/nvim/lua/foo.lua", and
"runtime/lua/foo.lua" is not used. See |lua-require| to understand how Nvim
-finds and loads Lua modules. The conventions are similar to VimL plugins,
-with some extra features. See |lua-require-example| for a walkthrough.
+finds and loads Lua modules. The conventions are similar to those of
+Vimscript |plugin|s, with some extra features. See |lua-require-example| for
+a walkthrough.
==============================================================================
-IMPORTING LUA MODULES *lua-require*
+IMPORTING LUA MODULES *lua-require*
*lua-package-path*
Nvim automatically adjusts `package.path` and `package.cpath` according to
@@ -157,7 +158,7 @@ function without any parentheses. This is most often used to approximate
------------------------------------------------------------------------------
-LUA PLUGIN EXAMPLE *lua-require-example*
+LUA PLUGIN EXAMPLE *lua-require-example*
The following example plugin adds a command `:MakeCharBlob` which transforms
current buffer into a long `unsigned char` array. Lua contains transformation
@@ -234,7 +235,7 @@ lua/charblob.lua: >
}
==============================================================================
-COMMANDS *lua-commands*
+COMMANDS *lua-commands*
These commands execute a Lua chunk from either the command line (:lua, :luado)
or a file (:luafile) on the given line [range]. As always in Lua, each chunk
@@ -298,19 +299,20 @@ arguments separated by " " (space) instead of "\t" (tab).
:luado if bp:match(line) then return "-->\t" .. line end
<
- *:luafile*
+ *:luafile*
:[range]luafile {file}
- Execute Lua script in {file}.
- The whole argument is used as a single file name.
+ Execute Lua script in {file}.
+ The whole argument is used as the filename (like
+ |:edit|), spaces do not need to be escaped.
+ Alternatively you can |:source| Lua files.
- Examples:
- >
+ Examples: >
:luafile script.lua
:luafile %
<
==============================================================================
-luaeval() *lua-eval* *luaeval()*
+luaeval() *lua-eval* *luaeval()*
The (dual) equivalent of "vim.eval" for passing Lua values to Nvim is
"luaeval". "luaeval" takes an expression string and an optional argument used
@@ -324,8 +326,8 @@ semantically equivalent in Lua to:
end
Lua nils, numbers, strings, tables and booleans are converted to their
-respective VimL types. An error is thrown if conversion of any other Lua types
-is attempted.
+respective Vimscript types. If a Lua string contains a NUL byte, it will be
+converted to a |Blob|. Conversion of other Lua types is an error.
The magic global "_A" contains the second argument to luaeval().
@@ -348,21 +350,21 @@ cases there is the following agreement:
3. Table with string keys, at least one of which contains NUL byte, is also
considered to be a dictionary, but this time it is converted to
a |msgpack-special-map|.
- *lua-special-tbl*
+ *lua-special-tbl*
4. Table with `vim.type_idx` key may be a dictionary, a list or floating-point
value:
- - `{[vim.type_idx]=vim.types.float, [vim.val_idx]=1}` is converted to
- a floating-point 1.0. Note that by default integral Lua numbers are
- converted to |Number|s, non-integral are converted to |Float|s. This
+ - `{[vim.type_idx]=vim.types.float, [vim.val_idx]=1}` is converted to
+ a floating-point 1.0. Note that by default integral Lua numbers are
+ converted to |Number|s, non-integral are converted to |Float|s. This
variant allows integral |Float|s.
- - `{[vim.type_idx]=vim.types.dictionary}` is converted to an empty
- dictionary, `{[vim.type_idx]=vim.types.dictionary, [42]=1, a=2}` is
- converted to a dictionary `{'a': 42}`: non-string keys are ignored.
- Without `vim.type_idx` key tables with keys not fitting in 1., 2. or 3.
+ - `{[vim.type_idx]=vim.types.dictionary}` is converted to an empty
+ dictionary, `{[vim.type_idx]=vim.types.dictionary, [42]=1, a=2}` is
+ converted to a dictionary `{'a': 42}`: non-string keys are ignored.
+ Without `vim.type_idx` key tables with keys not fitting in 1., 2. or 3.
are errors.
- - `{[vim.type_idx]=vim.types.list}` is converted to an empty list. As well
- as `{[vim.type_idx]=vim.types.list, [42]=1}`: integral keys that do not
- form a 1-step sequence from 1 to N are ignored, as well as all
+ - `{[vim.type_idx]=vim.types.list}` is converted to an empty list. As well
+ as `{[vim.type_idx]=vim.types.list, [42]=1}`: integral keys that do not
+ form a 1-step sequence from 1 to N are ignored, as well as all
non-integral keys.
Examples: >
@@ -373,13 +375,13 @@ Examples: >
: endfunction
:echo Rand(1,10)
-Note: second argument to `luaeval` undergoes VimL to Lua conversion
-("marshalled"), so changes to Lua containers do not affect values in VimL.
-Return value is also always converted. When converting,
-|msgpack-special-dict|s are treated specially.
+Note: second argument to `luaeval` is converted ("marshalled") from Vimscript
+to Lua, so changes to Lua containers do not affect values in Vimscript. Return
+value is also always converted. When converting, |msgpack-special-dict|s are
+treated specially.
==============================================================================
-Vimscript v:lua interface *v:lua-call*
+Vimscript v:lua interface *v:lua-call*
From Vimscript the special `v:lua` prefix can be used to call Lua functions
which are global or accessible from global tables. The expression >
@@ -391,6 +393,10 @@ where the args are converted to Lua values. The expression >
is equivalent to the Lua chunk >
return somemod.func(...)
+The `v:lua` prefix may be used to call Lua functions as |method|s. For
+example: >
+ arg1->v:lua.somemod.func(arg2)
+
You can use `v:lua` in "func" options like 'tagfunc', 'omnifunc', etc.
For example consider the following Lua omnifunc handler: >
@@ -415,7 +421,7 @@ Note: `v:lua` without a call is not allowed in a Vimscript expression:
==============================================================================
-Lua standard modules *lua-stdlib*
+Lua standard modules *lua-stdlib*
The Nvim Lua "standard library" (stdlib) is the `vim` module, which exposes
various functions and sub-modules. It is always loaded, thus require("vim")
@@ -449,7 +455,7 @@ Note that underscore-prefixed functions (e.g. "_os_proc_children") are
internal/private and must not be used by plugins.
------------------------------------------------------------------------------
-VIM.LOOP *lua-loop* *vim.loop*
+VIM.LOOP *lua-loop* *vim.loop*
`vim.loop` exposes all features of the Nvim event-loop. This is a low-level
API that provides functionality for networking, filesystem, and process
@@ -460,7 +466,7 @@ management. Try this command to see available functions: >
Reference: https://github.com/luvit/luv/blob/master/docs.md
Examples: https://github.com/luvit/luv/tree/master/examples
- *E5560* *lua-loop-callbacks*
+ *E5560* *lua-loop-callbacks*
It is an error to directly invoke `vim.api` functions (except |api-fast|) in
`vim.loop` callbacks. For example, this is an error: >
@@ -496,7 +502,7 @@ Example: repeating timer
print('sleeping');
-Example: File-change detection *watch-file*
+Example: File-change detection *watch-file*
1. Save this code to a file.
2. Execute it with ":luafile %".
3. Use ":Watch %" to watch any file.
@@ -522,7 +528,7 @@ Example: File-change detection *watch-file*
"command! -nargs=1 Watch call luaeval('watch_file(_A)', expand('<args>'))")
-Example: TCP echo-server *tcp-server*
+Example: TCP echo-server *tcp-server*
1. Save this code to a file.
2. Execute it with ":luafile %".
3. Note the port number.
@@ -552,7 +558,7 @@ Example: TCP echo-server *tcp-server*
print('TCP echo-server listening on port: '..server:getsockname().port)
------------------------------------------------------------------------------
-VIM.HIGHLIGHT *lua-highlight*
+VIM.HIGHLIGHT *lua-highlight*
Nvim includes a function for highlighting a selection on yank (see for example
https://github.com/machakann/vim-highlightedyank). To enable it, add
@@ -572,11 +578,11 @@ If you want to exclude visual selections from highlighting on yank, use
vim.highlight.on_yank({opts}) *vim.highlight.on_yank()*
Highlights the yanked text. The fields of the optional dict {opts}
control the highlight:
- - {higroup} highlight group for yanked region (default `"IncSearch"`)
+ - {higroup} highlight group for yanked region (default |hl-IncSearch|)
- {timeout} time in ms before highlight is cleared (default `150`)
- {on_macro} highlight when executing macro (default `false`)
- {on_visual} highlight when yanking visual selection (default `true`)
- - {event} event structure (default `vim.v.event`)
+ - {event} event structure (default |v:event|)
vim.highlight.range({bufnr}, {ns}, {higroup}, {start}, {finish}, {rtype}, {inclusive})
*vim.highlight.range()*
@@ -587,21 +593,19 @@ vim.highlight.range({bufnr}, {ns}, {higroup}, {start}, {finish}, {rtype}, {inclu
range is inclusive (default false).
------------------------------------------------------------------------------
-VIM.REGEX *lua-regex*
+VIM.REGEX *lua-regex*
Vim regexes can be used directly from lua. Currently they only allow
matching within a single line.
-vim.regex({re}) *vim.regex()*
+vim.regex({re}) *vim.regex()*
+ Parse the Vim regex {re} and return a regex object. Regexes are
+ "magic" and case-insensitive by default, regardless of 'magic' and
+ 'ignorecase'. The can be controlled with flags, see |/magic|.
- Parse the regex {re} and return a regex object. 'magic' and
- 'ignorecase' options are ignored, lua regexes always defaults to magic
- and ignoring case. The behavior can be changed with flags in
- the beginning of the string |/magic|.
+Methods on the regex object:
-Regex objects support the following methods:
-
-regex:match_str({str}) *regex:match_str()*
+regex:match_str({str}) *regex:match_str()*
Match the string against the regex. If the string should match the
regex precisely, surround the regex with `^` and `$`.
If the was a match, the byte indices for the beginning and end of
@@ -609,66 +613,144 @@ regex:match_str({str}) *regex:match_str()*
As any integer is truth-y, `regex:match()` can be directly used
as a condition in an if-statement.
-regex:match_line({bufnr}, {line_idx}[, {start}, {end}]) *regex:match_line()*
+regex:match_line({bufnr}, {line_idx}[, {start}, {end}]) *regex:match_line()*
Match line {line_idx} (zero-based) in buffer {bufnr}. If {start} and
{end} are supplied, match only this byte index range. Otherwise see
|regex:match_str()|. If {start} is used, then the returned byte
indices will be relative {start}.
------------------------------------------------------------------------------
-VIM *lua-builtin*
+VIM.DIFF *lua-diff*
+
+vim.diff({a}, {b}, {opts}) *vim.diff()*
+ Run diff on strings {a} and {b}. Any indices returned by this
+ function, either directly or via callback arguments, are
+ 1-based.
+
+ Examples: >
+ vim.diff('a\n', 'b\nc\n')
+ -->
+ @@ -1 +1,2 @@
+ -a
+ +b
+ +c
+
+ vim.diff('a\n', 'b\nc\n', {result_type = 'indices'})
+ -->
+ {
+ {1, 1, 1, 2}
+ }
+<
+ Parameters: ~
+ {a} First string to compare
+ {b} Second string to compare
+ {opts} Optional parameters:
+ • `on_hunk` (callback):
+ Invoked for each hunk in the diff. Return a
+ negative number to cancel the callback for any
+ remaining hunks.
+ Args:
+ • `start_a` (integer): Start line of hunk in {a}.
+ • `count_a` (integer): Hunk size in {a}.
+ • `start_b` (integer): Start line of hunk in {b}.
+ • `count_b` (integer): Hunk size in {b}.
+ • `result_type` (string): Form of the returned diff:
+ • "unified": (default) String in unified format.
+ • "indices": Array of hunk locations.
+ Note this option is ignored if `on_hunk` is
+ used.
+ • `algorithm` (string):
+ Diff algorithm to use. Values:
+ • "myers" the default algorithm
+ • "minimal" spend extra time to generate the
+ smallest possible diff
+ • "patience" patience diff algorithm
+ • "histogram" histogram diff algorithm
+ • `ctxlen` (integer): Context length
+ • `interhunkctxlen` (integer):
+ Inter hunk context length
+ • `ignore_whitespace` (boolean):
+ Ignore whitespace
+ • `ignore_whitespace_change` (boolean):
+ Ignore whitespace change
+ • `ignore_whitespace_change_at_eol` (boolean)
+ Ignore whitespace change at end-of-line.
+ • `ignore_cr_at_eol` (boolean)
+ Ignore carriage return at end-of-line
+ • `ignore_blank_lines` (boolean)
+ Ignore blank lines
+ • `indent_heuristic` (boolean):
+ Use the indent heuristic for the internal
+ diff library.
+
+ Return: ~
+ See {opts.result_type}. nil if {opts.on_hunk} is given.
+
+------------------------------------------------------------------------------
+VIM.MPACK *lua-mpack*
+
+The *vim.mpack* module provides packing and unpacking of lua objects to
+msgpack encoded strings. |vim.NIL| and |vim.empty_dict()| are supported.
+
+vim.mpack.pack({obj}) *vim.mpack.pack*
+ Packs a lua object {obj} and returns the msgpack representation as
+ a string
+
+vim.mpack.unpack({str}) *vim.mpack.unpack*
+ Unpacks the msgpack encoded {str} and returns a lua object
-vim.api.{func}({...}) *vim.api*
+------------------------------------------------------------------------------
+VIM *lua-builtin*
+
+vim.api.{func}({...}) *vim.api*
Invokes Nvim |API| function {func} with arguments {...}.
Example: call the "nvim_get_current_line()" API function: >
print(tostring(vim.api.nvim_get_current_line()))
-vim.version() *vim.version*
- Returns the version of the current neovim build.
+vim.version() *vim.version*
+ Gets the version of the current Nvim build.
-vim.in_fast_event() *vim.in_fast_event()*
+vim.in_fast_event() *vim.in_fast_event()*
Returns true if the code is executing as part of a "fast" event
handler, where most of the API is disabled. These are low-level events
(e.g. |lua-loop-callbacks|) which can be invoked whenever Nvim polls
for input. When this is `false` most API functions are callable (but
may be subject to other restrictions such as |textlock|).
-vim.NIL *vim.NIL*
- Special value used to represent NIL in msgpack-rpc and |v:null| in
- vimL interaction, and similar cases. Lua `nil` cannot be used as
- part of a lua table representing a Dictionary or Array, as it
- is equivalent to a missing value: `{"foo", nil}` is the same as
- `{"foo"}`
+vim.NIL *vim.NIL*
+ Special value representing NIL in |RPC| and |v:null| in Vimscript
+ conversion, and similar cases. Lua `nil` cannot be used as part of
+ a Lua table representing a Dictionary or Array, because it is
+ treated as missing: `{"foo", nil}` is the same as `{"foo"}`.
-vim.empty_dict() *vim.empty_dict()*
- Creates a special table which will be converted to an empty
- dictionary when converting lua values to vimL or API types. The
- table is empty, and this property is marked using a metatable. An
- empty table `{}` without this metatable will default to convert to
- an array/list.
+vim.empty_dict() *vim.empty_dict()*
+ Creates a special empty table (marked with a metatable), which Nvim
+ converts to an empty dictionary when translating Lua values to
+ Vimscript or API types. Nvim by default converts an empty table `{}`
+ without this metatable to an list/array.
- Note: if numeric keys are added to the table, the metatable will be
- ignored and the dict converted to a list/array anyway.
+ Note: if numeric keys are present in the table, Nvim ignores the
+ metatable marker and converts the dict to a list/array anyway.
-vim.rpcnotify({channel}, {method}[, {args}...]) *vim.rpcnotify()*
- Sends {event} to {channel} via |RPC| and returns immediately.
- If {channel} is 0, the event is broadcast to all channels.
+vim.rpcnotify({channel}, {method}[, {args}...]) *vim.rpcnotify()*
+ Sends {event} to {channel} via |RPC| and returns immediately. If
+ {channel} is 0, the event is broadcast to all channels.
- This function also works in a fast callback |lua-loop-callbacks|.
+ This function also works in a fast callback |lua-loop-callbacks|.
-vim.rpcrequest({channel}, {method}[, {args}...]) *vim.rpcrequest()*
- Sends a request to {channel} to invoke {method} via
- |RPC| and blocks until a response is received.
+vim.rpcrequest({channel}, {method}[, {args}...]) *vim.rpcrequest()*
+ Sends a request to {channel} to invoke {method} via |RPC| and blocks
+ until a response is received.
- Note: NIL values as part of the return value is represented as
- |vim.NIL| special value
+ Note: NIL values as part of the return value is represented as
+ |vim.NIL| special value
-vim.stricmp({a}, {b}) *vim.stricmp()*
+vim.stricmp({a}, {b}) *vim.stricmp()*
Compares strings case-insensitively. Returns 0, 1 or -1 if strings
are equal, {a} is greater than {b} or {a} is lesser than {b},
respectively.
-vim.str_utfindex({str}[, {index}]) *vim.str_utfindex()*
+vim.str_utfindex({str}[, {index}]) *vim.str_utfindex()*
Convert byte index to UTF-32 and UTF-16 indicies. If {index} is not
supplied, the length of the string is used. All indicies are zero-based.
Returns two values: the UTF-32 and UTF-16 indicies respectively.
@@ -756,40 +838,40 @@ vim.wait({time} [, {callback}, {interval}, {fast_only}]) *vim.wait()*
end
<
-vim.type_idx *vim.type_idx*
- Type index for use in |lua-special-tbl|. Specifying one of the
- values from |vim.types| allows typing the empty table (it is
- unclear whether empty Lua table represents empty list or empty array)
- and forcing integral numbers to be |Float|. See |lua-special-tbl| for
- more details.
+vim.type_idx *vim.type_idx*
+ Type index for use in |lua-special-tbl|. Specifying one of the values
+ from |vim.types| allows typing the empty table (it is unclear whether
+ empty Lua table represents empty list or empty array) and forcing
+ integral numbers to be |Float|. See |lua-special-tbl| for more
+ details.
-vim.val_idx *vim.val_idx*
- Value index for tables representing |Float|s. A table representing
- floating-point value 1.0 looks like this: >
+vim.val_idx *vim.val_idx*
+ Value index for tables representing |Float|s. A table representing
+ floating-point value 1.0 looks like this: >
{
[vim.type_idx] = vim.types.float,
[vim.val_idx] = 1.0,
}
-< See also |vim.type_idx| and |lua-special-tbl|.
-
-vim.types *vim.types*
- Table with possible values for |vim.type_idx|. Contains two sets
- of key-value pairs: first maps possible values for |vim.type_idx|
- to human-readable strings, second maps human-readable type names to
- values for |vim.type_idx|. Currently contains pairs for `float`,
- `array` and `dictionary` types.
-
- Note: one must expect that values corresponding to `vim.types.float`,
- `vim.types.array` and `vim.types.dictionary` fall under only two
- following assumptions:
- 1. Value may serve both as a key and as a value in a table. Given the
- properties of Lua tables this basically means “value is not `nil`”.
- 2. For each value in `vim.types` table `vim.types[vim.types[value]]`
- is the same as `value`.
- No other restrictions are put on types, and it is not guaranteed that
- values corresponding to `vim.types.float`, `vim.types.array` and
- `vim.types.dictionary` will not change or that `vim.types` table will
- only contain values for these three types.
+< See also |vim.type_idx| and |lua-special-tbl|.
+
+vim.types *vim.types*
+ Table with possible values for |vim.type_idx|. Contains two sets of
+ key-value pairs: first maps possible values for |vim.type_idx| to
+ human-readable strings, second maps human-readable type names to
+ values for |vim.type_idx|. Currently contains pairs for `float`,
+ `array` and `dictionary` types.
+
+ Note: one must expect that values corresponding to `vim.types.float`,
+ `vim.types.array` and `vim.types.dictionary` fall under only two
+ following assumptions:
+ 1. Value may serve both as a key and as a value in a table. Given the
+ properties of Lua tables this basically means “value is not `nil`”.
+ 2. For each value in `vim.types` table `vim.types[vim.types[value]]`
+ is the same as `value`.
+ No other restrictions are put on types, and it is not guaranteed that
+ values corresponding to `vim.types.float`, `vim.types.array` and
+ `vim.types.dictionary` will not change or that `vim.types` table will
+ only contain values for these three types.
------------------------------------------------------------------------------
LUA-VIMSCRIPT BRIDGE *lua-vimscript*
@@ -823,7 +905,7 @@ vim.fn.{func}({...}) *vim.fn*
To call autoload functions, use the syntax: >
vim.fn['some#function']({...})
<
- Unlike vim.api.|nvim_call_function| this converts directly between Vim
+ Unlike vim.api.|nvim_call_function()| this converts directly between Vim
objects and Lua objects. If the Vim function returns a float, it will
be represented directly as a Lua number. Empty lists and dictionaries
both are represented by an empty table.
@@ -882,8 +964,8 @@ vim.env *vim.env*
*lua-vim-optlocal*
*lua-vim-setlocal*
-In vimL, there is a succint and simple way to set options. For more
-information, see |set-option|. In Lua, the corresponding method is `vim.opt`.
+In Vimscript, there is an way to set options |set-option|. In Lua, the
+corresponding method is `vim.opt`.
`vim.opt` provides several conveniences for setting and controlling options
from within Lua.
@@ -891,18 +973,18 @@ from within Lua.
Examples: ~
To set a boolean toggle:
- In vimL:
+ In Vimscript:
`set number`
In Lua:
`vim.opt.number = true`
To set an array of values:
- In vimL:
+ In Vimscript:
`set wildignore=*.o,*.a,__pycache__`
In Lua, there are two ways you can do this now. One is very similar to
- the vimL way:
+ the Vimscript form:
`vim.opt.wildignore = '*.o,*.a,__pycache__'`
However, vim.opt also supports a more elegent way of setting
@@ -935,7 +1017,7 @@ from within Lua.
vim.opt.wildignore:remove { "node_modules" }
<
To set a map of values:
- In vimL:
+ In Vimscript:
`set listchars=space:_,tab:>~`
In Lua:
@@ -1110,7 +1192,9 @@ make_dict_accessor({scope}) *vim.make_dict_accessor()*
TODO: Documentation
notify({msg}, {log_level}, {_opts}) *vim.notify()*
- Notification provider without a runtime, writes to :Messages
+ Notification provider
+
+ Without a runtime, writes to :Messages
Parameters: ~
{msg} Content of the notification to show to the
@@ -1119,6 +1203,9 @@ notify({msg}, {log_level}, {_opts}) *vim.notify()*
{opts} Dictionary with optional options (timeout,
etc)
+ See also: ~
+ :help nvim_notify
+
paste({lines}, {phase}) *vim.paste()*
Paste handler, invoked by |nvim_paste()| when a conforming UI
(such as the |TUI|) pastes text into the editor.
@@ -1167,37 +1254,6 @@ region({bufnr}, {pos1}, {pos2}, {regtype}, {inclusive}) *vim.region()*
Return: ~
region lua table of the form {linenr = {startcol,endcol}}
- *vim.register_keystroke_callback()*
-register_keystroke_callback({fn}, {ns_id})
- Register a lua {fn} with an {id} to be run after every
- keystroke.
-
- If {fn} is nil, it removes the callback for the associated
- {ns_id}
- Note:
- {fn} will not be cleared from |nvim_buf_clear_namespace()|
-
- Note:
- {fn} will receive the keystrokes after mappings have been
- evaluated
-
- Parameters: ~
- {fn} function: Function to call. It should take one
- argument, which is a string. The string will contain
- the literal keys typed. See |i_CTRL-V|
- {ns_id} number? Namespace ID. If not passed or 0, will
- generate and return a new namespace ID from
- |nvim_create_namesapce()|
-
- Return: ~
- number Namespace ID associated with {fn}
-
- Note:
- {fn} will be automatically removed if an error occurs
- while calling. This is to prevent the annoying situation
- of every keystroke erroring while trying to remove a
- broken callback.
-
schedule_wrap({cb}) *vim.schedule_wrap()*
Defers callback `cb` until the Nvim API is safe to call.
@@ -1210,7 +1266,17 @@ schedule_wrap({cb}) *vim.schedule_wrap()*
deep_equal({a}, {b}) *vim.deep_equal()*
- TODO: Documentation
+ Deep compare values for equality
+
+ Tables are compared recursively unless they both provide the `eq` methamethod.
+ All other types are compared using the equality `==` operator.
+
+ Parameters: ~
+ {a} first value
+ {b} second value
+
+ Return: ~
+ `true` if values are equals, else `false` .
deepcopy({orig}) *vim.deepcopy()*
Returns a deep copy of the given object. Non-table objects are
@@ -1505,14 +1571,12 @@ validate({opt}) *vim.validate()*
vim.validate{arg1={{'foo'}, 'table'}, arg2={'foo', 'string'}}
=> NOP (success)
-<
->
- vim.validate{arg1={1, 'table'}}
- => error('arg1: expected table, got number')
-<
->
- vim.validate{arg1={3, function(a) return (a % 2) == 0 end, 'even number'}}
- => error('arg1: expected even number, got 3')
+
+ vim.validate{arg1={1, 'table'}}
+ => error('arg1: expected table, got number')
+
+ vim.validate{arg1={3, function(a) return (a % 2) == 0 end, 'even number'}}
+ => error('arg1: expected even number, got 3')
<
Parameters: ~
@@ -1581,4 +1645,25 @@ uri_to_fname({uri}) *vim.uri_to_fname()*
Return: ~
Filename
+
+==============================================================================
+Lua module: ui *lua-ui*
+
+select({items}, {opts}, {on_choice}) *vim.ui.select()*
+ Prompts the user to pick a single item from a collection of
+ entries
+
+ Parameters: ~
+ {items} table Arbitrary items
+ {opts} table Additional options
+ • prompt (string|nil) Text of the prompt.
+ Defaults to `Select one of:`
+ • format_item (function item -> text)
+ Function to format an individual item from
+ `items` . Defaults to `tostring` .
+ {on_choice} function ((item|nil, idx|nil) -> ()) Called
+ once the user made a choice. `idx` is the
+ 1-based index of `item` within `item` . `nil`
+ if the user aborted the dialog.
+
vim:tw=78:ts=8:ft=help:norl:
diff --git a/runtime/doc/map.txt b/runtime/doc/map.txt
index 10d503e180..64c0d96aed 100644
--- a/runtime/doc/map.txt
+++ b/runtime/doc/map.txt
@@ -1306,6 +1306,7 @@ completion can be enabled:
-complete=highlight highlight groups
-complete=history :history suboptions
-complete=locale locale names (as output of locale -a)
+ -complete=lua Lua expression
-complete=mapclear buffer argument
-complete=mapping mapping name
-complete=menu menus
diff --git a/runtime/doc/motion.txt b/runtime/doc/motion.txt
index 9f8acff88a..c473244827 100644
--- a/runtime/doc/motion.txt
+++ b/runtime/doc/motion.txt
@@ -52,9 +52,14 @@ or change text. The following operators are available:
|<| < shift left
|zf| zf define a fold
|g@| g@ call function set with the 'operatorfunc' option
-
+ *motion-count-multiplied*
If the motion includes a count and the operator also had a count before it,
the two counts are multiplied. For example: "2d3w" deletes six words.
+ *operator-doubled*
+When doubling the operator it operates on a line. When using a count, before
+or after the first character, that many lines are operated upon. Thus `3dd`
+deletes three lines. A count before and after the first character is
+multiplied, thus `2y3y` yanks six lines.
After applying the operator the cursor is mostly left at the start of the text
that was operated upon. For example, "yfe" doesn't move the cursor, but "yFe"
@@ -187,9 +192,9 @@ l or *l*
*$* *<End>* *<kEnd>*
$ or <End> To the end of the line. When a count is given also go
[count - 1] lines downward, or as far is possible.
- |inclusive| motion. If a count of 2 of larger is
+ |inclusive| motion. If a count of 2 or larger is
given and the cursor is on the last line, that is an
- error an the cursor doesn't move.
+ error and the cursor doesn't move.
In Visual mode the cursor goes to just after the last
character in the line.
When 'virtualedit' is active, "$" may move the cursor
diff --git a/runtime/doc/nvim_terminal_emulator.txt b/runtime/doc/nvim_terminal_emulator.txt
index 5885b20ab7..5ad69d1122 100644
--- a/runtime/doc/nvim_terminal_emulator.txt
+++ b/runtime/doc/nvim_terminal_emulator.txt
@@ -13,7 +13,7 @@ from the connected program.
Terminal buffers behave like normal buffers, except:
- With 'modifiable', lines can be edited but not deleted.
- 'scrollback' controls how many lines are kept.
-- Output is followed if the cursor is on the last line.
+- Output is followed ("tailed") if cursor is on the last line.
- 'modified' is the default. You can set 'nomodified' to avoid a warning when
closing the terminal buffer.
- 'bufhidden' defaults to "hide".
@@ -47,8 +47,9 @@ Input *terminal-input*
To send input, enter |Terminal-mode| using any command that would enter "insert
mode" in a normal buffer, such as |i| or |:startinsert|. In this mode all keys
-except <C-\><C-N> are sent to the underlying program. Use <C-\><C-N> to return
-to normal-mode. |CTRL-\_CTRL-N|
+except <C-\> are sent to the underlying program. If <C-\> is pressed, the
+next key is sent unless it is <C-N>. Use <C-\><C-N> to return to normal-mode.
+|CTRL-\_CTRL-N|
Terminal-mode forces these local options:
@@ -134,6 +135,10 @@ Example: >
programs can set this by emitting an escape sequence.
- |'channel'| Terminal PTY |job-id|. Can be used with |chansend()| to send
input to the terminal.
+- The |TermClose| event gives the terminal job exit code in the |v:event|
+ "status" field. For example, this autocmd closes terminal buffers if the job
+ exited without error: >
+ autocmd TermClose * if !v:event.status | exe 'bdelete! '..expand('<abuf>') | endif
Use |jobwait()| to check if the terminal job has finished: >
let running = jobwait([&channel], 0)[0] == -1
@@ -316,6 +321,34 @@ Other commands ~
isn't one
+Events ~
+ *termdebug-events*
+Four autocommands can be used: >
+ au User TermdebugStartPre echomsg 'debugging starting'
+ au User TermdebugStartPost echomsg 'debugging started'
+ au User TermdebugStopPre echomsg 'debugging stopping'
+ au User TermdebugStopPost echomsg 'debugging stopped'
+<
+ *TermdebugStartPre*
+TermdebugStartPre Before starting debugging.
+ Not triggered if the debugger is already
+ running or |g:termdebugger| cannot be
+ executed.
+ *TermdebugStartPost*
+TermdebugStartPost After debugging has initialized.
+ If a "!" bang is passed to `:Termdebug` or
+ `:TermdebugCommand` the event is triggered
+ before running the provided command in gdb.
+ *TermdebugStopPre*
+TermdebugStopPre Before debugging ends, when gdb is terminated,
+ most likely after issuing a "quit" command in
+ the gdb window.
+ *TermdebugStopPost*
+TermdebugStopPost After debugging has ended, gdb-related windows
+ are closed, debug buffers wiped out and
+ the state before the debugging was restored.
+
+
Prompt mode ~
*termdebug-prompt*
When on MS-Windows, gdb will run in a buffer with 'buftype' set to "prompt".
@@ -324,12 +357,10 @@ This works slightly differently:
mode with <Esc>, then you can move around in the buffer, copy/paste, etc.
Go back to editing the gdb command with any command that starts Insert mode,
such as `a` or `i`.
-- The program being debugged will run in a separate window. On MS-Windows
- this is a new console window. On Unix, if the |+terminal| feature is
- available a Terminal window will be opened to run the debugged program in.
+- A separate :terminal window will be opened to run the debugged program in.
*termdebug_use_prompt*
-Prompt mode can be used even when the |+terminal| feature is present with: >
+Prompt mode can be used with: >
let g:termdebug_use_prompt = 1
<
diff --git a/runtime/doc/options.txt b/runtime/doc/options.txt
index 791fb8664e..85be6eddaa 100644
--- a/runtime/doc/options.txt
+++ b/runtime/doc/options.txt
@@ -435,6 +435,15 @@ chance that a normal word like "lex:" is caught. There is one exception:
version 3.0). Using "ex:" at the start of the line will be ignored (this
could be short for "example:").
+If the modeline is disabled within a modeline, subsequent modelines will be
+ignored. This is to allow turning off modeline on a per-file basis. This is
+useful when a line looks like a modeline but isn't. For example, it would be
+good to start a YAML file containing strings like "vim:" with
+ # vim: nomodeline ~
+so as to avoid modeline misdetection. Following options on the same line
+after modeline deactivation, if any, are still evaluated (but you would
+normally not have any).
+
*modeline-local*
The options are set like with ":setlocal": The new value only applies to the
buffer and window that contain the file. Although it's possible to set global
@@ -824,12 +833,12 @@ A jump table for the options with a short description can be found at |Q_op|.
again not rename the file.
*'backupdir'* *'bdir'*
-'backupdir' 'bdir' string (default ".,$XDG_DATA_HOME/nvim/backup")
+'backupdir' 'bdir' string (default ".,$XDG_DATA_HOME/nvim/backup//")
global
List of directories for the backup file, separated with commas.
- The backup file will be created in the first directory in the list
- where this is possible. The directory must exist, Vim will not
- create it for you.
+ where this is possible. If none of the directories exist Nvim will
+ attempt to create the last directory in the list.
- Empty means that no backup file will be created ('patchmode' is
impossible!). Writing may fail because of this.
- A directory "." means to put the backup file in the same directory
@@ -1038,7 +1047,12 @@ A jump table for the options with a short description can be found at |Q_op|.
continuation (positive).
sbr Display the 'showbreak' value before applying the
additional indent.
- The default value for min is 20 and shift is 0.
+ list:{n} Adds an additional indent for lines that match a
+ numbered or bulleted list (using the
+ 'formatlistpat' setting).
+ list:-1 Uses the length of a match with 'formatlistpat'
+ for indentation.
+ The default value for min is 20, shift and list is 0.
*'browsedir'* *'bsdir'*
'browsedir' 'bsdir' string (default: "last")
@@ -1802,13 +1816,30 @@ A jump table for the options with a short description can be found at |Q_op|.
*'cursorline'* *'cul'* *'nocursorline'* *'nocul'*
'cursorline' 'cul' boolean (default off)
local to window
- Highlight the screen line of the cursor with CursorLine
- |hl-CursorLine|. Useful to easily spot the cursor. Will make screen
- redrawing slower.
+ Highlight the text line of the cursor with CursorLine |hl-CursorLine|.
+ Useful to easily spot the cursor. Will make screen redrawing slower.
When Visual mode is active the highlighting isn't used to make it
easier to see the selected text.
+ *'cursorlineopt'* *'culopt'*
+'cursorlineopt' 'culopt' string (default: "number,line")
+ local to window
+ Comma separated list of settings for how 'cursorline' is displayed.
+ Valid values:
+ "line" Highlight the text line of the cursor with
+ CursorLine |hl-CursorLine|.
+ "screenline" Highlight only the screen line of the cursor with
+ CursorLine |hl-CursorLine|.
+ "number" Highlight the line number of the cursor with
+ CursorLineNr |hl-CursorLineNr|.
+
+ Special value:
+ "both" Alias for the values "line,number".
+
+ "line" and "screenline" cannot be used together.
+
+
*'debug'*
'debug' string (default "")
global
@@ -2138,8 +2169,7 @@ A jump table for the options with a short description can be found at |Q_op|.
global or local to buffer |global-local|
External program to use for "=" command. When this option is empty
the internal formatting functions are used; either 'lisp', 'cindent'
- or 'indentexpr'. When Vim was compiled without internal formatting,
- the "indent" program is used.
+ or 'indentexpr'.
Environment variables are expanded |:set_env|. See |option-backslash|
about including spaces and backslashes.
This option cannot be set from a |modeline| or in the |sandbox|, for
@@ -3057,19 +3087,18 @@ A jump table for the options with a short description can be found at |Q_op|.
See |help-translated|.
*'hidden'* *'hid'* *'nohidden'* *'nohid'*
-'hidden' 'hid' boolean (default off)
- global
- When off a buffer is unloaded when it is |abandon|ed. When on a
- buffer becomes hidden when it is |abandon|ed. If the buffer is still
- displayed in another window, it does not become hidden, of course.
- The commands that move through the buffer list sometimes make a buffer
- hidden although the 'hidden' option is off: When the buffer is
- modified, 'autowrite' is off or writing is not possible, and the '!'
- flag was used. See also |windows.txt|.
- To only make one buffer hidden use the 'bufhidden' option.
- This option is set for one command with ":hide {command}" |:hide|.
- WARNING: It's easy to forget that you have changes in hidden buffers.
- Think twice when using ":q!" or ":qa!".
+'hidden' 'hid' boolean (default on)
+ global
+ When off a buffer is unloaded (including loss of undo information)
+ when it is |abandon|ed. When on a buffer becomes hidden when it is
+ |abandon|ed. A buffer displayed in another window does not become
+ hidden, of course.
+ Commands that move through the buffer list sometimes hide a buffer
+ although the 'hidden' option is off: when the buffer is modified,
+ 'autowrite' is off or writing is not possible, and the '!' flag was
+ used. See also |windows|.
+ To hide a specific buffer use the 'bufhidden' option.
+ 'hidden' is set for one command with ":hide {command}" |:hide|.
*'history'* *'hi'*
'history' 'hi' number (Vim default: 10000, Vi default: 0)
@@ -3192,7 +3221,7 @@ A jump table for the options with a short description can be found at |Q_op|.
option to a valid keymap name.
*'inccommand'* *'icm'*
-'inccommand' 'icm' string (default "")
+'inccommand' 'icm' string (default "nosplit")
global
"nosplit": Shows the effects of a command incrementally, as you type.
@@ -3477,7 +3506,7 @@ A jump table for the options with a short description can be found at |Q_op|.
|jumplist-stack|
*'joinspaces'* *'js'* *'nojoinspaces'* *'nojs'*
-'joinspaces' 'js' boolean (default on)
+'joinspaces' 'js' boolean (default off)
global
Insert two spaces after a '.', '?' and '!' with a join command.
Otherwise only one space is inserted.
@@ -3722,16 +3751,25 @@ A jump table for the options with a short description can be found at |Q_op|.
*lcs-space*
space:c Character to show for a space. When omitted, spaces
are left blank.
+ *lcs-multispace*
+ multispace:c...
+ One or more characters to use cyclically to show for
+ multiple consecutive spaces. Overrides the "space"
+ setting, except for single spaces. When omitted, the
+ "space" setting is used. For example,
+ `:set listchars=multispace:---+` shows ten consecutive
+ spaces as:
+ ---+---+--
*lcs-lead*
lead:c Character to show for leading spaces. When omitted,
- leading spaces are blank. Overrides the "space"
- setting for leading spaces. You can combine it with
- "tab:", for example: >
+ leading spaces are blank. Overrides the "space" and
+ "multispace" settings for leading spaces. You can
+ combine it with "tab:", for example: >
:set listchars+=tab:>-,lead:.
< *lcs-trail*
trail:c Character to show for trailing spaces. When omitted,
- trailing spaces are blank. Overrides the "space"
- setting for trailing spaces.
+ trailing spaces are blank. Overrides the "space" and
+ "multispace" settings for trailing spaces.
*lcs-extends*
extends:c Character to show in the last column, when 'wrap' is
off and the line continues beyond the right of the
@@ -3756,7 +3794,8 @@ A jump table for the options with a short description can be found at |Q_op|.
:set lcs=tab:>-,eol:<,nbsp:%
:set lcs=extends:>,precedes:<
< |hl-NonText| highlighting will be used for "eol", "extends" and
- "precedes". |hl-Whitespace| for "nbsp", "space", "tab" and "trail".
+ "precedes". |hl-Whitespace| for "nbsp", "space", "tab", "multispace",
+ "lead" and "trail".
*'lpl'* *'nolpl'* *'loadplugins'* *'noloadplugins'*
'loadplugins' 'lpl' boolean (default on)
@@ -3777,8 +3816,6 @@ A jump table for the options with a short description can be found at |Q_op|.
Only switch it off when working with old Vi scripts. In any other
situation write patterns that work when 'magic' is on. Include "\M"
when you want to |/\M|.
- In |Vim9| script the value of 'magic' is ignored, patterns behave like
- it is always set.
*'makeef'* *'mef'*
'makeef' 'mef' string (default: "")
@@ -4301,7 +4338,7 @@ A jump table for the options with a short description can be found at |Q_op|.
*'packpath'* *'pp'*
'packpath' 'pp' string (default: see 'runtimepath')
- Directories used to find packages. See |packages|.
+ Directories used to find packages. See |packages| and |rtp-packages|.
*'paragraphs'* *'para'*
@@ -4332,19 +4369,21 @@ A jump table for the options with a short description can be found at |Q_op|.
- abbreviations are disabled
- 'autoindent' is reset
- 'expandtab' is reset
- - 'formatoptions' is used like it is empty
+ - 'hkmap' is reset
- 'revins' is reset
- 'ruler' is reset
- 'showmatch' is reset
- - 'smartindent' is reset
- 'smarttab' is reset
- 'softtabstop' is set to 0
- 'textwidth' is set to 0
- 'wrapmargin' is set to 0
+ - 'varsofttabstop' is made empty
These options keep their value, but their effect is disabled:
- 'cindent'
+ - 'formatoptions' is used like it is empty
- 'indentexpr'
- 'lisp'
+ - 'smartindent'
NOTE: When you start editing another file while the 'paste' option is
on, settings from the modelines or autocommands may change the
settings again, causing trouble when pasting text. You might want to
@@ -4540,11 +4579,6 @@ A jump table for the options with a short description can be found at |Q_op|.
List of items that control the format of the output of |:hardcopy|.
See |popt-option|.
- *'prompt'* *'noprompt'*
-'prompt' boolean (default on)
- global
- When on a ":" prompt is used in Ex mode.
-
*'pumblend'* *'pb'*
'pumblend' 'pb' number (default 0)
global
@@ -4863,9 +4897,11 @@ A jump table for the options with a short description can be found at |Q_op|.
ordering. This is for preferences to overrule or add to the
distributed defaults or system-wide settings (rarely needed).
- More entries are added when using |packages|. If it gets very long
- then `:set rtp` will be truncated, use `:echo &rtp` to see the full
- string.
+ *rtp-packages*
+ "start" packages will additionally be used to search for runtime files
+ after these, but package entries are not visible in `:set rtp`.
+ See |runtime-search-path| for more information. "opt" packages
+ will be explicitly added to &rtp when |:packadd| is used.
Note that, unlike 'path', no wildcards like "**" are allowed. Normal
wildcards are allowed, but can significantly slow down searching for
@@ -5459,7 +5495,7 @@ A jump table for the options with a short description can be found at |Q_op|.
*'showbreak'* *'sbr'* *E595*
'showbreak' 'sbr' string (default "")
- global
+ global or local to window |global-local|
String to put at the start of lines that have been wrapped. Useful
values are "> " or "+++ ": >
:set showbreak=>\
@@ -5473,7 +5509,10 @@ A jump table for the options with a short description can be found at |Q_op|.
Note that tabs after the showbreak will be displayed differently.
If you want the 'showbreak' to appear in between line numbers, add the
"n" flag to 'cpoptions'.
-
+ A window-local value overrules a global value. If the global value is
+ set and you want no value in the current window use NONE: >
+ :setlocal showbreak=NONE
+<
*'showcmd'* *'sc'* *'noshowcmd'* *'nosc'*
'showcmd' 'sc' boolean (Vim default: on, Vi default: off)
global
@@ -5733,6 +5772,8 @@ A jump table for the options with a short description can be found at |Q_op|.
If the name "cjk" is included East Asian characters are excluded from
spell checking. This is useful when editing text that also has Asian
words.
+ Note that the "medical" dictionary does not exist, it is just an
+ example of a longer name.
*E757*
As a special case the name of a .spl file can be given as-is. The
first "_xx" in the name is removed and used as the region name
@@ -6100,9 +6141,11 @@ A jump table for the options with a short description can be found at |Q_op|.
specify special kinds of buffers. See |special-buffers|.
*'switchbuf'* *'swb'*
-'switchbuf' 'swb' string (default "")
+'switchbuf' 'swb' string (default "uselast")
global
This option controls the behavior when switching between buffers.
+ Mostly for |quickfix| commands some values are also used for other
+ commands, as mentioned below.
Possible values (comma separated list):
useopen If included, jump to the first open window that
contains the specified buffer (if there is one).
@@ -6518,17 +6561,17 @@ A jump table for the options with a short description can be found at |Q_op|.
'ttyfast' 'tf' Removed. |vim-differences|
*'undodir'* *'udir'* *E5003*
-'undodir' 'udir' string (default "$XDG_DATA_HOME/nvim/undo")
+'undodir' 'udir' string (default "$XDG_DATA_HOME/nvim/undo//")
global
List of directory names for undo files, separated with commas.
- See |'backupdir'| for details of the format.
+ See 'backupdir' for details of the format.
"." means using the directory of the file. The undo file name for
"file.txt" is ".file.txt.un~".
For other directories the file name is the full path of the edited
file, with path separators replaced with "%".
When writing: The first directory that exists is used. "." always
- works, no directories after "." will be used for writing. If none of
- the directories exist Neovim will attempt to create last directory in
+ works, no directories after "." will be used for writing. If none of
+ the directories exist Nvim will attempt to create the last directory in
the list.
When reading all entries are tried to find an undo file. The first
undo file that exists is used. When it cannot be read an error is
@@ -6537,6 +6580,10 @@ A jump table for the options with a short description can be found at |Q_op|.
This option cannot be set from a |modeline| or in the |sandbox|, for
security reasons.
+ Note that unlike 'directory' and 'backupdir', 'undodir' always acts as
+ though the trailing slashes are present (see 'backupdir' for what this
+ means).
+
*'undofile'* *'noundofile'* *'udf'* *'noudf'*
'undofile' 'udf' boolean (default off)
local to buffer
@@ -6677,14 +6724,14 @@ A jump table for the options with a short description can be found at |Q_op|.
displayed when 'verbosefile' is set.
*'viewdir'* *'vdir'*
-'viewdir' 'vdir' string (default: "$XDG_DATA_HOME/nvim/view")
+'viewdir' 'vdir' string (default: "$XDG_DATA_HOME/nvim/view//")
global
Name of the directory where to store files for |:mkview|.
This option cannot be set from a |modeline| or in the |sandbox|, for
security reasons.
*'viewoptions'* *'vop'*
-'viewoptions' 'vop' string (default: "folds,options,cursor,curdir")
+'viewoptions' 'vop' string (default: "folds,cursor,curdir")
global
Changes the effect of the |:mkview| command. It is a comma separated
list of words. Each word enables saving and restoring something:
@@ -6723,6 +6770,7 @@ A jump table for the options with a short description can be found at |Q_op|.
The `g$` command will move to the end of the screen line.
It doesn't make sense to combine "all" with "onemore", but you will
not get a warning for it.
+ When combined with other words, "none" is ignored.
*'visualbell'* *'vb'* *'novisualbell'* *'novb'* *beep*
'visualbell' 'vb' boolean (default off)
@@ -6773,8 +6821,9 @@ A jump table for the options with a short description can be found at |Q_op|.
More info here: |cmdline-completion|.
The character is not recognized when used inside a macro. See
'wildcharm' for that.
+ Some keys will not work, such as CTRL-C, <CR> and Enter.
Although 'wc' is a number option, you can set it to a special key: >
- :set wc=<Esc>
+ :set wc=<Tab>
<
*'wildcharm'* *'wcm'*
@@ -7093,8 +7142,7 @@ A jump table for the options with a short description can be found at |Q_op|.
Allows writing to any file with no need for "!" override.
*'writebackup'* *'wb'* *'nowritebackup'* *'nowb'*
-'writebackup' 'wb' boolean (default on with |+writebackup| feature, off
- otherwise)
+'writebackup' 'wb' boolean (default on)
global
Make a backup before overwriting a file. The backup is removed after
the file was successfully written, unless the 'backup' option is
diff --git a/runtime/doc/pattern.txt b/runtime/doc/pattern.txt
index e74f3b72bf..c49cc6d540 100644
--- a/runtime/doc/pattern.txt
+++ b/runtime/doc/pattern.txt
@@ -1204,7 +1204,7 @@ x A single character, with no special meaning, matches itself
\%d123 Matches the character specified with a decimal number. Must be
followed by a non-digit.
-\%o40 Matches the character specified with an octal number up to 0377.
+\%o40 Matches the character specified with an octal number up to 0o377.
Numbers below 0o40 must be followed by a non-octal digit or a
non-digit.
\%x2a Matches the character specified with up to two hexadecimal characters.
diff --git a/runtime/doc/pi_netrw.txt b/runtime/doc/pi_netrw.txt
index 4b61cd4c25..3ac61be6f2 100644
--- a/runtime/doc/pi_netrw.txt
+++ b/runtime/doc/pi_netrw.txt
@@ -54,6 +54,7 @@ Copyright: Copyright (C) 2017 Charles E Campbell *netrw-copyright*
Browsing With A Horizontally Split Window...........|netrw-o|
Browsing With A New Tab.............................|netrw-t|
Browsing With A Vertically Split Window.............|netrw-v|
+ Change File Permission..............................|netrw-gp|
Change Listing Style.(thin wide long tree)..........|netrw-i|
Changing To A Bookmarked Directory..................|netrw-gb|
Changing To A Predecessor Directory.................|netrw-u|
@@ -1095,6 +1096,7 @@ QUICK REFERENCE: MAPS *netrw-browse-maps* {{{2
gf Force treatment as file |netrw-gf|
gh Quick hide/unhide of dot-files |netrw-gh|
gn Make top of tree the directory below the cursor |netrw-gn|
+ gp Change local-only file permissions |netrw-gp|
i Cycle between thin, long, wide, and tree listings |netrw-i|
I Toggle the displaying of the banner |netrw-I|
mb Bookmark current directory |netrw-mb|
@@ -1510,6 +1512,8 @@ Netrw determines which special handler by the following method:
If g:netrw_browsex_viewer == '-', then netrwFileHandlers#Invoke() will be
used instead (see |netrw_filehandler|).
+ If the viewer you wish to use does not support handling of a remote URL
+ directory, set |g:netrw_browsex_support_remote| to 0.
* for Windows 32 or 64, the URL and FileProtocolHandler dlls are used.
* for Gnome (with gnome-open): gnome-open is used.
* for KDE (with kfmclient) : kfmclient is used
@@ -2104,8 +2108,8 @@ the two directories the same, use the "cd" map (type cd). That map will
set Vim's notion of the current directory to netrw's current browsing
directory.
-|netrw-cd|: This map's name was changed from "c" to cd (see |netrw-cd|).
- This change was done to allow for |netrw-cb| and |netrw-cB| maps.
+|netrw-cd| : This map's name was changed from "c" to cd (see |netrw-cd|).
+ This change was done to allow for |netrw-cb| and |netrw-cB| maps.
Associated setting variable: |g:netrw_keepdir|
@@ -2607,13 +2611,29 @@ your browsing preferences. (see also: |netrw-settings|)
a script/function to handle the given
extension. (see |netrw_filehandler|).
+ *g:netrw_browsex_support_remote*
+ specify if the specified viewer supports a
+ remote URL. (see |netrw-handler|).
+
*g:netrw_chgperm* Unix/Linux: "chmod PERM FILENAME"
Windows: "cacls FILENAME /e /p PERM"
Used to change access permission for a file.
+ *g:netrw_clipboard* =1
+ By default, netrw will attempt to insure that
+ the clipboard's values will remain unchanged.
+ However, some users report that they have
+ speed problems with this; consequently, this
+ option, when set to zero, lets such users
+ prevent netrw from saving and restoring the
+ clipboard (the latter is done only as needed).
+ That means that if the clipboard is changed
+ (inadvertently) by normal netrw operation that
+ it will not be restored to its prior state.
+
*g:netrw_compress* ="gzip"
- Will compress marked files with this
- command
+ Will compress marked files with this
+ command
*g:Netrw_corehandler* Allows one to specify something additional
to do when handling <core> files via netrw's
@@ -2639,12 +2659,23 @@ your browsing preferences. (see also: |netrw-settings|)
=2 cul u-cuc cul u-cuc
=3 cul u-cuc cul cuc
=4 cul cuc cul cuc
+ =5 U-cul U-cuc U-cul U-cuc
+ =6 U-cul U-cuc cul U-cuc
+ =7 cul U-cuc cul U-cuc
+ =8 cul U-cuc cul cuc
Where
- u-cul : user's |'cursorline'| setting used
- u-cuc : user's |'cursorcolumn'| setting used
- cul : |'cursorline'| locally set
- cuc : |'cursorcolumn'| locally set
+ u-cul : user's |'cursorline'| initial setting used
+ u-cuc : user's |'cursorcolumn'| initial setting used
+ U-cul : user's |'cursorline'| current setting used
+ U-cuc : user's |'cursorcolumn'| current setting used
+ cul : |'cursorline'| will be locally set
+ cuc : |'cursorcolumn'| will be locally set
+
+ The "initial setting" means the values of
+ the |'cuc'| and |'cul'| settings in effect when
+ netrw last saw |g:netrw_cursor| >= 5 or when
+ netrw was initially run.
*g:netrw_decompress* = { ".gz" : "gunzip" ,
".bz2" : "bunzip2" ,
@@ -2654,7 +2685,7 @@ your browsing preferences. (see also: |netrw-settings|)
decompression programs.
*g:netrw_dirhistmax* =10: controls maximum quantity of past
- history. May be zero to supppress
+ history. May be zero to suppress
history.
(related: |netrw-qb| |netrw-u| |netrw-U|)
@@ -3141,6 +3172,9 @@ To open a new file in netrw's current directory, press "%". This map
will query the user for a new filename; an empty file by that name will
be placed in the netrw's current directory (ie. b:netrw_curdir).
+If Lexplore (|netrw-:Lexplore|) is in use, the new file will be generated
+in the |g:netrw_chgwin| window.
+
Related topics: |netrw-d|
@@ -3876,6 +3910,32 @@ netrw:
==============================================================================
12. History *netrw-history* {{{1
+ v171: Oct 09, 2020 * included code in s:NetrwOptionsSafe()
+ to allow |'bh'| to be set to delete when
+ rather than hide when g:netrw_fastbrowse
+ was zero.
+ * Installed |g:netrw_clipboard| setting
+ * Installed option bypass for |'guioptions'|
+ a/A settings
+ * Changed popup_beval() to |popup_atcursor|()
+ in netrw#ErrorMsg (lacygoill). Apparently
+ popup_beval doesn't reliably close the
+ popup when the mouse is moved.
+ * VimEnter() now using win_execute to examine
+ buffers for an attempt to open a directory.
+ Avoids issues with popups/terminal from
+ command line. (lacygoill)
+ Jun 28, 2021 * (zeertzjq) provided a patch for use of
+ xmap,xno instead of vmap,vno in
+ netrwPlugin.vim. Avoids entanglement with
+ select mode.
+ Jul 14, 2021 * Fixed problem addressed by tst976; opening
+ a file using tree mode, going up a
+ directory, and opening a file there was
+ opening the file in the wrong directory.
+ Jul 28, 2021 * (Ingo Karkat) provided a patch fixing an
+ E488 error with netrwPlugin.vim
+ (occurred for vim versions < 8.02)
v170: Mar 11, 2020 * (reported by Reiner Herrmann) netrw+tree
would not hide with the ^\..* pattern
correctly.
@@ -3892,7 +3952,7 @@ netrw:
Jun 07, 2020 * (reported by Jo Totland) repeatedly invoking
:Lexplore and quitting it left unused
hidden buffers. Netrw will now set netrw
- buffers created by :Lexplore to |bh|=wipe.
+ buffers created by :Lexplore to |'bh'|=wipe.
v169: Dec 20, 2019 * (reported by amkarthik) that netrw's x
(|netrw-x|) would throw an error when
attempting to open a local directory.
diff --git a/runtime/doc/print.txt b/runtime/doc/print.txt
index e7de5b9ee3..d9320ad315 100644
--- a/runtime/doc/print.txt
+++ b/runtime/doc/print.txt
@@ -103,10 +103,9 @@ will use the "latin1" print character encoding file.
When 'encoding' is set to a multibyte encoding, Vim will try to convert
characters to the printing encoding for printing (if 'printencoding' is empty
-then the conversion will be to latin1). Conversion to a printing encoding
-other than latin1 will require Vim to be compiled with the |+iconv| feature.
-If no conversion is possible then printing will fail. Any characters that
-cannot be converted will be replaced with upside down question marks.
+then the conversion will be to latin1). If no conversion is possible then
+printing will fail. Any characters that cannot be converted will be replaced
+with upside down question marks.
Two print character encoding files are provided to support default Mac and
HPUX character encodings and are used by default on these platforms. Code page
@@ -176,9 +175,7 @@ the font. When omitted, the point size is 10.
'printheader' 'pheader' string (default "%<%f%h%m%=Page %N")
global
This defines the format of the header produced in |:hardcopy| output. The
-option is defined in the same way as the 'statusline' option. If Vim has not
-been compiled with the |+statusline| feature, this option has no effect and a
-simple default header is used, which shows the page number. The same simple
+option is defined in the same way as the 'statusline' option. The same simple
header is used when this option is empty.
*pmbcs-option*
diff --git a/runtime/doc/provider.txt b/runtime/doc/provider.txt
index be895f9e4e..b785010699 100644
--- a/runtime/doc/provider.txt
+++ b/runtime/doc/provider.txt
@@ -207,6 +207,7 @@ registers. Nvim looks for these clipboard tools, in order of priority:
- lemonade (for SSH) https://github.com/pocke/lemonade
- doitclient (for SSH) http://www.chiark.greenend.org.uk/~sgtatham/doit/
- win32yank (Windows)
+ - termux (via termux-clipboard-set, termux-clipboard-set)
- tmux (if $TMUX is set)
*g:clipboard*
diff --git a/runtime/doc/quickfix.txt b/runtime/doc/quickfix.txt
index 563fb0c962..9c1f584415 100644
--- a/runtime/doc/quickfix.txt
+++ b/runtime/doc/quickfix.txt
@@ -1333,7 +1333,8 @@ Basic items
%o module name (finds a string)
%l line number (finds a number)
%c column number (finds a number representing character
- column of the error, (1 <tab> == 1 character column))
+ column of the error, byte index, a <tab> is 1
+ character column)
%v virtual column number (finds a number representing
screen column of the error (1 <tab> == 8 screen
columns))
diff --git a/runtime/doc/quickref.txt b/runtime/doc/quickref.txt
index fb20a583c9..77e69a3eea 100644
--- a/runtime/doc/quickref.txt
+++ b/runtime/doc/quickref.txt
@@ -659,6 +659,7 @@ Short explanation of each option: *option-list*
'cursorbind' 'crb' move cursor in window as it moves in other windows
'cursorcolumn' 'cuc' highlight the screen column of the cursor
'cursorline' 'cul' highlight the screen line of the cursor
+'cursorlineopt' 'culopt' settings for 'cursorline'
'debug' set to "msg" to see all error messages
'define' 'def' pattern to be used to find a macro definition
'delcombine' 'deco' delete combining characters on their own
@@ -809,7 +810,6 @@ Short explanation of each option: *option-list*
'printmbcharset' 'pmbcs' CJK character set to be used for :hardcopy
'printmbfont' 'pmbfn' font names to be used for CJK output of :hardcopy
'printoptions' 'popt' controls the format of :hardcopy output
-'prompt' 'prompt' enable prompt in Ex mode
'pumheight' 'ph' maximum height of the popup menu
'pumwidth' 'pw' minimum width of the popup menu
'pythondll' name of the Python 2 dynamic library
diff --git a/runtime/doc/remote.txt b/runtime/doc/remote.txt
deleted file mode 100644
index 6c2ceb45be..0000000000
--- a/runtime/doc/remote.txt
+++ /dev/null
@@ -1,189 +0,0 @@
-*remote.txt* Nvim
-
-
- VIM REFERENCE MANUAL by Bram Moolenaar
-
-
-Vim client-server communication *client-server*
-
- Type |gO| to see the table of contents.
-
-==============================================================================
-1. Common functionality *clientserver*
-
-When compiled with the |+clientserver| option, Vim can act as a command
-server. It accepts messages from a client and executes them. At the same
-time, Vim can function as a client and send commands to a Vim server.
-
-The following command line arguments are available:
-
- argument meaning ~
-
- --remote [+{cmd}] {file} ... *--remote*
- Open the file list in a remote Vim. When
- there is no Vim server, execute locally.
- There is one optional init command: +{cmd}.
- This must be an Ex command that can be
- followed by "|".
- The rest of the command line is taken as the
- file list. Thus any non-file arguments must
- come before this.
- You cannot edit stdin this way |--|.
- The remote Vim is raised. If you don't want
- this use >
- vim --remote-send "<C-\><C-N>:n filename<CR>"
-<
- --remote-silent [+{cmd}] {file} ... *--remote-silent*
- As above, but don't complain if there is no
- server and the file is edited locally.
- --remote-wait [+{cmd}] {file} ... *--remote-wait*
- As --remote, but wait for files to complete
- (unload) in remote Vim.
- --remote-wait-silent [+{cmd}] {file} ... *--remote-wait-silent*
- As --remote-wait, but don't complain if there
- is no server.
- *--remote-tab*
- --remote-tab Like --remote but open each file in a new
- tabpage.
- *--remote-tab-silent*
- --remote-tab-silent Like --remote-silent but open each file in a
- new tabpage.
- *--remote-tab-wait*
- --remote-tab-wait Like --remote-wait but open each file in a new
- tabpage.
-
- *--remote-tab-wait-silent*
- --remote-tab-wait-silent Like --remote-wait-silent but open each file
- in a new tabpage.
- *--remote-send*
- --remote-send {keys} Send {keys} to server and exit. The {keys}
- are not mapped. Special key names are
- recognized, e.g., "<CR>" results in a CR
- character.
- *--remote-expr*
- --remote-expr {expr} Evaluate {expr} in server and print the result
- on stdout.
-
-Examples ~
-
-Edit "file.txt" in an already running GVIM server: >
- gvim --remote file.txt
-
-Edit "file.txt" in an already running server called FOOBAR: >
- gvim --servername FOOBAR --remote file.txt
-
-Edit "file.txt" in server "FILES" if it exists, become server "FILES"
-otherwise: >
- gvim --servername FILES --remote-silent file.txt
-
-This doesn't work, all arguments after --remote will be used as file names: >
- gvim --remote --servername FOOBAR file.txt
-
-Edit file "+foo" in a remote server (note the use of "./" to avoid the special
-meaning of the leading plus): >
- vim --remote ./+foo
-
-Tell the remote server "BLA" to write all files and exit: >
- vim --servername BLA --remote-send '<C-\><C-N>:wqa<CR>'
-
-
-SERVER NAME *client-server-name*
-
-By default Vim will try to register the name under which it was invoked (gvim,
-egvim ...). This can be overridden with the --servername argument. If the
-specified name is not available, a postfix is applied until a free name is
-encountered, i.e. "gvim1" for the second invocation of gvim on a particular
-X-server. The resulting name is available in the servername builtin variable
-|v:servername|. The case of the server name is ignored, thus "gvim" and
-"GVIM" are considered equal.
-
-When Vim is invoked with --remote, --remote-wait or --remote-send it will try
-to locate the server name determined by the invocation name and --servername
-argument as described above. If an exact match is not available, the first
-server with the number postfix will be used. If a name with the number
-postfix is specified with the --servername argument, it must match exactly.
-
-If no server can be located and --remote or --remote-wait was used, Vim will
-start up according to the rest of the command line and do the editing by
-itself. This way it is not necessary to know whether gvim is already started
-when sending command to it.
-
-The --serverlist argument will cause Vim to print a list of registered command
-servers on the standard output (stdout) and exit.
-
-Win32 Note: Making the Vim server go to the foreground doesn't always work,
-because MS-Windows doesn't allow it. The client will move the server to the
-foreground when using the --remote or --remote-wait argument and the server
-name starts with "g".
-
-
-REMOTE EDITING
-
-The --remote argument will cause a |:drop| command to be constructed from the
-rest of the command line and sent as described above.
-The --remote-wait argument does the same thing and additionally sets up to
-wait for each of the files to have been edited. This uses the BufUnload
-event, thus as soon as a file has been unloaded, Vim assumes you are done
-editing it.
-Note that the --remote and --remote-wait arguments will consume the rest of
-the command line. I.e. all remaining arguments will be regarded as filenames.
-You can not put options there!
-
-
-FUNCTIONS
- *E240* *E573*
-There are a number of Vim functions for scripting the command server. See
-the description in |eval.txt| or use CTRL-] on the function name to jump to
-the full explanation.
-
- synopsis explanation ~
- remote_startserver( name) run a server
- remote_expr( server, string, idvar) send expression
- remote_send( server, string, idvar) send key sequence
- serverlist() get a list of available servers
- remote_peek( serverid, retvar) check for reply string
- remote_read( serverid) read reply string
- server2client( serverid, string) send reply string
- remote_foreground( server) bring server to the front
-
-See also the explanation of |CTRL-\_CTRL-N|. Very useful as a leading key
-sequence.
-The {serverid} for server2client() can be obtained with expand("<client>")
-
-==============================================================================
-2. X11 specific items *x11-clientserver*
- *E247* *E248* *E251* *E258* *E277*
-
-The communication between client and server goes through the X server. The
-display of the Vim server must be specified. The usual protection of the X
-server is used, you must be able to open a window on the X server for the
-communication to work. It is possible to communicate between different
-systems.
-
-By default, a GUI Vim will register a name on the X-server by which it can be
-addressed for subsequent execution of injected strings. Vim can also act as
-a client and send strings to other instances of Vim on the same X11 display.
-
-When an X11 GUI Vim (gvim) is started, it will try to register a send-server
-name on the 'VimRegistry' property on the root window.
-
-An empty --servername argument will cause the command server to be disabled.
-
-To send commands to a Vim server from another application, read the source
-file src/if_xcmdsrv.c, it contains some hints about the protocol used.
-
-==============================================================================
-3. Win32 specific items *w32-clientserver*
-
-Every Win32 Vim can work as a server, also in the console. You do not need a
-version compiled with OLE. Windows messages are used, this works on any
-version of MS-Windows. But only communication within one system is possible.
-
-Since MS-Windows messages are used, any other application should be able to
-communicate with a Vim server.
-
-When using gvim, the --remote-wait only works properly this way: >
-
- start /w gvim --remote-wait file.txt
-<
- vim:tw=78:sw=4:ts=8:noet:ft=help:norl:
diff --git a/runtime/doc/repeat.txt b/runtime/doc/repeat.txt
index 6755747dcf..7e8d93aa71 100644
--- a/runtime/doc/repeat.txt
+++ b/runtime/doc/repeat.txt
@@ -172,47 +172,42 @@ Using Vim scripts *using-scripts*
For writing a Vim script, see chapter 41 of the user manual |usr_41.txt|.
*:so* *:source* *load-vim-script*
-:so[urce] {file} Runs vim or lua {file}
+:[range]so[urce] [file] Runs |Ex| commands or Lua code (".lua" files) from
+ [file], or from the current buffer if no [file] is
+ given.
Triggers the |SourcePre| autocommand.
-
- Note: Only files ending with `.lua` is sourced as
- lua file. Anything else is assumed to be vimscript.
*:source!*
-:so[urce]! {file} Read Vim commands from {file}. These are commands
- that are executed from Normal mode, like you type
- them.
- When used after |:global|, |:argdo|, |:windo|,
- |:bufdo|, in a loop or when another command follows
- the display won't be updated while executing the
- commands.
- Cannot be used in the |sandbox|.
+:[range]so[urce]! {file}
+ Runs |Normal-mode| commands from {file}. When used
+ after |:global|, |:argdo|, |:windo|, |:bufdo|, in
+ a loop or when another command follows the display
+ won't be updated while executing the commands.
*:ru* *:runtime*
:ru[ntime][!] [where] {file} ..
- Source vim/lua {file} in each directory given by
- 'runtimepath' and/or 'packpath'. The vim files are
- executed in same mannar as |:source| and lua files
- similarly as |:luafile|. There is no error
- for non-existing files.
+ Sources |Ex| commands or Lua code (".lua" files) read
+ from {file} (a relative path) in each directory given
+ by 'runtimepath' and/or 'packpath'.
+ Ignores non-existing files.
Example: >
:runtime syntax/c.vim
+ :runtime syntax/c.lua
-< There can be multiple {file} arguments, separated by
- spaces. Each {file} is searched for in the first
+< There can be multiple space-separated {file}
+ arguments. Each {file} is searched for in the first
directory from 'runtimepath', then in the second
- directory, etc. Use a backslash to include a space
- inside {file} (although it's better not to use spaces
- in file names, it causes trouble).
+ directory, etc.
When [!] is included, all found files are sourced.
- When it is not included only the first found file is
- sourced.
+ Else only the first found file is sourced.
- When [where] is omitted only 'runtimepath' is used.
+ When [where] is omitted, first 'runtimepath' is
+ searched, then directories under "start" in 'packpath'
+ are searched.
Other values:
- START search under "start" in 'packpath'
- OPT search under "opt" in 'packpath'
+ START search only under "start" in 'packpath'
+ OPT search only under "opt" in 'packpath'
PACK search under "start" and "opt" in
'packpath'
ALL first use 'runtimepath', then search
@@ -263,7 +258,9 @@ For writing a Vim script, see chapter 41 of the user manual |usr_41.txt|.
ftdetect scripts are loaded, only the matching
directories are added to 'runtimepath'. This is
useful in your .vimrc. The plugins will then be
- loaded during initialization, see |load-plugins|.
+ loaded during initialization, see |load-plugins| (note
+ that the loading order will be reversed, because each
+ directory is inserted before others).
Note that for ftdetect scripts to be loaded
you will need to write `filetype plugin indent on`
AFTER all `packadd!` commands.
@@ -519,16 +516,26 @@ You would now have these files under ~/.local/share/nvim/site:
pack/foo/start/foobar/syntax/some.vim
pack/foo/opt/foodebug/plugin/debugger.vim
-When Vim starts up, after processing your .vimrc, it scans all directories in
-'packpath' for plugins under the "pack/*/start" directory. First all those
-directories are added to 'runtimepath'. Then all the plugins are loaded.
-See |packload-two-steps| for how these two steps can be useful.
+ *runtime-search-path*
+When runtime files are searched for, first all paths in 'runtimepath' are
+searched, then all "pack/*/start/*" dirs are searched. However, package entries
+are not visible in `:set rtp` or `echo &rtp`, as the final concatenated path
+would be too long and get truncated. To list all used directories, use
+|nvim_list_runtime_paths()|. In addition |nvim_get_runtime_file()| can be used
+to query for specific files or sub-folders within the runtime path. For
+instance to list all runtime dirs and packages with lua paths, use >
+
+ :echo nvim_get_runtime_file("lua/", v:true)
+
+<When Vim starts up, after processing your .vimrc, it scans all directories in
+'packpath' for plugins under the "pack/*/start" directory, and all the plugins
+are loaded.
-In the example Vim will find "pack/foo/start/foobar/plugin/foo.vim" and adds
-"~/.local/share/nvim/site/pack/foo/start/foobar" to 'runtimepath'.
+In the example Vim will find "pack/foo/start/foobar/plugin/foo.vim" and load it.
If the "foobar" plugin kicks in and sets the 'filetype' to "some", Vim will
-find the syntax/some.vim file, because its directory is in 'runtimepath'.
+find the syntax/some.vim file, because its directory is in the runtime search
+path.
Vim will also load ftdetect files, if there are any.
@@ -539,7 +546,7 @@ is used.
Loading packages automatically will not happen if loading plugins is disabled,
see |load-plugins|.
-To load packages earlier, so that 'runtimepath' gets updated: >
+To load packages earlier, so that plugin/ files are sourced:
:packloadall
This also works when loading plugins is disabled. The automatic loading will
only happen once.
@@ -667,8 +674,8 @@ found automatically. Your package would have these files:
< pack/foo/start/lib/autoload/foolib.vim >
func foolib#getit()
-This works, because loading packages will first add all found directories to
-'runtimepath' before sourcing the plugins.
+This works, because start packages will be used to look for autoload files,
+when sourcing the plugins.
==============================================================================
Debugging scripts *debug-scripts*
@@ -827,8 +834,12 @@ DEFINING BREAKPOINTS
Sets a breakpoint, that will break whenever the {expression}
evaluates to a different value. Example: >
:breakadd expr g:lnum
-
< Will break, whenever the global variable lnum changes.
+
+ Errors in evaluation are suppressed, you can use the name of a
+ variable that does not exist yet. This also means you will
+ not notice anything if the expression has a mistake.
+
Note if you watch a |script-variable| this will break
when switching scripts, since the script variable is only
valid in the script where it has been defined and if that
@@ -911,11 +922,9 @@ OBSCURE
Profiling *profile* *profiling*
Profiling means that Vim measures the time that is spent on executing
-functions and/or scripts. The |+profile| feature is required for this.
-It is only included when Vim was compiled with "huge" features.
+functions and/or scripts.
-You can also use the |reltime()| function to measure time. This only requires
-the |+reltime| feature, which is present more often.
+You can also use the |reltime()| function to measure time.
For profiling syntax highlighting see |:syntime|.
diff --git a/runtime/doc/rileft.txt b/runtime/doc/rileft.txt
index d45a2dce7e..aa11462595 100644
--- a/runtime/doc/rileft.txt
+++ b/runtime/doc/rileft.txt
@@ -70,7 +70,7 @@ o Invocations
o Typing backwards *ins-reverse*
----------------
- In lieu of using full-fledged the 'rightleft' option, one can opt for
+ In lieu of using the full-fledged 'rightleft' option, one can opt for
reverse insertion. When the 'revins' (reverse insert) option is set,
inserting happens backwards. This can be used to type right-to-left
text. When inserting characters the cursor is not moved and the text
diff --git a/runtime/doc/russian.txt b/runtime/doc/russian.txt
index 776630a52b..a2bc9f3b5e 100644
--- a/runtime/doc/russian.txt
+++ b/runtime/doc/russian.txt
@@ -47,10 +47,6 @@ different codepages from
http://www.sourceforge.net/projects/ruvim/
-Make sure that your Vim is at least 6.2.506 and use ruvim 0.5 or later for
-automatic installs. Vim also needs to be compiled with |+gettext| feature for
-user interface items translations to work.
-
After downloading an archive from RuVim project, unpack it into your
$VIMRUNTIME directory. We recommend using UTF-8 archive.
diff --git a/runtime/doc/sign.txt b/runtime/doc/sign.txt
index e8ed29c1a4..5079d900c9 100644
--- a/runtime/doc/sign.txt
+++ b/runtime/doc/sign.txt
@@ -435,13 +435,13 @@ sign_getdefined([{name}]) *sign_getdefined()*
" Get the attribute of the sign named mySign
echo sign_getdefined("mySign")
<
-sign_getplaced([{expr} [, {dict}]]) *sign_getplaced()*
+sign_getplaced([{buf} [, {dict}]]) *sign_getplaced()*
Return a list of signs placed in a buffer or all the buffers.
This is similar to the |:sign-place-list| command.
- If the optional buffer name {expr} is specified, then only the
+ If the optional buffer name {buf} is specified, then only the
list of signs placed in that buffer is returned. For the use
- of {expr}, see |bufname()|. The optional {dict} can contain
+ of {buf}, see |bufname()|. The optional {dict} can contain
the following entries:
group select only signs in this group
id select sign with this identifier
@@ -496,12 +496,12 @@ sign_getplaced([{expr} [, {dict}]]) *sign_getplaced()*
echo sign_getplaced()
<
*sign_jump()*
-sign_jump({id}, {group}, {expr})
- Open the buffer {expr} or jump to the window that contains
- {expr} and position the cursor at sign {id} in group {group}.
+sign_jump({id}, {group}, {buf})
+ Open the buffer {buf} or jump to the window that contains
+ {buf} and position the cursor at sign {id} in group {group}.
This is similar to the |:sign-jump| command.
- For the use of {expr}, see |bufname()|.
+ For the use of {buf}, see |bufname()|.
Returns the line number of the sign. Returns -1 if the
arguments are invalid.
@@ -512,9 +512,9 @@ sign_jump({id}, {group}, {expr})
<
*sign_place()*
-sign_place({id}, {group}, {name}, {expr} [, {dict}])
+sign_place({id}, {group}, {name}, {buf} [, {dict}])
Place the sign defined as {name} at line {lnum} in file or
- buffer {expr} and assign {id} and {group} to sign. This is
+ buffer {buf} and assign {id} and {group} to sign. This is
similar to the |:sign-place| command.
If the sign identifier {id} is zero, then a new identifier is
@@ -525,12 +525,12 @@ sign_place({id}, {group}, {name}, {expr} [, {dict}])
and |sign-group| for more information.
{name} refers to a defined sign.
- {expr} refers to a buffer name or number. For the accepted
+ {buf} refers to a buffer name or number. For the accepted
values, see |bufname()|.
The optional {dict} argument supports the following entries:
lnum line number in the file or buffer
- {expr} where the sign is to be placed.
+ {buf} where the sign is to be placed.
For the accepted values, see |line()|.
priority priority of the sign. See
|sign-priority| for more information.
@@ -578,7 +578,7 @@ sign_placelist({list})
then a new unique identifier is allocated.
Otherwise the specified number is used. See
|sign-identifier| for more information.
- lnum line number in the buffer {expr} where the
+ lnum line number in the buffer {buf} where the
sign is to be placed. For the accepted values,
see |line()|.
name name of the sign to place. See |sign_define()|
diff --git a/runtime/doc/spell.txt b/runtime/doc/spell.txt
index 22d7cdf491..03c00c8495 100644
--- a/runtime/doc/spell.txt
+++ b/runtime/doc/spell.txt
@@ -1127,10 +1127,10 @@ flag to avoid lots of errors.
CIRCUMFIX *spell-CIRCUMFIX*
The CIRCUMFIX flag means a prefix and suffix must be added at the same time.
-If a prefix has the CIRCUMFIX flag than only suffixes with the CIRCUMFIX flag
+If a prefix has the CIRCUMFIX flag then only suffixes with the CIRCUMFIX flag
can be added, and the other way around.
-An alternative is to only specify the suffix, and give the that suffix two
-flags: The required prefix and the NEEDAFFIX flag. |spell-NEEDAFFIX|
+An alternative is to only specify the suffix, and give that suffix two flags:
+the required prefix and the NEEDAFFIX flag. |spell-NEEDAFFIX|
PFXPOSTPONE *spell-PFXPOSTPONE*
diff --git a/runtime/doc/starting.txt b/runtime/doc/starting.txt
index 5431ce3bd8..87a48e6d2a 100644
--- a/runtime/doc/starting.txt
+++ b/runtime/doc/starting.txt
@@ -329,12 +329,12 @@ argument.
-w{number} Set the 'window' option to {number}.
*-w*
--w {scriptout} All the characters that you type are recorded in the file
- "scriptout", until you exit Vim. This is useful if you want
- to create a script file to be used with "vim -s" or
- ":source!". When the "scriptout" file already exists, new
- characters are appended. See also |complex-repeat|.
- {scriptout} cannot start with a digit.
+-w {scriptout} All keys that you type are recorded in the file "scriptout",
+ until you exit Vim. Useful to create a script file to be used
+ with "vim -s" or ":source!". Appends to the "scriptout" file
+ if it already exists. {scriptout} cannot start with a digit.
+ See also |vim.on_key()|.
+ See also |complex-repeat|.
*-W*
-W {scriptout} Like -w, but do not append, overwrite an existing file.
@@ -388,8 +388,8 @@ argument.
==============================================================================
Initialization *initialization* *startup*
-At startup, Vim checks environment variables and files and sets values
-accordingly. Vim proceeds in this order:
+At startup, Nvim checks environment variables and files and sets values
+accordingly, proceeding as follows:
1. Set the 'shell' option *SHELL* *COMSPEC*
The environment variable SHELL, if it exists, is used to set the
@@ -406,21 +406,21 @@ accordingly. Vim proceeds in this order:
Nvim started with |--embed| waits for the UI to connect before
proceeding to load user configuration.
-4. Load user config (execute Ex commands from files, environment, …).
- An environment variable (e.g. $VIMINIT) is read as one Ex command
- line, where multiple commands must be separated with '|' or <NL>.
+4. Setup |default-mappings| and |default-autocmds|.
+
+5. Load user config (execute Ex commands from files, environment, …).
+ $VIMINIT environment variable is read as one Ex command line (separate
+ multiple commands with '|' or <NL>).
*config* *init.vim* *init.lua* *vimrc* *exrc*
- A file that contains initialization commands is generically called
- a "vimrc" or config file. It can be a Vimscript or Lua file named
- "init.vim" or "init.lua" respectively. It is an error to use both at
- the same time. Each line in a "init.vim" is executed as an Ex command
- line. See also |vimrc-intro| and |base-directories|.
+ A file containing initialization commands is generically called
+ a "vimrc" or config file. It can be either Vimscript ("init.vim") or
+ Lua ("init.lua"), but not both. *E5422*
+ See also |vimrc-intro| and |base-directories|.
The config file is located at:
- Unix ~/.config/nvim/init.vim (or init.lua)
- Windows ~/AppData/Local/nvim/init.vim (or init.lua)
- or if |$XDG_CONFIG_HOME| is defined:
- $XDG_CONFIG_HOME/nvim/init.vim (or init.lua)
+ Unix ~/.config/nvim/init.vim (or init.lua)
+ Windows ~/AppData/Local/nvim/init.vim (or init.lua)
+ |$XDG_CONFIG_HOME| $XDG_CONFIG_HOME/nvim/init.vim (or init.lua)
If Nvim was started with "-u {file}" then {file} is used as the config
and all initializations until 5. are skipped. $MYVIMRC is not set.
@@ -452,7 +452,7 @@ accordingly. Vim proceeds in this order:
- The file ".nvimrc"
- The file ".exrc"
-5. Enable filetype and indent plugins.
+6. Enable filetype and indent plugins.
This does the same as the commands: >
:runtime! filetype.vim
:runtime! ftplugin.vim
@@ -460,24 +460,21 @@ accordingly. Vim proceeds in this order:
< Skipped if ":filetype … off" was called or if the "-u NONE" command
line argument was given.
-6. Enable syntax highlighting.
+7. Enable syntax highlighting.
This does the same as the command: >
:runtime! syntax/syntax.vim
< Skipped if ":syntax off" was called or if the "-u NONE" command
line argument was given.
-7. Load the plugin scripts. *load-plugins*
+8. Load the plugin scripts. *load-plugins*
This does the same as the command: >
:runtime! plugin/**/*.vim
:runtime! plugin/**/*.lua
-< The result is that all directories in the 'runtimepath' option will be
- searched for the "plugin" sub-directory and all files ending in ".vim"
- and ".lua" will be sourced (in alphabetical order per directory),
- also in subdirectories. First all the "*.vim" files will be sourced and
- then all the "*.lua" files will be sourced. If two files with same
- name but different extensions exists they will be treated in same
- manner. For example when both "foo.vim" and "foo.lua" exists then
- first "foo.vim" will be sourced then "foo.lua" will be sourced.
+< The result is that all directories in 'runtimepath' will be searched
+ for the "plugin" sub-directory and all files ending in ".vim" or
+ ".lua" will be sourced (in alphabetical order per directory),
+ also in subdirectories. First "*.vim" are sourced, then "*.lua" files.
+
However, directories in 'runtimepath' ending in "after" are skipped
here and only loaded after packages, see below.
Loading plugins won't be done when:
@@ -485,7 +482,6 @@ accordingly. Vim proceeds in this order:
- The |--noplugin| command line argument is used.
- The |--clean| command line argument is used.
- The "-u NONE" command line argument is used |-u|.
- - When Vim was compiled without the |+eval| feature.
Note that using "-c 'set noloadplugins'" doesn't work, because the
commands from the command line have not been executed yet. You can
use "--cmd 'set noloadplugins'" or "--cmd 'set loadplugins'" |--cmd|.
@@ -500,38 +496,33 @@ accordingly. Vim proceeds in this order:
if packages have been found, but that should not add a directory
ending in "after".
-8. Set 'shellpipe' and 'shellredir'
+9. Set 'shellpipe' and 'shellredir'
The 'shellpipe' and 'shellredir' options are set according to the
value of the 'shell' option, unless they have been set before.
- This means that Vim will figure out the values of 'shellpipe' and
+ This means that Nvim will figure out the values of 'shellpipe' and
'shellredir' for you, unless you have set them yourself.
-9. Set 'updatecount' to zero, if "-n" command argument used
+10. Set 'updatecount' to zero, if "-n" command argument used
-10. Set binary options
- If the "-b" flag was given to Vim, the options for binary editing will
- be set now. See |-b|.
+11. Set binary options if the |-b| flag was given.
-11. Read the ShaDa file
- See |shada-file|.
+12. Read the |shada-file|.
-12. Read the quickfix file
- If the "-q" flag was given to Vim, the quickfix file is read. If this
- fails, Vim exits.
+13. Read the quickfix file if the |-q| flag was given, or exit on failure.
-13. Open all windows
+14. Open all windows
When the |-o| flag was given, windows will be opened (but not
displayed yet).
When the |-p| flag was given, tab pages will be created (but not
displayed yet).
When switching screens, it happens now. Redrawing starts.
- If the "-q" flag was given to Vim, the first error is jumped to.
+ If the |-q| flag was given, the first error is jumped to.
Buffers for all windows will be loaded, without triggering |BufAdd|
autocommands.
-14. Execute startup commands
- If a "-t" flag was given to Vim, the tag is jumped to.
- The commands given with the |-c| and |+cmd| arguments are executed.
+15. Execute startup commands
+ If a |-t| flag was given, the tag is jumped to.
+ Commands given with |-c| and |+cmd| are executed.
If the 'insertmode' option is set, Insert mode is entered.
The starting flag is reset, has("vim_starting") will now return zero.
The |v:vim_did_enter| variable is set to 1.
diff --git a/runtime/doc/syntax.txt b/runtime/doc/syntax.txt
index bf649b5940..ebc7ff6b80 100644
--- a/runtime/doc/syntax.txt
+++ b/runtime/doc/syntax.txt
@@ -25,11 +25,15 @@ In the User Manual:
==============================================================================
1. Quick start *:syn-qstart*
- *:syn-enable* *:syntax-enable*
+ *:syn-enable* *:syntax-enable* *:syn-on* *:syntax-on*
This command switches on syntax highlighting: >
:syntax enable
+Alternatively: >
+
+ :syntax on
+
What this command actually does is to execute the command >
:source $VIMRUNTIME/syntax/syntax.vim
@@ -42,19 +46,11 @@ are in the "/usr/vim/vim82/syntax" directory, set $VIMRUNTIME to
This command also sources the |menu.vim| script when the GUI is running or
will start soon. See |'go-M'| about avoiding that.
- *:syn-on* *:syntax-on*
-The `:syntax enable` command will keep most of your current color settings.
-This allows using `:highlight` commands to set your preferred colors before or
-after using this command. If you want Vim to overrule your settings with the
-defaults, use: >
- :syntax on
-<
*:hi-normal* *:highlight-normal*
If you are running in the GUI, you can get white text on a black background
with: >
:highlight Normal guibg=Black guifg=White
For a color terminal see |:hi-normal-cterm|.
-For setting up your own colors syntax highlighting see |syncolor|.
NOTE: The syntax files on MS-Windows have lines that end in <CR><NL>.
The files for Unix end in <NL>. This means you should use the right type of
@@ -277,12 +273,6 @@ located. This is used here as the variable |$VIMRUNTIME|.
|
+- Source first syntax/synload.vim in 'runtimepath'
| |
- | +- Setup the colors for syntax highlighting. If a color scheme is
- | | defined it is loaded again with ":colors {name}". Otherwise
- | | ":runtime! syntax/syncolor.vim" is used. ":syntax on" overrules
- | | existing colors, ":syntax enable" only sets groups that weren't
- | | set yet.
- | |
| +- Set up syntax autocmds to load the appropriate syntax file when
| | the 'syntax' option is set. *synload-1*
| |
@@ -371,9 +361,6 @@ the desired value, or restored to their default by removing the variable using
Remarks:
- Some truly ancient browsers may not show the background colors.
- From most browsers you can also print the file (in color)!
-- The latest TOhtml may actually work with older versions of Vim, but some
- features such as conceal support will not function, and the colors may be
- incorrect for an old Vim without GUI support compiled in.
Here is an example how to run the script over all .c and .h files from a
Unix shell: >
@@ -900,7 +887,7 @@ For Visual Basic use: >
BAAN *baan.vim* *baan-syntax*
-The baan.vim gives syntax support for BaanC of release BaanIV upto SSA ERP LN
+The baan.vim gives syntax support for BaanC of release BaanIV up to SSA ERP LN
for both 3 GL and 4 GL programming. Large number of standard defines/constants
are supported.
@@ -1109,11 +1096,13 @@ The ColdFusion syntax file is based on the HTML syntax file.
CPP *cpp.vim* *ft-cpp-syntax*
-Most of things are same as |ft-c-syntax|.
+Most things are the same as |ft-c-syntax|.
Variable Highlight ~
cpp_no_cpp11 don't highlight C++11 standard items
cpp_no_cpp14 don't highlight C++14 standard items
+cpp_no_cpp17 don't highlight C++17 standard items
+cpp_no_cpp20 don't highlight C++20 standard items
CSH *csh.vim* *ft-csh-syntax*
@@ -1397,11 +1386,17 @@ To select syntax highlighting file for Euphoria, as well as for
auto-detecting the *.e and *.E file extensions as Euphoria file type,
add the following line to your startup file: >
- :let filetype_euphoria="euphoria3"
+ :let g:filetype_euphoria = "euphoria3"
- or
+< or >
- :let filetype_euphoria="euphoria4"
+ :let g:filetype_euphoria = "euphoria4"
+
+Elixir and Euphoria share the *.ex file extension. If the filetype is
+specifically set as Euphoria with the g:filetype_euphoria variable, or the
+file is determined to be Euphoria based on keywords in the file, then the
+filetype will be set as Euphoria. Otherwise, the filetype will default to
+Elixir.
ERLANG *erlang.vim* *ft-erlang-syntax*
@@ -1419,6 +1414,22 @@ To enable highlighting some special atoms, put this in your vimrc: >
:let g:erlang_highlight_special_atoms = 1
+ELIXIR *elixir.vim* *ft-elixir-syntax*
+
+Elixir is a dynamic, functional language for building scalable and maintainable
+applications.
+
+The following file extensions are auto-detected as Elixir file types:
+
+ *.ex, *.exs, *.eex, *.leex, *.lock
+
+Elixir and Euphoria share the *.ex file extension. If the filetype is
+specifically set as Euphoria with the g:filetype_euphoria variable, or the
+file is determined to be Euphoria based on keywords in the file, then the
+filetype will be set as Euphoria. Otherwise, the filetype will default to
+Elixir.
+
+
FLEXWIKI *flexwiki.vim* *ft-flexwiki-syntax*
FlexWiki is an ASP.NET-based wiki package available at http://www.flexwiki.com
@@ -3398,8 +3409,8 @@ syntax highlighting script handles this with the following logic:
Tex: Match Check Control~
Sometimes one actually wants mismatched parentheses, square braces,
- and or curly braces; for example, \text{(1,10] is a range from but
- not including 1 to and including 10}. This wish, of course, conflicts
+ and or curly braces; for example, \text{(1,10]} is a range from but
+ not including 1 to and including 10. This wish, of course, conflicts
with the desire to provide delimiter mismatch detection. To
accommodate these conflicting goals, syntax/tex.vim provides >
g:tex_matchcheck = '[({[]'
@@ -4037,7 +4048,7 @@ match in the same position overrules an earlier one). The "transparent"
argument makes the "myVim" match use the same highlighting as "myString". But
it does not contain anything. If the "contains=NONE" argument would be left
out, then "myVim" would use the contains argument from myString and allow
-"myWord" to be contained, which will be highlighted as a Constant. This
+"myWord" to be contained, which will be highlighted as a Comment. This
happens because a contained match doesn't match inside itself in the same
position, thus the "myVim" match doesn't overrule the "myWord" match here.
@@ -4745,8 +4756,7 @@ in their own color.
This is basically the same as >
:echo g:colors_name
< In case g:colors_name has not been defined :colo will
- output "default". When compiled without the |+eval|
- feature it will output "unknown".
+ output "default".
:colo[rscheme] {name} Load color scheme {name}. This searches 'runtimepath'
for the file "colors/{name}.(vim|lua)". The first one that
@@ -5078,9 +5088,15 @@ Substitute |:substitute| replacement text highlighting
*hl-LineNr*
LineNr Line number for ":number" and ":#" commands, and when 'number'
or 'relativenumber' option is set.
+ *hl-LineNrAbove*
+LineNrAbove Line number for when the 'relativenumber'
+ option is set, above the cursor line.
+ *hl-LineNrBelow*
+LineNrBelow Line number for when the 'relativenumber'
+ option is set, below the cursor line.
*hl-CursorLineNr*
-CursorLineNr Like LineNr when 'cursorline' or 'relativenumber' is set for
- the cursor line.
+CursorLineNr Like LineNr when 'cursorline' is set and 'cursorlineopt'
+ contains "number" or is "both", for the cursor line.
*hl-MatchParen*
MatchParen The character under the cursor or just before it, if it
is a paired bracket, and its match. |pi_paren.txt|
@@ -5275,51 +5291,10 @@ back to their Vim default.
Note that if you are using a color scheme, the colors defined by the color
scheme for syntax highlighting will be lost.
-What this actually does is: >
-
- let g:syntax_cmd = "reset"
- runtime! syntax/syncolor.vim
-
-Note that this uses the 'runtimepath' option.
-
- *syncolor*
-If you want to use different colors for syntax highlighting, you can add a Vim
-script file to set these colors. Put this file in a directory in
-'runtimepath' which comes after $VIMRUNTIME, so that your settings overrule
-the default colors. This way these colors will be used after the ":syntax
-reset" command.
-
-For Unix you can use the file ~/.config/nvim/after/syntax/syncolor.vim.
-Example: >
-
- if &background == "light"
- highlight comment ctermfg=darkgreen guifg=darkgreen
- else
- highlight comment ctermfg=green guifg=green
- endif
-
- *E679*
-Do make sure this syncolor.vim script does not use a "syntax on", set the
-'background' option or uses a "colorscheme" command, because it results in an
-endless loop.
-
Note that when a color scheme is used, there might be some confusion whether
your defined colors are to be used or the colors from the scheme. This
depends on the color scheme file. See |:colorscheme|.
- *syntax_cmd*
-The "syntax_cmd" variable is set to one of these values when the
-syntax/syncolor.vim files are loaded:
- "on" ":syntax on" command. Highlight colors are overruled but
- links are kept
- "enable" ":syntax enable" command. Only define colors for groups that
- don't have highlighting yet. Use ":syntax default".
- "reset" ":syntax reset" command or loading a color scheme. Define all
- the colors.
- "skip" Don't define colors. Used to skip the default settings when a
- syncolor.vim file earlier in 'runtimepath' has already set
- them.
-
==============================================================================
16. Highlighting tags *tag-highlight*
@@ -5404,9 +5379,6 @@ If your syntax causes redrawing to be slow, here are a few hints on making it
faster. To see slowness switch on some features that usually interfere, such
as 'relativenumber' and |folding|.
-Note: this is only available when compiled with the |+profile| feature.
-You many need to build Vim with "huge" features.
-
To find out what patterns are consuming most time, get an overview with this
sequence: >
:syntime on
diff --git a/runtime/doc/tagsrch.txt b/runtime/doc/tagsrch.txt
index 2c1b927e5a..4d938c4a23 100644
--- a/runtime/doc/tagsrch.txt
+++ b/runtime/doc/tagsrch.txt
@@ -367,11 +367,11 @@ be a bug. If you really want the old Vi behavior, set the 't' flag in
'cpoptions'.
*tag-binary-search*
-Vim uses binary searching in the tags file to find the desired tag quickly
-(when enabled at compile time |+tag_binary|). But this only works if the
-tags file was sorted on ASCII byte value. Therefore, if no match was found,
-another try is done with a linear search. If you only want the linear search,
-reset the 'tagbsearch' option. Or better: Sort the tags file!
+Vim uses binary searching in the tags file to find the desired tag quickly.
+But this only works if the tags file was sorted on ASCII byte value.
+Therefore, if no match was found, another try is done with a linear search.
+If you only want the linear search, reset the 'tagbsearch' option. Or better:
+Sort the tags file!
Note that the binary searching is disabled when not looking for a tag with a
specific name. This happens when ignoring case and when a regular expression
@@ -666,9 +666,6 @@ included files (recursively). This can be used to find the definition of a
variable, function or macro. If you only want to search in the current
buffer, use the commands listed at |pattern-searches|.
-These commands are not available when the |+find_in_path| feature was disabled
-at compile time.
-
When a line is encountered that includes another file, that file is searched
before continuing in the current buffer. Files included by included files are
also searched. When an include file could not be found it is silently
diff --git a/runtime/doc/testing.txt b/runtime/doc/testing.txt
index b2ce6d670d..f0bda5aaf8 100644
--- a/runtime/doc/testing.txt
+++ b/runtime/doc/testing.txt
@@ -30,8 +30,7 @@ New tests should be added as new style tests. These use functions such as
|assert_equal()| to keep the test commands and the expected result in one
place.
*old-style-testing*
-In some cases an old style test needs to be used. E.g. when testing Vim
-without the |+eval| feature.
+In some cases an old style test needs to be used.
Find more information in the file src/testdir/README.txt.
@@ -54,6 +53,9 @@ assert_beeps({cmd}) *assert_beeps()*
Also see |assert_fails()|, |assert_nobeep()| and
|assert-return|.
+ Can also be used as a |method|: >
+ GetCmd()->assert_beeps()
+<
*assert_equal()*
assert_equal({expected}, {actual} [, {msg}])
When {expected} and {actual} are not equal an error message is
@@ -70,7 +72,10 @@ assert_equal({expected}, {actual} [, {msg}])
< Will result in a string to be added to |v:errors|:
test.vim line 12: Expected 'foo' but got 'bar' ~
- *assert_equalfile()*
+ Can also be used as a |method|: >
+ mylist->assert_equal([1, 2, 3])
+
+< *assert_equalfile()*
assert_equalfile({fname-one}, {fname-two})
When the files {fname-one} and {fname-two} do not contain
exactly the same text an error message is added to |v:errors|.
@@ -78,6 +83,9 @@ assert_equalfile({fname-one}, {fname-two})
When {fname-one} or {fname-two} does not exist the error will
mention that.
+ Can also be used as a |method|: >
+ GetLog()->assert_equalfile('expected.log')
+
assert_exception({error} [, {msg}]) *assert_exception()*
When v:exception does not contain the string {error} an error
message is added to |v:errors|. Also see |assert-return|.
@@ -98,6 +106,9 @@ assert_fails({cmd} [, {error} [, {msg}]]) *assert_fails()*
Note that beeping is not considered an error, and some failing
commands only beep. Use |assert_beeps()| for those.
+ Can also be used as a |method|: >
+ GetCmd()->assert_fails('E99:')
+
assert_false({actual} [, {msg}]) *assert_false()*
When {actual} is not false an error message is added to
|v:errors|, like with |assert_equal()|.
@@ -107,6 +118,9 @@ assert_false({actual} [, {msg}]) *assert_false()*
When {msg} is omitted an error in the form
"Expected False but got {actual}" is produced.
+ Can also be used as a |method|: >
+ GetResult()->assert_false()
+
assert_inrange({lower}, {upper}, {actual} [, {msg}]) *assert_inrange()*
This asserts number and |Float| values. When {actual} is lower
than {lower} or higher than {upper} an error message is added
@@ -135,6 +149,9 @@ assert_match({pattern}, {actual} [, {msg}])
< Will result in a string to be added to |v:errors|:
test.vim line 12: Pattern '^f.*o$' does not match 'foobar' ~
+ Can also be used as a |method|: >
+ getFile()->assert_match('foo.*')
+<
assert_nobeep({cmd}) *assert_nobeep()*
Run {cmd} and add an error message to |v:errors| if it
produces a beep or visual bell.
@@ -146,16 +163,27 @@ assert_notequal({expected}, {actual} [, {msg}])
|v:errors| when {expected} and {actual} are equal.
Also see |assert-return|.
- *assert_notmatch()*
+ Can also be used as a |method|: >
+ mylist->assert_notequal([1, 2, 3])
+
+< *assert_notmatch()*
assert_notmatch({pattern}, {actual} [, {msg}])
The opposite of `assert_match()`: add an error message to
|v:errors| when {pattern} matches {actual}.
Also see |assert-return|.
+ Can also be used as a |method|: >
+ getFile()->assert_notmatch('bar.*')
+
+
assert_report({msg}) *assert_report()*
- Report a test failure directly, using {msg}.
+ Report a test failure directly, using String {msg}.
Always returns one.
+ Can also be used as a |method|: >
+ GetMessage()->assert_report()
+
+
assert_true({actual} [, {msg}]) *assert_true()*
When {actual} is not true an error message is added to
|v:errors|, like with |assert_equal()|.
@@ -165,5 +193,8 @@ assert_true({actual} [, {msg}]) *assert_true()*
When {msg} is omitted an error in the form "Expected True but
got {actual}" is produced.
+ Can also be used as a |method|: >
+ GetResult()->assert_true()
+<
vim:tw=78:ts=8:noet:ft=help:norl:
diff --git a/runtime/doc/treesitter.txt b/runtime/doc/treesitter.txt
index 416ea3a08a..ac10aeec88 100644
--- a/runtime/doc/treesitter.txt
+++ b/runtime/doc/treesitter.txt
@@ -86,6 +86,18 @@ Node methods *lua-treesitter-node*
tsnode:parent() *tsnode:parent()*
Get the node's immediate parent.
+tsnode:next_sibling() *tsnode:next_sibling()*
+ Get the node's next sibling.
+
+tsnode:prev_sibling() *tsnode:prev_sibling()*
+ Get the node's previous sibling.
+
+tsnode:next_named_sibling() *tsnode:next_named_sibling()*
+ Get the node's next named sibling.
+
+tsnode:prev_named_sibling() *tsnode:prev_named_sibling()*
+ Get the node's previous named sibling.
+
tsnode:iter_children() *tsnode:iter_children()*
Iterates over all the direct children of {tsnode}, regardless of
wether they are named or not.
@@ -169,7 +181,7 @@ a tree, using a simple to write lisp-like format. See
https://tree-sitter.github.io/tree-sitter/using-parsers#query-syntax for more
information on how to write queries.
-Note: The perdicates listed in the web page above differ from those Neovim
+Note: The predicates listed in the web page above differ from those Neovim
supports. See |lua-treesitter-predicates| for a complete list of predicates
supported by Neovim.
@@ -215,9 +227,9 @@ Here is a list of built-in predicates :
((identifier) @foo-bar (#contains @foo-bar "foo" "bar"))
<
`any-of?` *ts-predicate-any-of?*
- Will check if the text is the same as any of the following
+ Will check if the text is the same as any of the following.
This is the recommended way to check if the node matches one
- of many keywords for exemple, as it has been optimized for
+ of many keywords for example, as it has been optimized for
this.
arguments : >
((identifier) @foo (#any-of? @foo "foo" "bar"))
@@ -226,10 +238,22 @@ Here is a list of built-in predicates :
Each predicate has a `not-` prefixed predicate that is just the negation of
the predicate.
+ *vim.treesitter.query.add_predicate()*
+vim.treesitter.query.add_predicate({name}, {handler})
+
+This adds a predicate with the name {name} to be used in queries.
+{handler} should be a function whose signature will be : >
+ handler(match, pattern, bufnr, predicate)
+<
+ *vim.treesitter.query.list_predicates()*
+vim.treesitter.query.list_predicates()
+
+This lists the currently available predicates to use in queries.
+
Treesitter Query Directive *lua-treesitter-directives*
Treesitter queries can also contain `directives`. Directives store metadata for a node
-or match and perform side effects. for example, the |set!| predicate sets metadata on
+or match and perform side effects. For example, the |set!| predicate sets metadata on
the match or node : >
((identifier) @foo (#set! "type" "parameter"))
@@ -249,6 +273,21 @@ Here is a list of built-in directives:
`({capture_id}, {start_row}, {start_col}, {end_row}, {end_col}, {key?})`
The default key is "offset".
+ *vim.treesitter.query.add_directive()*
+vim.treesitter.query.add_directive({name}, {handler})
+
+This adds a directive with the name {name} to be used in queries.
+{handler} should be a function whose signature will be : >
+ handler(match, pattern, bufnr, predicate, metadata)
+Handlers can set match level data by setting directly on the metadata object `metadata.key = value`
+Handlers can set node level data by using the capture id on the metadata table
+`metadata[capture_id].key = value`
+
+ *vim.treesitter.query.list_directives()*
+vim.treesitter.query.list_directives()
+
+This lists the currently available directives to use in queries.
+
Treesitter syntax highlighting (WIP) *lua-treesitter-highlight*
NOTE: This is a partially implemented feature, and not usable as a default
@@ -257,7 +296,7 @@ for those who want to experiment with this feature and contribute to
its development.
Highlights are defined in the same query format as in the tree-sitter highlight
-crate, which some limitations and additions. Set a highlight query for a
+crate, with some limitations and additions. Set a highlight query for a
buffer with this code: >
local query = [[
@@ -294,6 +333,19 @@ identical identifiers, highlighting both as |hl-WarningMsg|: >
((binary_expression left: (identifier) @WarningMsg.left right: (identifier) @WarningMsg.right)
(eq? @WarningMsg.left @WarningMsg.right))
<
+Treesitter Highlighting Priority *lua-treesitter-highlight-priority*
+
+Tree-sitter uses |nvim_buf_set_extmark()| to set highlights with a default
+priority of 100. This enables plugins to set a highlighting priority lower or
+higher than tree-sitter. It is also possible to change the priority of an
+individual query pattern manually by setting its `"priority"` metadata attribute: >
+
+ (
+ (super_important_node) @ImportantHighlight
+ ; Give the whole query highlight priority higher than the default (100)
+ (set! "priority" 105)
+ )
+<
==============================================================================
Lua module: vim.treesitter *lua-treesitter-core*
@@ -393,8 +445,13 @@ get_query_files({lang}, {query_name}, {is_included})
{is_included} Internal parameter, most of the time left
as `nil`
+list_directives() *list_directives()*
+ Return: ~
+ The list of supported directives.
+
list_predicates() *list_predicates()*
- TODO: Documentation
+ Return: ~
+ The list of supported predicates.
parse_query({lang}, {query}) *parse_query()*
Parse {query} as a string. (If the query is in a file, the
@@ -474,11 +531,9 @@ Query:iter_matches({self}, {node}, {source}, {start}, {stop})
for id, node in pairs(match) do
local name = query.captures[id]
-- `node` was captured by the `name` capture in the match
-<
->
- local node_data = metadata[id] -- Node level metadata
-<
->
+
+ local node_data = metadata[id] -- Node level metadata
+
... use the info here ...
end
end
@@ -712,17 +767,4 @@ new({source}, {lang}, {opts}) *languagetree.new()*
the injection language query per
language.
-
-==============================================================================
-Lua module: vim.treesitter.health *treesitter-health*
-
-check_health() *check_health()*
- TODO: Documentation
-
-list_parsers() *list_parsers()*
- Lists the parsers currently installed
-
- Return: ~
- A list of parsers
-
vim:tw=78:ts=8:ft=help:norl:
diff --git a/runtime/doc/usr_05.txt b/runtime/doc/usr_05.txt
index d0206ba82d..2edef0ca23 100644
--- a/runtime/doc/usr_05.txt
+++ b/runtime/doc/usr_05.txt
@@ -175,10 +175,8 @@ This switches on three very clever mechanisms:
*restore-cursor* *last-position-jump* >
- autocmd BufReadPost *
- \ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit'
- \ | exe "normal! g`\""
- \ | endif
+ autocmd BufRead * autocmd FileType <buffer> ++once
+ \ if &ft !~# 'commit\|rebase' && line("'\"") > 1 && line("'\"") <= line("$") | exe 'normal! g`"' | endif
Another autocommand. This time it is used after reading any file. The
complicated stuff after it checks if the '" mark is defined, and jumps to it
diff --git a/runtime/doc/usr_08.txt b/runtime/doc/usr_08.txt
index 8e69307a94..8ccaa73006 100644
--- a/runtime/doc/usr_08.txt
+++ b/runtime/doc/usr_08.txt
@@ -235,7 +235,7 @@ windows like this:
+----------------------------------+
Clearly the last one should be at the top. Go to that window (using CTRL-W w)
-and the type this command: >
+and then type this command: >
CTRL-W K
diff --git a/runtime/doc/usr_09.txt b/runtime/doc/usr_09.txt
index 757d13e0f3..8084d13b5d 100644
--- a/runtime/doc/usr_09.txt
+++ b/runtime/doc/usr_09.txt
@@ -109,7 +109,7 @@ when the 'wrap' option has been reset (more about that later).
When there are vertically split windows, only the windows on the right side
will have a scrollbar. However, when you move the cursor to a window on the
-left, it will be this one the that scrollbar controls. This takes a bit of
+left, it will be this one that the scrollbar controls. This takes a bit of
time to get used to.
When you work with vertically split windows, consider adding a scrollbar on
the left. This can be done with a menu item, or with the 'guioptions' option:
diff --git a/runtime/doc/usr_41.txt b/runtime/doc/usr_41.txt
index a190bf2f27..5d70834ddc 100644
--- a/runtime/doc/usr_41.txt
+++ b/runtime/doc/usr_41.txt
@@ -118,7 +118,8 @@ Numbers can be decimal, hexadecimal, octal or binary.
A hexadecimal number starts with "0x" or "0X". For example "0x1f" is decimal
31.
-An octal number starts with a zero and another digit. "017" is decimal 15.
+An octal number starts with "0o", "0O" or a zero and another digit. "0o17" is
+decimal 15.
A binary number starts with "0b" or "0B". For example "0b101" is decimal 5.
@@ -127,14 +128,14 @@ number, it will be interpreted as an octal number!
The ":echo" command always prints decimal numbers. Example: >
- :echo 0x7f 036
+ :echo 0x7f 0o36
< 127 30 ~
A number is made negative with a minus sign. This also works for hexadecimal,
octal and binary numbers. A minus sign is also used for subtraction. Compare
this with the previous example: >
- :echo 0x7f -036
+ :echo 0x7f -0o36
< 97 ~
White space in an expression is ignored. However, it's recommended to use it
@@ -142,7 +143,7 @@ for separating items, to make the expression easier to read. For example, to
avoid the confusion with a negative number above, put a space between the
minus sign and the following number: >
- :echo 0x7f - 036
+ :echo 0x7f - 0o36
==============================================================================
*41.2* Variables
@@ -743,6 +744,8 @@ Cursor and mark position: *cursor-functions* *mark-functions*
diff_filler() get the number of filler lines above a line
screenattr() get attribute at a screen line/row
screenchar() get character code at a screen line/row
+ screenchars() get character codes at a screen line/row
+ screenstring() get string of characters at a screen line/row
Working with text in the current buffer: *text-functions*
getline() get a line or list of lines from the buffer
@@ -1022,6 +1025,7 @@ Various: *various-functions*
undotree() return the state of the undo tree
getreg() get contents of a register
+ getreginfo() get information about a register
getregtype() get type of a register
setreg() set contents and type of a register
reg_executing() return the name of the register being executed
diff --git a/runtime/doc/usr_45.txt b/runtime/doc/usr_45.txt
index bc95f3405e..3199c4d8ea 100644
--- a/runtime/doc/usr_45.txt
+++ b/runtime/doc/usr_45.txt
@@ -31,13 +31,6 @@ this command: >
If it replies with "C", this means the default is being used, which is
English.
- Note:
- Using different languages only works when Vim was compiled to handle
- it. To find out if it works, use the ":version" command and check the
- output for "+gettext" and "+multi_lang". If they are there, you are
- OK. If you see "-gettext" or "-multi_lang" you will have to find
- another Vim.
-
What if you would like your messages in a different language? There are
several ways. Which one you should use depends on the capabilities of your
system.
diff --git a/runtime/doc/various.txt b/runtime/doc/various.txt
index ec91b6e29a..b06fa7518c 100644
--- a/runtime/doc/various.txt
+++ b/runtime/doc/various.txt
@@ -14,6 +14,10 @@ Various commands *various*
*CTRL-L*
CTRL-L Clears and redraws the screen. The redraw may happen
later, after processing typeahead.
+ *CTRL-L-default*
+ By default, also clears search highlighting
+ |:nohlsearch| and updates diffs |:diffupdate|.
+ |default-mappings|
*:mod* *:mode*
:mod[e] Clears and redraws the screen.
@@ -162,9 +166,13 @@ g8 Print the hex values of the bytes used in the
If the mark is "=", a line of dashes is printed
around the current line.
-:[range]z#[+-^.=][count] *:z#*
- Like ":z", but number the lines.
- {not in all versions of Vi, not with these arguments}
+ *:z!*
+:[range]z![+-^.=][count]
+ Like ":z:", but when [count] is not specified, it
+ defaults to the Vim window height minus one.
+
+:[range]z[!]#[+-^.=][count] *:z#*
+ Like ":z" or ":z!", but number the lines.
*:=*
:= [flags] Print the last line number.
@@ -456,20 +464,14 @@ defined while executing a function, user command or autocommand, the script in
which it was defined is reported.
*K*
-[count]K Run a program to lookup the keyword under the
- cursor. The name of the program is given with the
- 'keywordprg' (kp) option (default is "man"). The
- keyword is formed of letters, numbers and the
- characters in 'iskeyword'. The keyword under or
- right of the cursor is used. The same can be done
- with the command >
- :!{program} {keyword}
+[count]K Runs the program given by 'keywordprg' to lookup the
+ |word| (defined by 'iskeyword') under or right of the
+ cursor. Default is "man". Works like this: >
+ :tabnew | terminal {program} {keyword}
< Special cases:
- If 'keywordprg' begins with ":" it is invoked as
a Vim command with [count].
- - If 'keywordprg' is empty, the ":help" command is
- used. It's a good idea to include more characters
- in 'iskeyword' then, to be able to find more help.
+ - If 'keywordprg' is empty, |:help| is used.
- When 'keywordprg' is equal to "man", a [count]
before "K" is inserted after the "man" command and
before the keyword. For example, using "2K" while
@@ -506,7 +508,7 @@ gO Show a filetype-specific, navigable "outline" of the
Queued messages are processed during the sleep.
*:sl!* *:sleep!*
-:[N]sl[eep]! [N] [m] Same as above. Unlike Vim, it does not hide the
+:[N]sl[eep]! [N][m] Same as above. Unlike Vim, it does not hide the
cursor. |vim-differences|
==============================================================================
diff --git a/runtime/doc/vim_diff.txt b/runtime/doc/vim_diff.txt
index 27c4b82aca..64824b2e3f 100644
--- a/runtime/doc/vim_diff.txt
+++ b/runtime/doc/vim_diff.txt
@@ -6,16 +6,16 @@
Differences between Nvim and Vim *vim-differences*
-Nvim differs from Vim in many ways, although editor and VimL features are
-mostly identical. This document is a complete and centralized reference of
-the differences.
+Nvim differs from Vim in many ways, although editor and Vimscript (not
+Vim9script) features are mostly identical. This document is a complete and
+centralized reference of the differences.
Type |gO| to see the table of contents.
==============================================================================
1. Configuration *nvim-config*
-- Use `$XDG_CONFIG_HOME/nvim/init.vim` instead of `.vimrc` for configuration.
+- Use `$XDG_CONFIG_HOME/nvim/init.vim` instead of `.vimrc` for your |config|.
- Use `$XDG_CONFIG_HOME/nvim` instead of `.vim` to store configuration files.
- Use `$XDG_DATA_HOME/nvim/shada/main.shada` instead of `.viminfo` for persistent
session information. |shada|
@@ -30,7 +30,7 @@ the differences.
- 'autoread' is enabled
- 'background' defaults to "dark" (unless set automatically by the terminal/UI)
- 'backspace' defaults to "indent,eol,start"
-- 'backupdir' defaults to .,~/.local/share/nvim/backup (|xdg|)
+- 'backupdir' defaults to .,~/.local/share/nvim/backup// (|xdg|), auto-created
- 'belloff' defaults to "all"
- 'compatible' is always disabled
- 'complete' excludes "i"
@@ -41,9 +41,11 @@ the differences.
- 'fillchars' defaults (in effect) to "vert:│,fold:·,sep:│"
- 'formatoptions' defaults to "tcqj"
- 'fsync' is disabled
+- 'hidden' is enabled
- 'history' defaults to 10000 (the maximum)
- 'hlsearch' is enabled
- 'incsearch' is enabled
+- 'joinspaces' is disabled
- 'langnoremap' is enabled
- 'langremap' is disabled
- 'laststatus' defaults to 2 (statusline is always shown)
@@ -56,12 +58,13 @@ the differences.
- 'sidescroll' defaults to 1
- 'smarttab' is enabled
- 'startofline' is disabled
+- 'switchbuf' defaults to "uselast"
- 'tabpagemax' defaults to 50
- 'tags' defaults to "./tags;,tags"
- 'ttimeoutlen' defaults to 50
- 'ttyfast' is always set
-- 'viewoptions' includes "unix,slash"
-- 'undodir' defaults to ~/.local/share/nvim/undo (|xdg|), auto-created
+- 'undodir' defaults to ~/.local/share/nvim/undo// (|xdg|), auto-created
+- 'viewoptions' includes "unix,slash", excludes "options"
- 'viminfo' includes "!"
- 'wildmenu' is enabled
- 'wildoptions' defaults to "pum,tagfile"
@@ -72,23 +75,47 @@ the differences.
- |g:vimsyn_embed| defaults to "l" to enable Lua highlighting
+
+Default Mappings ~
+ *default-mappings*
+Nvim creates the following default mappings at |startup|. You can disable any
+of these in your config by simply removing the mapping, e.g. ":unmap Y".
+>
+ nnoremap Y y$
+ nnoremap <C-L> <Cmd>nohlsearch<Bar>diffupdate<CR><C-L>
+ inoremap <C-U> <C-G>u<C-U>
+ inoremap <C-W> <C-G>u<C-W>
+<
+Default Autocommands ~
+ *default-autocmds*
+Default autocommands exist in the following groups. Use ":autocmd! {group}" to
+remove them and ":autocmd {group}" to see how they're defined.
+
+nvim_terminal:
+- BufReadCmd: Treats "term://" buffers as |terminal| buffers. |terminal-start|
+
+nvim_cmdwin:
+- CmdwinEnter: Limits syntax sync to maxlines=1 in the |cmdwin|.
+
==============================================================================
3. New Features *nvim-features*
MAJOR COMPONENTS ~
API |API|
-Lua scripting |lua|
Job control |job-control|
-Remote plugins |remote-plugin|
+LSP framework |lsp|
+Lua scripting |lua|
+Parsing engine |treesitter|
Providers
Clipboard |provider-clipboard|
Node.js plugins |provider-nodejs|
Python plugins |provider-python|
Ruby plugins |provider-ruby|
+Remote plugins |remote-plugin|
Shared data |shada|
-Embedded terminal |terminal|
-VimL parser |nvim_parse_expression()|
+Terminal emulator |terminal|
+Vimscript parser |nvim_parse_expression()|
XDG base directories |xdg|
USER EXPERIENCE ~
@@ -137,7 +164,7 @@ FEATURES ~
Command-line highlighting:
The expression prompt (|@=|, |c_CTRL-R_=|, |i_CTRL-R_=|) is highlighted
- using a built-in VimL expression parser. |expr-highlight|
+ using a built-in Vimscript expression parser. |expr-highlight|
*E5408* *E5409*
|input()|, |inputdialog()| support custom highlighting. |input()-highlight|
*g:Nvim_color_cmdline*
@@ -150,6 +177,7 @@ Commands:
|:drop| is always available
|:Man| is available by default, with many improvements such as completion
|:sign-define| accepts a `numhl` argument, to highlight the line number
+ |:match| can be invoked before highlight group is defined
Events:
|Signal|
@@ -167,6 +195,7 @@ Functions:
|msgpackdump()|, |msgpackparse()| provide msgpack de/serialization
|stdpath()|
|system()|, |systemlist()| can run {cmd} directly (without 'shell')
+ |matchadd()| can be called before highlight group is defined
Highlight groups:
|highlight-blend| controls blend level for a highlight group
@@ -358,6 +387,14 @@ Startup:
- works by default: "-" file is optional
- works in more cases: |-Es|, file args
+Syntax highlighting:
+ syncolor.vim has been removed. Nvim now sets up default highlighting groups
+ automatically for both light and dark backgrounds, regardless of whether or
+ not syntax highlighting is enabled. This means that |:syntax-on| and
+ |:syntax-enable| are now identical. Users who previously used an
+ after/syntax/syncolor.vim file should transition that file into a
+ colorscheme. |:colorscheme|
+
TUI:
*:set-termcap*
Start Nvim with 'verbose' level 3 to show terminal capabilities: >
@@ -380,7 +417,7 @@ TUI:
UI/Display:
|Visual| selection highlights the character at cursor. |visual-use|
-VimL (Vim script) compatibility:
+Vimscript compatibility:
`count` does not alias to |v:count|
`errmsg` does not alias to |v:errmsg|
`shell_error` does not alias to |v:shell_error|
@@ -423,6 +460,7 @@ Commands:
:Print
:promptfind
:promptrepl
+ :scriptversion (always version 1)
:shell
:sleep! (does not hide the cursor; same as :sleep)
:smile
@@ -434,6 +472,7 @@ Compile-time features:
X11 integration (see |x11-selection|)
Eval:
+ Vim9script
*js_encode()*
*js_decode()*
*v:none* (used by Vim to represent JavaScript "undefined"); use |v:null| instead.
@@ -473,6 +512,7 @@ Options:
'maxmem' Nvim delegates memory-management to the OS.
'maxmemtot' Nvim delegates memory-management to the OS.
'maxcombine' (6 is always used)
+ *'prompt'* *'noprompt'*
*'restorescreen'* *'rs'* *'norestorescreen'* *'nors'*
'shelltype'
*'shortname'* *'sn'* *'noshortname'* *'nosn'*
diff --git a/runtime/doc/visual.txt b/runtime/doc/visual.txt
index f7828f0289..111588e43a 100644
--- a/runtime/doc/visual.txt
+++ b/runtime/doc/visual.txt
@@ -419,7 +419,7 @@ abcdefghijklmnopqrstuvwxyz
abcdefghijklmnSTRINGopqrstuvwxyz
abc STRING defghijklmnopqrstuvwxyz
-abcdef ghi STRING jklmnopqrstuvwxyz
+abcdef ghi STRING jklmnopqrstuvwxyz
abcdefghijklmnSTRINGopqrstuvwxyz
2. fo<C-v>3j$ASTRING<ESC> *v_b_A_example*
diff --git a/runtime/doc/windows.txt b/runtime/doc/windows.txt
index 3a58cc08d9..e0c33fa2c9 100644
--- a/runtime/doc/windows.txt
+++ b/runtime/doc/windows.txt
@@ -271,7 +271,7 @@ Closing a window
----------------
:q[uit]
-:{count}q[uit]
+:{count}q[uit] *:count_quit*
CTRL-W q *CTRL-W_q*
CTRL-W CTRL-Q *CTRL-W_CTRL-Q*
Without {count}: Quit the current window. If {count} is
@@ -363,7 +363,8 @@ CTRL-W CTRL-C *CTRL-W_CTRL-C*
CTRL-W o *CTRL-W_o* *E445*
CTRL-W CTRL-O *CTRL-W_CTRL-O* *:on* *:only*
Make the current window the only one on the screen. All other
- windows are closed. For {count} see |:quit|.
+ windows are closed. For {count} see the `:quit` command
+ above |:count_quit|.
When the 'hidden' option is set, all buffers in closed windows
become hidden.
diff --git a/runtime/filetype.vim b/runtime/filetype.vim
index 2617d8ffc0..bc3965d4b6 100644
--- a/runtime/filetype.vim
+++ b/runtime/filetype.vim
@@ -1,7 +1,7 @@
" Vim support file to detect file types
"
" Maintainer: Bram Moolenaar <Bram@vim.org>
-" Last Change: 2021 Apr 17
+" Last Change: 2021 Sep 21
" Listen very carefully, I will say this only once
if exists("did_load_filetypes")
@@ -533,8 +533,13 @@ au BufNewFile,BufRead *.drac,*.drc,*lvs,*lpe setf dracula
" Datascript
au BufNewFile,BufRead *.ds setf datascript
-" dsl
-au BufNewFile,BufRead *.dsl setf dsl
+" dsl: DSSSL or Structurizr
+au BufNewFile,BufRead *.dsl
+ \ if getline(1) =~ '^\s*<\!' |
+ \ setf dsl |
+ \ else |
+ \ setf structurizr |
+ \ endif
" DTD (Document Type Definition for XML)
au BufNewFile,BufRead *.dtd setf dtd
@@ -646,6 +651,9 @@ au BufNewFile,BufRead *.mo,*.gdmo setf gdmo
" Gedcom
au BufNewFile,BufRead *.ged,lltxxxxx.txt setf gedcom
+" Gemtext
+au BufNewFile,BufRead *.gmi,*.gemini setf gemtext
+
" Gift (Moodle)
autocmd BufRead,BufNewFile *.gift setf gift
@@ -864,6 +872,12 @@ au BufNewFile,BufRead *.json-patch setf json
" Jupyter Notebook is also json
au BufNewFile,BufRead *.ipynb setf json
+" JSONC
+au BufNewFile,BufRead *.jsonc setf jsonc
+
+" Julia
+au BufNewFile,BufRead *.jl setf julia
+
" Kixtart
au BufNewFile,BufRead *.kix setf kix
@@ -1011,7 +1025,7 @@ au BufNewFile,BufRead *.markdown,*.mdown,*.mkd,*.mkdn,*.mdwn,*.md setf markdown
" Mason
au BufNewFile,BufRead *.mason,*.mhtml,*.comp setf mason
-" Mathematica, Matlab, Murphi or Objective C
+" Mathematica, Matlab, Murphi, Objective C or Octave
au BufNewFile,BufRead *.m call dist#ft#FTm()
" Mathematica notebook
@@ -1157,6 +1171,9 @@ au BufNewFile,BufRead *.ml,*.mli,*.mll,*.mly,.ocamlinit,*.mlt,*.mlp,*.mlip,*.mli
" Occam
au BufNewFile,BufRead *.occ setf occam
+" Octave
+au BufNewFile,BufRead octave.conf,.octaverc,octaverc setf octave
+
" Omnimark
au BufNewFile,BufRead *.xom,*.xin setf omnimark
@@ -1365,6 +1382,9 @@ au BufNewFile,BufRead *.pk setf poke
" Protocols
au BufNewFile,BufRead */etc/protocols setf protocols
+" Pyret
+au BufNewFile,BufRead *.arr setf pyret
+
" Pyrex
au BufNewFile,BufRead *.pyx,*.pxd setf pyrex
@@ -1376,7 +1396,7 @@ au BufNewFile,BufRead *.ptl,*.pyi,SConstruct setf python
" Radiance
au BufNewFile,BufRead *.rad,*.mat setf radiance
-" Raku (formelly Perl6)
+" Raku (formerly Perl6)
au BufNewFile,BufRead *.pm6,*.p6,*.t6,*.pod6,*.raku,*.rakumod,*.rakudoc,*.rakutest setf raku
" Ratpoison config/command files
@@ -1513,6 +1533,9 @@ au BufNewFile,BufRead *.sbt setf sbt
" Scilab
au BufNewFile,BufRead *.sci,*.sce setf scilab
+" scdoc
+au BufNewFile,BufRead *.scd setf scdoc
+
" SCSS
au BufNewFile,BufRead *.scss setf scss
@@ -1602,7 +1625,7 @@ au BufNewFile,BufRead .zshrc,.zshenv,.zlogin,.zlogout,.zcompdump setf zsh
au BufNewFile,BufRead *.zsh setf zsh
" Scheme
-au BufNewFile,BufRead *.scm,*.ss,*.rkt setf scheme
+au BufNewFile,BufRead *.scm,*.ss,*.rkt,*.rktd,*.rktl setf scheme
" Screen RC
au BufNewFile,BufRead .screenrc,screenrc setf screen
diff --git a/runtime/ftplugin/8th.vim b/runtime/ftplugin/8th.vim
index 14301187d6..ad04f9ac84 100644
--- a/runtime/ftplugin/8th.vim
+++ b/runtime/ftplugin/8th.vim
@@ -1,9 +1,10 @@
" Vim ftplugin file
" Language: 8th
" Version: any
-" Last Change: 2015/11/08
+" Last Change: 2021 Sep 20
+" Last Change: 2021/09/20
" Maintainer: Ron Aaron <ron@aaron-tech.com>
-" URL: https://8th-dev.com/
+" URL: https://8th-dev.com/
" Filetypes: *.8th
" NOTE: 8th allows any non-whitespace in a name, so you need to do:
" setlocal iskeyword=!,@,33-35,%,$,38-64,A-Z,91-96,a-z,123-126,128-255
@@ -14,12 +15,13 @@ if exists("b:did_8thplugin")
finish
endif
-" Don't load another plugin for this buffer
+" Don't load another 8th plugin for this buffer
let b:did_8thplugin = 1
setlocal ts=2 sts=2 sw=2 et
-setlocal com=s1:/*,mb:*,ex:*/,:\|,:\\
+setlocal com=s1:/*,mb:*,ex:*/,b:--,be:\\
setlocal fo=tcrqol
setlocal matchpairs+=\::;
setlocal iskeyword=!,@,33-35,%,$,38-64,A-Z,91-96,a-z,123-126,128-255
setlocal suffixesadd=.8th
+let b:undo_ftplugin = "setlocal ts< sts< sw< et< com< fo< mps< isk< sua<"
diff --git a/runtime/ftplugin/c.vim b/runtime/ftplugin/c.vim
index 00937c2383..d4564a4aec 100644
--- a/runtime/ftplugin/c.vim
+++ b/runtime/ftplugin/c.vim
@@ -1,7 +1,7 @@
" Vim filetype plugin file
" Language: C
" Maintainer: Bram Moolenaar <Bram@vim.org>
-" Last Change: 2020 Feb 01
+" Last Change: 2021 Sep 21
" Only do this when not done yet for this buffer
if exists("b:did_ftplugin")
@@ -35,8 +35,11 @@ setlocal comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,://
" When the matchit plugin is loaded, this makes the % command skip parens and
" braces in comments properly.
-let b:match_words = '^\s*#\s*if\(\|def\|ndef\)\>:^\s*#\s*elif\>:^\s*#\s*else\>:^\s*#\s*endif\>'
-let b:match_skip = 's:comment\|string\|character\|special'
+if !exists("b:match_words")
+ let b:match_words = '^\s*#\s*if\(\|def\|ndef\)\>:^\s*#\s*elif\>:^\s*#\s*else\>:^\s*#\s*endif\>'
+ let b:match_skip = 's:comment\|string\|character\|special'
+ let b:undo_ftplugin ..= " | unlet! b:match_skip b:match_words"
+endif
" Win32 can filter files in the browse dialog
if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
@@ -57,6 +60,7 @@ if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
\ "C++ Source Files (*.cpp *.c++)\t*.cpp;*.c++\n" .
\ "All Files (*.*)\t*.*\n"
endif
+ let b:undo_ftplugin ..= " | unlet! b:browsefilter"
endif
let b:man_default_sects = '3,2'
diff --git a/runtime/ftplugin/chicken.vim b/runtime/ftplugin/chicken.vim
index 4dc1e57d0a..84d45bae1e 100644
--- a/runtime/ftplugin/chicken.vim
+++ b/runtime/ftplugin/chicken.vim
@@ -2,6 +2,7 @@
" Last Change: 2018-03-05
" Author: Evan Hanson <evhan@foldling.org>
" Maintainer: Evan Hanson <evhan@foldling.org>
+" Repository: https://git.foldling.org/vim-scheme.git
" URL: https://foldling.org/vim/ftplugin/chicken.vim
" Notes: These are supplemental settings, to be loaded after the core
" Scheme ftplugin file (ftplugin/scheme.vim). Enable it by setting
diff --git a/runtime/ftplugin/dosini.vim b/runtime/ftplugin/dosini.vim
index 0d0f0f8983..6a53dfd096 100644
--- a/runtime/ftplugin/dosini.vim
+++ b/runtime/ftplugin/dosini.vim
@@ -1,5 +1,5 @@
" Vim filetype plugin file
-" Language: Configuration File (ini file) for MSDOS/MS Windows
+" Language: Configuration File (ini file) for MS-DOS/MS Windows
" Previous Maintainer: Nikolai Weibull <now@bitwi.se>
" Latest Revision: 2008-07-09
diff --git a/runtime/ftplugin/eruby.vim b/runtime/ftplugin/eruby.vim
index 3c18bada78..e67b00b278 100644
--- a/runtime/ftplugin/eruby.vim
+++ b/runtime/ftplugin/eruby.vim
@@ -3,7 +3,7 @@
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
" URL: https://github.com/vim-ruby/vim-ruby
" Release Coordinator: Doug Kearns <dougkearns@gmail.com>
-" Last Change: 2019 Jan 06
+" Last Change: 2020 Jun 28
" Only do this when not done yet for this buffer
if exists("b:did_ftplugin")
@@ -118,7 +118,7 @@ endif
" TODO: comments=
setlocal commentstring=<%#%s%>
-let b:undo_ftplugin = "setl cms< "
+let b:undo_ftplugin = "setl cms< " .
\ " | unlet! b:browsefilter b:match_words | " . s:undo_ftplugin
let &cpo = s:save_cpo
diff --git a/runtime/ftplugin/gprof.vim b/runtime/ftplugin/gprof.vim
index d4547ae9a6..d8974bcc84 100644
--- a/runtime/ftplugin/gprof.vim
+++ b/runtime/ftplugin/gprof.vim
@@ -1,6 +1,7 @@
-" Language: gprof
-" Maintainer: Dominique Pelle <dominique.pelle@gmail.com>
-" Last Change: 2021 Apr 08
+" Language: gprof
+" Maintainer: Dominique Pelle <dominique.pelle@gmail.com>
+" Contributors: Doug Kearns <dougkearns@gmail.com>
+" Last Change: 2021 Sep 19
" When cursor is on one line of the gprof call graph,
" calling this function jumps to this function in the call graph.
@@ -9,7 +10,7 @@ if exists("b:did_ftplugin")
endif
let b:did_ftplugin=1
-fun! <SID>GprofJumpToFunctionIndex()
+func! <SID>GprofJumpToFunctionIndex()
let l:line = getline('.')
if l:line =~ '[\d\+\]$'
" We're in a line in the call graph.
@@ -22,11 +23,14 @@ fun! <SID>GprofJumpToFunctionIndex()
call search('^\[\d\+\].*\d\s\+' . escape(@", '[]*.') . '\>', 'sW')
norm! zz
endif
-endfun
+endfunc
-" Pressing <C-]> on a line in the gprof flat profile or in
-" the call graph, jumps to the corresponding function inside
-" the flat profile.
-map <buffer> <silent> <C-]> :call <SID>GprofJumpToFunctionIndex()<CR>
+if !exists("no_plugin_maps") && !exists("no_gprof_maps")
+ " Pressing <C-]> on a line in the gprof flat profile or in
+ " the call graph, jumps to the corresponding function inside
+ " the flat profile.
+ map <buffer> <silent> <C-]> :call <SID>GprofJumpToFunctionIndex()<CR>
+ let b:undo_ftplugin = "silent! unmap <buffer> <C-]>"
+endif
" vim:sw=2 fdm=indent
diff --git a/runtime/ftplugin/jsonc.vim b/runtime/ftplugin/jsonc.vim
new file mode 100644
index 0000000000..90d52cd0d3
--- /dev/null
+++ b/runtime/ftplugin/jsonc.vim
@@ -0,0 +1,27 @@
+" Vim filetype plugin
+" Language: JSONC (JSON with Comments)
+" Original Author: Izhak Jakov <izhak724@gmail.com>
+" Acknowledgement: Based off of vim-jsonc maintained by Kevin Locke <kevin@kevinlocke.name>
+" https://github.com/kevinoid/vim-jsonc
+" License: MIT
+" Last Change: 2021-07-01
+
+runtime! ftplugin/json.vim
+
+if exists('b:did_ftplugin_jsonc')
+ finish
+else
+ let b:did_ftplugin_jsonc = 1
+endif
+
+" A list of commands that undo buffer local changes made below.
+let s:undo_ftplugin = []
+
+" Set comment (formatting) related options. {{{1
+setlocal commentstring=//%s comments=sO:*\ -,mO:*\ \ ,exO:*/,s1:/*,mb:*,ex:*/,://
+call add(s:undo_ftplugin, 'commentstring< comments<')
+
+" Let Vim know how to disable the plug-in.
+call map(s:undo_ftplugin, "'execute ' . string(v:val)")
+let b:undo_ftplugin = join(s:undo_ftplugin, ' | ')
+unlet s:undo_ftplugin
diff --git a/runtime/ftplugin/julia.vim b/runtime/ftplugin/julia.vim
new file mode 100644
index 0000000000..32e364e436
--- /dev/null
+++ b/runtime/ftplugin/julia.vim
@@ -0,0 +1,92 @@
+" Vim filetype plugin file
+" Language: Julia
+" Maintainer: Carlo Baldassi <carlobaldassi@gmail.com>
+" Homepage: https://github.com/JuliaEditorSupport/julia-vim
+" Last Change: 2014 may 29
+" adapted from upstream 2021 Aug 4
+
+if exists("b:did_ftplugin")
+ finish
+endif
+let b:did_ftplugin = 1
+
+let s:save_cpo = &cpo
+set cpo-=C
+
+setlocal include=^\\s*\\%(reload\\\|include\\)\\>
+setlocal suffixesadd=.jl
+setlocal comments=:#
+setlocal commentstring=#\ %s
+setlocal cinoptions+=#1
+setlocal define=^\\s*macro\\>
+setlocal fo-=t fo+=croql
+
+let b:julia_vim_loaded = 1
+
+let b:undo_ftplugin = "setlocal include< suffixesadd< comments< commentstring<"
+ \ . " define< fo< shiftwidth< expandtab< indentexpr< indentkeys< cinoptions< completefunc<"
+ \ . " | unlet! b:julia_vim_loaded"
+
+" MatchIt plugin support
+if exists("loaded_matchit")
+ let b:match_ignorecase = 0
+
+ " note: begin_keywords must contain all blocks, in order
+ " for nested-structures-skipping to work properly
+ " note: 'mutable struct' and 'struct' are defined separately because
+ " using \? puts the cursor on 'struct' instead of 'mutable' for some reason
+ let b:julia_begin_keywords = '\%(\.\s*\|@\)\@<!\<\%(function\|macro\|begin\|mutable\s\+struct\|\%(mutable\s\+\)\@<!struct\|\%(abstract\|primitive\)\s\+type\|let\|do\|\%(bare\)\?module\|quote\|if\|for\|while\|try\)\>'
+ " note: the following regex not only recognizes macros, but also local/global keywords.
+ " the purpose is recognizing things like `@inline myfunction()`
+ " or `global myfunction(...)` etc, for matchit and block movement functionality
+ let s:macro_regex = '\%(@\%([#(]\@!\S\)\+\|\<\%(local\|global\)\)\s\+'
+ let s:nomacro = '\%(' . s:macro_regex . '\)\@<!'
+ let s:yesmacro = s:nomacro . '\%('. s:macro_regex . '\)\+'
+ let b:julia_begin_keywordsm = '\%(' . s:yesmacro . b:julia_begin_keywords . '\)\|'
+ \ . '\%(' . s:nomacro . b:julia_begin_keywords . '\)'
+ let b:julia_end_keywords = '\<end\>'
+
+ " note: this function relies heavily on the syntax file
+ function! JuliaGetMatchWords()
+ let [l,c] = [line('.'),col('.')]
+ let attr = synIDattr(synID(l, c, 1),"name")
+ let c1 = c
+ while attr == 'juliaMacro' || expand('<cword>') =~# '\<\%(global\|local\)\>'
+ normal! W
+ if line('.') > l || col('.') == c1
+ call cursor(l, c)
+ return ''
+ endif
+ let attr = synIDattr(synID(l, col('.'), 1),"name")
+ let c1 = col('.')
+ endwhile
+ call cursor(l, c)
+ if attr == 'juliaConditional'
+ return b:julia_begin_keywordsm . ':\<\%(elseif\|else\)\>:' . b:julia_end_keywords
+ elseif attr =~# '\<\%(juliaRepeat\|juliaRepKeyword\)\>'
+ return b:julia_begin_keywordsm . ':\<\%(break\|continue\)\>:' . b:julia_end_keywords
+ elseif attr == 'juliaBlKeyword'
+ return b:julia_begin_keywordsm . ':' . b:julia_end_keywords
+ elseif attr == 'juliaException'
+ return b:julia_begin_keywordsm . ':\<\%(catch\|finally\)\>:' . b:julia_end_keywords
+ endif
+ return '\<\>:\<\>'
+ endfunction
+
+ let b:match_words = 'JuliaGetMatchWords()'
+
+ " we need to skip everything within comments, strings and
+ " the 'begin' and 'end' keywords when they are used as a range rather than as
+ " the delimiter of a block
+ let b:match_skip = 'synIDattr(synID(line("."),col("."),0),"name") =~# '
+ \ . '"\\<julia\\%(Comprehension\\%(For\\|If\\)\\|RangeKeyword\\|Comment\\%([LM]\\|Delim\\)\\|\\%([bs]\\|Shell\\|Printf\\|Doc\\)\\?String\\|StringPrefixed\\|DocStringM\\(Raw\\)\\?\\|RegEx\\|SymbolS\\?\\|Dotted\\)\\>"'
+
+ let b:undo_ftplugin = b:undo_ftplugin
+ \ . " | unlet! b:match_words b:match_skip b:match_ignorecase"
+ \ . " | unlet! b:julia_begin_keywords b:julia_end_keywords"
+ \ . " | delfunction JuliaGetMatchWords"
+
+endif
+
+let &cpo = s:save_cpo
+unlet s:save_cpo
diff --git a/runtime/ftplugin/man.vim b/runtime/ftplugin/man.vim
index 5d3e00d033..fce12012b5 100644
--- a/runtime/ftplugin/man.vim
+++ b/runtime/ftplugin/man.vim
@@ -6,14 +6,6 @@ if exists('b:did_ftplugin') || &filetype !=# 'man'
endif
let b:did_ftplugin = 1
-let s:pager = !exists('b:man_sect')
-
-if s:pager
- call man#init_pager()
-endif
-
-setlocal noswapfile buftype=nofile bufhidden=hide
-setlocal nomodified readonly nomodifiable
setlocal noexpandtab tabstop=8 softtabstop=8 shiftwidth=8
setlocal wrap breakindent linebreak
@@ -32,11 +24,7 @@ if !exists('g:no_plugin_maps') && !exists('g:no_man_maps')
nnoremap <silent> <buffer> k gk
nnoremap <silent> <buffer> gO :call man#show_toc()<CR>
nnoremap <silent> <buffer> <2-LeftMouse> :Man<CR>
- if s:pager
- nnoremap <silent> <buffer> <nowait> q :lclose<CR>:q<CR>
- else
- nnoremap <silent> <buffer> <nowait> q :lclose<CR><C-W>c
- endif
+ nnoremap <silent> <buffer> <nowait> q :lclose<CR><C-W>c
endif
if get(g:, 'ft_man_folding_enable', 0)
diff --git a/runtime/ftplugin/matlab.vim b/runtime/ftplugin/matlab.vim
index a1a282f19e..d3c74b4ecf 100644
--- a/runtime/ftplugin/matlab.vim
+++ b/runtime/ftplugin/matlab.vim
@@ -1,7 +1,8 @@
" Vim filetype plugin file
" Language: matlab
" Maintainer: Jake Wasserman <jwasserman at gmail dot com>
-" Last Change: 2019 Sep 27
+" Update By: Gabriel Dupras
+" Last Change: 2021 Aug 30
" Contributors:
" Charles Campbell
@@ -15,9 +16,9 @@ let s:save_cpo = &cpo
set cpo-=C
if exists("loaded_matchit")
- let s:conditionalEnd = '\%(([^()]*\)\@!\<end\>\%([^()]*)\)\@!'
+ let s:conditionalEnd = '\%(\%(^\|;\)\s*\)\@<=end\>'
let b:match_words=
- \ '\<\%(if\|switch\|for\|while\)\>:\<\%(elseif\|case\|break\|continue\|else\|otherwise\)\>:'.s:conditionalEnd.','.
+ \ '\<\%(if\|switch\|for\|while\|try\)\>:\<\%(elseif\|case\|break\|continue\|else\|otherwise\|catch\)\>:' . s:conditionalEnd . ',' .
\ '\<function\>:\<return\>:\<endfunction\>'
unlet s:conditionalEnd
endif
diff --git a/runtime/ftplugin/ocaml.vim b/runtime/ftplugin/ocaml.vim
index 8a628604fa..20172c9b32 100644
--- a/runtime/ftplugin/ocaml.vim
+++ b/runtime/ftplugin/ocaml.vim
@@ -371,7 +371,7 @@ endfunction
endif
else
let annot_file_name = ''
- "(Pierre Vittet: I have commented 4b because this was chrashing
+ "(Pierre Vittet: I have commented 4b because this was crashing
"my vim (it produced infinite loop))
"
" 4b. anarchy : the renamed _build directory may be higher in the hierarchy
@@ -462,8 +462,8 @@ endfunction
"b. 'search' and 'match' work to find the type information
- "In: - lin1,col1: postion of expression first char
- " - lin2,col2: postion of expression last char
+ "In: - lin1,col1: position of expression first char
+ " - lin2,col2: position of expression last char
"Out: - the pattern to be looked for to find the block
" Must be called in the source buffer (use of line2byte)
function! s:Block_pattern(lin1,lin2,col1,col2)
@@ -581,7 +581,7 @@ endfunction
let res = substitute (a:res, "\n", "", "g" )
"remove double space
let res =substitute(res , " ", " ", "g")
- "remove space at begining of string.
+ "remove space at beginning of string.
let res = substitute(res, "^ *", "", "g")
return res
endfunction
diff --git a/runtime/ftplugin/octave.vim b/runtime/ftplugin/octave.vim
new file mode 100644
index 0000000000..7cab7c212a
--- /dev/null
+++ b/runtime/ftplugin/octave.vim
@@ -0,0 +1,63 @@
+" Vim filetype plugin file
+" Language: GNU Octave
+" Maintainer: Doug Kearns <dougkearns@gmail.com>
+" Last Change: 2021 Sep 02
+
+if exists("b:did_ftplugin")
+ finish
+endif
+let b:did_ftplugin = 1
+
+let s:cpo_save = &cpo
+set cpo&vim
+
+" TODO: update Matlab ftplugin and source it as the base file?
+
+setlocal comments=s:%{,m:\ ,e:%},s:#{,m:\ ,e:#},:%,:#
+setlocal commentstring=#\ %s
+setlocal formatoptions-=t formatoptions+=croql
+
+setlocal keywordprg=info\ octave\ --vi-keys\ --index-search
+
+if exists("loaded_matchit") && !exists("b:match_words")
+ let b:match_words = '\<unwind_protect\>:\<unwind_protect_cleanup\>:\<end_unwind_protect\>'
+ if exists("octave_use_matlab_end")
+ let b:match_words ..= ',' ..
+ \ '\<\%(classdef\|enumeration\|events\|for\|function\|if\|methods\|parfor\|properties\|switch\|while\|try\)\>' ..
+ \ ':' ..
+ \ '\<\%(elseif\|else\|case\|otherwise\|break\|continue\|catch\)\>' ..
+ \ ':' ..
+ \ '\<end\>'
+ else
+ let b:match_words ..= ',' ..
+ \ '\<classdef\>:\<endclassdef\>,' ..
+ \ '\<enumeration\>:\<endenumeration\>,' ..
+ \ '\<events\>:\<endevents\>,' ..
+ \ '\<do\>:\<\%(break\|continue\)\>:\<until\>' ..
+ \ '\<for\>:\<\%(break\|continue\)\>:\<endfor\>,' ..
+ \ '\<function\>:\<return\>:\<endfunction\>,' ..
+ \ '\<if\>:\<\%(elseif\|else\)\>:\<endif\>,' ..
+ \ '\<methods\>:\<endmethods\>,' ..
+ \ '\<parfor\>:\<endparfor\>,' ..
+ \ '\<properties\>:\<endproperties\>,' ..
+ \ '\<switch\>:\<\%(case\|otherwise\)\>:\<endswitch\>,' ..
+ \ '\<while\>:\<\%(break\|continue\)\>:\<endwhile\>,' ..
+ \ '\<try\>:\<catch\>:\<end_try_catch\>'
+ endif
+ " only match in statement position
+ let s:statement_start = escape('\%(\%(^\|;\)\s*\)\@<=', '\')
+ let b:match_words = substitute(b:match_words, '\\<', s:statement_start, 'g')
+endif
+
+if (has("gui_win32") || has("gui_gtk")) && !exists("b:browsefilter")
+ let b:browsefilter = "GNU Octave Source Files (*.m)\t*.m\n" ..
+ \ "All Files (*.*)\t*.*\n"
+endif
+
+let b:undo_ftplugin = "setl com< cms< fo< kp< " ..
+ \ "| unlet! b:browsefilter b:match_words"
+
+let &cpo = s:cpo_save
+unlet s:cpo_save
+
+" vim: nowrap sw=2 sts=2 ts=8 noet:
diff --git a/runtime/ftplugin/ruby.vim b/runtime/ftplugin/ruby.vim
index b4a8eaa0d8..4a476fd8cf 100644
--- a/runtime/ftplugin/ruby.vim
+++ b/runtime/ftplugin/ruby.vim
@@ -3,7 +3,7 @@
" Maintainer: Tim Pope <vimNOSPAM@tpope.org>
" URL: https://github.com/vim-ruby/vim-ruby
" Release Coordinator: Doug Kearns <dougkearns@gmail.com>
-" Last Change: 2019 Nov 06
+" Last Change: 2020 Feb 13
if (exists("b:did_ftplugin"))
finish
@@ -112,7 +112,7 @@ else
if !exists('g:ruby_default_path')
if has("ruby") && has("win32")
ruby ::VIM::command( 'let g:ruby_default_path = split("%s",",")' % $:.join(%q{,}) )
- elseif executable('ruby')
+ elseif executable('ruby') && !empty($HOME)
let g:ruby_default_path = s:query_path($HOME)
else
let g:ruby_default_path = map(split($RUBYLIB,':'), 'v:val ==# "." ? "" : v:val')
diff --git a/runtime/ftplugin/scala.vim b/runtime/ftplugin/scala.vim
index 18e16f1d5b..b484df99f3 100644
--- a/runtime/ftplugin/scala.vim
+++ b/runtime/ftplugin/scala.vim
@@ -3,7 +3,7 @@
" Maintainer: Derek Wyatt
" URL: https://github.com/derekwyatt/vim-scala
" License: Same as Vim
-" Last Change: 02 August 2016
+" Last Change: 11 August 2021
" ----------------------------------------------------------------------------
if exists('b:did_ftplugin') || &cp
@@ -26,8 +26,8 @@ setlocal commentstring=//\ %s
setlocal shiftwidth=2 softtabstop=2 expandtab
-setlocal include='^\s*import'
-setlocal includeexpr='substitute(v:fname,"\\.","/","g")'
+setlocal include=^\\s*import
+setlocal includeexpr=substitute(v:fname,'\\.','/','g')
setlocal path+=src/main/scala,src/test/scala
setlocal suffixesadd=.scala
diff --git a/runtime/ftplugin/scdoc.vim b/runtime/ftplugin/scdoc.vim
new file mode 100644
index 0000000000..2e98e647f4
--- /dev/null
+++ b/runtime/ftplugin/scdoc.vim
@@ -0,0 +1,26 @@
+" scdoc filetype plugin
+" Maintainer: Gregory Anders <greg@gpanders.com>
+" Last Updated: 2021-08-04
+
+" Only do this when not done yet for this buffer
+if exists('b:did_ftplugin')
+ finish
+endif
+
+" Don't load another plugin for this buffer
+let b:did_ftplugin = 1
+
+setlocal comments=b:;
+setlocal commentstring=;%s
+setlocal formatoptions+=t
+setlocal noexpandtab
+setlocal shiftwidth=0
+setlocal softtabstop=0
+setlocal textwidth=80
+
+let b:undo_ftplugin = 'setl com< cms< fo< et< sw< sts< tw<'
+
+if has('conceal')
+ setlocal conceallevel=2
+ let b:undo_ftplugin .= ' cole<'
+endif
diff --git a/runtime/ftplugin/scheme.vim b/runtime/ftplugin/scheme.vim
index 5778594c41..04655bc136 100644
--- a/runtime/ftplugin/scheme.vim
+++ b/runtime/ftplugin/scheme.vim
@@ -1,9 +1,10 @@
" Vim filetype plugin file
" Language: Scheme (R7RS)
-" Last Change: 2019 Nov 18
+" Last Change: 2019-11-19
" Author: Evan Hanson <evhan@foldling.org>
" Maintainer: Evan Hanson <evhan@foldling.org>
" Previous Maintainer: Sergey Khorev <sergey.khorev@gmail.com>
+" Repository: https://git.foldling.org/vim-scheme.git
" URL: https://foldling.org/vim/ftplugin/scheme.vim
if exists('b:did_ftplugin')
@@ -48,7 +49,7 @@ let b:undo_ftplugin = b:undo_ftplugin . ' lispwords<'
let b:did_scheme_ftplugin = 1
if exists('b:is_chicken') || exists('g:is_chicken')
- exe 'ru! ftplugin/chicken.vim'
+ runtime! ftplugin/chicken.vim
endif
unlet b:did_scheme_ftplugin
diff --git a/runtime/ftplugin/systemverilog.vim b/runtime/ftplugin/systemverilog.vim
index e350427022..38ed1ad32a 100644
--- a/runtime/ftplugin/systemverilog.vim
+++ b/runtime/ftplugin/systemverilog.vim
@@ -32,7 +32,7 @@ if exists("loaded_matchit")
\ '\<checker\>:\<endchecker\>,' .
\ '\<class\>:\<endclass\>,' .
\ '\<clocking\>:\<endclocking\>,' .
- \ '\<gruop\>:\<endgruop\>,' .
+ \ '\<group\>:\<endgroup\>,' .
\ '\<interface\>:\<endinterface\>,' .
\ '\<package\>:\<endpackage\>,' .
\ '\<program\>:\<endprogram\>,' .
diff --git a/runtime/ftplugin/tex.vim b/runtime/ftplugin/tex.vim
index 11470012f9..0d68b51d46 100644
--- a/runtime/ftplugin/tex.vim
+++ b/runtime/ftplugin/tex.vim
@@ -28,7 +28,7 @@ let &l:define .= '\|\\\(re\)\=new\(boolean\|command\|counter\|environment\|font'
" Tell Vim how to recognize LaTeX \include{foo} and plain \input bar :
let &l:include .= '\|\\include{'
-" On some file systems, "{" and "}" are inluded in 'isfname'. In case the
+" On some file systems, "{" and "}" are included in 'isfname'. In case the
" TeX file has \include{fname} (LaTeX only), strip everything except "fname".
let &l:includeexpr = "substitute(v:fname, '^.\\{-}{\\|}.*', '', 'g')"
diff --git a/runtime/indent/ada.vim b/runtime/indent/ada.vim
index 1ca7fbacbe..6c8ab05267 100644
--- a/runtime/indent/ada.vim
+++ b/runtime/indent/ada.vim
@@ -219,7 +219,7 @@ function GetAdaIndent()
" Move indent in twice (next 'when' will move back)
let ind = ind + 2 * shiftwidth()
elseif line =~ '^\s*end\s*record\>'
- " Move indent back to tallying 'type' preceeding the 'record'.
+ " Move indent back to tallying 'type' preceding the 'record'.
" Allow indent to be equal to 'end record's.
let ind = s:MainBlockIndent( ind+shiftwidth(), lnum, 'type\>', '' )
elseif line =~ '\(^\s*new\>.*\)\@<!)\s*[;,]\s*$'
diff --git a/runtime/indent/bzl.vim b/runtime/indent/bzl.vim
index 6904bfdedb..cf4cfb5fad 100644
--- a/runtime/indent/bzl.vim
+++ b/runtime/indent/bzl.vim
@@ -1,7 +1,7 @@
" Vim indent file
" Language: Bazel (http://bazel.io)
" Maintainer: David Barnett (https://github.com/google/vim-ft-bzl)
-" Last Change: 2017 Jun 13
+" Last Change: 2021 Jul 08
if exists('b:did_indent')
finish
@@ -41,30 +41,41 @@ function GetBzlIndent(lnum) abort
if exists('g:pyindent_open_paren')
let l:pyindent_open_paren = g:pyindent_open_paren
endif
- let g:pyindent_nested_paren = 'shiftwidth() * 2'
- let g:pyindent_open_paren = 'shiftwidth() * 2'
+ let g:pyindent_nested_paren = 'shiftwidth()'
+ let g:pyindent_open_paren = 'shiftwidth()'
endif
let l:indent = -1
- " Indent inside parens.
- " Align with the open paren unless it is at the end of the line.
- " E.g.
- " open_paren_not_at_EOL(100,
- " (200,
- " 300),
- " 400)
- " open_paren_at_EOL(
- " 100, 200, 300, 400)
call cursor(a:lnum, 1)
let [l:par_line, l:par_col] = searchpairpos('(\|{\|\[', '', ')\|}\|\]', 'bW',
\ "line('.') < " . (a:lnum - s:maxoff) . " ? dummy :" .
\ " synIDattr(synID(line('.'), col('.'), 1), 'name')" .
\ " =~ '\\(Comment\\|String\\)$'")
if l:par_line > 0
- call cursor(l:par_line, 1)
- if l:par_col != col('$') - 1
- let l:indent = l:par_col
+ " Indent inside parens.
+ if searchpair('(\|{\|\[', '', ')\|}\|\]', 'W',
+ \ "line('.') < " . (a:lnum - s:maxoff) . " ? dummy :" .
+ \ " synIDattr(synID(line('.'), col('.'), 1), 'name')" .
+ \ " =~ '\\(Comment\\|String\\)$'") && line('.') == a:lnum
+ " If cursor is at close parens, match indent with open parens.
+ " E.g.
+ " foo(
+ " )
+ let l:indent = indent(l:par_line)
+ else
+ " Align with the open paren unless it is at the end of the line.
+ " E.g.
+ " open_paren_not_at_EOL(100,
+ " (200,
+ " 300),
+ " 400)
+ " open_paren_at_EOL(
+ " 100, 200, 300, 400)
+ call cursor(l:par_line, 1)
+ if l:par_col != col('$') - 1
+ let l:indent = l:par_col
+ endif
endif
endif
diff --git a/runtime/indent/cdl.vim b/runtime/indent/cdl.vim
index 4f9b7a8967..fb4fe27310 100644
--- a/runtime/indent/cdl.vim
+++ b/runtime/indent/cdl.vim
@@ -16,8 +16,8 @@ if exists("*CdlGetIndent")
"finish
endif
-" find out if an "...=..." expresion is an assignment (or a conditional)
-" it scans 'line' first, and then the previos lines
+" find out if an "...=..." expression is an assignment (or a conditional)
+" it scans 'line' first, and then the previous lines
fun! CdlAsignment(lnum, line)
let f = -1
let lnum = a:lnum
@@ -33,7 +33,7 @@ fun! CdlAsignment(lnum, line)
endif
" it's formula if there's a ';', 'elsE', 'theN', 'enDif' or 'expr'
" conditional if there's a '<', '>', 'elseif', 'if', 'and', 'or', 'not',
- " 'memberis', 'childrenof' and other \k\+of funcions
+ " 'memberis', 'childrenof' and other \k\+of functions
let f = line[inicio-1] =~? '[en;]' || strpart(line, inicio-4, 4) =~? 'ndif\|expr'
endw
let lnum = prevnonblank(lnum-1)
@@ -106,7 +106,7 @@ fun! CdlGetIndent(lnum)
elseif c == '(' || c ==? 'f' " '(' or 'if'
let ind = ind + shiftwidth()
else " c == '='
- " if it is an asignment increase indent
+ " if it is an assignment increase indent
if f == -1 " we don't know yet, find out
let f = CdlAsignment(lnum, strpart(line, 0, inicio))
end
@@ -117,11 +117,11 @@ fun! CdlGetIndent(lnum)
endw
" CURRENT LINE, if it starts with a closing element, decrease indent
- " or if it starts with '=' (asignment), increase indent
+ " or if it starts with '=' (assignment), increase indent
if match(thisline, '^\c\s*\(else\|then\|endif\|[);]\)') >= 0
let ind = ind - shiftwidth()
elseif match(thisline, '^\s*=') >= 0
- if f == -1 " we don't know yet if is an asignment, find out
+ if f == -1 " we don't know yet if is an assignment, find out
let f = CdlAsignment(lnum, "")
end
if f == 1 " formula increase it
diff --git a/runtime/indent/config.vim b/runtime/indent/config.vim
index 074f467bee..c987a78d64 100644
--- a/runtime/indent/config.vim
+++ b/runtime/indent/config.vim
@@ -62,8 +62,8 @@ function GetConfigIndent()
let ind = s:GetOffsetOf(line, '\[')
endif
- " if previous line had an unmatched closing parantheses,
- " indent to the matching opening parantheses
+ " if previous line had an unmatched closing parentheses,
+ " indent to the matching opening parentheses
if line =~ '[^(]\+\\\@<!)$'
call search(')', 'bW')
let lnum = searchpair('\\\@<!(', '', ')', 'bWn')
diff --git a/runtime/indent/dtd.vim b/runtime/indent/dtd.vim
index 963ac408ef..30c06aa8b2 100644
--- a/runtime/indent/dtd.vim
+++ b/runtime/indent/dtd.vim
@@ -119,16 +119,16 @@ function GetDTDIndent()
" Next comes the content model. If the token we’ve found isn’t a
" parenthesis it must be either ANY, EMPTY or some random junk. Either
" way, we’re done indenting this element, so set it to that of the first
- " line so that the terminating “>” winds up having the same indention.
+ " line so that the terminating “>” winds up having the same indentation.
if token != '('
return indent
endif
" Now go through the content model. We need to keep track of the nesting
" of parentheses. As soon as we hit 0 we’re done. If that happens we must
- " have a complete content model. Thus set indention to be the same as that
+ " have a complete content model. Thus set indentation to be the same as that
" of the first line so that the terminating “>” winds up having the same
- " indention. Otherwise, we’ll indent to the innermost parentheses not yet
+ " indentation. Otherwise, we’ll indent to the innermost parentheses not yet
" matched.
let [indent_of_innermost, end] = s:indent_to_innermost_parentheses(line, end)
if indent_of_innermost != -1
diff --git a/runtime/indent/erlang.vim b/runtime/indent/erlang.vim
index 625cfde0c1..4e7bf4ef4d 100644
--- a/runtime/indent/erlang.vim
+++ b/runtime/indent/erlang.vim
@@ -57,7 +57,7 @@ endfunction
" ======================
" Indtokens are "indentation tokens". See their exact format in the
-" documentaiton of the s:GetTokensFromLine function.
+" documentation of the s:GetTokensFromLine function.
" Purpose:
" Calculate the new virtual column after the given segment of a line.
@@ -75,7 +75,7 @@ endfunction
" s:CalcVCol("\t'\tx', b", 1, 4, 4) -> 10
function! s:CalcVCol(line, first_index, last_index, vcol, tabstop)
- " We copy the relevent segment of the line, otherwise if the line were
+ " We copy the relevant segment of the line, otherwise if the line were
" e.g. `"\t", term` then the else branch below would consume the `", term`
" part at once.
let line = a:line[a:first_index : a:last_index]
@@ -604,7 +604,7 @@ endfunction
function! s:BeginElementFoundIfEmpty(stack, token, curr_vcol, stored_vcol, sw)
if empty(a:stack)
if a:stored_vcol ==# -1
- call s:Log(' "' . a:token . '" directly preceeds LTI -> return')
+ call s:Log(' "' . a:token . '" directly precedes LTI -> return')
return [1, a:curr_vcol + a:sw]
else
call s:Log(' "' . a:token .
@@ -825,7 +825,7 @@ function! s:ErlangCalcIndent2(lnum, stack)
if ret | return res | endif
if stored_vcol ==# -1
- call s:Log(' End of clause directly preceeds LTI -> return')
+ call s:Log(' End of clause directly precedes LTI -> return')
return 0
else
call s:Log(' End of clause (but not end of line) -> return')
diff --git a/runtime/indent/html.vim b/runtime/indent/html.vim
index 7019bd4a82..d4b91f6421 100644
--- a/runtime/indent/html.vim
+++ b/runtime/indent/html.vim
@@ -1,7 +1,7 @@
" Vim indent script for HTML
" Maintainer: Bram Moolenaar
" Original Author: Andy Wokula <anwoku@yahoo.de>
-" Last Change: 2021 Jan 26
+" Last Change: 2021 Jun 13
" Version: 1.0 "{{{
" Description: HTML indent script with cached state for faster indenting on a
" range of lines.
@@ -62,7 +62,7 @@ let s:tagname = '\w\+\(-\w\+\)*'
" Prefer using buffer-local settings over global settings, so that there can
" be defaults for all HTML files and exceptions for specific types of HTML
" files.
-func! HtmlIndent_CheckUserSettings()
+func HtmlIndent_CheckUserSettings()
"{{{
let inctags = ''
if exists("b:html_indent_inctags")
@@ -178,7 +178,7 @@ let s:endtags = [0,0,0,0,0,0,0] " long enough for the highest index
"}}}
" Add a list of tag names for a pair of <tag> </tag> to "tags".
-func! s:AddITags(tags, taglist)
+func s:AddITags(tags, taglist)
"{{{
for itag in a:taglist
let a:tags[itag] = 1
@@ -187,7 +187,7 @@ func! s:AddITags(tags, taglist)
endfunc "}}}
" Take a list of tag name pairs that are not to be used as tag pairs.
-func! s:RemoveITags(tags, taglist)
+func s:RemoveITags(tags, taglist)
"{{{
for itag in a:taglist
let a:tags[itag] = 1
@@ -196,7 +196,7 @@ func! s:RemoveITags(tags, taglist)
endfunc "}}}
" Add a block tag, that is a tag with a different kind of indenting.
-func! s:AddBlockTag(tag, id, ...)
+func s:AddBlockTag(tag, id, ...)
"{{{
if !(a:id >= 2 && a:id < len(s:endtags))
echoerr 'AddBlockTag ' . a:id
@@ -255,7 +255,7 @@ call s:AddBlockTag('<!--[', 6, '![endif]-->')
" Return non-zero when "tagname" is an opening tag, not being a block tag, for
" which there should be a closing tag. Can be used by scripts that include
" HTML indenting.
-func! HtmlIndent_IsOpenTag(tagname)
+func HtmlIndent_IsOpenTag(tagname)
"{{{
if get(s:indent_tags, a:tagname) == 1
return 1
@@ -264,7 +264,7 @@ func! HtmlIndent_IsOpenTag(tagname)
endfunc "}}}
" Get the value for "tagname", taking care of buffer-local tags.
-func! s:get_tag(tagname)
+func s:get_tag(tagname)
"{{{
let i = get(s:indent_tags, a:tagname)
if (i == 1 || i == -1) && get(b:hi_removed_tags, a:tagname) != 0
@@ -277,7 +277,7 @@ func! s:get_tag(tagname)
endfunc "}}}
" Count the number of start and end tags in "text".
-func! s:CountITags(text)
+func s:CountITags(text)
"{{{
" Store the result in s:curind and s:nextrel.
let s:curind = 0 " relative indent steps for current line [unit &sw]:
@@ -289,7 +289,7 @@ func! s:CountITags(text)
endfunc "}}}
" Count the number of start and end tags in text.
-func! s:CountTagsAndState(text)
+func s:CountTagsAndState(text)
"{{{
" Store the result in s:curind and s:nextrel. Update b:hi_newstate.block.
let s:curind = 0 " relative indent steps for current line [unit &sw]:
@@ -304,7 +304,7 @@ func! s:CountTagsAndState(text)
endfunc "}}}
" Used by s:CountITags() and s:CountTagsAndState().
-func! s:CheckTag(itag)
+func s:CheckTag(itag)
"{{{
" Returns an empty string or "SCRIPT".
" a:itag can be "tag" or "/tag" or "<!--" or "-->"
@@ -338,7 +338,7 @@ func! s:CheckTag(itag)
endfunc "}}}
" Used by s:CheckTag(). Returns an empty string or "SCRIPT".
-func! s:CheckBlockTag(blocktag, ind)
+func s:CheckBlockTag(blocktag, ind)
"{{{
if a:ind > 0
" a block starts here
@@ -366,7 +366,7 @@ func! s:CheckBlockTag(blocktag, ind)
endfunc "}}}
" Used by s:CheckTag().
-func! s:CheckCustomTag(ctag)
+func s:CheckCustomTag(ctag)
"{{{
" Returns 1 if ctag is the tag for a custom element, 0 otherwise.
" a:ctag can be "tag" or "/tag" or "<!--" or "-->"
@@ -396,7 +396,7 @@ func! s:CheckCustomTag(ctag)
endfunc "}}}
" Return the <script> type: either "javascript" or ""
-func! s:GetScriptType(str)
+func s:GetScriptType(str)
"{{{
if a:str == "" || a:str =~ "java"
return "javascript"
@@ -407,7 +407,7 @@ endfunc "}}}
" Look back in the file, starting at a:lnum - 1, to compute a state for the
" start of line a:lnum. Return the new state.
-func! s:FreshState(lnum)
+func s:FreshState(lnum)
"{{{
" A state is to know ALL relevant details about the
" lines 1..a:lnum-1, initial calculating (here!) can be slow, but updating is
@@ -568,24 +568,29 @@ func! s:FreshState(lnum)
endfunc "}}}
" Indent inside a <pre> block: Keep indent as-is.
-func! s:Alien2()
+func s:Alien2()
"{{{
return -1
endfunc "}}}
" Return the indent inside a <script> block for javascript.
-func! s:Alien3()
+func s:Alien3()
"{{{
let lnum = prevnonblank(v:lnum - 1)
while lnum > 1 && getline(lnum) =~ '^\s*/[/*]'
" Skip over comments to avoid that cindent() aligns with the <script> tag
let lnum = prevnonblank(lnum - 1)
endwhile
+ if lnum < b:hi_indent.blocklnr
+ " indent for <script> itself
+ return b:hi_indent.blocktagind
+ endif
if lnum == b:hi_indent.blocklnr
" indent for the first line after <script>
return eval(b:hi_js1indent)
endif
if b:hi_indent.scripttype == "javascript"
+ " indent for further lines
return eval(b:hi_js1indent) + GetJavascriptIndent()
else
return -1
@@ -593,7 +598,7 @@ func! s:Alien3()
endfunc "}}}
" Return the indent inside a <style> block.
-func! s:Alien4()
+func s:Alien4()
"{{{
if prevnonblank(v:lnum-1) == b:hi_indent.blocklnr
" indent for first content line
@@ -603,7 +608,7 @@ func! s:Alien4()
endfunc "}}}
" Indending inside a <style> block. Returns the indent.
-func! s:CSSIndent()
+func s:CSSIndent()
"{{{
" This handles standard CSS and also Closure stylesheets where special lines
" start with @.
@@ -720,13 +725,13 @@ endfunc "}}}
" tag: blah
" tag: blah &&
" tag: blah ||
-func! s:CssUnfinished(text)
+func s:CssUnfinished(text)
"{{{
return a:text =~ '\(||\|&&\|:\|\k\)\s*$'
endfunc "}}}
" Search back for the first unfinished line above "lnum".
-func! s:CssFirstUnfinished(lnum, min_lnum)
+func s:CssFirstUnfinished(lnum, min_lnum)
"{{{
let align_lnum = a:lnum
while align_lnum > a:min_lnum && s:CssUnfinished(getline(align_lnum - 1))
@@ -736,7 +741,7 @@ func! s:CssFirstUnfinished(lnum, min_lnum)
endfunc "}}}
" Find the non-empty line at or before "lnum" that is not a comment.
-func! s:CssPrevNonComment(lnum, stopline)
+func s:CssPrevNonComment(lnum, stopline)
"{{{
" caller starts from a line a:lnum + 1 that is not a comment
let lnum = prevnonblank(a:lnum)
@@ -761,7 +766,7 @@ func! s:CssPrevNonComment(lnum, stopline)
endfunc "}}}
" Check the number of {} and () in line "lnum". Return a dict with the counts.
-func! HtmlIndent_CountBraces(lnum)
+func HtmlIndent_CountBraces(lnum)
"{{{
let brs = substitute(getline(a:lnum), '[''"].\{-}[''"]\|/\*.\{-}\*/\|/\*.*$\|[^{}()]', '', 'g')
let c_open = 0
@@ -794,7 +799,7 @@ func! HtmlIndent_CountBraces(lnum)
endfunc "}}}
" Return the indent for a comment: <!-- -->
-func! s:Alien5()
+func s:Alien5()
"{{{
let curtext = getline(v:lnum)
if curtext =~ '^\s*\zs-->'
@@ -826,7 +831,7 @@ func! s:Alien5()
endfunc "}}}
" Return the indent for conditional comment: <!--[ ![endif]-->
-func! s:Alien6()
+func s:Alien6()
"{{{
let curtext = getline(v:lnum)
if curtext =~ '\s*\zs<!\[endif\]-->'
@@ -840,7 +845,7 @@ func! s:Alien6()
endfunc "}}}
" When the "lnum" line ends in ">" find the line containing the matching "<".
-func! HtmlIndent_FindTagStart(lnum)
+func HtmlIndent_FindTagStart(lnum)
"{{{
" Avoids using the indent of a continuation line.
" Moves the cursor.
@@ -863,7 +868,7 @@ func! HtmlIndent_FindTagStart(lnum)
endfunc "}}}
" Find the unclosed start tag from the current cursor position.
-func! HtmlIndent_FindStartTag()
+func HtmlIndent_FindStartTag()
"{{{
" The cursor must be on or before a closing tag.
" If found, positions the cursor at the match and returns the line number.
@@ -877,7 +882,7 @@ func! HtmlIndent_FindStartTag()
endfunc "}}}
" Moves the cursor from a "<" to the matching ">".
-func! HtmlIndent_FindTagEnd()
+func HtmlIndent_FindTagEnd()
"{{{
" Call this with the cursor on the "<" of a start tag.
" This will move the cursor to the ">" of the matching end tag or, when it's
@@ -897,7 +902,7 @@ func! HtmlIndent_FindTagEnd()
endfunc "}}}
" Indenting inside a start tag. Return the correct indent or -1 if unknown.
-func! s:InsideTag(foundHtmlString)
+func s:InsideTag(foundHtmlString)
"{{{
if a:foundHtmlString
" Inside an attribute string.
@@ -958,7 +963,7 @@ func! s:InsideTag(foundHtmlString)
endfunc "}}}
" THE MAIN INDENT FUNCTION. Return the amount of indent for v:lnum.
-func! HtmlIndent()
+func HtmlIndent()
"{{{
if prevnonblank(v:lnum - 1) < 1
" First non-blank line has no indent.
diff --git a/runtime/indent/json.vim b/runtime/indent/json.vim
index c649e37013..09c7d7a85a 100644
--- a/runtime/indent/json.vim
+++ b/runtime/indent/json.vim
@@ -1,6 +1,6 @@
" Vim indent file
" Language: JSON
-" Mantainer: Eli Parra <eli@elzr.com> https://github.com/elzr/vim-json
+" Maintainer: Eli Parra <eli@elzr.com> https://github.com/elzr/vim-json
" Last Change: 2020 Aug 30
" https://github.com/jakar/vim-json/commit/20b650e22aa750c4ab6a66aa646bdd95d7cd548a#diff-e81fc111b2052e306d126bd9989f7b7c
" Original Author: Rogerz Zhang <rogerz.zhang at gmail.com> http://github.com/rogerz/vim-json
diff --git a/runtime/indent/jsonc.vim b/runtime/indent/jsonc.vim
new file mode 100644
index 0000000000..bf8e501dd5
--- /dev/null
+++ b/runtime/indent/jsonc.vim
@@ -0,0 +1,189 @@
+" Vim indent file
+" Language: JSONC (JSON with Comments)
+" Original Author: Izhak Jakov <izhak724@gmail.com>
+" Acknowledgement: Based off of vim-json maintained by Eli Parra <eli@elzr.com>
+" https://github.com/elzr/vim-json
+" Last Change: 2021-07-01
+
+" 0. Initialization {{{1
+" =================
+
+" Only load this indent file when no other was loaded.
+if exists("b:did_indent")
+ finish
+endif
+let b:did_indent = 1
+
+setlocal nosmartindent
+
+" Now, set up our indentation expression and keys that trigger it.
+setlocal indentexpr=GetJSONCIndent()
+setlocal indentkeys=0{,0},0),0[,0],!^F,o,O,e
+
+" Only define the function once.
+if exists("*GetJSONCIndent")
+ finish
+endif
+
+let s:cpo_save = &cpo
+set cpo&vim
+
+" 1. Variables {{{1
+" ============
+
+let s:line_term = '\s*\%(\%(\/\/\).*\)\=$'
+" Regex that defines blocks.
+let s:block_regex = '\%({\)\s*\%(|\%([*@]\=\h\w*,\=\s*\)\%(,\s*[*@]\=\h\w*\)*|\)\=' . s:line_term
+
+" 2. Auxiliary Functions {{{1
+" ======================
+
+" Check if the character at lnum:col is inside a string.
+function s:IsInString(lnum, col)
+ return synIDattr(synID(a:lnum, a:col, 1), 'name') == 'jsonString'
+endfunction
+
+" Find line above 'lnum' that isn't empty, or in a string.
+function s:PrevNonBlankNonString(lnum)
+ let lnum = prevnonblank(a:lnum)
+ while lnum > 0
+ " If the line isn't empty or in a string, end search.
+ let line = getline(lnum)
+ if !(s:IsInString(lnum, 1) && s:IsInString(lnum, strlen(line)))
+ break
+ endif
+ let lnum = prevnonblank(lnum - 1)
+ endwhile
+ return lnum
+endfunction
+
+" Check if line 'lnum' has more opening brackets than closing ones.
+function s:LineHasOpeningBrackets(lnum)
+ let open_0 = 0
+ let open_2 = 0
+ let open_4 = 0
+ let line = getline(a:lnum)
+ let pos = match(line, '[][(){}]', 0)
+ while pos != -1
+ let idx = stridx('(){}[]', line[pos])
+ if idx % 2 == 0
+ let open_{idx} = open_{idx} + 1
+ else
+ let open_{idx - 1} = open_{idx - 1} - 1
+ endif
+ let pos = match(line, '[][(){}]', pos + 1)
+ endwhile
+ return (open_0 > 0) . (open_2 > 0) . (open_4 > 0)
+endfunction
+
+function s:Match(lnum, regex)
+ let col = match(getline(a:lnum), a:regex) + 1
+ return col > 0 && !s:IsInString(a:lnum, col) ? col : 0
+endfunction
+
+" 3. GetJSONCIndent Function {{{1
+" =========================
+
+function GetJSONCIndent()
+ if !exists("s:inside_comment")
+ let s:inside_comment = 0
+ endif
+
+ " 3.1. Setup {{{2
+ " ----------
+
+ " Set up variables for restoring position in file. Could use v:lnum here.
+ let vcol = col('.')
+
+ " 3.2. Work on the current line {{{2
+ " -----------------------------
+
+
+ " Get the current line.
+ let line = getline(v:lnum)
+ let ind = -1
+ if s:inside_comment == 0
+ " TODO iterate through all the matches in a line
+ let col = matchend(line, '\/\*')
+ if col > 0 && !s:IsInString(v:lnum, col)
+ let s:inside_comment = 1
+ endif
+ endif
+ " If we're in the middle of a comment
+ if s:inside_comment == 1
+ let col = matchend(line, '\*\/')
+ if col > 0 && !s:IsInString(v:lnum, col)
+ let s:inside_comment = 0
+ endif
+ return ind
+ endif
+ if line =~ '^\s*//'
+ return ind
+ endif
+
+ " If we got a closing bracket on an empty line, find its match and indent
+ " according to it.
+ let col = matchend(line, '^\s*[]}]')
+
+ if col > 0 && !s:IsInString(v:lnum, col)
+ call cursor(v:lnum, col)
+ let bs = strpart('{}[]', stridx('}]', line[col - 1]) * 2, 2)
+
+ let pairstart = escape(bs[0], '[')
+ let pairend = escape(bs[1], ']')
+ let pairline = searchpair(pairstart, '', pairend, 'bW')
+
+ if pairline > 0
+ let ind = indent(pairline)
+ else
+ let ind = virtcol('.') - 1
+ endif
+
+ return ind
+ endif
+
+ " If we are in a multi-line string, don't do anything to it.
+ if s:IsInString(v:lnum, matchend(line, '^\s*') + 1)
+ return indent('.')
+ endif
+
+ " 3.3. Work on the previous line. {{{2
+ " -------------------------------
+
+ let lnum = prevnonblank(v:lnum - 1)
+
+ if lnum == 0
+ return 0
+ endif
+
+ " Set up variables for current line.
+ let line = getline(lnum)
+ let ind = indent(lnum)
+
+ " If the previous line ended with a block opening, add a level of indent.
+ " if s:Match(lnum, s:block_regex)
+ " return indent(lnum) + shiftwidth()
+ " endif
+
+ " If the previous line contained an opening bracket, and we are still in it,
+ " add indent depending on the bracket type.
+ if line =~ '[[({]'
+ let counts = s:LineHasOpeningBrackets(lnum)
+ if counts[0] == '1' || counts[1] == '1' || counts[2] == '1'
+ return ind + shiftwidth()
+ else
+ call cursor(v:lnum, vcol)
+ end
+ endif
+
+ " }}}2
+
+ return ind
+endfunction
+
+" }}}1
+
+let &cpo = s:cpo_save
+unlet s:cpo_save
+
+" vim:set sw=2 sts=2 ts=8 noet:
diff --git a/runtime/indent/julia.vim b/runtime/indent/julia.vim
new file mode 100644
index 0000000000..a90cff49e4
--- /dev/null
+++ b/runtime/indent/julia.vim
@@ -0,0 +1,491 @@
+" Vim indent file
+" Language: Julia
+" Maintainer: Carlo Baldassi <carlobaldassi@gmail.com>
+" Homepage: https://github.com/JuliaEditorSupport/julia-vim
+" Last Change: 2016 jun 16
+" Notes: originally based on Bram Molenaar's indent file for vim
+
+setlocal autoindent
+
+setlocal indentexpr=GetJuliaIndent()
+setlocal indentkeys+==end,=else,=catch,=finally,),],}
+setlocal indentkeys-=0#
+setlocal indentkeys-=:
+setlocal indentkeys-=0{
+setlocal indentkeys-=0}
+setlocal nosmartindent
+
+" Only define the function once.
+if exists("*GetJuliaIndent")
+ finish
+endif
+
+let s:skipPatternsBasic = '\<julia\%(Comment\%([LM]\|Delim\)\)\>'
+let s:skipPatterns = '\<julia\%(Comprehension\%(For\|If\)\|RangeKeyword\|Comment\%([LM]\|Delim\)\|\%([bs]\|Shell\|Printf\|Doc\)\?String\|StringPrefixed\|DocStringM\(Raw\)\?\|RegEx\|SymbolS\?\|Macro\|Dotted\)\>'
+
+function JuliaMatch(lnum, str, regex, st, ...)
+ let s = a:st
+ let e = a:0 > 0 ? a:1 : -1
+ let basic_skip = a:0 > 1 ? a:2 : 'all'
+ let skip = basic_skip ==# 'basic' ? s:skipPatternsBasic : s:skipPatterns
+ while 1
+ let f = match(a:str, '\C' . a:regex, s)
+ if e >= 0 && f >= e
+ return -1
+ endif
+ if f >= 0
+ let attr = synIDattr(synID(a:lnum,f+1,1),"name")
+ let attrT = synIDattr(synID(a:lnum,f+1,0),"name")
+ if attr =~# skip || attrT =~# skip
+ let s = f+1
+ continue
+ endif
+ endif
+ break
+ endwhile
+ return f
+endfunction
+
+function GetJuliaNestingStruct(lnum, ...)
+ " Auxiliary function to inspect the block structure of a line
+ let line = getline(a:lnum)
+ let s = a:0 > 0 ? a:1 : 0
+ let e = a:0 > 1 ? a:2 : -1
+ let blocks_stack = []
+ let num_closed_blocks = 0
+ while 1
+ let fb = JuliaMatch(a:lnum, line, '\<\%(if\|else\%(if\)\?\|while\|for\|try\|catch\|finally\|\%(staged\)\?function\|macro\|begin\|mutable\s\+struct\|\%(mutable\s\+\)\@<!struct\|\%(abstract\|primitive\)\s\+type\|let\|\%(bare\)\?module\|quote\|do\)\>', s, e)
+ let fe = JuliaMatch(a:lnum, line, '\<end\>', s, e)
+
+ if fb < 0 && fe < 0
+ " No blocks found
+ break
+ end
+
+ if fb >= 0 && (fb < fe || fe < 0)
+ " The first occurrence is an opening block keyword
+ " Note: some keywords (elseif,else,catch,finally) are both
+ " closing blocks and opening new ones
+
+ let i = JuliaMatch(a:lnum, line, '\<if\>', s)
+ if i >= 0 && i == fb
+ let s = i+1
+ call add(blocks_stack, 'if')
+ continue
+ endif
+ let i = JuliaMatch(a:lnum, line, '\<elseif\>', s)
+ if i >= 0 && i == fb
+ let s = i+1
+ if len(blocks_stack) > 0 && blocks_stack[-1] == 'if'
+ let blocks_stack[-1] = 'elseif'
+ elseif (len(blocks_stack) > 0 && blocks_stack[-1] != 'elseif') || len(blocks_stack) == 0
+ call add(blocks_stack, 'elseif')
+ let num_closed_blocks += 1
+ endif
+ continue
+ endif
+ let i = JuliaMatch(a:lnum, line, '\<else\>', s)
+ if i >= 0 && i == fb
+ let s = i+1
+ if len(blocks_stack) > 0 && blocks_stack[-1] =~# '\<\%(else\)\=if\>'
+ let blocks_stack[-1] = 'else'
+ else
+ call add(blocks_stack, 'else')
+ let num_closed_blocks += 1
+ endif
+ continue
+ endif
+
+ let i = JuliaMatch(a:lnum, line, '\<try\>', s)
+ if i >= 0 && i == fb
+ let s = i+1
+ call add(blocks_stack, 'try')
+ continue
+ endif
+ let i = JuliaMatch(a:lnum, line, '\<catch\>', s)
+ if i >= 0 && i == fb
+ let s = i+1
+ if len(blocks_stack) > 0 && blocks_stack[-1] == 'try'
+ let blocks_stack[-1] = 'catch'
+ else
+ call add(blocks_stack, 'catch')
+ let num_closed_blocks += 1
+ endif
+ continue
+ endif
+ let i = JuliaMatch(a:lnum, line, '\<finally\>', s)
+ if i >= 0 && i == fb
+ let s = i+1
+ if len(blocks_stack) > 0 && (blocks_stack[-1] == 'try' || blocks_stack[-1] == 'catch')
+ let blocks_stack[-1] = 'finally'
+ else
+ call add(blocks_stack, 'finally')
+ let num_closed_blocks += 1
+ endif
+ continue
+ endif
+
+ let i = JuliaMatch(a:lnum, line, '\<\%(bare\)\?module\>', s)
+ if i >= 0 && i == fb
+ let s = i+1
+ if i == 0
+ call add(blocks_stack, 'col1module')
+ else
+ call add(blocks_stack, 'other')
+ endif
+ continue
+ endif
+
+ let i = JuliaMatch(a:lnum, line, '\<\%(while\|for\|function\|macro\|begin\|\%(mutable\s\+\)\?struct\|\%(abstract\|primitive\)\s\+type\|let\|quote\|do\)\>', s)
+ if i >= 0 && i == fb
+ if match(line, '\C\<\%(mutable\|abstract\|primitive\)', i) != -1
+ let s = i+11
+ else
+ let s = i+1
+ endif
+ call add(blocks_stack, 'other')
+ continue
+ endif
+
+ " Note: it should be impossible to get here
+ break
+
+ else
+ " The first occurrence is an 'end'
+
+ let s = fe+1
+ if len(blocks_stack) == 0
+ let num_closed_blocks += 1
+ else
+ call remove(blocks_stack, -1)
+ endif
+ continue
+
+ endif
+
+ " Note: it should be impossible to get here
+ break
+ endwhile
+ let num_open_blocks = len(blocks_stack) - count(blocks_stack, 'col1module')
+ return [num_open_blocks, num_closed_blocks]
+endfunction
+
+function GetJuliaNestingBrackets(lnum, c)
+ " Auxiliary function to inspect the brackets structure of a line
+ let line = getline(a:lnum)[0 : (a:c - 1)]
+ let s = 0
+ let brackets_stack = []
+ let last_closed_bracket = -1
+ while 1
+ let fb = JuliaMatch(a:lnum, line, '[([{]', s)
+ let fe = JuliaMatch(a:lnum, line, '[])}]', s)
+
+ if fb < 0 && fe < 0
+ " No brackets found
+ break
+ end
+
+ if fb >= 0 && (fb < fe || fe < 0)
+ " The first occurrence is an opening bracket
+
+ let i = JuliaMatch(a:lnum, line, '(', s)
+ if i >= 0 && i == fb
+ let s = i+1
+ call add(brackets_stack, ['par',i])
+ continue
+ endif
+
+ let i = JuliaMatch(a:lnum, line, '\[', s)
+ if i >= 0 && i == fb
+ let s = i+1
+ call add(brackets_stack, ['sqbra',i])
+ continue
+ endif
+
+ let i = JuliaMatch(a:lnum, line, '{', s)
+ if i >= 0 && i == fb
+ let s = i+1
+ call add(brackets_stack, ['curbra',i])
+ continue
+ endif
+
+ " Note: it should be impossible to get here
+ break
+
+ else
+ " The first occurrence is a closing bracket
+
+ let i = JuliaMatch(a:lnum, line, ')', s)
+ if i >= 0 && i == fe
+ let s = i+1
+ if len(brackets_stack) > 0 && brackets_stack[-1][0] == 'par'
+ call remove(brackets_stack, -1)
+ else
+ let last_closed_bracket = i + 1
+ endif
+ continue
+ endif
+
+ let i = JuliaMatch(a:lnum, line, ']', s)
+ if i >= 0 && i == fe
+ let s = i+1
+ if len(brackets_stack) > 0 && brackets_stack[-1][0] == 'sqbra'
+ call remove(brackets_stack, -1)
+ else
+ let last_closed_bracket = i + 1
+ endif
+ continue
+ endif
+
+ let i = JuliaMatch(a:lnum, line, '}', s)
+ if i >= 0 && i == fe
+ let s = i+1
+ if len(brackets_stack) > 0 && brackets_stack[-1][0] == 'curbra'
+ call remove(brackets_stack, -1)
+ else
+ let last_closed_bracket = i + 1
+ endif
+ continue
+ endif
+
+ " Note: it should be impossible to get here
+ break
+
+ endif
+
+ " Note: it should be impossible to get here
+ break
+ endwhile
+ let first_open_bracket = -1
+ let last_open_bracket = -1
+ let infuncargs = 0
+ if len(brackets_stack) > 0
+ let first_open_bracket = brackets_stack[0][1]
+ let last_open_bracket = brackets_stack[-1][1]
+ if brackets_stack[-1][0] == 'par' && IsFunctionArgPar(a:lnum, last_open_bracket+1)
+ let infuncargs = 1
+ endif
+ endif
+ return [first_open_bracket, last_open_bracket, last_closed_bracket, infuncargs]
+endfunction
+
+let s:bracketBlocks = '\<julia\%(\%(\%(Printf\)\?Par\|SqBra\%(Idx\)\?\|CurBra\)Block\|ParBlockInRange\|StringVars\%(Par\|SqBra\|CurBra\)\|Dollar\%(Par\|SqBra\)\|QuotedParBlockS\?\)\>'
+
+function IsInBrackets(lnum, c)
+ let stack = map(synstack(a:lnum, a:c), 'synIDattr(v:val, "name")')
+ call filter(stack, 'v:val =~# s:bracketBlocks')
+ return len(stack) > 0
+endfunction
+
+function IsInDocString(lnum)
+ let stack = map(synstack(a:lnum, 1), 'synIDattr(v:val, "name")')
+ call filter(stack, 'v:val =~# "\\<juliaDocString\\(Delim\\|M\\\(Raw\\)\\?\\)\\?\\>"')
+ return len(stack) > 0
+endfunction
+
+function IsInContinuationImportLine(lnum)
+ let stack = map(synstack(a:lnum, 1), 'synIDattr(v:val, "name")')
+ call filter(stack, 'v:val =~# "\\<juliaImportLine\\>"')
+ if len(stack) == 0
+ return 0
+ endif
+ return JuliaMatch(a:lnum, getline(a:lnum), '\<\%(import\|using\|export\)\>', indent(a:lnum)) == -1
+endfunction
+
+function IsFunctionArgPar(lnum, c)
+ if a:c == 0
+ return 0
+ endif
+ let stack = map(synstack(a:lnum, a:c-1), 'synIDattr(v:val, "name")')
+ return len(stack) >= 2 && stack[-2] ==# 'juliaFunctionDef'
+endfunction
+
+function JumpToMatch(lnum, last_closed_bracket)
+ " we use the % command to skip back (tries to ues matchit if possible,
+ " otherwise resorts to vim's default, which is buggy but better than
+ " nothing)
+ call cursor(a:lnum, a:last_closed_bracket)
+ let percmap = maparg("%", "n")
+ if exists("g:loaded_matchit") && percmap =~# 'Match\%(it\|_wrapper\)'
+ normal %
+ else
+ normal! %
+ end
+endfunction
+
+" Auxiliary function to find a line which does not start in the middle of a
+" multiline bracketed expression, to be used as reference for block
+" indentation.
+function LastBlockIndent(lnum)
+ let lnum = a:lnum
+ let ind = 0
+ while lnum > 0
+ let ind = indent(lnum)
+ if ind == 0
+ return [lnum, 0]
+ endif
+ if !IsInBrackets(lnum, 1)
+ break
+ endif
+ let lnum = prevnonblank(lnum - 1)
+ endwhile
+ return [max([lnum,1]), ind]
+endfunction
+
+function GetJuliaIndent()
+ " Do not alter doctrings indentation
+ if IsInDocString(v:lnum)
+ return -1
+ endif
+
+ " Find a non-blank line above the current line.
+ let lnum = prevnonblank(v:lnum - 1)
+
+ " At the start of the file use zero indent.
+ if lnum == 0
+ return 0
+ endif
+
+ let ind = -1
+ let st = -1
+ let lim = -1
+
+ " Multiline bracketed expressions take precedence
+ let align_brackets = get(g:, "julia_indent_align_brackets", 1)
+ let align_funcargs = get(g:, "julia_indent_align_funcargs", 0)
+ let c = len(getline(lnum)) + 1
+ while IsInBrackets(lnum, c)
+ let [first_open_bracket, last_open_bracket, last_closed_bracket, infuncargs] = GetJuliaNestingBrackets(lnum, c)
+
+ " First scenario: the previous line has a hanging open bracket:
+ " set the indentation to match the opening bracket (plus an extra space)
+ " unless we're in a function arguments list or alignment is disabled, in
+ " which case we just add an extra indent
+ if last_open_bracket != -1
+ if (!infuncargs && align_brackets) || (infuncargs && align_funcargs)
+ let st = last_open_bracket
+ let ind = virtcol([lnum, st + 1])
+ else
+ let ind = indent(lnum) + shiftwidth()
+ endif
+
+ " Second scenario: some multiline bracketed expression was closed in the
+ " previous line. But since we know we are still in a bracketed expression,
+ " we need to find the line where the bracket was opened
+ elseif last_closed_bracket != -1
+ call JumpToMatch(lnum, last_closed_bracket)
+ if line(".") == lnum
+ " something wrong here, give up
+ let ind = indent(lnum)
+ else
+ let lnum = line(".")
+ let c = col(".") - 1
+ if c == 0
+ " uhm, give up
+ let ind = 0
+ else
+ " we skipped a bracket set, keep searching for an opening bracket
+ let lim = c
+ continue
+ endif
+ endif
+
+ " Third scenario: nothing special: keep the indentation
+ else
+ let ind = indent(lnum)
+ endif
+
+ " Does the current line start with a closing bracket? Then depending on
+ " the situation we align it with the opening one, or we let the rest of
+ " the code figure it out (the case in which we're closing a function
+ " argument list is special-cased)
+ if JuliaMatch(v:lnum, getline(v:lnum), '[])}]', indent(v:lnum)) == indent(v:lnum) && ind > 0
+ if !align_brackets && !align_funcargs
+ call JumpToMatch(v:lnum, indent(v:lnum))
+ return indent(line("."))
+ elseif (align_brackets && getline(v:lnum)[indent(v:lnum)] != ')') || align_funcargs
+ return ind - 1
+ else " must be a ')' and align_brackets==1 and align_funcargs==0
+ call JumpToMatch(v:lnum, indent(v:lnum))
+ if IsFunctionArgPar(line("."), col("."))
+ let ind = -1
+ else
+ return ind - 1
+ endif
+ endif
+ endif
+
+ break
+ endwhile
+
+ if ind == -1
+ " We are not in a multiline bracketed expression. Thus we look for a
+ " previous line to use as a reference
+ let [lnum,ind] = LastBlockIndent(lnum)
+ let c = len(getline(lnum)) + 1
+ if IsInBrackets(lnum, c)
+ let [first_open_bracket, last_open_bracket, last_closed_bracket, infuncargs] = GetJuliaNestingBrackets(lnum, c)
+ let lim = first_open_bracket
+ endif
+ end
+
+ " Analyse the reference line
+ let [num_open_blocks, num_closed_blocks] = GetJuliaNestingStruct(lnum, st, lim)
+ " Increase indentation for each newly opened block in the reference line
+ let ind += shiftwidth() * num_open_blocks
+
+ " Analyse the current line
+ let [num_open_blocks, num_closed_blocks] = GetJuliaNestingStruct(v:lnum)
+ " Decrease indentation for each closed block in the current line
+ let ind -= shiftwidth() * num_closed_blocks
+
+ " Additional special case: multiline import/using/export statements
+
+ let prevline = getline(lnum)
+ " Are we in a multiline import/using/export statement, right below the
+ " opening line?
+ if IsInContinuationImportLine(v:lnum) && !IsInContinuationImportLine(lnum)
+ if get(g:, 'julia_indent_align_import', 1)
+ " if the opening line has a colon followed by non-comments, use it as
+ " reference point
+ let cind = JuliaMatch(lnum, prevline, ':', indent(lnum), lim)
+ if cind >= 0
+ let nonwhiteind = JuliaMatch(lnum, prevline, '\S', cind+1, -1, 'basic')
+ if nonwhiteind >= 0
+ " return match(prevline, '\S', cind+1) " a bit overkill...
+ return cind + 2
+ endif
+ else
+ " if the opening line is not a naked import/using/export statement, use
+ " it as reference
+ let iind = JuliaMatch(lnum, prevline, '\<import\|using\|export\>', indent(lnum), lim)
+ if iind >= 0
+ " assuming whitespace after using... so no `using(XYZ)` please!
+ let nonwhiteind = JuliaMatch(lnum, prevline, '\S', iind+6, -1, 'basic')
+ if nonwhiteind >= 0
+ return match(prevline, '\S', iind+6)
+ endif
+ endif
+ endif
+ endif
+ let ind += shiftwidth()
+
+ " Or did we just close a multiline import/using/export statement?
+ elseif !IsInContinuationImportLine(v:lnum) && IsInContinuationImportLine(lnum)
+ " find the starting line of the statement
+ let ilnum = 0
+ for iln in range(lnum-1, 1, -1)
+ if !IsInContinuationImportLine(iln)
+ let ilnum = iln
+ break
+ endif
+ endfor
+ if ilnum == 0
+ " something went horribly wrong, give up
+ let ind = indent(lnum)
+ endif
+ let ind = indent(ilnum)
+ endif
+
+ return ind
+endfunction
diff --git a/runtime/indent/lifelines.vim b/runtime/indent/lifelines.vim
index 0d9b2b46e4..e6d61617dc 100644
--- a/runtime/indent/lifelines.vim
+++ b/runtime/indent/lifelines.vim
@@ -11,7 +11,7 @@ endif
let b:did_indent = 1
" LifeLines uses cindent without ; line terminator, C functions
-" declarations, C keywords, C++ formating
+" declarations, C keywords, C++ formatting
setlocal cindent
setlocal cinwords=""
setlocal cinoptions+=+0
diff --git a/runtime/indent/objc.vim b/runtime/indent/objc.vim
index beadca9fa4..a5451a5a11 100644
--- a/runtime/indent/objc.vim
+++ b/runtime/indent/objc.vim
@@ -15,7 +15,7 @@ setlocal cindent
" Set the function to do the work.
setlocal indentexpr=GetObjCIndent()
-" To make a colon (:) suggest an indentation other than a goto/swich label,
+" To make a colon (:) suggest an indentation other than a goto/switch label,
setlocal indentkeys-=:
setlocal indentkeys+=<:>
diff --git a/runtime/indent/pascal.vim b/runtime/indent/pascal.vim
index c7955d669b..1f39fd1cad 100644
--- a/runtime/indent/pascal.vim
+++ b/runtime/indent/pascal.vim
@@ -2,7 +2,7 @@
" Language: Pascal
" Maintainer: Neil Carter <n.carter@swansea.ac.uk>
" Created: 2004 Jul 13
-" Last Change: 2017 Jun 13
+" Last Change: 2021 Jul 01
"
" This is version 2.0, a complete rewrite.
"
@@ -20,6 +20,8 @@ setlocal indentkeys+==end;,==const,==type,==var,==begin,==repeat,==until,==for
setlocal indentkeys+==program,==function,==procedure,==object,==private
setlocal indentkeys+==record,==if,==else,==case
+let b:undo_indent = "setl indentkeys< indentexpr<"
+
if exists("*GetPascalIndent")
finish
endif
diff --git a/runtime/indent/pov.vim b/runtime/indent/pov.vim
index e806756c8e..f74c96b7f7 100644
--- a/runtime/indent/pov.vim
+++ b/runtime/indent/pov.vim
@@ -44,7 +44,7 @@ function GetPoVRayIndent()
return -1
endif
- " Search backwards for the frist non-empty, non-comment line.
+ " Search backwards for the first non-empty, non-comment line.
let plnum = prevnonblank(v:lnum - 1)
let plind = indent(plnum)
while plnum > 0 && synIDattr(synID(plnum, plind+1, 0), "name") =~? "comment"
diff --git a/runtime/indent/python.vim b/runtime/indent/python.vim
index f9236e63c7..307b7f656b 100644
--- a/runtime/indent/python.vim
+++ b/runtime/indent/python.vim
@@ -2,7 +2,7 @@
" Language: Python
" Maintainer: Bram Moolenaar <Bram@vim.org>
" Original Author: David Bustos <bustos@caltech.edu>
-" Last Change: 2019 Feb 21
+" Last Change: 2021 May 26
" Only load this indent file when no other was loaded.
if exists("b:did_indent")
@@ -191,7 +191,7 @@ function GetPythonIndent(lnum)
if getline(a:lnum) =~ '^\s*\(elif\|else\)\>'
" Unless the previous line was a one-liner
- if getline(plnumstart) =~ '^\s*\(for\|if\|try\)\>'
+ if getline(plnumstart) =~ '^\s*\(for\|if\|elif\|try\)\>'
return plindent
endif
diff --git a/runtime/indent/ruby.vim b/runtime/indent/ruby.vim
index 657aa763b1..559d8652a6 100644
--- a/runtime/indent/ruby.vim
+++ b/runtime/indent/ruby.vim
@@ -4,6 +4,7 @@
" Previous Maintainer: Nikolai Weibull <now at bitwi.se>
" URL: https://github.com/vim-ruby/vim-ruby
" Release Coordinator: Doug Kearns <dougkearns@gmail.com>
+" Last Change: 2021 Feb 03
" 0. Initialization {{{1
" =================
@@ -264,7 +265,7 @@ function! GetRubyIndent(...) abort
\ ]
" Most Significant line based on the previous one -- in case it's a
- " contination of something above
+ " continuation of something above
let indent_info.plnum_msl = s:GetMSL(indent_info.plnum)
for callback_name in indent_callback_names
diff --git a/runtime/indent/scala.vim b/runtime/indent/scala.vim
index 6fd8ca9d81..b5eba29543 100644
--- a/runtime/indent/scala.vim
+++ b/runtime/indent/scala.vim
@@ -20,7 +20,10 @@ endif
let s:keepcpo= &cpo
set cpo&vim
-let s:defMatcher = '\%(\%(private\|protected\)\%(\[[^\]]*\]\)\?\s\+\|abstract\s\+\|override\s\+\)*\<def\>'
+let s:annotationMatcher = '@[A-Za-z._]\+\s\+'
+let s:modifierMatcher = s:annotationMatcher . '\|\%(private\|protected\)\%(\[[^\]]*\]\)\?\s\+\|abstract\s\+\|override\s\+\|final\s\+'
+let s:defMatcher = '\%(' . s:modifierMatcher . '\)*\<def\>'
+let s:valMatcher = '\%(' . s:modifierMatcher . '\|lazy\s\+\)*\<va[lr]\>'
let s:funcNameMatcher = '\w\+'
let s:typeSpecMatcher = '\%(\s*\[\_[^\]]*\]\)'
let s:defArgMatcher = '\%((\_.\{-})\)'
@@ -184,7 +187,7 @@ function! scala#NumberOfBraceGroups(line)
endfunction
function! scala#MatchesIncompleteDefValr(line)
- if a:line =~ '^\s*\%(' . s:defMatcher . '\|\<va[lr]\>\).*[=({]\s*$'
+ if a:line =~ '^\s*\%(' . s:defMatcher . '\|' . s:valMatcher . '\).*[=({]\s*$'
return 1
else
return 0
@@ -434,7 +437,7 @@ function! GetScalaIndent()
" If 'val', 'var', 'def' end with =, this is a one-line block
if (prevline =~ '^\s*\<\%(\%(}\?\s*else\s\+\)\?if\|for\|while\)\>.*[)=]\s*$' && scala#NumberOfBraceGroups(prevline) <= 1)
\ || prevline =~ '^\s*' . s:defMatcher . '.*=\s*$'
- \ || prevline =~ '^\s*\<va[lr]\>.*[=]\s*$'
+ \ || prevline =~ '^\s*' . s:valMatcher . '.*[=]\s*$'
\ || prevline =~ '^\s*\%(}\s*\)\?\<else\>\s*$'
\ || prevline =~ '=\s*$'
call scala#ConditionalConfirm("4")
diff --git a/runtime/indent/sqlanywhere.vim b/runtime/indent/sqlanywhere.vim
index 601c567adc..d39fa3240e 100644
--- a/runtime/indent/sqlanywhere.vim
+++ b/runtime/indent/sqlanywhere.vim
@@ -9,7 +9,7 @@
" Notes:
" Indenting keywords are based on Oracle and Sybase Adaptive Server
" Anywhere (ASA). Test indenting was done with ASA stored procedures and
-" fuctions and Oracle packages which contain stored procedures and
+" functions and Oracle packages which contain stored procedures and
" functions.
" This has not been tested against Microsoft SQL Server or
" Sybase Adaptive Server Enterprise (ASE) which use the Transact-SQL
diff --git a/runtime/indent/systemverilog.vim b/runtime/indent/systemverilog.vim
index 590fd4d998..16fb4515c5 100644
--- a/runtime/indent/systemverilog.vim
+++ b/runtime/indent/systemverilog.vim
@@ -64,7 +64,7 @@ function SystemVerilogIndent()
let vverb = 0
endif
- " Indent accoding to last line
+ " Indent according to last line
" End of multiple-line comment
if last_line =~ '\*/\s*$' && last_line !~ '/\*.\{-}\*/'
let ind = ind - offset_comment1
@@ -220,7 +220,7 @@ function SystemVerilogIndent()
endif
- " Return the indention
+ " Return the indentation
return ind
endfunction
diff --git a/runtime/indent/testdir/xml.in b/runtime/indent/testdir/xml.in
index b6333340e2..88ad51e484 100644
--- a/runtime/indent/testdir/xml.in
+++ b/runtime/indent/testdir/xml.in
@@ -15,7 +15,7 @@ text comment
</tag1>
<!--
text comment
-end coment -->
+end comment -->
</tag0>
<!-- END_INDENT -->
diff --git a/runtime/indent/testdir/xml.ok b/runtime/indent/testdir/xml.ok
index cfdf701c11..d5e2289cb3 100644
--- a/runtime/indent/testdir/xml.ok
+++ b/runtime/indent/testdir/xml.ok
@@ -15,7 +15,7 @@
</tag1>
<!--
text comment
- end coment -->
+ end comment -->
</tag0>
<!-- END_INDENT -->
diff --git a/runtime/indent/tex.vim b/runtime/indent/tex.vim
index 8a44ade1ac..d356ba905b 100644
--- a/runtime/indent/tex.vim
+++ b/runtime/indent/tex.vim
@@ -288,7 +288,7 @@ function! GetTeXIndent() " {{{
let ind = ind - shiftwidth()
let stay = 0
endif
- " lines following to '\item' are intented once again:
+ " lines following to '\item' are indented once again:
if line =~ g:tex_items
let ind = ind + shiftwidth()
let stay = 0
diff --git a/runtime/indent/treetop.vim b/runtime/indent/treetop.vim
index 2c6eecf5c4..42ec1c8ad9 100644
--- a/runtime/indent/treetop.vim
+++ b/runtime/indent/treetop.vim
@@ -34,5 +34,5 @@ function GetTreetopIndent()
let ind -= shiftwidth()
end
- retur ind
+ return ind
endfunction
diff --git a/runtime/indent/typescript.vim b/runtime/indent/typescript.vim
index b6b2cb5acf..e899f83d0f 100644
--- a/runtime/indent/typescript.vim
+++ b/runtime/indent/typescript.vim
@@ -460,7 +460,7 @@ function! Fixedgq(lnum, count)
return 1
endif
- " Put all the lines on one line and do normal spliting after that
+ " Put all the lines on one line and do normal splitting after that
if l:count > 1
while l:count > 1
let l:count -= 1
diff --git a/runtime/indent/verilog.vim b/runtime/indent/verilog.vim
index ab3d0ba3e0..e81197c3b4 100644
--- a/runtime/indent/verilog.vim
+++ b/runtime/indent/verilog.vim
@@ -76,7 +76,7 @@ function GetVerilogIndent()
let vverb = 0
endif
- " Indent accoding to last line
+ " Indent according to last line
" End of multiple-line comment
if last_line =~ '\*/\s*$' && last_line !~ '/\*.\{-}\*/'
let ind = ind - offset_comment1
@@ -219,7 +219,7 @@ function GetVerilogIndent()
endif
- " Return the indention
+ " Return the indentation
return ind
endfunction
diff --git a/runtime/indent/yaml.vim b/runtime/indent/yaml.vim
index 8dca5cd763..ed57e68d8b 100644
--- a/runtime/indent/yaml.vim
+++ b/runtime/indent/yaml.vim
@@ -2,7 +2,7 @@
" Language: YAML
" Maintainer: Nikolai Pavlov <zyx.vim@gmail.com>
" Last Update: Lukas Reineke
-" Last Change: 2021 Jan 19
+" Last Change: 2021 Aug 13
" Only load this indent file when no other was loaded.
if exists('b:did_indent')
diff --git a/runtime/keymap/kana.vim b/runtime/keymap/kana.vim
index 23b5f876ac..9aff4eba41 100644
--- a/runtime/keymap/kana.vim
+++ b/runtime/keymap/kana.vim
@@ -364,7 +364,7 @@ ppu っぷ
ppe っぺ
ppo っぽ
-" Proceded by a small `tu' and followed by a small 'ya', 'yu' or 'yo'
+" Preceded by a small `tu' and followed by a small 'ya', 'yu' or 'yo'
kkya っきゃ
kkyu っきゅ
kkyo っきょ
@@ -683,7 +683,7 @@ PPU ップ
PPE ッペ
PPO ッポ
-" Proceded by a small `tu' and followed by a small 'ya', 'yu' or 'yo'
+" Preceded by a small `tu' and followed by a small 'ya', 'yu' or 'yo'
KKYA ッキャ
KKYU ッキュ
KKYO ッキョ
diff --git a/runtime/keymap/korean.vim b/runtime/keymap/korean.vim
index 044e3b9918..64ae519320 100644
--- a/runtime/keymap/korean.vim
+++ b/runtime/keymap/korean.vim
@@ -10,7 +10,7 @@
" BUT, simply mapping each letter of Hangul with sequence of alphabet 1 by 1
" can fail to combine Hangul jamo (conconants and vowels) right.
" For example, sequentially pressing `ㅅㅓㅇㅜㄹㄷㅐㅎㅏㄱㅛ` can not only be
-" combined as `서울대학교`, but alse `성ㅜㄹ댛ㅏㄱ교`, which is totally
+" combined as `서울대학교`, but also `성ㅜㄹ댛ㅏㄱ교`, which is totally
" nonsense.
" Though combining Hangul is deterministic with law that each letter must be
" one of (consonant + vowel) or (consonant + vowel + consonant), there is no
diff --git a/runtime/keymap/russian-jcukenwintype.vim b/runtime/keymap/russian-jcukenwintype.vim
index 25d6286e24..2d5856ad0c 100644
--- a/runtime/keymap/russian-jcukenwintype.vim
+++ b/runtime/keymap/russian-jcukenwintype.vim
@@ -4,7 +4,7 @@
" Useful mainly with utf-8 but may work with other encodings
" Derived from russian-jcuken.vim by Artem Chuprina <ran@ran.pp.ru>
-" Typewriter variant of standart russian layout
+" Typewriter variant of standard russian layout
" Maintainer: Denis Proskurin <danwerspb@gmail.com>
" Last Changed: 2015 May 15
diff --git a/runtime/keymap/russian-typograph.vim b/runtime/keymap/russian-typograph.vim
index a85e861e32..e0fbf22884 100644
--- a/runtime/keymap/russian-typograph.vim
+++ b/runtime/keymap/russian-typograph.vim
@@ -106,7 +106,7 @@ loadkeymap
<char-0x005d> <char-0x044a> " CYRILLIC SMALL LETTER HARD SIGN
<char-0x007d> <char-0x042a> " CYRILLIC CAPITAL LETTER HARD SIGN
-" ALPHABETIC 2st ROW
+" ALPHABETIC 2nd ROW
<char-0x0061> <char-0x0444> " CYRILLIC SMALL LETTER EF
<char-0x0041> <char-0x0424> " CYRILLIC CAPITAL LETTER EF
@@ -131,7 +131,7 @@ loadkeymap
<char-0x0027> <char-0x044d> " CYRILLIC SMALL LETTER E
<char-0x0022> <char-0x042d> " CYRILLIC CAPITAL LETTER E
-" ALPHABETIC 3st ROW
+" ALPHABETIC 3rd ROW
<char-0x007a> <char-0x044f> " CYRILLIC SMALL LETTER YA
<char-0x005a> <char-0x042f> " CYRILLIC CAPITAL LETTER YA
diff --git a/runtime/lua/vim/F.lua b/runtime/lua/vim/F.lua
index 7925ff6e44..1a258546a5 100644
--- a/runtime/lua/vim/F.lua
+++ b/runtime/lua/vim/F.lua
@@ -2,8 +2,8 @@ local F = {}
--- Returns {a} if it is not nil, otherwise returns {b}.
---
---@param a
---@param b
+---@param a
+---@param b
function F.if_nil(a, b)
if a == nil then return b end
return a
@@ -27,5 +27,14 @@ function F.nil_wrap(fn)
end
end
+--- like {...} except preserve the lenght explicitly
+function F.pack_len(...)
+ return {n=select('#', ...), ...}
+end
+
+--- like unpack() but use the length set by F.pack_len if present
+function F.unpack_len(t)
+ return unpack(t, 1, t.n)
+end
return F
diff --git a/runtime/lua/vim/_meta.lua b/runtime/lua/vim/_meta.lua
index b1f935541c..f7d47c1030 100644
--- a/runtime/lua/vim/_meta.lua
+++ b/runtime/lua/vim/_meta.lua
@@ -494,7 +494,6 @@ local convert_value_to_lua = (function()
for _, key_value_str in ipairs(comma_split) do
local key, value = unpack(vim.split(key_value_str, ":"))
key = vim.trim(key)
- value = vim.trim(value)
result[key] = value
end
diff --git a/runtime/lua/vim/diagnostic.lua b/runtime/lua/vim/diagnostic.lua
new file mode 100644
index 0000000000..00945a7fb3
--- /dev/null
+++ b/runtime/lua/vim/diagnostic.lua
@@ -0,0 +1,1381 @@
+local M = {}
+
+M.severity = {
+ ERROR = 1,
+ WARN = 2,
+ INFO = 3,
+ HINT = 4,
+}
+
+vim.tbl_add_reverse_lookup(M.severity)
+
+-- Mappings from qflist/loclist error types to severities
+M.severity.E = M.severity.ERROR
+M.severity.W = M.severity.WARN
+M.severity.I = M.severity.INFO
+M.severity.N = M.severity.HINT
+
+local global_diagnostic_options = {
+ signs = true,
+ underline = true,
+ virtual_text = true,
+ update_in_insert = false,
+ severity_sort = false,
+}
+
+-- Local functions {{{
+
+---@private
+local function to_severity(severity)
+ return type(severity) == 'string' and M.severity[string.upper(severity)] or severity
+end
+
+---@private
+local function filter_by_severity(severity, diagnostics)
+ if not severity then
+ return diagnostics
+ end
+
+ if type(severity) ~= "table" then
+ severity = to_severity(severity)
+ return vim.tbl_filter(function(t) return t.severity == severity end, diagnostics)
+ end
+
+ local min_severity = to_severity(severity.min) or M.severity.HINT
+ local max_severity = to_severity(severity.max) or M.severity.ERROR
+
+ return vim.tbl_filter(function(t) return t.severity <= min_severity and t.severity >= max_severity end, diagnostics)
+end
+
+---@private
+local function prefix_source(source, diagnostics)
+ vim.validate { source = {source, function(v)
+ return v == "always" or v == "if_many"
+ end, "Invalid value for option 'source'" } }
+
+ if source == "if_many" then
+ local sources = {}
+ for _, d in pairs(diagnostics) do
+ if d.source then
+ sources[d.source] = true
+ end
+ end
+ if #vim.tbl_keys(sources) <= 1 then
+ return diagnostics
+ end
+ end
+
+ return vim.tbl_map(function(d)
+ if not d.source then
+ return d
+ end
+
+ local t = vim.deepcopy(d)
+ t.message = string.format("%s: %s", d.source, d.message)
+ return t
+ end, diagnostics)
+end
+
+---@private
+local function reformat_diagnostics(format, diagnostics)
+ vim.validate {
+ format = {format, 'f'},
+ diagnostics = {diagnostics, 't'},
+ }
+
+ local formatted = vim.deepcopy(diagnostics)
+ for _, diagnostic in ipairs(formatted) do
+ diagnostic.message = format(diagnostic)
+ end
+ return formatted
+end
+
+---@private
+local function resolve_optional_value(option, namespace, bufnr)
+ local enabled_val = {}
+
+ if not option then
+ return false
+ elseif option == true then
+ return enabled_val
+ elseif type(option) == 'function' then
+ local val = option(namespace, bufnr)
+ if val == true then
+ return enabled_val
+ else
+ return val
+ end
+ elseif type(option) == 'table' then
+ return option
+ else
+ error("Unexpected option type: " .. vim.inspect(option))
+ end
+end
+
+local all_namespaces = {}
+
+---@private
+local function get_namespace(ns)
+ if not all_namespaces[ns] then
+ local name
+ for k, v in pairs(vim.api.nvim_get_namespaces()) do
+ if ns == v then
+ name = k
+ break
+ end
+ end
+
+ if not name then
+ return vim.notify("namespace does not exist or is anonymous", vim.log.levels.ERROR)
+ end
+
+ all_namespaces[ns] = {
+ name = name,
+ sign_group = string.format("vim.diagnostic.%s", name),
+ opts = {}
+ }
+ end
+ return all_namespaces[ns]
+end
+
+---@private
+local function get_resolved_options(opts, namespace, bufnr)
+ local ns = get_namespace(namespace)
+ local resolved = vim.tbl_extend('keep', opts or {}, ns.opts, global_diagnostic_options)
+ for k in pairs(global_diagnostic_options) do
+ if resolved[k] ~= nil then
+ resolved[k] = resolve_optional_value(resolved[k], namespace, bufnr)
+ end
+ end
+ return resolved
+end
+
+-- Default diagnostic highlights
+local diagnostic_severities = {
+ [M.severity.ERROR] = { ctermfg = 1, guifg = "Red" };
+ [M.severity.WARN] = { ctermfg = 3, guifg = "Orange" };
+ [M.severity.INFO] = { ctermfg = 4, guifg = "LightBlue" };
+ [M.severity.HINT] = { ctermfg = 7, guifg = "LightGrey" };
+}
+
+-- Make a map from DiagnosticSeverity -> Highlight Name
+---@private
+local function make_highlight_map(base_name)
+ local result = {}
+ for k in pairs(diagnostic_severities) do
+ local name = M.severity[k]
+ name = name:sub(1, 1) .. name:sub(2):lower()
+ result[k] = "Diagnostic" .. base_name .. name
+ end
+
+ return result
+end
+
+local virtual_text_highlight_map = make_highlight_map("VirtualText")
+local underline_highlight_map = make_highlight_map("Underline")
+local floating_highlight_map = make_highlight_map("Floating")
+local sign_highlight_map = make_highlight_map("Sign")
+
+---@private
+local define_default_signs = (function()
+ local signs_defined = false
+ return function()
+ if signs_defined then
+ return
+ end
+
+ for severity, sign_hl_name in pairs(sign_highlight_map) do
+ if vim.tbl_isempty(vim.fn.sign_getdefined(sign_hl_name)) then
+ local severity_name = M.severity[severity]
+ vim.fn.sign_define(sign_hl_name, {
+ text = (severity_name or 'U'):sub(1, 1),
+ texthl = sign_hl_name,
+ linehl = '',
+ numhl = '',
+ })
+ end
+ end
+
+ signs_defined = true
+ end
+end)()
+
+---@private
+local function get_bufnr(bufnr)
+ if not bufnr or bufnr == 0 then
+ return vim.api.nvim_get_current_buf()
+ end
+ return bufnr
+end
+
+-- Metatable that automatically creates an empty table when assigning to a missing key
+local bufnr_and_namespace_cacher_mt = {
+ __index = function(t, bufnr)
+ if not bufnr or bufnr == 0 then
+ bufnr = vim.api.nvim_get_current_buf()
+ end
+
+ if rawget(t, bufnr) == nil then
+ rawset(t, bufnr, {})
+ end
+
+ return rawget(t, bufnr)
+ end,
+
+ __newindex = function(t, bufnr, v)
+ if not bufnr or bufnr == 0 then
+ bufnr = vim.api.nvim_get_current_buf()
+ end
+
+ rawset(t, bufnr, v)
+ end,
+}
+
+local diagnostic_cleanup = setmetatable({}, bufnr_and_namespace_cacher_mt)
+local diagnostic_cache = setmetatable({}, bufnr_and_namespace_cacher_mt)
+local diagnostic_cache_extmarks = setmetatable({}, bufnr_and_namespace_cacher_mt)
+local diagnostic_attached_buffers = {}
+local diagnostic_disabled = {}
+local bufs_waiting_to_update = setmetatable({}, bufnr_and_namespace_cacher_mt)
+
+---@private
+local function is_disabled(namespace, bufnr)
+ if type(diagnostic_disabled[bufnr]) == "table" then
+ return diagnostic_disabled[bufnr][namespace]
+ end
+ return diagnostic_disabled[bufnr]
+end
+
+---@private
+local function diagnostic_lines(diagnostics)
+ if not diagnostics then
+ return {}
+ end
+
+ local diagnostics_by_line = {}
+ for _, diagnostic in ipairs(diagnostics) do
+ local line_diagnostics = diagnostics_by_line[diagnostic.lnum]
+ if not line_diagnostics then
+ line_diagnostics = {}
+ diagnostics_by_line[diagnostic.lnum] = line_diagnostics
+ end
+ table.insert(line_diagnostics, diagnostic)
+ end
+ return diagnostics_by_line
+end
+
+---@private
+local function set_diagnostic_cache(namespace, bufnr, diagnostics)
+ for _, diagnostic in ipairs(diagnostics) do
+ diagnostic.severity = diagnostic.severity and to_severity(diagnostic.severity) or M.severity.ERROR
+ diagnostic.end_lnum = diagnostic.end_lnum or diagnostic.lnum
+ diagnostic.end_col = diagnostic.end_col or diagnostic.col
+ diagnostic.namespace = namespace
+ diagnostic.bufnr = bufnr
+ end
+ diagnostic_cache[bufnr][namespace] = diagnostics
+end
+
+---@private
+local function clear_diagnostic_cache(namespace, bufnr)
+ diagnostic_cache[bufnr][namespace] = nil
+end
+
+---@private
+local function restore_extmarks(bufnr, last)
+ for ns, extmarks in pairs(diagnostic_cache_extmarks[bufnr]) do
+ local extmarks_current = vim.api.nvim_buf_get_extmarks(bufnr, ns, 0, -1, {details = true})
+ local found = {}
+ for _, extmark in ipairs(extmarks_current) do
+ -- nvim_buf_set_lines will move any extmark to the line after the last
+ -- nvim_buf_set_text will move any extmark to the last line
+ if extmark[2] ~= last + 1 then
+ found[extmark[1]] = true
+ end
+ end
+ for _, extmark in ipairs(extmarks) do
+ if not found[extmark[1]] then
+ local opts = extmark[4]
+ opts.id = extmark[1]
+ -- HACK: end_row should be end_line
+ if opts.end_row then
+ opts.end_line = opts.end_row
+ opts.end_row = nil
+ end
+ pcall(vim.api.nvim_buf_set_extmark, bufnr, ns, extmark[2], extmark[3], opts)
+ end
+ end
+ end
+end
+
+---@private
+local function save_extmarks(namespace, bufnr)
+ bufnr = bufnr == 0 and vim.api.nvim_get_current_buf() or bufnr
+ if not diagnostic_attached_buffers[bufnr] then
+ vim.api.nvim_buf_attach(bufnr, false, {
+ on_lines = function(_, _, _, _, _, last)
+ restore_extmarks(bufnr, last - 1)
+ end,
+ on_detach = function()
+ diagnostic_cache_extmarks[bufnr] = nil
+ end})
+ diagnostic_attached_buffers[bufnr] = true
+ end
+ diagnostic_cache_extmarks[bufnr][namespace] = vim.api.nvim_buf_get_extmarks(bufnr, namespace, 0, -1, {details = true})
+end
+
+local registered_autocmds = {}
+
+---@private
+local function make_augroup_key(namespace, bufnr)
+ local ns = get_namespace(namespace)
+ return string.format("DiagnosticInsertLeave:%s:%s", bufnr, ns.name)
+end
+
+--- Table of autocmd events to fire the update for displaying new diagnostic information
+local insert_leave_auto_cmds = { "InsertLeave", "CursorHoldI" }
+
+---@private
+local function schedule_display(namespace, bufnr, args)
+ bufs_waiting_to_update[bufnr][namespace] = args
+
+ local key = make_augroup_key(namespace, bufnr)
+ if not registered_autocmds[key] then
+ vim.cmd(string.format("augroup %s", key))
+ vim.cmd(" au!")
+ vim.cmd(
+ string.format(
+ [[autocmd %s <buffer=%s> lua vim.diagnostic._execute_scheduled_display(%s, %s)]],
+ table.concat(insert_leave_auto_cmds, ","),
+ bufnr,
+ namespace,
+ bufnr
+ )
+ )
+ vim.cmd("augroup END")
+
+ registered_autocmds[key] = true
+ end
+end
+
+---@private
+local function clear_scheduled_display(namespace, bufnr)
+ local key = make_augroup_key(namespace, bufnr)
+
+ if registered_autocmds[key] then
+ vim.cmd(string.format("augroup %s", key))
+ vim.cmd(" au!")
+ vim.cmd("augroup END")
+
+ registered_autocmds[key] = nil
+ end
+end
+
+---@private
+--- Open a floating window with the provided diagnostics
+---@param opts table Configuration table
+--- - show_header (boolean, default true): Show "Diagnostics:" header
+--- - all opts for |vim.util.open_floating_preview()| can be used here
+---@param diagnostics table: The diagnostics to display
+---@return table {popup_bufnr, win_id}
+local function show_diagnostics(opts, diagnostics)
+ if not diagnostics or vim.tbl_isempty(diagnostics) then
+ return
+ end
+ local lines = {}
+ local highlights = {}
+ local show_header = vim.F.if_nil(opts.show_header, true)
+ if show_header then
+ table.insert(lines, "Diagnostics:")
+ table.insert(highlights, {0, "Bold"})
+ end
+
+ if opts.format then
+ diagnostics = reformat_diagnostics(opts.format, diagnostics)
+ end
+
+ if opts.source then
+ diagnostics = prefix_source(opts.source, diagnostics)
+ end
+
+ for i, diagnostic in ipairs(diagnostics) do
+ local prefix = string.format("%d. ", i)
+ local hiname = floating_highlight_map[diagnostic.severity]
+ assert(hiname, 'unknown severity: ' .. tostring(diagnostic.severity))
+
+ local message_lines = vim.split(diagnostic.message, '\n', true)
+ table.insert(lines, prefix..message_lines[1])
+ table.insert(highlights, {#prefix, hiname})
+ for j = 2, #message_lines do
+ table.insert(lines, string.rep(' ', #prefix) .. message_lines[j])
+ table.insert(highlights, {0, hiname})
+ end
+ end
+
+ local popup_bufnr, winnr = require('vim.lsp.util').open_floating_preview(lines, 'plaintext', opts)
+ for i, hi in ipairs(highlights) do
+ local prefixlen, hiname = unpack(hi)
+ -- Start highlight after the prefix
+ vim.api.nvim_buf_add_highlight(popup_bufnr, -1, hiname, i-1, prefixlen, -1)
+ end
+
+ return popup_bufnr, winnr
+end
+
+---@private
+local function set_list(loclist, opts)
+ opts = opts or {}
+ local open = vim.F.if_nil(opts.open, true)
+ local title = opts.title or "Diagnostics"
+ local winnr = opts.winnr or 0
+ local bufnr
+ if loclist then
+ bufnr = vim.api.nvim_win_get_buf(winnr)
+ end
+ local diagnostics = M.get(bufnr, opts)
+ local items = M.toqflist(diagnostics)
+ if loclist then
+ vim.fn.setloclist(winnr, {}, ' ', { title = title, items = items })
+ else
+ vim.fn.setqflist({}, ' ', { title = title, items = items })
+ end
+ if open then
+ vim.api.nvim_command(loclist and "lopen" or "copen")
+ end
+end
+
+---@private
+local function clamp_line_numbers(bufnr, diagnostics)
+ local buf_line_count = vim.api.nvim_buf_line_count(bufnr)
+ if buf_line_count == 0 then
+ return
+ end
+
+ for _, diagnostic in ipairs(diagnostics) do
+ diagnostic.lnum = math.max(math.min(diagnostic.lnum, buf_line_count - 1), 0)
+ diagnostic.end_lnum = math.max(math.min(diagnostic.end_lnum, buf_line_count - 1), 0)
+ end
+end
+
+---@private
+local function next_diagnostic(position, search_forward, bufnr, opts, namespace)
+ position[1] = position[1] - 1
+ bufnr = get_bufnr(bufnr)
+ local wrap = vim.F.if_nil(opts.wrap, true)
+ local line_count = vim.api.nvim_buf_line_count(bufnr)
+ local diagnostics = M.get(bufnr, vim.tbl_extend("keep", opts, {namespace = namespace}))
+ clamp_line_numbers(bufnr, diagnostics)
+ local line_diagnostics = diagnostic_lines(diagnostics)
+ for i = 0, line_count do
+ local offset = i * (search_forward and 1 or -1)
+ local lnum = position[1] + offset
+ if lnum < 0 or lnum >= line_count then
+ if not wrap then
+ return
+ end
+ lnum = (lnum + line_count) % line_count
+ end
+ if line_diagnostics[lnum] and not vim.tbl_isempty(line_diagnostics[lnum]) then
+ local sort_diagnostics, is_next
+ if search_forward then
+ sort_diagnostics = function(a, b) return a.col < b.col end
+ is_next = function(diagnostic) return diagnostic.col > position[2] end
+ else
+ sort_diagnostics = function(a, b) return a.col > b.col end
+ is_next = function(diagnostic) return diagnostic.col < position[2] end
+ end
+ table.sort(line_diagnostics[lnum], sort_diagnostics)
+ if i == 0 then
+ for _, v in pairs(line_diagnostics[lnum]) do
+ if is_next(v) then
+ return v
+ end
+ end
+ else
+ return line_diagnostics[lnum][1]
+ end
+ end
+ end
+end
+
+---@private
+local function diagnostic_move_pos(opts, pos)
+ opts = opts or {}
+
+ local enable_popup = vim.F.if_nil(opts.enable_popup, true)
+ local win_id = opts.win_id or vim.api.nvim_get_current_win()
+
+ if not pos then
+ vim.api.nvim_echo({{"No more valid diagnostics to move to", "WarningMsg"}}, true, {})
+ return
+ end
+
+ vim.api.nvim_win_set_cursor(win_id, {pos[1] + 1, pos[2]})
+
+ if enable_popup then
+ -- This is a bit weird... I'm surprised that we need to wait til the next tick to do this.
+ vim.schedule(function()
+ M.show_position_diagnostics(opts.popup_opts, vim.api.nvim_win_get_buf(win_id))
+ end)
+ end
+end
+
+-- }}}
+
+-- Public API {{{
+
+--- Configure diagnostic options globally or for a specific diagnostic
+--- namespace.
+---
+---@note Each of the configuration options below accepts one of the following:
+--- - `false`: Disable this feature
+--- - `true`: Enable this feature, use default settings.
+--- - `table`: Enable this feature with overrides.
+--- - `function`: Function with signature (namespace, bufnr) that returns any of the above.
+---
+---@param opts table Configuration table with the following keys:
+--- - underline: (default true) Use underline for diagnostics. Options:
+--- * severity: Only underline diagnostics matching the given severity
+--- |diagnostic-severity|
+--- - virtual_text: (default true) Use virtual text for diagnostics. Options:
+--- * severity: Only show virtual text for diagnostics matching the given
+--- severity |diagnostic-severity|
+--- * source: (string) Include the diagnostic source in virtual
+--- text. One of "always" or "if_many".
+--- * format: (function) A function that takes a diagnostic as input and
+--- returns a string. The return value is the text used to display
+--- the diagnostic. Example:
+--- <pre>
+--- function(diagnostic)
+--- if diagnostic.severity == vim.diagnostic.severity.ERROR then
+--- return string.format("E: %s", diagnostic.message)
+--- end
+--- return diagnostic.message
+--- end
+--- </pre>
+--- - signs: (default true) Use signs for diagnostics. Options:
+--- * severity: Only show signs for diagnostics matching the given severity
+--- |diagnostic-severity|
+--- - update_in_insert: (default false) Update diagnostics in Insert mode (if false,
+--- diagnostics are updated on InsertLeave)
+--- - severity_sort: (default false) Sort diagnostics by severity. This affects the order in
+--- which signs and virtual text are displayed. When true, higher severities
+--- are displayed before lower severities (e.g. ERROR is displayed before WARN).
+--- Options:
+--- * reverse: (boolean) Reverse sort order
+---@param namespace number|nil Update the options for the given namespace. When omitted, update the
+--- global diagnostic options.
+function M.config(opts, namespace)
+ vim.validate {
+ opts = { opts, 't' },
+ namespace = { namespace, 'n', true },
+ }
+
+ local t
+ if namespace then
+ local ns = get_namespace(namespace)
+ t = ns.opts
+ else
+ t = global_diagnostic_options
+ end
+
+ for opt in pairs(global_diagnostic_options) do
+ if opts[opt] ~= nil then
+ t[opt] = opts[opt]
+ end
+ end
+
+ if namespace then
+ for bufnr, v in pairs(diagnostic_cache) do
+ if vim.api.nvim_buf_is_loaded(bufnr) and v[namespace] then
+ M.show(namespace, bufnr)
+ end
+ end
+ else
+ for bufnr, v in pairs(diagnostic_cache) do
+ if vim.api.nvim_buf_is_loaded(bufnr) then
+ for ns in pairs(v) do
+ M.show(ns, bufnr)
+ end
+ end
+ end
+ end
+end
+
+--- Set diagnostics for the given namespace and buffer.
+---
+---@param namespace number The diagnostic namespace
+---@param bufnr number Buffer number
+---@param diagnostics table A list of diagnostic items |diagnostic-structure|
+---@param opts table|nil Display options to pass to |vim.diagnostic.show()|
+function M.set(namespace, bufnr, diagnostics, opts)
+ vim.validate {
+ namespace = {namespace, 'n'},
+ bufnr = {bufnr, 'n'},
+ diagnostics = {diagnostics, 't'},
+ opts = {opts, 't', true},
+ }
+
+ if vim.tbl_isempty(diagnostics) then
+ return M.reset(namespace, bufnr)
+ end
+
+ if not diagnostic_cleanup[bufnr][namespace] then
+ diagnostic_cleanup[bufnr][namespace] = true
+
+ -- Clean up our data when the buffer unloads.
+ vim.api.nvim_buf_attach(bufnr, false, {
+ on_detach = function(_, b)
+ clear_diagnostic_cache(b, namespace)
+ diagnostic_cleanup[b][namespace] = nil
+ end
+ })
+ end
+
+ set_diagnostic_cache(namespace, bufnr, diagnostics)
+
+ if vim.api.nvim_buf_is_loaded(bufnr) then
+ M.show(namespace, bufnr, diagnostics, opts)
+ elseif opts then
+ M.config(opts, namespace)
+ end
+
+ vim.api.nvim_command("doautocmd <nomodeline> User DiagnosticsChanged")
+end
+
+--- Get current diagnostics.
+---
+---@param bufnr number|nil Buffer number to get diagnostics from. Use 0 for
+--- current buffer or nil for all buffers.
+---@param opts table|nil A table with the following keys:
+--- - namespace: (number) Limit diagnostics to the given namespace.
+--- - lnum: (number) Limit diagnostics to the given line number.
+--- - severity: See |diagnostic-severity|.
+---@return table A list of diagnostic items |diagnostic-structure|.
+function M.get(bufnr, opts)
+ vim.validate {
+ bufnr = { bufnr, 'n', true },
+ opts = { opts, 't', true },
+ }
+
+ opts = opts or {}
+
+ local namespace = opts.namespace
+ local diagnostics = {}
+
+ ---@private
+ local function add(d)
+ if not opts.lnum or d.lnum == opts.lnum then
+ table.insert(diagnostics, d)
+ end
+ end
+
+ if namespace == nil and bufnr == nil then
+ for _, t in pairs(diagnostic_cache) do
+ for _, v in pairs(t) do
+ for _, diagnostic in pairs(v) do
+ add(diagnostic)
+ end
+ end
+ end
+ elseif namespace == nil then
+ for iter_namespace in pairs(diagnostic_cache[bufnr]) do
+ for _, diagnostic in pairs(diagnostic_cache[bufnr][iter_namespace]) do
+ add(diagnostic)
+ end
+ end
+ elseif bufnr == nil then
+ for _, t in pairs(diagnostic_cache) do
+ for _, diagnostic in pairs(t[namespace] or {}) do
+ add(diagnostic)
+ end
+ end
+ else
+ for _, diagnostic in pairs(diagnostic_cache[bufnr][namespace] or {}) do
+ add(diagnostic)
+ end
+ end
+
+ if opts.severity then
+ diagnostics = filter_by_severity(opts.severity, diagnostics)
+ end
+
+ return diagnostics
+end
+
+--- Get the previous diagnostic closest to the cursor position.
+---
+---@param opts table See |vim.diagnostic.goto_next()|
+---@return table Previous diagnostic
+function M.get_prev(opts)
+ opts = opts or {}
+
+ local win_id = opts.win_id or vim.api.nvim_get_current_win()
+ local bufnr = vim.api.nvim_win_get_buf(win_id)
+ local cursor_position = opts.cursor_position or vim.api.nvim_win_get_cursor(win_id)
+
+ return next_diagnostic(cursor_position, false, bufnr, opts, opts.namespace)
+end
+
+--- Return the position of the previous diagnostic in the current buffer.
+---
+---@param opts table See |vim.diagnostic.goto_next()|
+---@return table Previous diagnostic position as a (row, col) tuple.
+function M.get_prev_pos(opts)
+ local prev = M.get_prev(opts)
+ if not prev then
+ return false
+ end
+
+ return {prev.lnum, prev.col}
+end
+
+--- Move to the previous diagnostic in the current buffer.
+---@param opts table See |vim.diagnostic.goto_next()|
+function M.goto_prev(opts)
+ return diagnostic_move_pos(
+ opts,
+ M.get_prev_pos(opts)
+ )
+end
+
+--- Get the next diagnostic closest to the cursor position.
+---
+---@param opts table See |vim.diagnostic.goto_next()|
+---@return table Next diagnostic
+function M.get_next(opts)
+ opts = opts or {}
+
+ local win_id = opts.win_id or vim.api.nvim_get_current_win()
+ local bufnr = vim.api.nvim_win_get_buf(win_id)
+ local cursor_position = opts.cursor_position or vim.api.nvim_win_get_cursor(win_id)
+
+ return next_diagnostic(cursor_position, true, bufnr, opts, opts.namespace)
+end
+
+--- Return the position of the next diagnostic in the current buffer.
+---
+---@param opts table See |vim.diagnostic.goto_next()|
+---@return table Next diagnostic position as a (row, col) tuple.
+function M.get_next_pos(opts)
+ local next = M.get_next(opts)
+ if not next then
+ return false
+ end
+
+ return {next.lnum, next.col}
+end
+
+--- Move to the next diagnostic.
+---
+---@param opts table|nil Configuration table with the following keys:
+--- - namespace: (number) Only consider diagnostics from the given namespace.
+--- - cursor_position: (cursor position) Cursor position as a (row, col) tuple. See
+--- |nvim_win_get_cursor()|. Defaults to the current cursor position.
+--- - wrap: (boolean, default true) Whether to loop around file or not. Similar to 'wrapscan'.
+--- - severity: See |diagnostic-severity|.
+--- - enable_popup: (boolean, default true) Call |vim.diagnostic.show_line_diagnostics()|
+--- on jump.
+--- - popup_opts: (table) Table to pass as {opts} parameter to
+--- |vim.diagnostic.show_line_diagnostics()|
+--- - win_id: (number, default 0) Window ID
+function M.goto_next(opts)
+ return diagnostic_move_pos(
+ opts,
+ M.get_next_pos(opts)
+ )
+end
+
+-- Diagnostic Setters {{{
+
+--- Set signs for given diagnostics.
+---
+---@param namespace number The diagnostic namespace
+---@param bufnr number Buffer number
+---@param diagnostics table A list of diagnostic items |diagnostic-structure|. When omitted the
+--- current diagnostics in the given buffer are used.
+---@param opts table Configuration table with the following keys:
+--- - priority: Set the priority of the signs |sign-priority|.
+---@private
+function M._set_signs(namespace, bufnr, diagnostics, opts)
+ vim.validate {
+ namespace = {namespace, 'n'},
+ bufnr = {bufnr, 'n'},
+ diagnostics = {diagnostics, 't'},
+ opts = {opts, 't', true},
+ }
+
+ bufnr = get_bufnr(bufnr)
+ opts = get_resolved_options({ signs = opts }, namespace, bufnr)
+
+ if opts.signs and opts.signs.severity then
+ diagnostics = filter_by_severity(opts.signs.severity, diagnostics)
+ end
+
+ local ns = get_namespace(namespace)
+
+ define_default_signs()
+
+ -- 10 is the default sign priority when none is explicitly specified
+ local priority = opts.signs and opts.signs.priority or 10
+ local get_priority
+ if opts.severity_sort then
+ if type(opts.severity_sort) == "table" and opts.severity_sort.reverse then
+ get_priority = function(severity)
+ return priority + (severity - vim.diagnostic.severity.ERROR)
+ end
+ else
+ get_priority = function(severity)
+ return priority + (vim.diagnostic.severity.HINT - severity)
+ end
+ end
+ else
+ get_priority = function()
+ return priority
+ end
+ end
+
+ for _, diagnostic in ipairs(diagnostics) do
+ vim.fn.sign_place(
+ 0,
+ ns.sign_group,
+ sign_highlight_map[diagnostic.severity],
+ bufnr,
+ {
+ priority = get_priority(diagnostic.severity),
+ lnum = diagnostic.lnum + 1
+ }
+ )
+ end
+end
+
+--- Set underline for given diagnostics.
+---
+---@param namespace number The diagnostic namespace
+---@param bufnr number Buffer number
+---@param diagnostics table A list of diagnostic items |diagnostic-structure|. When omitted the
+--- current diagnostics in the given buffer are used.
+---@param opts table Configuration table. Currently unused.
+---@private
+function M._set_underline(namespace, bufnr, diagnostics, opts)
+ vim.validate {
+ namespace = {namespace, 'n'},
+ bufnr = {bufnr, 'n'},
+ diagnostics = {diagnostics, 't'},
+ opts = {opts, 't', true},
+ }
+
+ bufnr = get_bufnr(bufnr)
+ opts = get_resolved_options({ underline = opts }, namespace, bufnr).underline
+
+ if opts and opts.severity then
+ diagnostics = filter_by_severity(opts.severity, diagnostics)
+ end
+
+ for _, diagnostic in ipairs(diagnostics) do
+ local higroup = underline_highlight_map[diagnostic.severity]
+
+ if higroup == nil then
+ -- Default to error if we don't have a highlight associated
+ higroup = underline_highlight_map.Error
+ end
+
+ vim.highlight.range(
+ bufnr,
+ namespace,
+ higroup,
+ { diagnostic.lnum, diagnostic.col },
+ { diagnostic.end_lnum, diagnostic.end_col }
+ )
+ end
+end
+
+--- Set virtual text for given diagnostics.
+---
+---@param namespace number The diagnostic namespace
+---@param bufnr number Buffer number
+---@param diagnostics table A list of diagnostic items |diagnostic-structure|. When omitted the
+--- current diagnostics in the given buffer are used.
+---@param opts table|nil Configuration table with the following keys:
+--- - prefix: (string) Prefix to display before virtual text on line.
+--- - spacing: (number) Number of spaces to insert before virtual text.
+--- - source: (string) Include the diagnostic source in virtual text. One of "always" or
+--- "if_many".
+---@private
+function M._set_virtual_text(namespace, bufnr, diagnostics, opts)
+ vim.validate {
+ namespace = {namespace, 'n'},
+ bufnr = {bufnr, 'n'},
+ diagnostics = {diagnostics, 't'},
+ opts = {opts, 't', true},
+ }
+
+ bufnr = get_bufnr(bufnr)
+ opts = get_resolved_options({ virtual_text = opts }, namespace, bufnr).virtual_text
+
+ if opts and opts.format then
+ diagnostics = reformat_diagnostics(opts.format, diagnostics)
+ end
+
+ if opts and opts.source then
+ diagnostics = prefix_source(opts.source, diagnostics)
+ end
+
+ local buffer_line_diagnostics = diagnostic_lines(diagnostics)
+ for line, line_diagnostics in pairs(buffer_line_diagnostics) do
+ if opts and opts.severity then
+ line_diagnostics = filter_by_severity(opts.severity, line_diagnostics)
+ end
+ local virt_texts = M._get_virt_text_chunks(line_diagnostics, opts)
+
+ if virt_texts then
+ vim.api.nvim_buf_set_extmark(bufnr, namespace, line, 0, {
+ hl_mode = "combine",
+ virt_text = virt_texts,
+ })
+ end
+ end
+end
+
+--- Get virtual text chunks to display using |nvim_buf_set_extmark()|.
+---
+--- Exported for backward compatibility with
+--- vim.lsp.diagnostic.get_virtual_text_chunks_for_line(). When that function is eventually removed,
+--- this can be made local.
+---@private
+function M._get_virt_text_chunks(line_diags, opts)
+ if #line_diags == 0 then
+ return nil
+ end
+
+ opts = opts or {}
+ local prefix = opts.prefix or "■"
+ local spacing = opts.spacing or 4
+
+ -- Create a little more space between virtual text and contents
+ local virt_texts = {{string.rep(" ", spacing)}}
+
+ for i = 1, #line_diags - 1 do
+ table.insert(virt_texts, {prefix, virtual_text_highlight_map[line_diags[i].severity]})
+ end
+ local last = line_diags[#line_diags]
+
+ -- TODO(tjdevries): Allow different servers to be shown first somehow?
+ -- TODO(tjdevries): Display server name associated with these?
+ if last.message then
+ table.insert(
+ virt_texts,
+ {
+ string.format("%s %s", prefix, last.message:gsub("\r", ""):gsub("\n", " ")),
+ virtual_text_highlight_map[last.severity]
+ }
+ )
+
+ return virt_texts
+ end
+end
+
+--- Callback scheduled when leaving Insert mode.
+---
+--- This function must be exported publicly so that it is available to be
+--- called from the Vimscript autocommand.
+---
+--- See @ref schedule_display()
+---
+---@private
+function M._execute_scheduled_display(namespace, bufnr)
+ local args = bufs_waiting_to_update[bufnr][namespace]
+ if not args then
+ return
+ end
+
+ -- Clear the args so we don't display unnecessarily.
+ bufs_waiting_to_update[bufnr][namespace] = nil
+
+ M.show(namespace, bufnr, nil, args)
+end
+
+--- Hide currently displayed diagnostics.
+---
+--- This only clears the decorations displayed in the buffer. Diagnostics can
+--- be redisplayed with |vim.diagnostic.show()|. To completely remove
+--- diagnostics, use |vim.diagnostic.reset()|.
+---
+--- To hide diagnostics and prevent them from re-displaying, use
+--- |vim.diagnostic.disable()|.
+---
+---@param namespace number The diagnostic namespace
+---@param bufnr number|nil Buffer number. Defaults to the current buffer.
+function M.hide(namespace, bufnr)
+ vim.validate {
+ namespace = { namespace, 'n' },
+ bufnr = { bufnr, 'n', true },
+ }
+
+ bufnr = get_bufnr(bufnr)
+ diagnostic_cache_extmarks[bufnr][namespace] = {}
+
+ local ns = get_namespace(namespace)
+
+ -- clear sign group
+ vim.fn.sign_unplace(ns.sign_group, {buffer=bufnr})
+
+ -- clear virtual text namespace
+ vim.api.nvim_buf_clear_namespace(bufnr, namespace, 0, -1)
+end
+
+
+--- Display diagnostics for the given namespace and buffer.
+---
+---@param namespace number Diagnostic namespace
+---@param bufnr number|nil Buffer number. Defaults to the current buffer.
+---@param diagnostics table|nil The diagnostics to display. When omitted, use the
+--- saved diagnostics for the given namespace and
+--- buffer. This can be used to display a list of diagnostics
+--- without saving them or to display only a subset of
+--- diagnostics.
+---@param opts table|nil Display options. See |vim.diagnostic.config()|.
+function M.show(namespace, bufnr, diagnostics, opts)
+ vim.validate {
+ namespace = { namespace, 'n' },
+ bufnr = { bufnr, 'n', true },
+ diagnostics = { diagnostics, 't', true },
+ opts = { opts, 't', true },
+ }
+
+ bufnr = get_bufnr(bufnr)
+ if is_disabled(namespace, bufnr) then
+ return
+ end
+
+ M.hide(namespace, bufnr)
+
+ diagnostics = diagnostics or M.get(bufnr, {namespace=namespace})
+
+ if not diagnostics or vim.tbl_isempty(diagnostics) then
+ return
+ end
+
+ opts = get_resolved_options(opts, namespace, bufnr)
+
+ if opts.update_in_insert then
+ clear_scheduled_display(namespace, bufnr)
+ else
+ local mode = vim.api.nvim_get_mode()
+ if string.sub(mode.mode, 1, 1) == 'i' then
+ schedule_display(namespace, bufnr, opts)
+ return
+ end
+ end
+
+ if vim.F.if_nil(opts.severity_sort, false) then
+ if type(opts.severity_sort) == "table" and opts.severity_sort.reverse then
+ table.sort(diagnostics, function(a, b) return a.severity < b.severity end)
+ else
+ table.sort(diagnostics, function(a, b) return a.severity > b.severity end)
+ end
+ end
+
+ clamp_line_numbers(bufnr, diagnostics)
+
+ if opts.underline then
+ M._set_underline(namespace, bufnr, diagnostics, opts.underline)
+ end
+
+ if opts.virtual_text then
+ M._set_virtual_text(namespace, bufnr, diagnostics, opts.virtual_text)
+ end
+
+ if opts.signs then
+ M._set_signs(namespace, bufnr, diagnostics, opts.signs)
+ end
+
+ save_extmarks(namespace, bufnr)
+end
+
+--- Open a floating window with the diagnostics at the given position.
+---
+---@param opts table|nil Configuration table with the same keys as
+--- |vim.lsp.util.open_floating_preview()| in addition to the following:
+--- - namespace: (number) Limit diagnostics to the given namespace
+--- - severity: See |diagnostic-severity|.
+--- - show_header: (boolean, default true) Show "Diagnostics:" header
+--- - source: (string) Include the diagnostic source in
+--- the message. One of "always" or "if_many".
+--- - format: (function) A function that takes a diagnostic as input and returns a
+--- string. The return value is the text used to display the diagnostic.
+---@param bufnr number|nil Buffer number. Defaults to the current buffer.
+---@param position table|nil The (0,0)-indexed position. Defaults to the current cursor position.
+---@return tuple ({popup_bufnr}, {win_id})
+function M.show_position_diagnostics(opts, bufnr, position)
+ vim.validate {
+ opts = { opts, 't', true },
+ bufnr = { bufnr, 'n', true },
+ position = { position, 't', true },
+ }
+
+ opts = opts or {}
+
+ opts.focus_id = "position_diagnostics"
+ bufnr = get_bufnr(bufnr)
+ if not position then
+ local curr_position = vim.api.nvim_win_get_cursor(0)
+ curr_position[1] = curr_position[1] - 1
+ position = curr_position
+ end
+ local match_position_predicate = function(diag)
+ return position[1] == diag.lnum and
+ position[2] >= diag.col and
+ (position[2] <= diag.end_col or position[1] < diag.end_lnum)
+ end
+ local diagnostics = M.get(bufnr, opts)
+ clamp_line_numbers(bufnr, diagnostics)
+ local position_diagnostics = vim.tbl_filter(match_position_predicate, diagnostics)
+ table.sort(position_diagnostics, function(a, b) return a.severity < b.severity end)
+ return show_diagnostics(opts, position_diagnostics)
+end
+
+--- Open a floating window with the diagnostics from the given line.
+---
+---@param opts table Configuration table. See |vim.diagnostic.show_position_diagnostics()|.
+---@param bufnr number|nil Buffer number. Defaults to the current buffer.
+---@param lnum number|nil Line number. Defaults to line number of cursor.
+---@return tuple ({popup_bufnr}, {win_id})
+function M.show_line_diagnostics(opts, bufnr, lnum)
+ vim.validate {
+ opts = { opts, 't', true },
+ bufnr = { bufnr, 'n', true },
+ lnum = { lnum, 'n', true },
+ }
+
+ opts = opts or {}
+ opts.focus_id = "line_diagnostics"
+ bufnr = get_bufnr(bufnr)
+ local diagnostics = M.get(bufnr, opts)
+ clamp_line_numbers(bufnr, diagnostics)
+ lnum = lnum or (vim.api.nvim_win_get_cursor(0)[1] - 1)
+ local line_diagnostics = diagnostic_lines(diagnostics)[lnum]
+ return show_diagnostics(opts, line_diagnostics)
+end
+
+--- Remove all diagnostics from the given namespace.
+---
+--- Unlike |vim.diagnostic.hide()|, this function removes all saved
+--- diagnostics. They cannot be redisplayed using |vim.diagnostic.show()|. To
+--- simply remove diagnostic decorations in a way that they can be
+--- re-displayed, use |vim.diagnostic.hide()|.
+---
+---@param namespace number
+---@param bufnr number|nil Remove diagnostics for the given buffer. When omitted,
+--- diagnostics are removed for all buffers.
+function M.reset(namespace, bufnr)
+ if bufnr == nil then
+ for iter_bufnr, namespaces in pairs(diagnostic_cache) do
+ if namespaces[namespace] then
+ M.reset(namespace, iter_bufnr)
+ end
+ end
+ else
+ clear_diagnostic_cache(namespace, bufnr)
+ M.hide(namespace, bufnr)
+ end
+
+ vim.api.nvim_command("doautocmd <nomodeline> User DiagnosticsChanged")
+end
+
+--- Add all diagnostics to the quickfix list.
+---
+---@param opts table|nil Configuration table with the following keys:
+--- - namespace: (number) Only add diagnostics from the given namespace.
+--- - open: (boolean, default true) Open quickfix list after setting.
+--- - title: (string) Title of quickfix list. Defaults to "Diagnostics".
+--- - severity: See |diagnostic-severity|.
+function M.setqflist(opts)
+ set_list(false, opts)
+end
+
+--- Add buffer diagnostics to the location list.
+---
+---@param opts table|nil Configuration table with the following keys:
+--- - namespace: (number) Only add diagnostics from the given namespace.
+--- - winnr: (number, default 0) Window number to set location list for.
+--- - open: (boolean, default true) Open the location list after setting.
+--- - title: (string) Title of the location list. Defaults to "Diagnostics".
+--- - severity: See |diagnostic-severity|.
+function M.setloclist(opts)
+ set_list(true, opts)
+end
+
+--- Disable diagnostics in the given buffer.
+---
+---@param bufnr number|nil Buffer number. Defaults to the current buffer.
+---@param namespace number|nil Only disable diagnostics for the given namespace.
+function M.disable(bufnr, namespace)
+ vim.validate { bufnr = {bufnr, 'n', true}, namespace = {namespace, 'n', true} }
+ bufnr = get_bufnr(bufnr)
+ if namespace == nil then
+ diagnostic_disabled[bufnr] = true
+ for ns in pairs(diagnostic_cache[bufnr]) do
+ M.hide(ns, bufnr)
+ end
+ else
+ if type(diagnostic_disabled[bufnr]) ~= "table" then
+ diagnostic_disabled[bufnr] = {}
+ end
+ diagnostic_disabled[bufnr][namespace] = true
+ M.hide(namespace, bufnr)
+ end
+end
+
+--- Enable diagnostics in the given buffer.
+---
+---@param bufnr number|nil Buffer number. Defaults to the current buffer.
+---@param namespace number|nil Only enable diagnostics for the given namespace.
+function M.enable(bufnr, namespace)
+ vim.validate { bufnr = {bufnr, 'n', true}, namespace = {namespace, 'n', true} }
+ bufnr = get_bufnr(bufnr)
+ if namespace == nil then
+ diagnostic_disabled[bufnr] = nil
+ for ns in pairs(diagnostic_cache[bufnr]) do
+ M.show(ns, bufnr)
+ end
+ else
+ if type(diagnostic_disabled[bufnr]) ~= "table" then
+ return
+ end
+ diagnostic_disabled[bufnr][namespace] = nil
+ M.show(namespace, bufnr)
+ end
+end
+
+--- Parse a diagnostic from a string.
+---
+--- For example, consider a line of output from a linter:
+--- <pre>
+--- WARNING filename:27:3: Variable 'foo' does not exist
+--- </pre>
+--- This can be parsed into a diagnostic |diagnostic-structure|
+--- with:
+--- <pre>
+--- local s = "WARNING filename:27:3: Variable 'foo' does not exist"
+--- local pattern = "^(%w+) %w+:(%d+):(%d+): (.+)$"
+--- local groups = {"severity", "lnum", "col", "message"}
+--- vim.diagnostic.match(s, pattern, groups, {WARNING = vim.diagnostic.WARN})
+--- </pre>
+---
+---@param str string String to parse diagnostics from.
+---@param pat string Lua pattern with capture groups.
+---@param groups table List of fields in a |diagnostic-structure| to
+--- associate with captures from {pat}.
+---@param severity_map table A table mapping the severity field from {groups}
+--- with an item from |vim.diagnostic.severity|.
+---@param defaults table|nil Table of default values for any fields not listed in {groups}.
+--- When omitted, numeric values default to 0 and "severity" defaults to
+--- ERROR.
+---@return diagnostic |diagnostic-structure| or `nil` if {pat} fails to match {str}.
+function M.match(str, pat, groups, severity_map, defaults)
+ vim.validate {
+ str = { str, 's' },
+ pat = { pat, 's' },
+ groups = { groups, 't' },
+ severity_map = { severity_map, 't', true },
+ defaults = { defaults, 't', true },
+ }
+
+ severity_map = severity_map or M.severity
+
+ local diagnostic = {}
+ local matches = {string.match(str, pat)}
+ if vim.tbl_isempty(matches) then
+ return
+ end
+
+ for i, match in ipairs(matches) do
+ local field = groups[i]
+ if field == "severity" then
+ match = severity_map[match]
+ elseif field == "lnum" or field == "end_lnum" or field == "col" or field == "end_col" then
+ match = assert(tonumber(match)) - 1
+ end
+ diagnostic[field] = match
+ end
+
+ diagnostic = vim.tbl_extend("keep", diagnostic, defaults or {})
+ diagnostic.severity = diagnostic.severity or M.severity.ERROR
+ diagnostic.col = diagnostic.col or 0
+ diagnostic.end_lnum = diagnostic.end_lnum or diagnostic.lnum
+ diagnostic.end_col = diagnostic.end_col or diagnostic.col
+ return diagnostic
+end
+
+local errlist_type_map = {
+ [M.severity.ERROR] = 'E',
+ [M.severity.WARN] = 'W',
+ [M.severity.INFO] = 'I',
+ [M.severity.HINT] = 'N',
+}
+
+--- Convert a list of diagnostics to a list of quickfix items that can be
+--- passed to |setqflist()| or |setloclist()|.
+---
+---@param diagnostics table List of diagnostics |diagnostic-structure|.
+---@return array of quickfix list items |setqflist-what|
+function M.toqflist(diagnostics)
+ vim.validate { diagnostics = {diagnostics, 't'} }
+
+ local list = {}
+ for _, v in ipairs(diagnostics) do
+ local item = {
+ bufnr = v.bufnr,
+ lnum = v.lnum + 1,
+ col = v.col and (v.col + 1) or nil,
+ end_lnum = v.end_lnum and (v.end_lnum + 1) or nil,
+ end_col = v.end_col and (v.end_col + 1) or nil,
+ text = v.message,
+ type = errlist_type_map[v.severity] or 'E',
+ }
+ table.insert(list, item)
+ end
+ table.sort(list, function(a, b)
+ if a.bufnr == b.bufnr then
+ return a.lnum < b.lnum
+ else
+ return a.bufnr < b.bufnr
+ end
+ end)
+ return list
+end
+
+--- Convert a list of quickfix items to a list of diagnostics.
+---
+---@param list table A list of quickfix items from |getqflist()| or
+--- |getloclist()|.
+---@return array of diagnostics |diagnostic-structure|
+function M.fromqflist(list)
+ vim.validate { list = {list, 't'} }
+
+ local diagnostics = {}
+ for _, item in ipairs(list) do
+ if item.valid == 1 then
+ local lnum = math.max(0, item.lnum - 1)
+ local col = item.col > 0 and (item.col - 1) or nil
+ local end_lnum = item.end_lnum > 0 and (item.end_lnum - 1) or lnum
+ local end_col = item.end_col > 0 and (item.end_col - 1) or col
+ local severity = item.type ~= "" and M.severity[item.type] or M.severity.ERROR
+ table.insert(diagnostics, {
+ bufnr = item.bufnr,
+ lnum = lnum,
+ col = col,
+ end_lnum = end_lnum,
+ end_col = end_col,
+ severity = severity,
+ message = item.text,
+ })
+ end
+ end
+ return diagnostics
+end
+
+-- }}}
+
+return M
diff --git a/runtime/lua/vim/highlight.lua b/runtime/lua/vim/highlight.lua
index 0012dce081..236f3165f2 100644
--- a/runtime/lua/vim/highlight.lua
+++ b/runtime/lua/vim/highlight.lua
@@ -2,7 +2,7 @@ local api = vim.api
local highlight = {}
---@private
+---@private
function highlight.create(higroup, hi_info, default)
local options = {}
-- TODO: Add validation
@@ -12,7 +12,7 @@ function highlight.create(higroup, hi_info, default)
vim.cmd(string.format([[highlight %s %s %s]], default and "default" or "", higroup, table.concat(options, " ")))
end
---@private
+---@private
function highlight.link(higroup, link_to, force)
vim.cmd(string.format([[highlight%s link %s %s]], force and "!" or " default", higroup, link_to))
end
@@ -20,11 +20,11 @@ end
--- Highlight range between two positions
---
---@param bufnr number of buffer to apply highlighting to
---@param ns namespace to add highlight to
---@param higroup highlight group to use for highlighting
---@param rtype type of range (:help setreg, default charwise)
---@param inclusive boolean indicating whether the range is end-inclusive (default false)
+---@param bufnr number of buffer to apply highlighting to
+---@param ns namespace to add highlight to
+---@param higroup highlight group to use for highlighting
+---@param rtype type of range (:help setreg, default charwise)
+---@param inclusive boolean indicating whether the range is end-inclusive (default false)
function highlight.range(bufnr, ns, higroup, start, finish, rtype, inclusive)
rtype = rtype or 'v'
inclusive = inclusive or false
@@ -85,7 +85,11 @@ function highlight.on_yank(opts)
highlight.range(bufnr, yank_ns, higroup, pos1, pos2, event.regtype, event.inclusive)
vim.defer_fn(
- function() api.nvim_buf_clear_namespace(bufnr, yank_ns, 0, -1) end,
+ function()
+ if api.nvim_buf_is_valid(bufnr) then
+ api.nvim_buf_clear_namespace(bufnr, yank_ns, 0, -1)
+ end
+ end,
timeout
)
end
diff --git a/runtime/lua/vim/lsp.lua b/runtime/lua/vim/lsp.lua
index 75faf9bcc7..c7a88a0993 100644
--- a/runtime/lua/vim/lsp.lua
+++ b/runtime/lua/vim/lsp.lua
@@ -55,21 +55,21 @@ lsp._request_name_to_capability = {
-- TODO improve handling of scratch buffers with LSP attached.
---@private
+---@private
--- Concatenates and writes a list of strings to the Vim error buffer.
---
---@param {...} (List of strings) List to write to the buffer
+---@param {...} (List of strings) List to write to the buffer
local function err_message(...)
nvim_err_writeln(table.concat(vim.tbl_flatten{...}))
nvim_command("redraw")
end
---@private
+---@private
--- Returns the buffer number for the given {bufnr}.
---
---@param bufnr (number) Buffer number to resolve. Defaults to the current
+---@param bufnr (number) Buffer number to resolve. Defaults to the current
---buffer if not given.
---@returns bufnr (number) Number of requested buffer
+---@returns bufnr (number) Number of requested buffer
local function resolve_bufnr(bufnr)
validate { bufnr = { bufnr, 'n', true } }
if bufnr == nil or bufnr == 0 then
@@ -78,21 +78,21 @@ local function resolve_bufnr(bufnr)
return bufnr
end
---@private
+---@private
--- Called by the client when trying to call a method that's not
--- supported in any of the servers registered for the current buffer.
---@param method (string) name of the method
+---@param method (string) name of the method
function lsp._unsupported_method(method)
local msg = string.format("method %s is not supported by any of the servers registered for the current buffer", method)
log.warn(msg)
return lsp.rpc_response_error(protocol.ErrorCodes.MethodNotFound, msg)
end
---@private
+---@private
--- Checks whether a given path is a directory.
---
---@param filename (string) path to check
---@returns true if {filename} exists and is a directory, false otherwise
+---@param filename (string) path to check
+---@returns true if {filename} exists and is a directory, false otherwise
local function is_dir(filename)
validate{filename={filename,'s'}}
local stat = uv.fs_stat(filename)
@@ -108,10 +108,10 @@ local valid_encodings = {
}
local client_index = 0
---@private
+---@private
--- Returns a new, unused client id.
---
---@returns (number) client id
+---@returns (number) client id
local function next_client_id()
client_index = client_index + 1
return client_index
@@ -124,11 +124,11 @@ local uninitialized_clients = {}
-- Tracks all buffers attached to a client.
local all_client_active_buffers = {}
---@private
+---@private
--- Invokes a function for each LSP client attached to the buffer {bufnr}.
---
---@param bufnr (Number) of buffer
---@param fn (function({client}, {client_id}, {bufnr}) Function to run on
+---@param bufnr (Number) of buffer
+---@param fn (function({client}, {client_id}, {bufnr}) Function to run on
---each client attached to that buffer.
local function for_each_buffer_client(bufnr, fn)
validate {
@@ -154,11 +154,11 @@ lsp.client_errors = tbl_extend("error", lsp_rpc.client_errors, vim.tbl_add_rever
ON_INIT_CALLBACK_ERROR = table.maxn(lsp_rpc.client_errors) + 1;
})
---@private
+---@private
--- Normalizes {encoding} to valid LSP encoding names.
---
---@param encoding (string) Encoding to normalize
---@returns (string) normalized encoding name
+---@param encoding (string) Encoding to normalize
+---@returns (string) normalized encoding name
local function validate_encoding(encoding)
validate {
encoding = { encoding, 's' };
@@ -167,13 +167,13 @@ local function validate_encoding(encoding)
or error(string.format("Invalid offset encoding %q. Must be one of: 'utf-8', 'utf-16', 'utf-32'", encoding))
end
---@internal
+---@internal
--- Parses a command invocation into the command itself and its args. If there
--- are no arguments, an empty table is returned as the second argument.
---
---@param input (List)
---@returns (string) the command
---@returns (list of strings) its arguments
+---@param input (List)
+---@returns (string) the command
+---@returns (list of strings) its arguments
function lsp._cmd_parts(input)
vim.validate{cmd={
input,
@@ -192,12 +192,12 @@ function lsp._cmd_parts(input)
return cmd, cmd_args
end
---@private
+---@private
--- Augments a validator function with support for optional (nil) values.
---
---@param fn (function(v)) The original validator function; should return a
+---@param fn (function(v)) The original validator function; should return a
---bool.
---@returns (function(v)) The augmented function. Also returns true if {v} is
+---@returns (function(v)) The augmented function. Also returns true if {v} is
---`nil`.
local function optional_validator(fn)
return function(v)
@@ -205,20 +205,20 @@ local function optional_validator(fn)
end
end
---@private
+---@private
--- Validates a client configuration as given to |vim.lsp.start_client()|.
---
---@param config (table)
---@returns (table) "Cleaned" config, containing only the command, its
+---@param config (table)
+---@returns (table) "Cleaned" config, containing only the command, its
---arguments, and a valid encoding.
---
---@see |vim.lsp.start_client()|
+---@see |vim.lsp.start_client()|
local function validate_client_config(config)
validate {
config = { config, 't' };
}
validate {
- root_dir = { config.root_dir, is_dir, "directory" };
+ root_dir = { config.root_dir, optional_validator(is_dir), "directory" };
handlers = { config.handlers, "t", true };
capabilities = { config.capabilities, "t", true };
cmd_cwd = { config.cmd_cwd, optional_validator(is_dir), "directory" };
@@ -253,11 +253,11 @@ local function validate_client_config(config)
}
end
---@private
+---@private
--- Returns full text of buffer {bufnr} as a string.
---
---@param bufnr (number) Buffer handle, or 0 for current.
---@returns Buffer text as string.
+---@param bufnr (number) Buffer handle, or 0 for current.
+---@returns Buffer text as string.
local function buf_get_full_text(bufnr)
local text = table.concat(nvim_buf_get_lines(bufnr, 0, -1, true), '\n')
if nvim_buf_get_option(bufnr, 'eol') then
@@ -266,14 +266,14 @@ local function buf_get_full_text(bufnr)
return text
end
---@private
+---@private
--- Memoizes a function. On first run, the function return value is saved and
--- immediately returned on subsequent runs. If the function returns a multival,
--- only the first returned value will be memoized and returned. The function will only be run once,
--- even if it has side-effects.
---
---@param fn (function) Function to run
---@returns (function) Memoized function
+---@param fn (function) Function to run
+---@returns (function) Memoized function
local function once(fn)
local value
local ran = false
@@ -289,6 +289,7 @@ end
local changetracking = {}
do
+ --@private
--- client_id → state
---
--- state
@@ -380,7 +381,7 @@ do
end
state.pending_change = function()
state.pending_change = nil
- if client.is_stopped() then
+ if client.is_stopped() or not vim.api.nvim_buf_is_valid(bufnr) then
return
end
local contentChanges
@@ -425,11 +426,11 @@ do
end
---@private
+---@private
--- Default handler for the 'textDocument/didOpen' LSP notification.
---
---@param bufnr (Number) Number of the buffer, or 0 for current
---@param client Client object
+---@param bufnr (Number) Number of the buffer, or 0 for current
+---@param client Client object
local function text_document_did_open_handler(bufnr, client)
changetracking.init(client, bufnr)
if not client.resolved_capabilities.text_document_open_close then
@@ -453,15 +454,7 @@ local function text_document_did_open_handler(bufnr, client)
-- Next chance we get, we should re-do the diagnostics
vim.schedule(function()
- vim.lsp.handlers["textDocument/publishDiagnostics"](
- nil,
- "textDocument/publishDiagnostics",
- {
- diagnostics = vim.lsp.diagnostic.get(bufnr, client.id),
- uri = vim.uri_from_bufnr(bufnr),
- },
- client.id
- )
+ vim.lsp.diagnostic.redraw(bufnr, client.id)
end)
end
@@ -555,16 +548,16 @@ end
---
--- The following parameters describe fields in the {config} table.
---
---@param root_dir: (required, string) Directory where the LSP server will base
+---@param root_dir: (string) Directory where the LSP server will base
--- its rootUri on initialization.
---
---@param cmd: (required, string or list treated like |jobstart()|) Base command
+---@param cmd: (required, string or list treated like |jobstart()|) Base command
--- that initiates the LSP client.
---
---@param cmd_cwd: (string, default=|getcwd()|) Directory to launch
+---@param cmd_cwd: (string, default=|getcwd()|) Directory to launch
--- the `cmd` process. Not related to `root_dir`.
---
---@param cmd_env: (table) Environment flags to pass to the LSP on
+---@param cmd_env: (table) Environment flags to pass to the LSP on
--- spawn. Can be specified using keys like a map or as a list with `k=v`
--- pairs or both. Non-string values are coerced to string.
--- Example:
@@ -572,7 +565,7 @@ end
--- { "PRODUCTION=true"; "TEST=123"; PORT = 8080; HOST = "0.0.0.0"; }
--- </pre>
---
---@param capabilities Map overriding the default capabilities defined by
+---@param capabilities Map overriding the default capabilities defined by
--- |vim.lsp.protocol.make_client_capabilities()|, passed to the language
--- server on initialization. Hint: use make_client_capabilities() and modify
--- its result.
@@ -580,37 +573,41 @@ end
--- `{[vim.type_idx]=vim.types.dictionary}`, else it will be encoded as an
--- array.
---
---@param handlers Map of language server method names to |lsp-handler|
+---@param handlers Map of language server method names to |lsp-handler|
---
---@param settings Map with language server specific settings. These are
+---@param settings Map with language server specific settings. These are
--- returned to the language server if requested via `workspace/configuration`.
--- Keys are case-sensitive.
---
---@param init_options Values to pass in the initialization request
+---@param init_options Values to pass in the initialization request
--- as `initializationOptions`. See `initialize` in the LSP spec.
---
---@param name (string, default=client-id) Name in log messages.
+---@param name (string, default=client-id) Name in log messages.
+--
+---@param workspace_folders (table) List of workspace folders passed to the
+--- language server. Defaults to root_dir if not set. See `workspaceFolders` in
+--- the LSP spec
---
---@param get_language_id function(bufnr, filetype) -> language ID as string.
+---@param get_language_id function(bufnr, filetype) -> language ID as string.
--- Defaults to the filetype.
---
---@param offset_encoding (default="utf-16") One of "utf-8", "utf-16",
+---@param offset_encoding (default="utf-16") One of "utf-8", "utf-16",
--- or "utf-32" which is the encoding that the LSP server expects. Client does
--- not verify this is correct.
---
---@param on_error Callback with parameters (code, ...), invoked
+---@param on_error Callback with parameters (code, ...), invoked
--- when the client operation throws an error. `code` is a number describing
--- the error. Other arguments may be passed depending on the error kind. See
--- |vim.lsp.client_errors| for possible errors.
--- Use `vim.lsp.client_errors[code]` to get human-friendly name.
---
---@param before_init Callback with parameters (initialize_params, config)
+---@param before_init Callback with parameters (initialize_params, config)
--- invoked before the LSP "initialize" phase, where `params` contains the
--- parameters being sent to the server and `config` is the config that was
--- passed to |vim.lsp.start_client()|. You can use this to modify parameters before
--- they are sent.
---
---@param on_init Callback (client, initialize_result) invoked after LSP
+---@param on_init Callback (client, initialize_result) invoked after LSP
--- "initialize", where `result` is a table of `capabilities` and anything else
--- the server may send. For example, clangd sends
--- `initialize_result.offsetEncoding` if `capabilities.offsetEncoding` was
@@ -620,24 +617,24 @@ end
--- `workspace/didChangeConfiguration` notification should be sent
--- to the server during on_init.
---
---@param on_exit Callback (code, signal, client_id) invoked on client
+---@param on_exit Callback (code, signal, client_id) invoked on client
--- exit.
--- - code: exit code of the process
--- - signal: number describing the signal used to terminate (if any)
--- - client_id: client handle
---
---@param on_attach Callback (client, bufnr) invoked when client
+---@param on_attach Callback (client, bufnr) invoked when client
--- attaches to a buffer.
---
---@param trace: "off" | "messages" | "verbose" | nil passed directly to the language
+---@param trace: "off" | "messages" | "verbose" | nil passed directly to the language
--- server in the initialize request. Invalid/empty values will default to "off"
---@param flags: A table with flags for the client. The current (experimental) flags are:
+---@param flags: A table with flags for the client. The current (experimental) flags are:
--- - allow_incremental_sync (bool, default true): Allow using incremental sync for buffer edits
--- - debounce_text_changes (number, default nil): Debounce didChange
--- notifications to the server by the given number in milliseconds. No debounce
--- occurs if nil
---
---@returns Client id. |vim.lsp.get_client_by_id()| Note: client may not be
+---@returns Client id. |vim.lsp.get_client_by_id()| Note: client may not be
--- fully initialized. Use `on_init` to do any actions once
--- the client has been initialized.
function lsp.start_client(config)
@@ -660,53 +657,53 @@ function lsp.start_client(config)
local dispatch = {}
- --@private
+ ---@private
--- Returns the handler associated with an LSP method.
--- Returns the default handler if the user hasn't set a custom one.
---
- --@param method (string) LSP method name
- --@returns (fn) The handler for the given method, if defined, or the default from |vim.lsp.handlers|
+ ---@param method (string) LSP method name
+ ---@returns (fn) The handler for the given method, if defined, or the default from |vim.lsp.handlers|
local function resolve_handler(method)
return handlers[method] or default_handlers[method]
end
- --@private
+ ---@private
--- Handles a notification sent by an LSP server by invoking the
--- corresponding handler.
---
- --@param method (string) LSP method name
- --@param params (table) The parameters for that method.
+ ---@param method (string) LSP method name
+ ---@param params (table) The parameters for that method.
function dispatch.notification(method, params)
- local _ = log.debug() and log.debug('notification', method, params)
+ local _ = log.trace() and log.trace('notification', method, params)
local handler = resolve_handler(method)
if handler then
-- Method name is provided here for convenience.
- handler(nil, method, params, client_id)
+ handler(nil, params, {method=method, client_id=client_id})
end
end
- --@private
+ ---@private
--- Handles a request from an LSP server by invoking the corresponding handler.
---
- --@param method (string) LSP method name
- --@param params (table) The parameters for that method
+ ---@param method (string) LSP method name
+ ---@param params (table) The parameters for that method
function dispatch.server_request(method, params)
- local _ = log.debug() and log.debug('server_request', method, params)
+ local _ = log.trace() and log.trace('server_request', method, params)
local handler = resolve_handler(method)
if handler then
- local _ = log.debug() and log.debug("server_request: found handler for", method)
- return handler(nil, method, params, client_id)
+ local _ = log.trace() and log.trace("server_request: found handler for", method)
+ return handler(nil, params, {method=method, client_id=client_id})
end
- local _ = log.debug() and log.debug("server_request: no handler found for", method)
+ local _ = log.warn() and log.warn("server_request: no handler found for", method)
return nil, lsp.rpc_response_error(protocol.ErrorCodes.MethodNotFound)
end
- --@private
+ ---@private
--- Invoked when the client operation throws an error.
---
- --@param code (number) Error code
- --@param err (...) Other arguments may be passed depending on the error kind
- --@see |vim.lsp.client_errors| for possible errors. Use
+ ---@param code (number) Error code
+ ---@param err (...) Other arguments may be passed depending on the error kind
+ ---@see |vim.lsp.client_errors| for possible errors. Use
---`vim.lsp.client_errors[code]` to get a human-friendly name.
function dispatch.on_error(code, err)
local _ = log.error() and log.error(log_prefix, "on_error", { code = lsp.client_errors[code], err = err })
@@ -720,11 +717,11 @@ function lsp.start_client(config)
end
end
- --@private
+ ---@private
--- Invoked on client exit.
---
- --@param code (number) exit code of the process
- --@param signal (number) the signal used to terminate (if any)
+ ---@param code (number) exit code of the process
+ ---@param signal (number) the signal used to terminate (if any)
function dispatch.on_exit(code, signal)
active_clients[client_id] = nil
uninitialized_clients[client_id] = nil
@@ -769,12 +766,20 @@ function lsp.start_client(config)
-- Store the uninitialized_clients for cleanup in case we exit before initialize finishes.
uninitialized_clients[client_id] = client;
- --@private
+ ---@private
local function initialize()
local valid_traces = {
off = 'off'; messages = 'messages'; verbose = 'verbose';
}
local version = vim.version()
+
+ if config.root_dir and not config.workspace_folders then
+ config.workspace_folders = {{
+ uri = vim.uri_from_fname(config.root_dir);
+ name = string.format("%s", config.root_dir);
+ }};
+ end
+
local initialize_params = {
-- The process Id of the parent process that started the server. Is null if
-- the process has not been started by another process. If the parent
@@ -793,7 +798,7 @@ function lsp.start_client(config)
rootPath = config.root_dir;
-- The rootUri of the workspace. Is null if no folder is open. If both
-- `rootPath` and `rootUri` are set `rootUri` wins.
- rootUri = vim.uri_from_fname(config.root_dir);
+ rootUri = config.root_dir and vim.uri_from_fname(config.root_dir);
-- User provided initialization options.
initializationOptions = config.init_options;
-- The capabilities provided by the client (editor or tool)
@@ -815,20 +820,17 @@ function lsp.start_client(config)
-- -- workspace folder in the user interface.
-- name
-- }
- workspaceFolders = {{
- uri = vim.uri_from_fname(config.root_dir);
- name = string.format("%s", config.root_dir);
- }};
+ workspaceFolders = config.workspace_folders,
}
if config.before_init then
-- TODO(ashkan) handle errors here.
pcall(config.before_init, initialize_params, config)
end
- local _ = log.debug() and log.debug(log_prefix, "initialize_params", initialize_params)
+ local _ = log.trace() and log.trace(log_prefix, "initialize_params", initialize_params)
rpc.request('initialize', initialize_params, function(init_err, result)
assert(not init_err, tostring(init_err))
assert(result, "server sent empty result")
- rpc.notify('initialized', {[vim.type_idx]=vim.types.dictionary})
+ rpc.notify('initialized', vim.empty_dict())
client.initialized = true
uninitialized_clients[client_id] = nil
client.workspaceFolders = initialize_params.workspaceFolders
@@ -867,23 +869,23 @@ function lsp.start_client(config)
end)
end
- --@private
+ ---@private
--- Sends a request to the server.
---
--- This is a thin wrapper around {client.rpc.request} with some additional
--- checks for capabilities and handler availability.
---
- --@param method (string) LSP method name.
- --@param params (table) LSP request params.
- --@param handler (function, optional) Response |lsp-handler| for this method.
- --@param bufnr (number) Buffer handle (0 for current).
- --@returns ({status}, [request_id]): {status} is a bool indicating
+ ---@param method (string) LSP method name.
+ ---@param params (table) LSP request params.
+ ---@param handler (function, optional) Response |lsp-handler| for this method.
+ ---@param bufnr (number) Buffer handle (0 for current).
+ ---@returns ({status}, [request_id]): {status} is a bool indicating
---whether the request was successful. If it is `false`, then it will
---always be `false` (the client has shutdown). If it was
---successful, then it will return {request_id} as the
---second result. You can use this with `client.cancel_request(request_id)`
---to cancel the-request.
- --@see |vim.lsp.buf_request()|
+ ---@see |vim.lsp.buf_request()|
function client.request(method, params, handler, bufnr)
if not handler then
handler = resolve_handler(method)
@@ -894,28 +896,28 @@ function lsp.start_client(config)
local _ = log.debug() and log.debug(log_prefix, "client.request", client_id, method, params, handler, bufnr)
return rpc.request(method, params, function(err, result)
- handler(err, method, result, client_id, bufnr)
+ handler(err, result, {method=method, client_id=client_id, bufnr=bufnr, params=params})
end)
end
- --@private
+ ---@private
--- Sends a request to the server and synchronously waits for the response.
---
--- This is a wrapper around {client.request}
---
- --@param method (string) LSP method name.
- --@param params (table) LSP request params.
- --@param timeout_ms (number, optional, default=1000) Maximum time in
+ ---@param method (string) LSP method name.
+ ---@param params (table) LSP request params.
+ ---@param timeout_ms (number, optional, default=1000) Maximum time in
---milliseconds to wait for a result.
- --@param bufnr (number) Buffer handle (0 for current).
- --@returns { err=err, result=result }, a dictionary, where `err` and `result` come from the |lsp-handler|.
+ ---@param bufnr (number) Buffer handle (0 for current).
+ ---@returns { err=err, result=result }, a dictionary, where `err` and `result` come from the |lsp-handler|.
---On timeout, cancel or error, returns `(nil, err)` where `err` is a
---string describing the failure reason. If the request was unsuccessful
---returns `nil`.
- --@see |vim.lsp.buf_request_sync()|
+ ---@see |vim.lsp.buf_request_sync()|
function client.request_sync(method, params, timeout_ms, bufnr)
local request_result = nil
- local function _sync_handler(err, _, result)
+ local function _sync_handler(err, result)
request_result = { err = err, result = result }
end
@@ -934,25 +936,25 @@ function lsp.start_client(config)
return request_result
end
- --@private
+ ---@private
--- Sends a notification to an LSP server.
---
- --@param method (string) LSP method name.
- --@param params (optional, table) LSP request params.
- --@param bufnr (number) Buffer handle, or 0 for current.
- --@returns {status} (bool) true if the notification was successful.
+ ---@param method (string) LSP method name.
+ ---@param params (optional, table) LSP request params.
+ ---@param bufnr (number) Buffer handle, or 0 for current.
+ ---@returns {status} (bool) true if the notification was successful.
---If it is false, then it will always be false
---(the client has shutdown).
function client.notify(...)
return rpc.notify(...)
end
- --@private
+ ---@private
--- Cancels a request with a given request id.
---
- --@param id (number) id of request to cancel
- --@returns true if any client returns true; false otherwise
- --@see |vim.lsp.client.notify()|
+ ---@param id (number) id of request to cancel
+ ---@returns true if any client returns true; false otherwise
+ ---@see |vim.lsp.client.notify()|
function client.cancel_request(id)
validate{id = {id, 'n'}}
return rpc.notify("$/cancelRequest", { id = id })
@@ -961,14 +963,14 @@ function lsp.start_client(config)
-- Track this so that we can escalate automatically if we've alredy tried a
-- graceful shutdown
local graceful_shutdown_failed = false
- --@private
+ ---@private
--- Stops a client, optionally with force.
---
---By default, it will just ask the - server to shutdown without force. If
--- you request to stop a client which has previously been requested to
--- shutdown, it will automatically escalate and force shutdown.
---
- --@param force (bool, optional)
+ ---@param force (bool, optional)
function client.stop(force)
lsp.diagnostic.reset(client_id, all_buffer_active_clients)
@@ -998,18 +1000,18 @@ function lsp.start_client(config)
end)
end
- --@private
+ ---@private
--- Checks whether a client is stopped.
---
- --@returns (bool) true if client is stopped or in the process of being
+ ---@returns (bool) true if client is stopped or in the process of being
---stopped; false otherwise
function client.is_stopped()
return rpc.handle:is_closing()
end
- --@private
+ ---@private
--- Runs the on_attach function from the client's config if it was defined.
- --@param bufnr (number) Buffer number
+ ---@param bufnr (number) Buffer number
function client._on_attach(bufnr)
text_document_did_open_handler(bufnr, client)
if config.on_attach then
@@ -1023,8 +1025,8 @@ function lsp.start_client(config)
return client_id
end
---@private
---@fn text_document_did_change_handler(_, bufnr, changedtick, firstline, lastline, new_lastline, old_byte_size, old_utf32_size, old_utf16_size)
+---@private
+---@fn text_document_did_change_handler(_, bufnr, changedtick, firstline, lastline, new_lastline, old_byte_size, old_utf32_size, old_utf16_size)
--- Notify all attached clients that a buffer has changed.
local text_document_did_change_handler
do
@@ -1074,8 +1076,8 @@ end
---
--- Without calling this, the server won't be notified of changes to a buffer.
---
---- @param bufnr (number) Buffer handle, or 0 for current
---- @param client_id (number) Client id
+---@param bufnr (number) Buffer handle, or 0 for current
+---@param client_id (number) Client id
function lsp.buf_attach_client(bufnr, client_id)
validate {
bufnr = {bufnr, 'n', true};
@@ -1150,23 +1152,23 @@ end
---@param bufnr (number) Buffer handle, or 0 for current
---@param client_id (number) the client id
function lsp.buf_is_attached(bufnr, client_id)
- return (all_buffer_active_clients[bufnr] or {})[client_id] == true
+ return (all_buffer_active_clients[resolve_bufnr(bufnr)] or {})[client_id] == true
end
--- Gets a client by id, or nil if the id is invalid.
--- The returned client may not yet be fully initialized.
--
---@param client_id client id number
+---@param client_id client id number
---
---@returns |vim.lsp.client| object, or nil
+---@returns |vim.lsp.client| object, or nil
function lsp.get_client_by_id(client_id)
return active_clients[client_id] or uninitialized_clients[client_id]
end
--- Returns list of buffers attached to client_id.
--
---@param client_id client id
---@returns list of buffer ids
+---@param client_id client id
+---@returns list of buffer ids
function lsp.get_buffers_by_client_id(client_id)
local active_client_buffers = all_client_active_buffers[client_id]
if active_client_buffers then
@@ -1188,8 +1190,8 @@ end
--- By default asks the server to shutdown, unless stop was requested
--- already for this client, then force-shutdown is attempted.
---
---@param client_id client id or |vim.lsp.client| object, or list thereof
---@param force boolean (optional) shutdown forcefully
+---@param client_id client id or |vim.lsp.client| object, or list thereof
+---@param force boolean (optional) shutdown forcefully
function lsp.stop_client(client_id, force)
local ids = type(client_id) == 'table' and client_id or {client_id}
for _, id in ipairs(ids) do
@@ -1205,7 +1207,7 @@ end
--- Gets all active clients.
---
---@returns Table of |vim.lsp.client| objects
+---@returns Table of |vim.lsp.client| objects
function lsp.get_active_clients()
return vim.tbl_values(active_clients)
end
@@ -1236,13 +1238,13 @@ nvim_command("autocmd VimLeavePre * lua vim.lsp._vim_exit_handler()")
--- Sends an async request for all active clients attached to the
--- buffer.
---
---@param bufnr (number) Buffer handle, or 0 for current.
---@param method (string) LSP method name
---@param params (optional, table) Parameters to send to the server
---@param handler (optional, function) See |lsp-handler|
+---@param bufnr (number) Buffer handle, or 0 for current.
+---@param method (string) LSP method name
+---@param params (optional, table) Parameters to send to the server
+---@param handler (optional, function) See |lsp-handler|
-- If nil, follows resolution strategy defined in |lsp-handler-configuration|
--
---@returns 2-tuple:
+---@returns 2-tuple:
--- - Map of client-id:request-id pairs for all successful requests.
--- - Function which can be used to cancel all the requests. You could instead
--- iterate all clients and call their `cancel_request()` methods.
@@ -1274,7 +1276,7 @@ function lsp.buf_request(bufnr, method, params, handler)
local unsupported_err = lsp._unsupported_method(method)
handler = handler or lsp.handlers[method]
if handler then
- handler(unsupported_err, method, bufnr)
+ handler(unsupported_err, nil, {method=method, bufnr=bufnr})
end
return
end
@@ -1294,14 +1296,14 @@ end
---Parameters are the same as |vim.lsp.buf_request()| but the return result and callback are
---different.
---
---@param bufnr (number) Buffer handle, or 0 for current.
---@param method (string) LSP method name
---@param params (optional, table) Parameters to send to the server
---@param callback (function) The callback to call when all requests are finished.
+---@param bufnr (number) Buffer handle, or 0 for current.
+---@param method (string) LSP method name
+---@param params (optional, table) Parameters to send to the server
+---@param callback (function) The callback to call when all requests are finished.
-- Unlike `buf_request`, this will collect all the responses from each server instead of handling them.
-- A map of client_id:request_result will be provided to the callback
--
---@returns (function) A function that will cancel all requests which is the same as the one returned from `buf_request`.
+---@returns (function) A function that will cancel all requests which is the same as the one returned from `buf_request`.
function lsp.buf_request_all(bufnr, method, params, callback)
local request_results = {}
local result_count = 0
@@ -1314,8 +1316,8 @@ function lsp.buf_request_all(bufnr, method, params, callback)
end
end)
- local function _sync_handler(err, _, result, client_id)
- request_results[client_id] = { error = err, result = result }
+ local function _sync_handler(err, result, ctx)
+ request_results[ctx.client_id] = { error = err, result = result }
result_count = result_count + 1
set_expected_result_count()
@@ -1335,13 +1337,13 @@ end
--- Parameters are the same as |vim.lsp.buf_request()| but the return result is
--- different. Wait maximum of {timeout_ms} (default 1000) ms.
---
---@param bufnr (number) Buffer handle, or 0 for current.
---@param method (string) LSP method name
---@param params (optional, table) Parameters to send to the server
---@param timeout_ms (optional, number, default=1000) Maximum time in
+---@param bufnr (number) Buffer handle, or 0 for current.
+---@param method (string) LSP method name
+---@param params (optional, table) Parameters to send to the server
+---@param timeout_ms (optional, number, default=1000) Maximum time in
--- milliseconds to wait for a result.
---
---@returns Map of client_id:request_result. On timeout, cancel or error,
+---@returns Map of client_id:request_result. On timeout, cancel or error,
--- returns `(nil, err)` where `err` is a string describing the failure
--- reason.
function lsp.buf_request_sync(bufnr, method, params, timeout_ms)
@@ -1364,11 +1366,11 @@ function lsp.buf_request_sync(bufnr, method, params, timeout_ms)
end
--- Send a notification to a server
---@param bufnr [number] (optional): The number of the buffer
---@param method [string]: Name of the request method
---@param params [string]: Arguments to send to the server
+---@param bufnr [number] (optional): The number of the buffer
+---@param method [string]: Name of the request method
+---@param params [string]: Arguments to send to the server
---
---@returns true if any client returns true; false otherwise
+---@returns true if any client returns true; false otherwise
function lsp.buf_notify(bufnr, method, params)
validate {
bufnr = { bufnr, 'n', true };
@@ -1383,14 +1385,14 @@ end
--- Implements 'omnifunc' compatible LSP completion.
---
---@see |complete-functions|
---@see |complete-items|
---@see |CompleteDone|
+---@see |complete-functions|
+---@see |complete-items|
+---@see |CompleteDone|
---
---@param findstart 0 or 1, decides behavior
---@param base If findstart=0, text to match against
+---@param findstart 0 or 1, decides behavior
+---@param base If findstart=0, text to match against
---
---@returns (number) Decided by `findstart`:
+---@returns (number) Decided by `findstart`:
--- - findstart=0: column where the completion starts, or -2 or -3
--- - findstart=1: list of matches (actually just calls |complete()|)
function lsp.omnifunc(findstart, base)
@@ -1421,7 +1423,7 @@ function lsp.omnifunc(findstart, base)
local params = util.make_position_params()
local items = {}
- lsp.buf_request(bufnr, 'textDocument/completion', params, function(err, _, result)
+ lsp.buf_request(bufnr, 'textDocument/completion', params, function(err, result)
if err or not result or vim.fn.mode() ~= "i" then return end
local matches = util.text_document_completion_list_to_complete_items(result, prefix)
-- TODO(ashkan): is this the best way to do this?
@@ -1436,8 +1438,8 @@ end
---Checks whether a client is stopped.
---
---@param client_id (Number)
---@returns true if client is stopped, false otherwise.
+---@param client_id (Number)
+---@returns true if client is stopped, false otherwise.
function lsp.client_is_stopped(client_id)
return active_clients[client_id] == nil
end
@@ -1445,7 +1447,7 @@ end
--- Gets a map of client_id:client pairs for the given buffer, where each value
--- is a |vim.lsp.client| object.
---
---@param bufnr (optional, number): Buffer handle, or 0 for current
+---@param bufnr (optional, number): Buffer handle, or 0 for current
function lsp.buf_get_clients(bufnr)
bufnr = resolve_bufnr(bufnr)
local result = {}
@@ -1470,9 +1472,9 @@ lsp.log_levels = log.levels
---
--- Use `lsp.log_levels` for reverse lookup.
---
---@see |vim.lsp.log_levels|
+---@see |vim.lsp.log_levels|
---
---@param level [number|string] the case insensitive level name or number
+---@param level [number|string] the case insensitive level name or number
function lsp.set_log_level(level)
if type(level) == 'string' or type(level) == 'number' then
log.set_level(level)
@@ -1482,7 +1484,7 @@ function lsp.set_log_level(level)
end
--- Gets the path of the logfile used by the LSP client.
---@returns (String) Path to logfile.
+---@returns (String) Path to logfile.
function lsp.get_log_path()
return log.get_filename()
end
@@ -1493,11 +1495,11 @@ function lsp.for_each_buffer_client(bufnr, fn)
end
--- Function to manage overriding defaults for LSP handlers.
---@param handler (function) See |lsp-handler|
---@param override_config (table) Table containing the keys to override behavior of the {handler}
+---@param handler (function) See |lsp-handler|
+---@param override_config (table) Table containing the keys to override behavior of the {handler}
function lsp.with(handler, override_config)
- return function(err, method, params, client_id, bufnr, config)
- return handler(err, method, params, client_id, bufnr, vim.tbl_deep_extend("force", config or {}, override_config))
+ return function(err, result, ctx, config)
+ return handler(err, result, ctx, vim.tbl_deep_extend("force", config or {}, override_config))
end
end
@@ -1532,8 +1534,34 @@ function lsp._with_extend(name, options, user_config)
return resulting_config
end
--- Define the LspDiagnostics signs if they're not defined already.
-require('vim.lsp.diagnostic')._define_default_signs_and_highlights()
+
+--- Registry for client side commands.
+--- This is an extension point for plugins to handle custom commands which are
+--- not part of the core language server protocol specification.
+---
+--- The registry is a table where the key is a unique command name,
+--- and the value is a function which is called if any LSP action
+--- (code action, code lenses, ...) triggers the command.
+---
+--- If a LSP response contains a command for which no matching entry is
+--- available in this registry, the command will be executed via the LSP server
+--- using `workspace/executeCommand`.
+---
+--- The first argument to the function will be the `Command`:
+-- Command
+-- title: String
+-- command: String
+-- arguments?: any[]
+--
+--- The second argument is the `ctx` of |lsp-handler|
+lsp.commands = setmetatable({}, {
+ __newindex = function(tbl, key, value)
+ assert(type(key) == 'string', "The key for commands in `vim.lsp.commands` must be a string")
+ assert(type(value) == 'function', "Command added to `vim.lsp.commands` must be a function")
+ rawset(tbl, key, value)
+ end;
+})
+
return lsp
-- vim:sw=2 ts=2 et
diff --git a/runtime/lua/vim/lsp/_snippet.lua b/runtime/lua/vim/lsp/_snippet.lua
new file mode 100644
index 0000000000..0140b0aee3
--- /dev/null
+++ b/runtime/lua/vim/lsp/_snippet.lua
@@ -0,0 +1,399 @@
+local P = {}
+
+---Take characters until the target characters (The escape sequence is '\' + char)
+---@param targets string[] The character list for stop consuming text.
+---@param specials string[] If the character isn't contained in targets/specials, '\' will be left.
+P.take_until = function(targets, specials)
+ targets = targets or {}
+ specials = specials or {}
+
+ return function(input, pos)
+ local new_pos = pos
+ local raw = {}
+ local esc = {}
+ while new_pos <= #input do
+ local c = string.sub(input, new_pos, new_pos)
+ if c == '\\' then
+ table.insert(raw, '\\')
+ new_pos = new_pos + 1
+ c = string.sub(input, new_pos, new_pos)
+ if not vim.tbl_contains(targets, c) and not vim.tbl_contains(specials, c) then
+ table.insert(esc, '\\')
+ end
+ table.insert(raw, c)
+ table.insert(esc, c)
+ new_pos = new_pos + 1
+ else
+ if vim.tbl_contains(targets, c) then
+ break
+ end
+ table.insert(raw, c)
+ table.insert(esc, c)
+ new_pos = new_pos + 1
+ end
+ end
+
+ if new_pos == pos then
+ return P.unmatch(pos)
+ end
+
+ return {
+ parsed = true,
+ value = {
+ raw = table.concat(raw, ''),
+ esc = table.concat(esc, '')
+ },
+ pos = new_pos,
+ }
+ end
+end
+
+P.unmatch = function(pos)
+ return {
+ parsed = false,
+ value = nil,
+ pos = pos,
+ }
+end
+
+P.map = function(parser, map)
+ return function(input, pos)
+ local result = parser(input, pos)
+ if result.parsed then
+ return {
+ parsed = true,
+ value = map(result.value),
+ pos = result.pos,
+ }
+ end
+ return P.unmatch(pos)
+ end
+end
+
+P.lazy = function(factory)
+ return function(input, pos)
+ return factory()(input, pos)
+ end
+end
+
+P.token = function(token)
+ return function(input, pos)
+ local maybe_token = string.sub(input, pos, pos + #token - 1)
+ if token == maybe_token then
+ return {
+ parsed = true,
+ value = maybe_token,
+ pos = pos + #token,
+ }
+ end
+ return P.unmatch(pos)
+ end
+end
+
+P.pattern = function(p)
+ return function(input, pos)
+ local maybe_match = string.match(string.sub(input, pos), '^' .. p)
+ if maybe_match then
+ return {
+ parsed = true,
+ value = maybe_match,
+ pos = pos + #maybe_match,
+ }
+ end
+ return P.unmatch(pos)
+ end
+end
+
+P.many = function(parser)
+ return function(input, pos)
+ local values = {}
+ local new_pos = pos
+ while new_pos <= #input do
+ local result = parser(input, new_pos)
+ if not result.parsed then
+ break
+ end
+ table.insert(values, result.value)
+ new_pos = result.pos
+ end
+ if #values > 0 then
+ return {
+ parsed = true,
+ value = values,
+ pos = new_pos,
+ }
+ end
+ return P.unmatch(pos)
+ end
+end
+
+P.any = function(...)
+ local parsers = { ... }
+ return function(input, pos)
+ for _, parser in ipairs(parsers) do
+ local result = parser(input, pos)
+ if result.parsed then
+ return result
+ end
+ end
+ return P.unmatch(pos)
+ end
+end
+
+P.opt = function(parser)
+ return function(input, pos)
+ local result = parser(input, pos)
+ return {
+ parsed = true,
+ value = result.value,
+ pos = result.pos,
+ }
+ end
+end
+
+P.seq = function(...)
+ local parsers = { ... }
+ return function(input, pos)
+ local values = {}
+ local new_pos = pos
+ for _, parser in ipairs(parsers) do
+ local result = parser(input, new_pos)
+ if result.parsed then
+ table.insert(values, result.value)
+ new_pos = result.pos
+ else
+ return P.unmatch(pos)
+ end
+ end
+ return {
+ parsed = true,
+ value = values,
+ pos = new_pos,
+ }
+ end
+end
+
+local Node = {}
+
+Node.Type = {
+ SNIPPET = 0,
+ TABSTOP = 1,
+ PLACEHOLDER = 2,
+ VARIABLE = 3,
+ CHOICE = 4,
+ TRANSFORM = 5,
+ FORMAT = 6,
+ TEXT = 7,
+}
+
+function Node:__tostring()
+ local insert_text = {}
+ if self.type == Node.Type.SNIPPET then
+ for _, c in ipairs(self.children) do
+ table.insert(insert_text, tostring(c))
+ end
+ elseif self.type == Node.Type.CHOICE then
+ table.insert(insert_text, self.items[1])
+ elseif self.type == Node.Type.PLACEHOLDER then
+ for _, c in ipairs(self.children or {}) do
+ table.insert(insert_text, tostring(c))
+ end
+ elseif self.type == Node.Type.TEXT then
+ table.insert(insert_text, self.esc)
+ end
+ return table.concat(insert_text, '')
+end
+
+--@see https://code.visualstudio.com/docs/editor/userdefinedsnippets#_grammar
+
+local S = {}
+S.dollar = P.token('$')
+S.open = P.token('{')
+S.close = P.token('}')
+S.colon = P.token(':')
+S.slash = P.token('/')
+S.comma = P.token(',')
+S.pipe = P.token('|')
+S.plus = P.token('+')
+S.minus = P.token('-')
+S.question = P.token('?')
+S.int = P.map(P.pattern('[0-9]+'), function(value)
+ return tonumber(value, 10)
+end)
+S.var = P.pattern('[%a_][%w_]+')
+S.text = function(targets, specials)
+ return P.map(P.take_until(targets, specials), function(value)
+ return setmetatable({
+ type = Node.Type.TEXT,
+ raw = value.raw,
+ esc = value.esc,
+ }, Node)
+ end)
+end
+
+S.toplevel = P.lazy(function()
+ return P.any(S.placeholder, S.tabstop, S.variable, S.choice)
+end)
+
+S.format = P.any(
+ P.map(P.seq(S.dollar, S.int), function(values)
+ return setmetatable({
+ type = Node.Type.FORMAT,
+ capture_index = values[2],
+ }, Node)
+ end),
+ P.map(P.seq(S.dollar, S.open, S.int, S.close), function(values)
+ return setmetatable({
+ type = Node.Type.FORMAT,
+ capture_index = values[3],
+ }, Node)
+ end),
+ P.map(P.seq(S.dollar, S.open, S.int, S.colon, S.slash, P.any(
+ P.token('upcase'),
+ P.token('downcase'),
+ P.token('capitalize'),
+ P.token('camelcase'),
+ P.token('pascalcase')
+ ), S.close), function(values)
+ return setmetatable({
+ type = Node.Type.FORMAT,
+ capture_index = values[3],
+ modifier = values[6],
+ }, Node)
+ end),
+ P.map(P.seq(S.dollar, S.open, S.int, S.colon, P.any(
+ P.seq(S.question, P.take_until({ ':' }, { '\\' }), S.colon, P.take_until({ '}' }, { '\\' })),
+ P.seq(S.plus, P.take_until({ '}' }, { '\\' })),
+ P.seq(S.minus, P.take_until({ '}' }, { '\\' }))
+ ), S.close), function(values)
+ return setmetatable({
+ type = Node.Type.FORMAT,
+ capture_index = values[3],
+ if_text = values[5][2].esc,
+ else_text = (values[5][4] or {}).esc,
+ }, Node)
+ end)
+)
+
+S.transform = P.map(P.seq(
+ S.slash,
+ P.take_until({ '/' }, { '\\' }),
+ S.slash,
+ P.many(P.any(S.format, S.text({ '$', '/' }, { '\\' }))),
+ S.slash,
+ P.opt(P.pattern('[ig]+'))
+), function(values)
+ return setmetatable({
+ type = Node.Type.TRANSFORM,
+ pattern = values[2].raw,
+ format = values[4],
+ option = values[6],
+ }, Node)
+end)
+
+S.tabstop = P.any(
+ P.map(P.seq(S.dollar, S.int), function(values)
+ return setmetatable({
+ type = Node.Type.TABSTOP,
+ tabstop = values[2],
+ }, Node)
+ end),
+ P.map(P.seq(S.dollar, S.open, S.int, S.close), function(values)
+ return setmetatable({
+ type = Node.Type.TABSTOP,
+ tabstop = values[3],
+ }, Node)
+ end),
+ P.map(P.seq(S.dollar, S.open, S.int, S.transform, S.close), function(values)
+ return setmetatable({
+ type = Node.Type.TABSTOP,
+ tabstop = values[3],
+ transform = values[4],
+ }, Node)
+ end)
+)
+
+S.placeholder = P.any(
+ P.map(P.seq(S.dollar, S.open, S.int, S.colon, P.many(P.any(S.toplevel, S.text({ '$', '}' }, { '\\' }))), S.close), function(values)
+ return setmetatable({
+ type = Node.Type.PLACEHOLDER,
+ tabstop = values[3],
+ children = values[5],
+ }, Node)
+ end)
+)
+
+S.choice = P.map(P.seq(
+ S.dollar,
+ S.open,
+ S.int,
+ S.pipe,
+ P.many(
+ P.map(P.seq(S.text({ ',', '|' }), P.opt(S.comma)), function(values)
+ return values[1].esc
+ end)
+ ),
+ S.pipe,
+ S.close
+), function(values)
+ return setmetatable({
+ type = Node.Type.CHOICE,
+ tabstop = values[3],
+ items = values[5],
+ }, Node)
+end)
+
+S.variable = P.any(
+ P.map(P.seq(S.dollar, S.var), function(values)
+ return setmetatable({
+ type = Node.Type.VARIABLE,
+ name = values[2],
+ }, Node)
+ end),
+ P.map(P.seq(S.dollar, S.open, S.var, S.close), function(values)
+ return setmetatable({
+ type = Node.Type.VARIABLE,
+ name = values[3],
+ }, Node)
+ end),
+ P.map(P.seq(S.dollar, S.open, S.var, S.transform, S.close), function(values)
+ return setmetatable({
+ type = Node.Type.VARIABLE,
+ name = values[3],
+ transform = values[4],
+ }, Node)
+ end),
+ P.map(P.seq(S.dollar, S.open, S.var, S.colon, P.many(P.any(S.toplevel, S.text({ '$', '}' }, { '\\' }))), S.close), function(values)
+ return setmetatable({
+ type = Node.Type.VARIABLE,
+ name = values[3],
+ children = values[5],
+ }, Node)
+ end)
+)
+
+S.snippet = P.map(P.many(P.any(S.toplevel, S.text({ '$' }, { '}', '\\' }))), function(values)
+ return setmetatable({
+ type = Node.Type.SNIPPET,
+ children = values,
+ }, Node)
+end)
+
+local M = {}
+
+---The snippet node type enum
+---@types table<string, number>
+M.NodeType = Node.Type
+
+---Parse snippet string and returns the AST
+---@param input string
+---@return table
+function M.parse(input)
+ local result = S.snippet(input, 1)
+ if not result.parsed then
+ error('snippet parsing failed.')
+ end
+ return result.value
+end
+
+return M
diff --git a/runtime/lua/vim/lsp/buf.lua b/runtime/lua/vim/lsp/buf.lua
index b13d662ccb..245f29943e 100644
--- a/runtime/lua/vim/lsp/buf.lua
+++ b/runtime/lua/vim/lsp/buf.lua
@@ -5,7 +5,7 @@ local util = require 'vim.lsp.util'
local M = {}
---@private
+---@private
--- Returns nil if {status} is false or nil, otherwise returns the rest of the
--- arguments.
local function ok_or_nil(status, ...)
@@ -13,31 +13,31 @@ local function ok_or_nil(status, ...)
return ...
end
---@private
+---@private
--- Swallows errors.
---
---@param fn Function to run
---@param ... Function arguments
---@returns Result of `fn(...)` if there are no errors, otherwise nil.
+---@param fn Function to run
+---@param ... Function arguments
+---@returns Result of `fn(...)` if there are no errors, otherwise nil.
--- Returns nil if errors occur during {fn}, otherwise returns
local function npcall(fn, ...)
return ok_or_nil(pcall(fn, ...))
end
---@private
+---@private
--- Sends an async request to all active clients attached to the current
--- buffer.
---
---@param method (string) LSP method name
---@param params (optional, table) Parameters to send to the server
---@param handler (optional, functionnil) See |lsp-handler|. Follows |lsp-handler-resolution|
+---@param method (string) LSP method name
+---@param params (optional, table) Parameters to send to the server
+---@param handler (optional, functionnil) See |lsp-handler|. Follows |lsp-handler-resolution|
--
---@returns 2-tuple:
+---@returns 2-tuple:
--- - Map of client-id:request-id pairs for all successful requests.
--- - Function which can be used to cancel all the requests. You could instead
--- iterate all clients and call their `cancel_request()` methods.
---
---@see |vim.lsp.buf_request()|
+---@see |vim.lsp.buf_request()|
local function request(method, params, handler)
validate {
method = {method, 's'};
@@ -49,7 +49,7 @@ end
--- Checks whether the language servers attached to the current buffer are
--- ready.
---
---@returns `true` if server responds.
+---@returns `true` if server responds.
function M.server_ready()
return not not vim.lsp.buf_notify(0, "window/progress", {})
end
@@ -62,7 +62,7 @@ function M.hover()
end
--- Jumps to the declaration of the symbol under the cursor.
---@note Many servers do not implement this method. Generally, see |vim.lsp.buf.definition()| instead.
+---@note Many servers do not implement this method. Generally, see |vim.lsp.buf.definition()| instead.
---
function M.declaration()
local params = util.make_position_params()
@@ -100,22 +100,22 @@ end
--- Retrieves the completion items at the current cursor position. Can only be
--- called in Insert mode.
---
---@param context (context support not yet implemented) Additional information
+---@param context (context support not yet implemented) Additional information
--- about the context in which a completion was triggered (how it was triggered,
--- and by which trigger character, if applicable)
---
---@see |vim.lsp.protocol.constants.CompletionTriggerKind|
+---@see |vim.lsp.protocol.constants.CompletionTriggerKind|
function M.completion(context)
local params = util.make_position_params()
params.context = context
return request('textDocument/completion', params)
end
---@private
+---@private
--- If there is more than one client that supports the given method,
--- asks the user to select one.
--
---@returns The client that the user selected or nil
+---@returns The client that the user selected or nil
local function select_client(method)
local clients = vim.tbl_values(vim.lsp.buf_get_clients());
clients = vim.tbl_filter(function (client)
@@ -126,7 +126,7 @@ local function select_client(method)
if #clients > 1 then
local choices = {}
- for k,v in ipairs(clients) do
+ for k,v in pairs(clients) do
table.insert(choices, string.format("%d %s", k, v.name))
end
local user_choice = vim.fn.confirm(
@@ -146,11 +146,11 @@ end
--- Formats the current buffer.
---
---@param options (optional, table) Can be used to specify FormattingOptions.
+---@param options (optional, table) Can be used to specify FormattingOptions.
--- Some unspecified options will be automatically derived from the current
--- Neovim options.
--
---@see https://microsoft.github.io/language-server-protocol/specification#textDocument_formatting
+---@see https://microsoft.github.io/language-server-protocol/specification#textDocument_formatting
function M.formatting(options)
local client = select_client("textDocument/formatting")
if client == nil then return end
@@ -168,9 +168,9 @@ end
--- vim.api.nvim_command[[autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_sync()]]
--- </pre>
---
---@param options Table with valid `FormattingOptions` entries
---@param timeout_ms (number) Request timeout
---@see |vim.lsp.buf.formatting_seq_sync|
+---@param options Table with valid `FormattingOptions` entries
+---@param timeout_ms (number) Request timeout
+---@see |vim.lsp.buf.formatting_seq_sync|
function M.formatting_sync(options, timeout_ms)
local client = select_client("textDocument/formatting")
if client == nil then return end
@@ -195,18 +195,18 @@ end
--- vim.api.nvim_command[[autocmd BufWritePre <buffer> lua vim.lsp.buf.formatting_seq_sync()]]
--- </pre>
---
---@param options (optional, table) `FormattingOptions` entries
---@param timeout_ms (optional, number) Request timeout
---@param order (optional, table) List of client names. Formatting is requested from clients
+---@param options (optional, table) `FormattingOptions` entries
+---@param timeout_ms (optional, number) Request timeout
+---@param order (optional, table) List of client names. Formatting is requested from clients
---in the following order: first all clients that are not in the `order` list, then
---the remaining clients in the order as they occur in the `order` list.
function M.formatting_seq_sync(options, timeout_ms, order)
local clients = vim.tbl_values(vim.lsp.buf_get_clients());
-- sort the clients according to `order`
- for _, client_name in ipairs(order or {}) do
+ for _, client_name in pairs(order or {}) do
-- if the client exists, move to the end of the list
- for i, client in ipairs(clients) do
+ for i, client in pairs(clients) do
if client.name == client_name then
table.insert(clients, table.remove(clients, i))
break
@@ -215,7 +215,7 @@ function M.formatting_seq_sync(options, timeout_ms, order)
end
-- loop through the clients and make synchronous formatting requests
- for _, client in ipairs(clients) do
+ for _, client in pairs(clients) do
if client.resolved_capabilities.document_formatting then
local params = util.make_formatting_params(options)
local result, err = client.request_sync("textDocument/formatting", params, timeout_ms, vim.api.nvim_get_current_buf())
@@ -230,10 +230,10 @@ end
--- Formats a given range.
---
---@param options Table with valid `FormattingOptions` entries.
---@param start_pos ({number, number}, optional) mark-indexed position.
+---@param options Table with valid `FormattingOptions` entries.
+---@param start_pos ({number, number}, optional) mark-indexed position.
---Defaults to the start of the last visual selection.
---@param end_pos ({number, number}, optional) mark-indexed position.
+---@param end_pos ({number, number}, optional) mark-indexed position.
---Defaults to the end of the last visual selection.
function M.range_formatting(options, start_pos, end_pos)
local client = select_client("textDocument/rangeFormatting")
@@ -246,29 +246,49 @@ end
--- Renames all references to the symbol under the cursor.
---
---@param new_name (string) If not provided, the user will be prompted for a new
+---@param new_name (string) If not provided, the user will be prompted for a new
---name using |input()|.
function M.rename(new_name)
- -- TODO(ashkan) use prepareRename
- -- * result: [`Range`](#range) \| `{ range: Range, placeholder: string }` \| `null` describing the range of the string to rename and optionally a placeholder text of the string content to be renamed. If `null` is returned then it is deemed that a 'textDocument/rename' request is not valid at the given position.
local params = util.make_position_params()
- new_name = new_name or npcall(vfn.input, "New Name: ", vfn.expand('<cword>'))
- if not (new_name and #new_name > 0) then return end
- params.newName = new_name
- request('textDocument/rename', params)
+ local function prepare_rename(err, result)
+ if err == nil and result == nil then
+ vim.notify('nothing to rename', vim.log.levels.INFO)
+ return
+ end
+ if result and result.placeholder then
+ new_name = new_name or npcall(vfn.input, "New Name: ", result.placeholder)
+ elseif result and result.start and result['end'] and
+ result.start.line == result['end'].line then
+ local line = vfn.getline(result.start.line+1)
+ local start_char = result.start.character+1
+ local end_char = result['end'].character
+ new_name = new_name or npcall(vfn.input, "New Name: ", string.sub(line, start_char, end_char))
+ else
+ -- fallback to guessing symbol using <cword>
+ --
+ -- this can happen if the language server does not support prepareRename,
+ -- returns an unexpected response, or requests for "default behavior"
+ --
+ -- see https://microsoft.github.io/language-server-protocol/specification#textDocument_prepareRename
+ new_name = new_name or npcall(vfn.input, "New Name: ", vfn.expand('<cword>'))
+ end
+ if not (new_name and #new_name > 0) then return end
+ params.newName = new_name
+ request('textDocument/rename', params)
+ end
+ request('textDocument/prepareRename', params, prepare_rename)
end
--- Lists all the references to the symbol under the cursor in the quickfix window.
---
---@param context (table) Context for the request
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_references
+---@param context (table) Context for the request
+---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_references
function M.references(context)
validate { context = { context, 't', true } }
local params = util.make_position_params()
params.context = context or {
includeDeclaration = true;
}
- params[vim.type_idx] = vim.types.dictionary
request('textDocument/references', params)
end
@@ -279,14 +299,14 @@ function M.document_symbol()
request('textDocument/documentSymbol', params)
end
---@private
+---@private
local function pick_call_hierarchy_item(call_hierarchy_items)
if not call_hierarchy_items then return end
if #call_hierarchy_items == 1 then
return call_hierarchy_items[1]
end
local items = {}
- for i, item in ipairs(call_hierarchy_items) do
+ for i, item in pairs(call_hierarchy_items) do
local entry = item.detail or item.name
table.insert(items, string.format("%d. %s", i, entry))
end
@@ -297,16 +317,24 @@ local function pick_call_hierarchy_item(call_hierarchy_items)
return choice
end
---@private
+---@private
local function call_hierarchy(method)
local params = util.make_position_params()
- request('textDocument/prepareCallHierarchy', params, function(err, _, result)
+ request('textDocument/prepareCallHierarchy', params, function(err, result, ctx)
if err then
vim.notify(err.message, vim.log.levels.WARN)
return
end
local call_hierarchy_item = pick_call_hierarchy_item(result)
- vim.lsp.buf_request(0, method, { item = call_hierarchy_item })
+ local client = vim.lsp.get_client_by_id(ctx.client_id)
+ if client then
+ client.request(method, { item = call_hierarchy_item }, nil, ctx.bufnr)
+ else
+ vim.notify(string.format(
+ 'Client with id=%d disappeared during call hierarchy request', ctx.client_id),
+ vim.log.levels.WARN
+ )
+ end
end)
end
@@ -328,8 +356,8 @@ end
---
function M.list_workspace_folders()
local workspace_folders = {}
- for _, client in ipairs(vim.lsp.buf_get_clients()) do
- for _, folder in ipairs(client.workspaceFolders) do
+ for _, client in pairs(vim.lsp.buf_get_clients()) do
+ for _, folder in pairs(client.workspaceFolders) do
table.insert(workspace_folders, folder.name)
end
end
@@ -347,9 +375,9 @@ function M.add_workspace_folder(workspace_folder)
return
end
local params = util.make_workspace_params({{uri = vim.uri_from_fname(workspace_folder); name = workspace_folder}}, {{}})
- for _, client in ipairs(vim.lsp.buf_get_clients()) do
+ for _, client in pairs(vim.lsp.buf_get_clients()) do
local found = false
- for _, folder in ipairs(client.workspaceFolders) do
+ for _, folder in pairs(client.workspaceFolders) do
if folder.name == workspace_folder then
found = true
print(workspace_folder, "is already part of this workspace")
@@ -371,8 +399,8 @@ function M.remove_workspace_folder(workspace_folder)
vim.api.nvim_command("redraw")
if not (workspace_folder and #workspace_folder > 0) then return end
local params = util.make_workspace_params({{}}, {{uri = vim.uri_from_fname(workspace_folder); name = workspace_folder}})
- for _, client in ipairs(vim.lsp.buf_get_clients()) do
- for idx, folder in ipairs(client.workspaceFolders) do
+ for _, client in pairs(vim.lsp.buf_get_clients()) do
+ for idx, folder in pairs(client.workspaceFolders) do
if folder.name == workspace_folder then
vim.lsp.buf_notify(0, 'workspace/didChangeWorkspaceFolders', params)
client.workspaceFolders[idx] = nil
@@ -389,7 +417,7 @@ end
--- call, the user is prompted to enter a string on the command line. An empty
--- string means no filtering is done.
---
---@param query (string, optional)
+---@param query (string, optional)
function M.workspace_symbol(query)
query = query or npcall(vfn.input, "Query: ")
local params = {query = query}
@@ -422,38 +450,157 @@ function M.clear_references()
util.buf_clear_references()
end
---- Selects a code action from the input list that is available at the current
---- cursor position.
+
+---@private
--
---@param context: (table, optional) Valid `CodeActionContext` object
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_codeAction
+--- This is not public because the main extension point is
+--- vim.ui.select which can be overridden independently.
+---
+--- Can't call/use vim.lsp.handlers['textDocument/codeAction'] because it expects
+--- `(err, CodeAction[] | Command[], ctx)`, but we want to aggregate the results
+--- from multiple clients to have 1 single UI prompt for the user, yet we still
+--- need to be able to link a `CodeAction|Command` to the right client for
+--- `codeAction/resolve`
+local function on_code_action_results(results, ctx)
+ local action_tuples = {}
+ for client_id, result in pairs(results) do
+ for _, action in pairs(result.result or {}) do
+ table.insert(action_tuples, { client_id, action })
+ end
+ end
+ if #action_tuples == 0 then
+ vim.notify('No code actions available', vim.log.levels.INFO)
+ return
+ end
+
+ ---@private
+ local function apply_action(action, client)
+ if action.edit then
+ util.apply_workspace_edit(action.edit)
+ end
+ if action.command then
+ local command = type(action.command) == 'table' and action.command or action
+ local fn = vim.lsp.commands[command.command]
+ if fn then
+ local enriched_ctx = vim.deepcopy(ctx)
+ enriched_ctx.client_id = client.id
+ fn(command, ctx)
+ else
+ M.execute_command(command)
+ end
+ end
+ end
+
+ ---@private
+ local function on_user_choice(action_tuple)
+ if not action_tuple then
+ return
+ end
+ -- textDocument/codeAction can return either Command[] or CodeAction[]
+ --
+ -- CodeAction
+ -- ...
+ -- edit?: WorkspaceEdit -- <- must be applied before command
+ -- command?: Command
+ --
+ -- Command:
+ -- title: string
+ -- command: string
+ -- arguments?: any[]
+ --
+ local client = vim.lsp.get_client_by_id(action_tuple[1])
+ local action = action_tuple[2]
+ if not action.edit
+ and client
+ and type(client.resolved_capabilities.code_action) == 'table'
+ and client.resolved_capabilities.code_action.resolveProvider then
+
+ client.request('codeAction/resolve', action, function(err, resolved_action)
+ if err then
+ vim.notify(err.code .. ': ' .. err.message, vim.log.levels.ERROR)
+ return
+ end
+ apply_action(resolved_action, client)
+ end)
+ else
+ apply_action(action, client)
+ end
+ end
+
+ vim.ui.select(action_tuples, {
+ prompt = 'Code actions:',
+ format_item = function(action_tuple)
+ local title = action_tuple[2].title:gsub('\r\n', '\\r\\n')
+ return title:gsub('\n', '\\n')
+ end,
+ }, on_user_choice)
+end
+
+
+--- Requests code actions from all clients and calls the handler exactly once
+--- with all aggregated results
+---@private
+local function code_action_request(params)
+ local bufnr = vim.api.nvim_get_current_buf()
+ local method = 'textDocument/codeAction'
+ vim.lsp.buf_request_all(bufnr, method, params, function(results)
+ on_code_action_results(results, { bufnr = bufnr, method = method, params = params })
+ end)
+end
+
+--- Selects a code action available at the current
+--- cursor position.
+---
+---@param context table|nil `CodeActionContext` of the LSP specification:
+--- - diagnostics: (table|nil)
+--- LSP `Diagnostic[]`. Inferred from the current
+--- position if not provided.
+--- - only: (string|nil)
+--- LSP `CodeActionKind` used to filter the code actions.
+--- Most language servers support values like `refactor`
+--- or `quickfix`.
+---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_codeAction
function M.code_action(context)
validate { context = { context, 't', true } }
- context = context or { diagnostics = vim.lsp.diagnostic.get_line_diagnostics() }
+ context = context or {}
+ if not context.diagnostics then
+ context.diagnostics = vim.lsp.diagnostic.get_line_diagnostics()
+ end
local params = util.make_range_params()
params.context = context
- request('textDocument/codeAction', params)
+ code_action_request(params)
end
--- Performs |vim.lsp.buf.code_action()| for a given range.
---
---@param context: (table, optional) Valid `CodeActionContext` object
---@param start_pos ({number, number}, optional) mark-indexed position.
+---
+---@param context table|nil `CodeActionContext` of the LSP specification:
+--- - diagnostics: (table|nil)
+--- LSP `Diagnostic[]`. Inferred from the current
+--- position if not provided.
+--- - only: (string|nil)
+--- LSP `CodeActionKind` used to filter the code actions.
+--- Most language servers support values like `refactor`
+--- or `quickfix`.
+---@param start_pos ({number, number}, optional) mark-indexed position.
---Defaults to the start of the last visual selection.
---@param end_pos ({number, number}, optional) mark-indexed position.
+---@param end_pos ({number, number}, optional) mark-indexed position.
---Defaults to the end of the last visual selection.
function M.range_code_action(context, start_pos, end_pos)
validate { context = { context, 't', true } }
- context = context or { diagnostics = vim.lsp.diagnostic.get_line_diagnostics() }
+ context = context or {}
+ if not context.diagnostics then
+ context.diagnostics = vim.lsp.diagnostic.get_line_diagnostics()
+ end
local params = util.make_given_range_params(start_pos, end_pos)
params.context = context
- request('textDocument/codeAction', params)
+ code_action_request(params)
end
--- Executes an LSP server command.
---
---@param command A valid `ExecuteCommandParams` object
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_executeCommand
+---@param command A valid `ExecuteCommandParams` object
+---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_executeCommand
function M.execute_command(command)
validate {
command = { command.command, 's' },
diff --git a/runtime/lua/vim/lsp/codelens.lua b/runtime/lua/vim/lsp/codelens.lua
index fbd37e3830..20b203fe99 100644
--- a/runtime/lua/vim/lsp/codelens.lua
+++ b/runtime/lua/vim/lsp/codelens.lua
@@ -22,19 +22,33 @@ local namespaces = setmetatable({}, {
end;
})
---@private
+---@private
M.__namespaces = namespaces
---@private
+---@private
local function execute_lens(lens, bufnr, client_id)
local line = lens.range.start.line
api.nvim_buf_clear_namespace(bufnr, namespaces[client_id], line, line + 1)
+ local command = lens.command
+ local fn = vim.lsp.commands[command.command]
+ if fn then
+ fn(command, { bufnr = bufnr, client_id = client_id })
+ return
+ end
-- Need to use the client that returned the lens → must not use buf_request
local client = vim.lsp.get_client_by_id(client_id)
assert(client, 'Client is required to execute lens, client_id=' .. client_id)
- client.request('workspace/executeCommand', lens.command, function(...)
+ local command_provider = client.server_capabilities.executeCommandProvider
+ local commands = type(command_provider) == 'table' and command_provider.commands or {}
+ if not vim.tbl_contains(commands, command.command) then
+ vim.notify(string.format(
+ "Language server does not support command `%s`. This command may require a client extension.", command.command),
+ vim.log.levels.WARN)
+ return
+ end
+ client.request('workspace/executeCommand', command, function(...)
local result = vim.lsp.handlers['workspace/executeCommand'](...)
M.refresh()
return result
@@ -44,9 +58,10 @@ end
--- Return all lenses for the given buffer
---
+---@param bufnr number Buffer number. 0 can be used for the current buffer.
---@return table (`CodeLens[]`)
function M.get(bufnr)
- local lenses_by_client = lens_cache_by_buf[bufnr]
+ local lenses_by_client = lens_cache_by_buf[bufnr or 0]
if not lenses_by_client then return {} end
local lenses = {}
for _, client_lenses in pairs(lenses_by_client) do
@@ -111,15 +126,19 @@ function M.display(lenses, bufnr, client_id)
local ns = namespaces[client_id]
local num_lines = api.nvim_buf_line_count(bufnr)
for i = 0, num_lines do
- local line_lenses = lenses_by_lnum[i]
+ local line_lenses = lenses_by_lnum[i] or {}
api.nvim_buf_clear_namespace(bufnr, ns, i, i + 1)
local chunks = {}
- for _, lens in pairs(line_lenses or {}) do
+ local num_line_lenses = #line_lenses
+ for j, lens in ipairs(line_lenses) do
local text = lens.command and lens.command.title or 'Unresolved lens ...'
table.insert(chunks, {text, 'LspCodeLens' })
+ if j < num_line_lenses then
+ table.insert(chunks, {' | ', 'LspCodeLensSeparator' })
+ end
end
if #chunks > 0 then
- api.nvim_buf_set_virtual_text(bufnr, ns, i, chunks, {})
+ api.nvim_buf_set_extmark(bufnr, ns, i, 0, { virt_text = chunks })
end
end
end
@@ -147,7 +166,7 @@ function M.save(lenses, bufnr, client_id)
end
---@private
+---@private
local function resolve_lenses(lenses, bufnr, client_id, callback)
lenses = lenses or {}
local num_lens = vim.tbl_count(lenses)
@@ -156,7 +175,7 @@ local function resolve_lenses(lenses, bufnr, client_id, callback)
return
end
- --@private
+ ---@private
local function countdown()
num_lens = num_lens - 1
if num_lens == 0 then
@@ -169,18 +188,18 @@ local function resolve_lenses(lenses, bufnr, client_id, callback)
if lens.command then
countdown()
else
- client.request('codeLens/resolve', lens, function(_, _, result)
+ client.request('codeLens/resolve', lens, function(_, result)
if result and result.command then
lens.command = result.command
-- Eager display to have some sort of incremental feedback
-- Once all lenses got resolved there will be a full redraw for all lenses
-- So that multiple lens per line are properly displayed
- api.nvim_buf_set_virtual_text(
+ api.nvim_buf_set_extmark(
bufnr,
ns,
lens.range.start.line,
- {{ lens.command.title, 'LspCodeLens' },},
- {}
+ 0,
+ { virt_text = {{ lens.command.title, 'LspCodeLens' }} }
)
end
countdown()
@@ -192,17 +211,17 @@ end
--- |lsp-handler| for the method `textDocument/codeLens`
---
-function M.on_codelens(err, _, result, client_id, bufnr)
+function M.on_codelens(err, result, ctx, _)
assert(not err, vim.inspect(err))
- M.save(result, bufnr, client_id)
+ M.save(result, ctx.bufnr, ctx.client_id)
-- Eager display for any resolved (and unresolved) lenses and refresh them
-- once resolved.
- M.display(result, bufnr, client_id)
- resolve_lenses(result, bufnr, client_id, function()
- M.display(result, bufnr, client_id)
- active_refreshes[bufnr] = nil
+ M.display(result, ctx.bufnr, ctx.client_id)
+ resolve_lenses(result, ctx.bufnr, ctx.client_id, function()
+ M.display(result, ctx.bufnr, ctx.client_id)
+ active_refreshes[ctx.bufnr] = nil
end)
end
diff --git a/runtime/lua/vim/lsp/diagnostic.lua b/runtime/lua/vim/lsp/diagnostic.lua
index 64dde78f17..c6c08a15d3 100644
--- a/runtime/lua/vim/lsp/diagnostic.lua
+++ b/runtime/lua/vim/lsp/diagnostic.lua
@@ -1,126 +1,19 @@
-local api = vim.api
-local validate = vim.validate
-
-local highlight = vim.highlight
-local log = require('vim.lsp.log')
-local protocol = require('vim.lsp.protocol')
-local util = require('vim.lsp.util')
-
-local if_nil = vim.F.if_nil
-
---@class DiagnosticSeverity
-local DiagnosticSeverity = protocol.DiagnosticSeverity
-
-local to_severity = function(severity)
- if not severity then return nil end
- return type(severity) == 'string' and DiagnosticSeverity[severity] or severity
-end
-
-local filter_to_severity_limit = function(severity, diagnostics)
- local filter_level = to_severity(severity)
- if not filter_level then
- return diagnostics
- end
-
- return vim.tbl_filter(function(t) return t.severity == filter_level end, diagnostics)
-end
-
-local filter_by_severity_limit = function(severity_limit, diagnostics)
- local filter_level = to_severity(severity_limit)
- if not filter_level then
- return diagnostics
- end
-
- return vim.tbl_filter(function(t) return t.severity <= filter_level end, diagnostics)
-end
-
-local to_position = function(position, bufnr)
- vim.validate { position = {position, 't'} }
-
- return {
- position.line,
- util._get_line_byte_from_position(bufnr, position)
- }
-end
-
-
---@brief lsp-diagnostic
---
---@class Diagnostic
---@field range Range
---@field message string
---@field severity DiagnosticSeverity|nil
---@field code number | string
---@field source string
---@field tags DiagnosticTag[]
---@field relatedInformation DiagnosticRelatedInformation[]
+---@class Diagnostic
+---@field range Range
+---@field message string
+---@field severity DiagnosticSeverity|nil
+---@field code number | string
+---@field source string
+---@field tags DiagnosticTag[]
+---@field relatedInformation DiagnosticRelatedInformation[]
local M = {}
--- Diagnostic Highlights {{{
-
--- TODO(tjdevries): Determine how to generate documentation for these
--- and how to configure them to be easy for users.
---
--- For now, just use the following script. It should work pretty good.
---[[
-local levels = {"Error", "Warning", "Information", "Hint" }
-
-local all_info = {
- { "Default", "Used as the base highlight group, other highlight groups link to", },
- { "VirtualText", 'Used for "%s" diagnostic virtual text.\n See |vim.lsp.diagnostic.set_virtual_text()|', },
- { "Underline", 'Used to underline "%s" diagnostics.\n See |vim.lsp.diagnostic.set_underline()|', },
- { "Floating", 'Used to color "%s" diagnostic messages in diagnostics float.\n See |vim.lsp.diagnostic.show_line_diagnostics()|', },
- { "Sign", 'Used for "%s" signs in sing column.\n See |vim.lsp.diagnostic.set_signs()|', },
-}
-
-local results = {}
-for _, info in ipairs(all_info) do
- for _, level in ipairs(levels) do
- local name = info[1]
- local description = info[2]
- local fullname = string.format("Lsp%s%s", name, level)
- table.insert(results, string.format(
- "%78s", string.format("*hl-%s*", fullname))
- )
-
- table.insert(results, fullname)
- table.insert(results, string.format(" %s", description))
- table.insert(results, "")
- end
-end
-
--- print(table.concat(results, '\n'))
-vim.fn.setreg("*", table.concat(results, '\n'))
---]]
-
-local diagnostic_severities = {
- [DiagnosticSeverity.Error] = { guifg = "Red" };
- [DiagnosticSeverity.Warning] = { guifg = "Orange" };
- [DiagnosticSeverity.Information] = { guifg = "LightBlue" };
- [DiagnosticSeverity.Hint] = { guifg = "LightGrey" };
-}
-
--- Make a map from DiagnosticSeverity -> Highlight Name
-local make_highlight_map = function(base_name)
- local result = {}
- for k, _ in pairs(diagnostic_severities) do
- result[k] = "LspDiagnostics" .. base_name .. DiagnosticSeverity[k]
- end
-
- return result
-end
-
-local default_highlight_map = make_highlight_map("Default")
-local virtual_text_highlight_map = make_highlight_map("VirtualText")
-local underline_highlight_map = make_highlight_map("Underline")
-local floating_highlight_map = make_highlight_map("Floating")
-local sign_highlight_map = make_highlight_map("Sign")
-
--- }}}
--- Diagnostic Namespaces {{{
local DEFAULT_CLIENT_ID = -1
-local get_client_id = function(client_id)
+---@private
+local function get_client_id(client_id)
if client_id == nil then
client_id = DEFAULT_CLIENT_ID
end
@@ -128,472 +21,414 @@ local get_client_id = function(client_id)
return client_id
end
-local get_bufnr = function(bufnr)
+---@private
+local function get_bufnr(bufnr)
if not bufnr then
- return api.nvim_get_current_buf()
+ return vim.api.nvim_get_current_buf()
elseif bufnr == 0 then
- return api.nvim_get_current_buf()
+ return vim.api.nvim_get_current_buf()
end
return bufnr
end
-
---- Create a namespace table, used to track a client's buffer local items
-local _make_namespace_table = function(namespace, api_namespace)
- vim.validate { namespace = { namespace, 's' } }
-
- return setmetatable({
- [DEFAULT_CLIENT_ID] = api.nvim_create_namespace(namespace)
- }, {
- __index = function(t, client_id)
- client_id = get_client_id(client_id)
-
- if rawget(t, client_id) == nil then
- local value = string.format("%s:%s", namespace, client_id)
-
- if api_namespace then
- value = api.nvim_create_namespace(value)
- end
-
- rawset(t, client_id, value)
- end
-
- return rawget(t, client_id)
- end
- })
+---@private
+local function severity_lsp_to_vim(severity)
+ if type(severity) == 'string' then
+ severity = vim.lsp.protocol.DiagnosticSeverity[severity]
+ end
+ return severity
end
-local _diagnostic_namespaces = _make_namespace_table("vim_lsp_diagnostics", true)
-local _sign_namespaces = _make_namespace_table("vim_lsp_signs", false)
-
---@private
-function M._get_diagnostic_namespace(client_id)
- return _diagnostic_namespaces[client_id]
+---@private
+local function severity_vim_to_lsp(severity)
+ if type(severity) == 'string' then
+ severity = vim.diagnostic.severity[severity]
+ end
+ return severity
end
---@private
-function M._get_sign_namespace(client_id)
- return _sign_namespaces[client_id]
-end
--- }}}
--- Diagnostic Buffer & Client metatables {{{
-local bufnr_and_client_cacher_mt = {
- __index = function(t, bufnr)
- if bufnr == 0 or bufnr == nil then
- bufnr = vim.api.nvim_get_current_buf()
- end
+---@private
+local function line_byte_from_position(lines, lnum, col, offset_encoding)
+ if not lines or offset_encoding == "utf-8" then
+ return col
+ end
- if rawget(t, bufnr) == nil then
- rawset(t, bufnr, {})
- end
+ local line = lines[lnum + 1]
+ local ok, result = pcall(vim.str_byteindex, line, col, offset_encoding == "utf-16")
+ if ok then
+ return result
+ end
- return rawget(t, bufnr)
- end,
+ return col
+end
- __newindex = function(t, bufnr, v)
- if bufnr == 0 or bufnr == nil then
- bufnr = vim.api.nvim_get_current_buf()
- end
+---@private
+local function get_buf_lines(bufnr)
+ if vim.api.nvim_buf_is_loaded(bufnr) then
+ return vim.api.nvim_buf_get_lines(bufnr, 0, -1, false)
+ end
- rawset(t, bufnr, v)
- end,
-}
--- }}}
--- Diagnostic Saving & Caching {{{
-local _diagnostic_cleanup = setmetatable({}, bufnr_and_client_cacher_mt)
-local diagnostic_cache = setmetatable({}, bufnr_and_client_cacher_mt)
-local diagnostic_cache_lines = setmetatable({}, bufnr_and_client_cacher_mt)
-local diagnostic_cache_counts = setmetatable({}, bufnr_and_client_cacher_mt)
+ local filename = vim.api.nvim_buf_get_name(bufnr)
+ local f = io.open(filename)
+ if not f then
+ return
+ end
-local _bufs_waiting_to_update = setmetatable({}, bufnr_and_client_cacher_mt)
+ local content = f:read("*a")
+ if not content then
+ -- Some LSP servers report diagnostics at a directory level, in which case
+ -- io.read() returns nil
+ f:close()
+ return
+ end
---- Store Diagnostic[] by line
----
----@param diagnostics Diagnostic[]
----@return table<number, Diagnostic[]>
-local _diagnostic_lines = function(diagnostics)
- if not diagnostics then return end
+ local lines = vim.split(content, "\n")
+ f:close()
+ return lines
+end
- local diagnostics_by_line = {}
- for _, diagnostic in ipairs(diagnostics) do
+---@private
+local function diagnostic_lsp_to_vim(diagnostics, bufnr, client_id)
+ local buf_lines = get_buf_lines(bufnr)
+ local client = vim.lsp.get_client_by_id(client_id)
+ local offset_encoding = client and client.offset_encoding or "utf-16"
+ return vim.tbl_map(function(diagnostic)
local start = diagnostic.range.start
- local line_diagnostics = diagnostics_by_line[start.line]
- if not line_diagnostics then
- line_diagnostics = {}
- diagnostics_by_line[start.line] = line_diagnostics
- end
- table.insert(line_diagnostics, diagnostic)
+ local _end = diagnostic.range["end"]
+ return {
+ lnum = start.line,
+ col = line_byte_from_position(buf_lines, start.line, start.character, offset_encoding),
+ end_lnum = _end.line,
+ end_col = line_byte_from_position(buf_lines, _end.line, _end.character, offset_encoding),
+ severity = severity_lsp_to_vim(diagnostic.severity),
+ message = diagnostic.message,
+ source = diagnostic.source,
+ user_data = {
+ lsp = {
+ code = diagnostic.code,
+ codeDescription = diagnostic.codeDescription,
+ tags = diagnostic.tags,
+ relatedInformation = diagnostic.relatedInformation,
+ data = diagnostic.data,
+ },
+ },
+ }
+ end, diagnostics)
+end
+
+---@private
+local function diagnostic_vim_to_lsp(diagnostics)
+ return vim.tbl_map(function(diagnostic)
+ return vim.tbl_extend("error", {
+ range = {
+ start = {
+ line = diagnostic.lnum,
+ character = diagnostic.col,
+ },
+ ["end"] = {
+ line = diagnostic.end_lnum,
+ character = diagnostic.end_col,
+ },
+ },
+ severity = severity_vim_to_lsp(diagnostic.severity),
+ message = diagnostic.message,
+ source = diagnostic.source,
+ }, diagnostic.user_data and (diagnostic.user_data.lsp or {}) or {})
+ end, diagnostics)
+end
+
+local _client_namespaces = {}
+
+--- Get the diagnostic namespace associated with an LSP client |vim.diagnostic|.
+---
+---@param client_id number The id of the LSP client
+function M.get_namespace(client_id)
+ vim.validate { client_id = { client_id, 'n' } }
+ if not _client_namespaces[client_id] then
+ local name = string.format("vim.lsp.client-%d", client_id)
+ _client_namespaces[client_id] = vim.api.nvim_create_namespace(name)
end
- return diagnostics_by_line
+ return _client_namespaces[client_id]
end
---- Get the count of M by Severity
+--- Save diagnostics to the current buffer.
---
+--- Handles saving diagnostics from multiple clients in the same buffer.
---@param diagnostics Diagnostic[]
----@return table<DiagnosticSeverity, number>
-local _diagnostic_counts = function(diagnostics)
- if not diagnostics then return end
+---@param bufnr number
+---@param client_id number
+---@private
+function M.save(diagnostics, bufnr, client_id)
+ local namespace = M.get_namespace(client_id)
+ vim.diagnostic.set(namespace, bufnr, diagnostic_lsp_to_vim(diagnostics, bufnr, client_id))
+end
+-- }}}
- local counts = {}
- for _, diagnostic in pairs(diagnostics) do
- if diagnostic.severity then
- local val = counts[diagnostic.severity]
- if val == nil then
- val = 0
- end
+--- |lsp-handler| for the method "textDocument/publishDiagnostics"
+---
+--- See |vim.diagnostic.config()| for configuration options. Handler-specific
+--- configuration can be set using |vim.lsp.with()|:
+--- <pre>
+--- vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
+--- vim.lsp.diagnostic.on_publish_diagnostics, {
+--- -- Enable underline, use default values
+--- underline = true,
+--- -- Enable virtual text, override spacing to 4
+--- virtual_text = {
+--- spacing = 4,
+--- },
+--- -- Use a function to dynamically turn signs off
+--- -- and on, using buffer local variables
+--- signs = function(bufnr, client_id)
+--- return vim.bo[bufnr].show_signs == false
+--- end,
+--- -- Disable a feature
+--- update_in_insert = false,
+--- }
+--- )
+--- </pre>
+---
+---@param config table Configuration table (see |vim.diagnostic.config()|).
+function M.on_publish_diagnostics(_, result, ctx, config)
+ local client_id = ctx.client_id
+ local uri = result.uri
+ local bufnr = vim.uri_to_bufnr(uri)
- counts[diagnostic.severity] = val + 1
- end
+ if not bufnr then
+ return
end
- return counts
-end
-
---@private
---- Set the different diagnostic cache after `textDocument/publishDiagnostics`
----@param diagnostics Diagnostic[]
----@param bufnr number
----@param client_id number
----@return nil
-local function set_diagnostic_cache(diagnostics, bufnr, client_id)
client_id = get_client_id(client_id)
-
- -- https://microsoft.github.io/language-server-protocol/specifications/specification-current/#diagnostic
- --
- -- The diagnostic's severity. Can be omitted. If omitted it is up to the
- -- client to interpret diagnostics as error, warning, info or hint.
- -- TODO: Replace this with server-specific heuristics to infer severity.
- local buf_line_count = vim.api.nvim_buf_line_count(bufnr)
- for _, diagnostic in ipairs(diagnostics) do
- if diagnostic.severity == nil then
- diagnostic.severity = DiagnosticSeverity.Error
- end
- -- Account for servers that place diagnostics on terminating newline
- if buf_line_count > 0 then
- diagnostic.range.start.line = math.max(math.min(
- diagnostic.range.start.line, buf_line_count - 1
- ), 0)
- diagnostic.range["end"].line = math.max(math.min(
- diagnostic.range["end"].line, buf_line_count - 1
- ), 0)
+ local namespace = M.get_namespace(client_id)
+ local diagnostics = result.diagnostics
+
+ if config then
+ for _, opt in pairs(config) do
+ if type(opt) == 'table' then
+ if not opt.severity and opt.severity_limit then
+ opt.severity = {min=severity_lsp_to_vim(opt.severity_limit)}
+ end
+ end
end
end
- diagnostic_cache[bufnr][client_id] = diagnostics
- diagnostic_cache_lines[bufnr][client_id] = _diagnostic_lines(diagnostics)
- diagnostic_cache_counts[bufnr][client_id] = _diagnostic_counts(diagnostics)
-end
-
+ vim.diagnostic.set(namespace, bufnr, diagnostic_lsp_to_vim(diagnostics, bufnr, client_id), config)
---@private
---- Clear the cached diagnostics
----@param bufnr number
----@param client_id number
-local function clear_diagnostic_cache(bufnr, client_id)
- client_id = get_client_id(client_id)
-
- diagnostic_cache[bufnr][client_id] = nil
- diagnostic_cache_lines[bufnr][client_id] = nil
- diagnostic_cache_counts[bufnr][client_id] = nil
+ -- Keep old autocmd for back compat. This should eventually be removed.
+ vim.api.nvim_command("doautocmd <nomodeline> User LspDiagnosticsChanged")
end
---- Save diagnostics to the current buffer.
+--- Clear diagnotics and diagnostic cache.
+---
+--- Diagnostic producers should prefer |vim.diagnostic.reset()|. However,
+--- this method signature is still used internally in some parts of the LSP
+--- implementation so it's simply marked @private rather than @deprecated.
---
---- Handles saving diagnostics from multiple clients in the same buffer.
----@param diagnostics Diagnostic[]
----@param bufnr number
---@param client_id number
-function M.save(diagnostics, bufnr, client_id)
- validate {
- diagnostics = {diagnostics, 't'},
- bufnr = {bufnr, 'n'},
- client_id = {client_id, 'n', true},
- }
-
- if not diagnostics then return end
-
- bufnr = get_bufnr(bufnr)
- client_id = get_client_id(client_id)
-
- if not _diagnostic_cleanup[bufnr][client_id] then
- _diagnostic_cleanup[bufnr][client_id] = true
-
- -- Clean up our data when the buffer unloads.
- api.nvim_buf_attach(bufnr, false, {
- on_detach = function(_, b)
- clear_diagnostic_cache(b, client_id)
- _diagnostic_cleanup[b][client_id] = nil
+---@param buffer_client_map table map of buffers to active clients
+---@private
+function M.reset(client_id, buffer_client_map)
+ buffer_client_map = vim.deepcopy(buffer_client_map)
+ vim.schedule(function()
+ for bufnr, client_ids in pairs(buffer_client_map) do
+ if client_ids[client_id] then
+ local namespace = M.get_namespace(client_id)
+ vim.diagnostic.reset(namespace, bufnr)
end
- })
- end
-
- set_diagnostic_cache(diagnostics, bufnr, client_id)
+ end
+ end)
end
--- }}}
--- Diagnostic Retrieval {{{
+-- Deprecated Functions {{{
--- Get all diagnostics for clients
---
+---@deprecated Prefer |vim.diagnostic.get()|
+---
---@param client_id number Restrict included diagnostics to the client
--- If nil, diagnostics of all clients are included.
---@return table with diagnostics grouped by bufnr (bufnr: Diagnostic[])
function M.get_all(client_id)
- local diagnostics_by_bufnr = {}
- for bufnr, buf_diagnostics in pairs(diagnostic_cache) do
- diagnostics_by_bufnr[bufnr] = {}
- for cid, client_diagnostics in pairs(buf_diagnostics) do
- if client_id == nil or cid == client_id then
- vim.list_extend(diagnostics_by_bufnr[bufnr], client_diagnostics)
- end
- end
+ local result = {}
+ local namespace
+ if client_id then
+ namespace = M.get_namespace(client_id)
end
- return diagnostics_by_bufnr
+ for _, bufnr in ipairs(vim.api.nvim_list_bufs()) do
+ local diagnostics = diagnostic_vim_to_lsp(vim.diagnostic.get(bufnr, {namespace = namespace}))
+ result[bufnr] = diagnostics
+ end
+ return result
end
--- Return associated diagnostics for bufnr
---
+---@deprecated Prefer |vim.diagnostic.get()|
+---
---@param bufnr number
---@param client_id number|nil If nil, then return all of the diagnostics.
--- Else, return just the diagnostics associated with the client_id.
-function M.get(bufnr, client_id)
+---@param predicate function|nil Optional function for filtering diagnostics
+function M.get(bufnr, client_id, predicate)
+ predicate = predicate or function() return true end
if client_id == nil then
local all_diagnostics = {}
- for iter_client_id, _ in pairs(diagnostic_cache[bufnr]) do
- local iter_diagnostics = M.get(bufnr, iter_client_id)
-
+ vim.lsp.for_each_buffer_client(bufnr, function(_, iter_client_id, _)
+ local iter_diagnostics = vim.tbl_filter(predicate, M.get(bufnr, iter_client_id))
for _, diagnostic in ipairs(iter_diagnostics) do
table.insert(all_diagnostics, diagnostic)
end
- end
-
+ end)
return all_diagnostics
end
- return diagnostic_cache[bufnr][client_id] or {}
+ local namespace = M.get_namespace(client_id)
+ return diagnostic_vim_to_lsp(vim.tbl_filter(predicate, vim.diagnostic.get(bufnr, {namespace=namespace})))
end
--- Get the diagnostics by line
---
----@param bufnr number The buffer number
----@param line_nr number The line number
+--- Marked private as this is used internally by the LSP subsystem, but
+--- most users should instead prefer |vim.diagnostic.get()|.
+---
+---@param bufnr number|nil The buffer number
+---@param line_nr number|nil The line number
---@param opts table|nil Configuration keys
--- - severity: (DiagnosticSeverity, default nil)
--- - Only return diagnostics with this severity. Overrides severity_limit
--- - severity_limit: (DiagnosticSeverity, default nil)
--- - Limit severity of diagnostics found. E.g. "Warning" means { "Error", "Warning" } will be valid.
----@param client_id number the client id
+---@param client_id|nil number the client id
---@return table Table with map of line number to list of diagnostics.
--- Structured: { [1] = {...}, [5] = {.... } }
+--- Structured: { [1] = {...}, [5] = {.... } }
+---@private
function M.get_line_diagnostics(bufnr, line_nr, opts, client_id)
opts = opts or {}
-
- bufnr = bufnr or vim.api.nvim_get_current_buf()
- line_nr = line_nr or vim.api.nvim_win_get_cursor(0)[1] - 1
-
- local client_get_diags = function(iter_client_id)
- return (diagnostic_cache_lines[bufnr][iter_client_id] or {})[line_nr] or {}
+ if opts.severity then
+ opts.severity = severity_lsp_to_vim(opts.severity)
+ elseif opts.severity_limit then
+ opts.severity = {min=severity_lsp_to_vim(opts.severity_limit)}
end
- local line_diagnostics
- if client_id == nil then
- line_diagnostics = {}
- for iter_client_id, _ in pairs(diagnostic_cache_lines[bufnr]) do
- for _, diagnostic in ipairs(client_get_diags(iter_client_id)) do
- table.insert(line_diagnostics, diagnostic)
- end
- end
- else
- line_diagnostics = vim.deepcopy(client_get_diags(client_id))
+ if client_id then
+ opts.namespace = M.get_namespace(client_id)
end
- if opts.severity then
- line_diagnostics = filter_to_severity_limit(opts.severity, line_diagnostics)
- elseif opts.severity_limit then
- line_diagnostics = filter_by_severity_limit(opts.severity_limit, line_diagnostics)
+ if not line_nr then
+ line_nr = vim.api.nvim_win_get_cursor(0)[1] - 1
end
- table.sort(line_diagnostics, function(a, b) return a.severity < b.severity end)
+ opts.lnum = line_nr
- return line_diagnostics
+ return diagnostic_vim_to_lsp(vim.diagnostic.get(bufnr, opts))
end
--- Get the counts for a particular severity
---
---- Useful for showing diagnostic counts in statusline. eg:
----
---- <pre>
---- function! LspStatus() abort
---- let sl = ''
---- if luaeval('not vim.tbl_isempty(vim.lsp.buf_get_clients(0))')
---- let sl.='%#MyStatuslineLSP#E:'
---- let sl.='%#MyStatuslineLSPErrors#%{luaeval("vim.lsp.diagnostic.get_count(0, [[Error]])")}'
---- let sl.='%#MyStatuslineLSP# W:'
---- let sl.='%#MyStatuslineLSPWarnings#%{luaeval("vim.lsp.diagnostic.get_count(0, [[Warning]])")}'
---- else
---- let sl.='%#MyStatuslineLSPErrors#off'
---- endif
---- return sl
---- endfunction
---- let &l:statusline = '%#MyStatuslineLSP#LSP '.LspStatus()
---- </pre>
+---@deprecated Prefer |vim.diagnostic.get_count()|
---
---@param bufnr number The buffer number
---@param severity DiagnosticSeverity
---@param client_id number the client id
function M.get_count(bufnr, severity, client_id)
- if client_id == nil then
- local total = 0
- for iter_client_id, _ in pairs(diagnostic_cache_counts[bufnr]) do
- total = total + M.get_count(bufnr, severity, iter_client_id)
- end
-
- return total
+ severity = severity_lsp_to_vim(severity)
+ local opts = { severity = severity }
+ if client_id ~= nil then
+ opts.namespace = M.get_namespace(client_id)
end
- return (diagnostic_cache_counts[bufnr][client_id] or {})[DiagnosticSeverity[severity]] or 0
-end
-
-
--- }}}
--- Diagnostic Movements {{{
-
---- Helper function to iterate through all of the diagnostic lines
----@return table list of diagnostics
-local _iter_diagnostic_lines = function(start, finish, step, bufnr, opts, client_id)
- if bufnr == nil then
- bufnr = vim.api.nvim_get_current_buf()
- end
-
- local wrap = if_nil(opts.wrap, true)
-
- local search = function(search_start, search_finish, search_step)
- for line_nr = search_start, search_finish, search_step do
- local line_diagnostics = M.get_line_diagnostics(bufnr, line_nr, opts, client_id)
- if line_diagnostics and not vim.tbl_isempty(line_diagnostics) then
- return line_diagnostics
- end
- end
- end
-
- local result = search(start, finish, step)
-
- if wrap then
- local wrap_start, wrap_finish
- if step == 1 then
- wrap_start, wrap_finish = 1, start
- else
- wrap_start, wrap_finish = vim.api.nvim_buf_line_count(bufnr), start
- end
-
- if not result then
- result = search(wrap_start, wrap_finish, step)
- end
- end
-
- return result
-end
-
---@private
---- Helper function to ierate through diagnostic lines and return a position
----
----@return table {row, col}
-local function _iter_diagnostic_lines_pos(opts, line_diagnostics)
- opts = opts or {}
-
- local win_id = opts.win_id or vim.api.nvim_get_current_win()
- local bufnr = vim.api.nvim_win_get_buf(win_id)
-
- if line_diagnostics == nil or vim.tbl_isempty(line_diagnostics) then
- return false
- end
-
- local iter_diagnostic = line_diagnostics[1]
- return to_position(iter_diagnostic.range.start, bufnr)
-end
-
---@private
--- Move to the diagnostic position
-local function _iter_diagnostic_move_pos(name, opts, pos)
- opts = opts or {}
-
- local enable_popup = if_nil(opts.enable_popup, true)
- local win_id = opts.win_id or vim.api.nvim_get_current_win()
-
- if not pos then
- print(string.format("%s: No more valid diagnostics to move to.", name))
- return
- end
-
- vim.api.nvim_win_set_cursor(win_id, {pos[1] + 1, pos[2]})
-
- if enable_popup then
- -- This is a bit weird... I'm surprised that we need to wait til the next tick to do this.
- vim.schedule(function()
- M.show_line_diagnostics(opts.popup_opts, vim.api.nvim_win_get_buf(win_id))
- end)
- end
+ return #vim.diagnostic.get(bufnr, opts)
end
--- Get the previous diagnostic closest to the cursor_position
---
+---@deprecated Prefer |vim.diagnostic.get_prev()|
+---
---@param opts table See |vim.lsp.diagnostic.goto_next()|
---@return table Previous diagnostic
function M.get_prev(opts)
- opts = opts or {}
-
- local win_id = opts.win_id or vim.api.nvim_get_current_win()
- local bufnr = vim.api.nvim_win_get_buf(win_id)
- local cursor_position = opts.cursor_position or vim.api.nvim_win_get_cursor(win_id)
-
- return _iter_diagnostic_lines(cursor_position[1] - 2, 0, -1, bufnr, opts, opts.client_id)
+ if opts then
+ if opts.severity then
+ opts.severity = severity_lsp_to_vim(opts.severity)
+ elseif opts.severity_limit then
+ opts.severity = {min=severity_lsp_to_vim(opts.severity_limit)}
+ end
+ end
+ return diagnostic_vim_to_lsp({vim.diagnostic.get_prev(opts)})[1]
end
--- Return the pos, {row, col}, for the prev diagnostic in the current buffer.
+---
+---@deprecated Prefer |vim.diagnostic.get_prev_pos()|
+---
---@param opts table See |vim.lsp.diagnostic.goto_next()|
---@return table Previous diagnostic position
function M.get_prev_pos(opts)
- return _iter_diagnostic_lines_pos(
- opts,
- M.get_prev(opts)
- )
+ if opts then
+ if opts.severity then
+ opts.severity = severity_lsp_to_vim(opts.severity)
+ elseif opts.severity_limit then
+ opts.severity = {min=severity_lsp_to_vim(opts.severity_limit)}
+ end
+ end
+ return vim.diagnostic.get_prev_pos(opts)
end
--- Move to the previous diagnostic
+---
+---@deprecated Prefer |vim.diagnostic.goto_prev()|
+---
---@param opts table See |vim.lsp.diagnostic.goto_next()|
function M.goto_prev(opts)
- return _iter_diagnostic_move_pos(
- "DiagnosticPrevious",
- opts,
- M.get_prev_pos(opts)
- )
+ if opts then
+ if opts.severity then
+ opts.severity = severity_lsp_to_vim(opts.severity)
+ elseif opts.severity_limit then
+ opts.severity = {min=severity_lsp_to_vim(opts.severity_limit)}
+ end
+ end
+ return vim.diagnostic.goto_prev(opts)
end
--- Get the next diagnostic closest to the cursor_position
+---
+---@deprecated Prefer |vim.diagnostic.get_next()|
+---
---@param opts table See |vim.lsp.diagnostic.goto_next()|
---@return table Next diagnostic
function M.get_next(opts)
- opts = opts or {}
-
- local win_id = opts.win_id or vim.api.nvim_get_current_win()
- local bufnr = vim.api.nvim_win_get_buf(win_id)
- local cursor_position = opts.cursor_position or vim.api.nvim_win_get_cursor(win_id)
-
- return _iter_diagnostic_lines(cursor_position[1], vim.api.nvim_buf_line_count(bufnr), 1, bufnr, opts, opts.client_id)
+ if opts then
+ if opts.severity then
+ opts.severity = severity_lsp_to_vim(opts.severity)
+ elseif opts.severity_limit then
+ opts.severity = {min=severity_lsp_to_vim(opts.severity_limit)}
+ end
+ end
+ return diagnostic_vim_to_lsp({vim.diagnostic.get_next(opts)})[1]
end
--- Return the pos, {row, col}, for the next diagnostic in the current buffer.
+---
+---@deprecated Prefer |vim.diagnostic.get_next_pos()|
+---
---@param opts table See |vim.lsp.diagnostic.goto_next()|
---@return table Next diagnostic position
function M.get_next_pos(opts)
- return _iter_diagnostic_lines_pos(
- opts,
- M.get_next(opts)
- )
+ if opts then
+ if opts.severity then
+ opts.severity = severity_lsp_to_vim(opts.severity)
+ elseif opts.severity_limit then
+ opts.severity = {min=severity_lsp_to_vim(opts.severity_limit)}
+ end
+ end
+ return vim.diagnostic.get_next_pos(opts)
end
--- Move to the next diagnostic
+---
+---@deprecated Prefer |vim.diagnostic.goto_next()|
+---
---@param opts table|nil Configuration table. Keys:
--- - {client_id}: (number)
--- - If nil, will consider all clients attached to buffer.
@@ -612,25 +447,20 @@ end
--- - {win_id}: (number, default 0)
--- - Window ID
function M.goto_next(opts)
- return _iter_diagnostic_move_pos(
- "DiagnosticNext",
- opts,
- M.get_next_pos(opts)
- )
+ if opts then
+ if opts.severity then
+ opts.severity = severity_lsp_to_vim(opts.severity)
+ elseif opts.severity_limit then
+ opts.severity = {min=severity_lsp_to_vim(opts.severity_limit)}
+ end
+ end
+ return vim.diagnostic.goto_next(opts)
end
--- }}}
--- Diagnostic Setters {{{
--- Set signs for given diagnostics
---
---- Sign characters can be customized with the following commands:
+---@deprecated Prefer |vim.diagnostic._set_signs()|
---
---- <pre>
---- sign define LspDiagnosticsSignError text=E texthl=LspDiagnosticsSignError linehl= numhl=
---- sign define LspDiagnosticsSignWarning text=W texthl=LspDiagnosticsSignWarning linehl= numhl=
---- sign define LspDiagnosticsSignInformation text=I texthl=LspDiagnosticsSignInformation linehl= numhl=
---- sign define LspDiagnosticsSignHint text=H texthl=LspDiagnosticsSignHint linehl= numhl=
---- </pre>
---@param diagnostics Diagnostic[]
---@param bufnr number The buffer number
---@param client_id number the client id
@@ -639,51 +469,18 @@ end
--- - priority: Set the priority of the signs.
--- - severity_limit (DiagnosticSeverity):
--- - Limit severity of diagnostics found. E.g. "Warning" means { "Error", "Warning" } will be valid.
-function M.set_signs(diagnostics, bufnr, client_id, sign_ns, opts)
- opts = opts or {}
- sign_ns = sign_ns or M._get_sign_namespace(client_id)
-
- if not diagnostics then
- diagnostics = diagnostic_cache[bufnr][client_id]
- end
-
- if not diagnostics then
- return
+function M.set_signs(diagnostics, bufnr, client_id, _, opts)
+ local namespace = M.get_namespace(client_id)
+ if opts and not opts.severity and opts.severity_limit then
+ opts.severity = {min=severity_lsp_to_vim(opts.severity_limit)}
end
- bufnr = get_bufnr(bufnr)
- diagnostics = filter_by_severity_limit(opts.severity_limit, diagnostics)
-
- local ok = true
- for _, diagnostic in ipairs(diagnostics) do
-
- ok = ok and pcall(vim.fn.sign_place,
- 0,
- sign_ns,
- sign_highlight_map[diagnostic.severity],
- bufnr,
- {
- priority = opts.priority,
- lnum = diagnostic.range.start.line + 1
- }
- )
- end
-
- if not ok then
- log.debug("Failed to place signs:", diagnostics)
- end
+ vim.diagnostic._set_signs(namespace, bufnr, diagnostic_lsp_to_vim(diagnostics, bufnr, client_id), opts)
end
--- Set underline for given diagnostics
---
---- Underline highlights can be customized by changing the following |:highlight| groups.
----
---- <pre>
---- LspDiagnosticsUnderlineError
---- LspDiagnosticsUnderlineWarning
---- LspDiagnosticsUnderlineInformation
---- LspDiagnosticsUnderlineHint
---- </pre>
+---@deprecated Prefer |vim.diagnostic._set_underline()|
---
---@param diagnostics Diagnostic[]
---@param bufnr number: The buffer number
@@ -692,43 +489,17 @@ end
---@param opts table: Configuration table:
--- - severity_limit (DiagnosticSeverity):
--- - Limit severity of diagnostics found. E.g. "Warning" means { "Error", "Warning" } will be valid.
-function M.set_underline(diagnostics, bufnr, client_id, diagnostic_ns, opts)
- opts = opts or {}
-
- diagnostic_ns = diagnostic_ns or M._get_diagnostic_namespace(client_id)
- diagnostics = filter_by_severity_limit(opts.severity_limit, diagnostics)
-
- for _, diagnostic in ipairs(diagnostics) do
- local start = diagnostic.range["start"]
- local finish = diagnostic.range["end"]
- local higroup = underline_highlight_map[diagnostic.severity]
-
- if higroup == nil then
- -- Default to error if we don't have a highlight associated
- higroup = underline_highlight_map[DiagnosticSeverity.Error]
- end
-
- highlight.range(
- bufnr,
- diagnostic_ns,
- higroup,
- to_position(start, bufnr),
- to_position(finish, bufnr)
- )
+function M.set_underline(diagnostics, bufnr, client_id, _, opts)
+ local namespace = M.get_namespace(client_id)
+ if opts and not opts.severity and opts.severity_limit then
+ opts.severity = {min=severity_lsp_to_vim(opts.severity_limit)}
end
+ return vim.diagnostic._set_underline(namespace, bufnr, diagnostic_lsp_to_vim(diagnostics, bufnr, client_id), opts)
end
--- Virtual Text {{{
--- Set virtual text given diagnostics
---
---- Virtual text highlights can be customized by changing the following |:highlight| groups.
----
---- <pre>
---- LspDiagnosticsVirtualTextError
---- LspDiagnosticsVirtualTextWarning
---- LspDiagnosticsVirtualTextInformation
---- LspDiagnosticsVirtualTextHint
---- </pre>
+---@deprecated Prefer |vim.diagnostic._set_virtual_text()|
---
---@param diagnostics Diagnostic[]
---@param bufnr number
@@ -739,460 +510,133 @@ end
--- - spacing (number): Number of spaces to insert before virtual text
--- - severity_limit (DiagnosticSeverity):
--- - Limit severity of diagnostics found. E.g. "Warning" means { "Error", "Warning" } will be valid.
-function M.set_virtual_text(diagnostics, bufnr, client_id, diagnostic_ns, opts)
- opts = opts or {}
-
- client_id = get_client_id(client_id)
- diagnostic_ns = diagnostic_ns or M._get_diagnostic_namespace(client_id)
-
- local buffer_line_diagnostics
- if diagnostics then
- buffer_line_diagnostics = _diagnostic_lines(diagnostics)
- else
- buffer_line_diagnostics = diagnostic_cache_lines[bufnr][client_id]
- end
-
- if not buffer_line_diagnostics then
- return nil
- end
-
- for line, line_diagnostics in pairs(buffer_line_diagnostics) do
- line_diagnostics = filter_by_severity_limit(opts.severity_limit, line_diagnostics)
- local virt_texts = M.get_virtual_text_chunks_for_line(bufnr, line, line_diagnostics, opts)
-
- if virt_texts then
- api.nvim_buf_set_virtual_text(bufnr, diagnostic_ns, line, virt_texts, {})
- end
+function M.set_virtual_text(diagnostics, bufnr, client_id, _, opts)
+ local namespace = M.get_namespace(client_id)
+ if opts and not opts.severity and opts.severity_limit then
+ opts.severity = {min=severity_lsp_to_vim(opts.severity_limit)}
end
+ return vim.diagnostic._set_virtual_text(namespace, bufnr, diagnostic_lsp_to_vim(diagnostics, bufnr, client_id), opts)
end
---- Default function to get text chunks to display using `nvim_buf_set_virtual_text`.
+--- Default function to get text chunks to display using |nvim_buf_set_extmark()|.
+---
+---@deprecated Prefer |vim.diagnostic.get_virt_text_chunks()|
+---
---@param bufnr number The buffer to display the virtual text in
---@param line number The line number to display the virtual text on
---@param line_diags Diagnostic[] The diagnostics associated with the line
---@param opts table See {opts} from |vim.lsp.diagnostic.set_virtual_text()|
----@return table chunks, as defined by |nvim_buf_set_virtual_text()|
-function M.get_virtual_text_chunks_for_line(bufnr, line, line_diags, opts)
- assert(bufnr or line)
-
- if #line_diags == 0 then
- return nil
- end
-
- opts = opts or {}
- local prefix = opts.prefix or "■"
- local spacing = opts.spacing or 4
-
- -- Create a little more space between virtual text and contents
- local virt_texts = {{string.rep(" ", spacing)}}
-
- for i = 1, #line_diags - 1 do
- table.insert(virt_texts, {prefix, virtual_text_highlight_map[line_diags[i].severity]})
- end
- local last = line_diags[#line_diags]
-
- -- TODO(tjdevries): Allow different servers to be shown first somehow?
- -- TODO(tjdevries): Display server name associated with these?
- if last.message then
- table.insert(
- virt_texts,
- {
- string.format("%s %s", prefix, last.message:gsub("\r", ""):gsub("\n", " ")),
- virtual_text_highlight_map[last.severity]
- }
- )
-
- return virt_texts
- end
+---@return an array of [text, hl_group] arrays. This can be passed directly to
+--- the {virt_text} option of |nvim_buf_set_extmark()|.
+function M.get_virtual_text_chunks_for_line(bufnr, _, line_diags, opts)
+ return vim.diagnostic._get_virt_text_chunks(diagnostic_lsp_to_vim(line_diags, bufnr), opts)
end
--- }}}
--- }}}
--- Diagnostic Clear {{{
---- Clears the currently displayed diagnostics
----@param bufnr number The buffer number
----@param client_id number the client id
----@param diagnostic_ns number|nil Associated diagnostic namespace
----@param sign_ns number|nil Associated sign namespace
-function M.clear(bufnr, client_id, diagnostic_ns, sign_ns)
- validate { bufnr = { bufnr, 'n' } }
-
- bufnr = (bufnr == 0 and api.nvim_get_current_buf()) or bufnr
-
- if client_id == nil then
- return vim.lsp.for_each_buffer_client(bufnr, function(_, iter_client_id, _)
- return M.clear(bufnr, iter_client_id)
- end)
- end
-
- diagnostic_ns = diagnostic_ns or M._get_diagnostic_namespace(client_id)
- sign_ns = sign_ns or M._get_sign_namespace(client_id)
-
- assert(bufnr, "bufnr is required")
- assert(diagnostic_ns, "Need diagnostic_ns, got nil")
- assert(sign_ns, string.format("Need sign_ns, got nil %s", sign_ns))
- -- clear sign group
- vim.fn.sign_unplace(sign_ns, {buffer=bufnr})
-
- -- clear virtual text namespace
- api.nvim_buf_clear_namespace(bufnr, diagnostic_ns, 0, -1)
-end
--- }}}
--- Diagnostic Insert Leave Handler {{{
-
---- Callback scheduled for after leaving insert mode
+--- Open a floating window with the diagnostics from {position}
---
---- Used to handle
---@private
-function M._execute_scheduled_display(bufnr, client_id)
- local args = _bufs_waiting_to_update[bufnr][client_id]
- if not args then
- return
- end
-
- -- Clear the args so we don't display unnecessarily.
- _bufs_waiting_to_update[bufnr][client_id] = nil
-
- M.display(nil, bufnr, client_id, args)
-end
-
-local registered = {}
-
-local make_augroup_key = function(bufnr, client_id)
- return string.format("LspDiagnosticInsertLeave:%s:%s", bufnr, client_id)
-end
-
---- Table of autocmd events to fire the update for displaying new diagnostic information
-M.insert_leave_auto_cmds = { "InsertLeave", "CursorHoldI" }
-
---- Used to schedule diagnostic updates upon leaving insert mode.
+---@deprecated Prefer |vim.diagnostic.show_position_diagnostics()|
---
---- For parameter description, see |M.display()|
-function M._schedule_display(bufnr, client_id, args)
- _bufs_waiting_to_update[bufnr][client_id] = args
-
- local key = make_augroup_key(bufnr, client_id)
- if not registered[key] then
- vim.cmd(string.format("augroup %s", key))
- vim.cmd(" au!")
- vim.cmd(
- string.format(
- [[autocmd %s <buffer=%s> :lua vim.lsp.diagnostic._execute_scheduled_display(%s, %s)]],
- table.concat(M.insert_leave_auto_cmds, ","),
- bufnr,
- bufnr,
- client_id
- )
- )
- vim.cmd("augroup END")
-
- registered[key] = true
- end
-end
-
-
---- Used in tandem with
----
---- For parameter description, see |M.display()|
-function M._clear_scheduled_display(bufnr, client_id)
- local key = make_augroup_key(bufnr, client_id)
-
- if registered[key] then
- vim.cmd(string.format("augroup %s", key))
- vim.cmd(" au!")
- vim.cmd("augroup END")
-
- registered[key] = nil
- end
-end
--- }}}
-
--- Diagnostic Private Highlight Utilies {{{
---- Get the severity highlight name
---@private
-function M._get_severity_highlight_name(severity)
- return virtual_text_highlight_map[severity]
-end
-
---- Get floating severity highlight name
---@private
-function M._get_floating_severity_highlight_name(severity)
- return floating_highlight_map[severity]
-end
-
---- This should be called to update the highlights for the LSP client.
-function M._define_default_signs_and_highlights()
- --@private
- local function define_default_sign(name, properties)
- if vim.tbl_isempty(vim.fn.sign_getdefined(name)) then
- vim.fn.sign_define(name, properties)
+---@param opts table|nil Configuration keys
+--- - severity: (DiagnosticSeverity, default nil)
+--- - Only return diagnostics with this severity. Overrides severity_limit
+--- - severity_limit: (DiagnosticSeverity, default nil)
+--- - Limit severity of diagnostics found. E.g. "Warning" means { "Error", "Warning" } will be valid.
+--- - all opts for |show_diagnostics()| can be used here
+---@param buf_nr number|nil The buffer number
+---@param position table|nil The (0,0)-indexed position
+---@return table {popup_bufnr, win_id}
+function M.show_position_diagnostics(opts, buf_nr, position)
+ if opts then
+ if opts.severity then
+ opts.severity = severity_lsp_to_vim(opts.severity)
+ elseif opts.severity_limit then
+ opts.severity = {min=severity_lsp_to_vim(opts.severity_limit)}
end
end
-
- -- Initialize default diagnostic highlights
- for severity, hi_info in pairs(diagnostic_severities) do
- local default_highlight_name = default_highlight_map[severity]
- highlight.create(default_highlight_name, hi_info, true)
-
- -- Default link all corresponding highlights to the default highlight
- highlight.link(virtual_text_highlight_map[severity], default_highlight_name, false)
- highlight.link(floating_highlight_map[severity], default_highlight_name, false)
- highlight.link(sign_highlight_map[severity], default_highlight_name, false)
- end
-
- -- Create all signs
- for severity, sign_hl_name in pairs(sign_highlight_map) do
- local severity_name = DiagnosticSeverity[severity]
-
- define_default_sign(sign_hl_name, {
- text = (severity_name or 'U'):sub(1, 1),
- texthl = sign_hl_name,
- linehl = '',
- numhl = '',
- })
- end
-
- -- Initialize Underline highlights
- for severity, underline_highlight_name in pairs(underline_highlight_map) do
- highlight.create(underline_highlight_name, {
- cterm = 'underline',
- gui = 'underline',
- guisp = diagnostic_severities[severity].guifg
- }, true)
- end
+ return vim.diagnostic.show_position_diagnostics(opts, buf_nr, position)
end
--- }}}
--- Diagnostic Display {{{
---- |lsp-handler| for the method "textDocument/publishDiagnostics"
+--- Open a floating window with the diagnostics from {line_nr}
---
----@note Each of the configuration options accepts:
---- - `false`: Disable this feature
---- - `true`: Enable this feature, use default settings.
---- - `table`: Enable this feature, use overrides.
---- - `function`: Function with signature (bufnr, client_id) that returns any of the above.
---- <pre>
---- vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with(
---- vim.lsp.diagnostic.on_publish_diagnostics, {
---- -- Enable underline, use default values
---- underline = true,
---- -- Enable virtual text, override spacing to 4
---- virtual_text = {
---- spacing = 4,
---- },
---- -- Use a function to dynamically turn signs off
---- -- and on, using buffer local variables
---- signs = function(bufnr, client_id)
---- return vim.bo[bufnr].show_signs == false
---- end,
---- -- Disable a feature
---- update_in_insert = false,
---- }
---- )
---- </pre>
+---@deprecated Prefer |vim.diagnostic.show_line_diagnostics()|
---
----@param config table Configuration table.
---- - underline: (default=true)
---- - Apply underlines to diagnostics.
---- - See |vim.lsp.diagnostic.set_underline()|
---- - virtual_text: (default=true)
---- - Apply virtual text to line endings.
---- - See |vim.lsp.diagnostic.set_virtual_text()|
---- - signs: (default=true)
---- - Apply signs for diagnostics.
---- - See |vim.lsp.diagnostic.set_signs()|
---- - update_in_insert: (default=false)
---- - Update diagnostics in InsertMode or wait until InsertLeave
---- - severity_sort: (default=false)
---- - Sort diagnostics (and thus signs and virtual text)
-function M.on_publish_diagnostics(_, _, params, client_id, _, config)
- local uri = params.uri
- local bufnr = vim.uri_to_bufnr(uri)
-
- if not bufnr then
- return
- end
-
- local diagnostics = params.diagnostics
-
- if config and if_nil(config.severity_sort, false) then
- table.sort(diagnostics, function(a, b) return a.severity > b.severity end)
- end
-
- -- Always save the diagnostics, even if the buf is not loaded.
- -- Language servers may report compile or build errors via diagnostics
- -- Users should be able to find these, even if they're in files which
- -- are not loaded.
- M.save(diagnostics, bufnr, client_id)
-
- -- Unloaded buffers should not handle diagnostics.
- -- When the buffer is loaded, we'll call on_attach, which sends textDocument/didOpen.
- -- This should trigger another publish of the diagnostics.
- --
- -- In particular, this stops a ton of spam when first starting a server for current
- -- unloaded buffers.
- if not api.nvim_buf_is_loaded(bufnr) then
- return
+---@param opts table Configuration table
+--- - all opts for |vim.lsp.diagnostic.get_line_diagnostics()| and
+--- |show_diagnostics()| can be used here
+---@param buf_nr number|nil The buffer number
+---@param line_nr number|nil The line number
+---@param client_id number|nil the client id
+---@return table {popup_bufnr, win_id}
+function M.show_line_diagnostics(opts, buf_nr, line_nr, client_id)
+ if client_id then
+ opts = opts or {}
+ opts.namespace = M.get_namespace(client_id)
end
-
- M.display(diagnostics, bufnr, client_id, config)
+ return vim.diagnostic.show_line_diagnostics(opts, buf_nr, line_nr)
end
---@private
---- Display diagnostics for the buffer, given a configuration.
-function M.display(diagnostics, bufnr, client_id, config)
- config = vim.lsp._with_extend('vim.lsp.diagnostic.on_publish_diagnostics', {
- signs = true,
- underline = true,
- virtual_text = true,
- update_in_insert = false,
- severity_sort = false,
- }, config)
-
- -- TODO(tjdevries): Consider how we can make this a "standardized" kind of thing for |lsp-handlers|.
- -- It seems like we would probably want to do this more often as we expose more of them.
- -- It provides a very nice functional interface for people to override configuration.
- local resolve_optional_value = function(option)
- local enabled_val = {}
-
- if not option then
- return false
- elseif option == true then
- return enabled_val
- elseif type(option) == 'function' then
- local val = option(bufnr, client_id)
- if val == true then
- return enabled_val
- else
- return val
- end
- elseif type(option) == 'table' then
- return option
- else
- error("Unexpected option type: " .. vim.inspect(option))
- end
- end
-
- if resolve_optional_value(config.update_in_insert) then
- M._clear_scheduled_display(bufnr, client_id)
- else
- local mode = vim.api.nvim_get_mode()
-
- if string.sub(mode.mode, 1, 1) == 'i' then
- M._schedule_display(bufnr, client_id, config)
- return
- end
- end
-
- M.clear(bufnr, client_id)
-
- diagnostics = diagnostics or M.get(bufnr, client_id)
-
- vim.api.nvim_command("doautocmd <nomodeline> User LspDiagnosticsChanged")
-
- if not diagnostics or vim.tbl_isempty(diagnostics) then
- return
- end
-
- local underline_opts = resolve_optional_value(config.underline)
- if underline_opts then
- M.set_underline(diagnostics, bufnr, client_id, nil, underline_opts)
- end
-
- local virtual_text_opts = resolve_optional_value(config.virtual_text)
- if virtual_text_opts then
- M.set_virtual_text(diagnostics, bufnr, client_id, nil, virtual_text_opts)
+--- Redraw diagnostics for the given buffer and client
+---
+---@deprecated Prefer |vim.diagnostic.redraw()|
+---
+--- This calls the "textDocument/publishDiagnostics" handler manually using
+--- the cached diagnostics already received from the server. This can be useful
+--- for redrawing diagnostics after making changes in diagnostics
+--- configuration. |lsp-handler-configuration|
+---
+---@param bufnr (optional, number): Buffer handle, defaults to current
+---@param client_id (optional, number): Redraw diagnostics for the given
+--- client. The default is to redraw diagnostics for all attached
+--- clients.
+function M.redraw(bufnr, client_id)
+ bufnr = get_bufnr(bufnr)
+ if not client_id then
+ return vim.lsp.for_each_buffer_client(bufnr, function(client)
+ M.redraw(bufnr, client.id)
+ end)
end
- local signs_opts = resolve_optional_value(config.signs)
- if signs_opts then
- M.set_signs(diagnostics, bufnr, client_id, nil, signs_opts)
- end
+ local namespace = M.get_namespace(client_id)
+ return vim.diagnostic.show(namespace, bufnr)
end
--- }}}
--- Diagnostic User Functions {{{
---- Open a floating window with the diagnostics from {line_nr}
+--- Sets the quickfix list
---
---- The floating window can be customized with the following highlight groups:
---- <pre>
---- LspDiagnosticsFloatingError
---- LspDiagnosticsFloatingWarning
---- LspDiagnosticsFloatingInformation
---- LspDiagnosticsFloatingHint
---- </pre>
----@param opts table Configuration table
---- - show_header (boolean, default true): Show "Diagnostics:" header.
---- - Plus all the opts for |vim.lsp.diagnostic.get_line_diagnostics()|
---- and |vim.lsp.util.open_floating_preview()| can be used here.
----@param bufnr number The buffer number
----@param line_nr number The line number
----@param client_id number|nil the client id
----@return table {popup_bufnr, win_id}
-function M.show_line_diagnostics(opts, bufnr, line_nr, client_id)
+---@deprecated Prefer |vim.diagnostic.setqflist()|
+---
+---@param opts table|nil Configuration table. Keys:
+--- - {open}: (boolean, default true)
+--- - Open quickfix list after set
+--- - {client_id}: (number)
+--- - If nil, will consider all clients attached to buffer.
+--- - {severity}: (DiagnosticSeverity)
+--- - Exclusive severity to consider. Overrides {severity_limit}
+--- - {severity_limit}: (DiagnosticSeverity)
+--- - Limit severity of diagnostics found. E.g. "Warning" means { "Error", "Warning" } will be valid.
+--- - {workspace}: (boolean, default true)
+--- - Set the list with workspace diagnostics
+function M.set_qflist(opts)
opts = opts or {}
-
- local show_header = if_nil(opts.show_header, true)
-
- bufnr = bufnr or 0
- line_nr = line_nr or (vim.api.nvim_win_get_cursor(0)[1] - 1)
-
- local lines = {}
- local highlights = {}
- if show_header then
- table.insert(lines, "Diagnostics:")
- table.insert(highlights, {0, "Bold"})
- end
-
- local line_diagnostics = M.get_line_diagnostics(bufnr, line_nr, opts, client_id)
- if vim.tbl_isempty(line_diagnostics) then return end
-
- for i, diagnostic in ipairs(line_diagnostics) do
- local prefix = string.format("%d. ", i)
- local hiname = M._get_floating_severity_highlight_name(diagnostic.severity)
- assert(hiname, 'unknown severity: ' .. tostring(diagnostic.severity))
-
- local message_lines = vim.split(diagnostic.message, '\n', true)
- table.insert(lines, prefix..message_lines[1])
- table.insert(highlights, {#prefix, hiname})
- for j = 2, #message_lines do
- table.insert(lines, message_lines[j])
- table.insert(highlights, {0, hiname})
- end
+ if opts.severity then
+ opts.severity = severity_lsp_to_vim(opts.severity)
+ elseif opts.severity_limit then
+ opts.severity = {min=severity_lsp_to_vim(opts.severity_limit)}
end
-
- opts.focus_id = "line_diagnostics"
- local popup_bufnr, winnr = util.open_floating_preview(lines, 'plaintext', opts)
- for i, hi in ipairs(highlights) do
- local prefixlen, hiname = unpack(hi)
- -- Start highlight after the prefix
- api.nvim_buf_add_highlight(popup_bufnr, -1, hiname, i-1, prefixlen, -1)
+ if opts.client_id then
+ opts.client_id = nil
+ opts.namespace = M.get_namespace(opts.client_id)
end
-
- return popup_bufnr, winnr
-end
-
-
---- Clear diagnotics and diagnostic cache
----
---- Handles saving diagnostics from multiple clients in the same buffer.
----@param client_id number
----@param buffer_client_map table map of buffers to active clients
-function M.reset(client_id, buffer_client_map)
- buffer_client_map = vim.deepcopy(buffer_client_map)
- vim.schedule(function()
- for bufnr, client_ids in pairs(buffer_client_map) do
- if client_ids[client_id] then
- clear_diagnostic_cache(bufnr, client_id)
- M.clear(bufnr, client_id)
- end
- end
- end)
+ local workspace = vim.F.if_nil(opts.workspace, true)
+ opts.bufnr = not workspace and 0
+ return vim.diagnostic.setqflist(opts)
end
--- Sets the location list
+---
+---@deprecated Prefer |vim.diagnostic.setloclist()|
+---
---@param opts table|nil Configuration table. Keys:
---- - {open_loclist}: (boolean, default true)
+--- - {open}: (boolean, default true)
--- - Open loclist after set
--- - {client_id}: (number)
--- - If nil, will consider all clients attached to buffer.
@@ -1204,29 +648,65 @@ end
--- - Set the list with workspace diagnostics
function M.set_loclist(opts)
opts = opts or {}
- local open_loclist = if_nil(opts.open_loclist, true)
- local current_bufnr = api.nvim_get_current_buf()
- local diags = opts.workspace and M.get_all(opts.client_id) or {
- [current_bufnr] = M.get(current_bufnr, opts.client_id)
- }
- local predicate = function(d)
- local severity = to_severity(opts.severity)
- if severity then
- return d.severity == severity
- end
- local severity_limit = to_severity(opts.severity_limit)
- if severity_limit then
- return d.severity <= severity_limit
- end
- return true
+ if opts.severity then
+ opts.severity = severity_lsp_to_vim(opts.severity)
+ elseif opts.severity_limit then
+ opts.severity = {min=severity_lsp_to_vim(opts.severity_limit)}
end
- local items = util.diagnostics_to_items(diags, predicate)
- local win_id = vim.api.nvim_get_current_win()
- util.set_loclist(items, win_id)
- if open_loclist then
- vim.cmd [[lopen]]
+ if opts.client_id then
+ opts.client_id = nil
+ opts.namespace = M.get_namespace(opts.client_id)
end
+ local workspace = vim.F.if_nil(opts.workspace, false)
+ opts.bufnr = not workspace and 0
+ return vim.diagnostic.setloclist(opts)
end
+
+--- Disable diagnostics for the given buffer and client
+---
+---@deprecated Prefer |vim.diagnostic.disable()|
+---
+---@param bufnr (optional, number): Buffer handle, defaults to current
+---@param client_id (optional, number): Disable diagnostics for the given
+--- client. The default is to disable diagnostics for all attached
+--- clients.
+-- Note that when diagnostics are disabled for a buffer, the server will still
+-- send diagnostic information and the client will still process it. The
+-- diagnostics are simply not displayed to the user.
+function M.disable(bufnr, client_id)
+ if not client_id then
+ return vim.lsp.for_each_buffer_client(bufnr, function(client)
+ M.disable(bufnr, client.id)
+ end)
+ end
+
+ bufnr = get_bufnr(bufnr)
+ local namespace = M.get_namespace(client_id)
+ return vim.diagnostic.disable(bufnr, namespace)
+end
+
+--- Enable diagnostics for the given buffer and client
+---
+---@deprecated Prefer |vim.diagnostic.enable()|
+---
+---@param bufnr (optional, number): Buffer handle, defaults to current
+---@param client_id (optional, number): Enable diagnostics for the given
+--- client. The default is to enable diagnostics for all attached
+--- clients.
+function M.enable(bufnr, client_id)
+ if not client_id then
+ return vim.lsp.for_each_buffer_client(bufnr, function(client)
+ M.enable(bufnr, client.id)
+ end)
+ end
+
+ bufnr = get_bufnr(bufnr)
+ local namespace = M.get_namespace(client_id)
+ return vim.diagnostic.enable(bufnr, namespace)
+end
+
-- }}}
return M
+
+-- vim: fdm=marker
diff --git a/runtime/lua/vim/lsp/handlers.lua b/runtime/lua/vim/lsp/handlers.lua
index 41852b9d88..eff27807be 100644
--- a/runtime/lua/vim/lsp/handlers.lua
+++ b/runtime/lua/vim/lsp/handlers.lua
@@ -3,37 +3,34 @@ local protocol = require 'vim.lsp.protocol'
local util = require 'vim.lsp.util'
local vim = vim
local api = vim.api
-local buf = require 'vim.lsp.buf'
local M = {}
-- FIXME: DOC: Expose in vimdocs
---@private
+---@private
--- Writes to error buffer.
---@param ... (table of strings) Will be concatenated before being written
+---@param ... (table of strings) Will be concatenated before being written
local function err_message(...)
vim.notify(table.concat(vim.tbl_flatten{...}), vim.log.levels.ERROR)
api.nvim_command("redraw")
end
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_executeCommand
-M['workspace/executeCommand'] = function(err, _)
- if err then
- error("Could not execute code action: "..err.message)
- end
+--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_executeCommand
+M['workspace/executeCommand'] = function(_, _, _, _)
+ -- Error handling is done implicitly by wrapping all handlers; see end of this file
end
--- @msg of type ProgressParams
--- Basically a token of type number/string
-local function progress_handler(_, _, params, client_id)
+---@private
+local function progress_handler(_, result, ctx, _)
+ local client_id = ctx.client_id
local client = vim.lsp.get_client_by_id(client_id)
local client_name = client and client.name or string.format("id=%d", client_id)
if not client then
err_message("LSP[", client_name, "] client has shut down after sending the message")
end
- local val = params.value -- unspecified yet
- local token = params.token -- string or number
+ local val = result.value -- unspecified yet
+ local token = result.token -- string or number
if val.kind then
@@ -61,13 +58,14 @@ local function progress_handler(_, _, params, client_id)
vim.api.nvim_command("doautocmd <nomodeline> User LspProgressUpdate")
end
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#progress
+--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#progress
M['$/progress'] = progress_handler
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window_workDoneProgress_create
-M['window/workDoneProgress/create'] = function(_, _, params, client_id)
+--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window_workDoneProgress_create
+M['window/workDoneProgress/create'] = function(_, result, ctx)
+ local client_id = ctx.client_id
local client = vim.lsp.get_client_by_id(client_id)
- local token = params.token -- string or number
+ local token = result.token -- string or number
local client_name = client and client.name or string.format("id=%d", client_id)
if not client then
err_message("LSP[", client_name, "] client has shut down after sending the message")
@@ -76,12 +74,12 @@ M['window/workDoneProgress/create'] = function(_, _, params, client_id)
return vim.NIL
end
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window_showMessageRequest
-M['window/showMessageRequest'] = function(_, _, params)
+--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window_showMessageRequest
+M['window/showMessageRequest'] = function(_, result)
- local actions = params.actions
- print(params.message)
- local option_strings = {params.message, "\nRequest Actions:"}
+ local actions = result.actions
+ print(result.message)
+ local option_strings = {result.message, "\nRequest Actions:"}
for i, action in ipairs(actions) do
local title = action.title:gsub('\r\n', '\\r\\n')
title = title:gsub('\n', '\\n')
@@ -97,8 +95,9 @@ M['window/showMessageRequest'] = function(_, _, params)
end
end
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#client_registerCapability
-M['client/registerCapability'] = function(_, _, _, client_id)
+--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#client_registerCapability
+M['client/registerCapability'] = function(_, _, ctx)
+ local client_id = ctx.client_id
local warning_tpl = "The language server %s triggers a registerCapability "..
"handler despite dynamicRegistration set to false. "..
"Report upstream, this warning is harmless"
@@ -109,42 +108,8 @@ M['client/registerCapability'] = function(_, _, _, client_id)
return vim.NIL
end
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_codeAction
-M['textDocument/codeAction'] = function(_, _, actions)
- if actions == nil or vim.tbl_isempty(actions) then
- print("No code actions available")
- return
- end
-
- local option_strings = {"Code Actions:"}
- for i, action in ipairs(actions) do
- local title = action.title:gsub('\r\n', '\\r\\n')
- title = title:gsub('\n', '\\n')
- table.insert(option_strings, string.format("%d. %s", i, title))
- end
-
- local choice = vim.fn.inputlist(option_strings)
- if choice < 1 or choice > #actions then
- return
- end
- local action_chosen = actions[choice]
- -- textDocument/codeAction can return either Command[] or CodeAction[].
- -- If it is a CodeAction, it can have either an edit, a command or both.
- -- Edits should be executed first
- if action_chosen.edit or type(action_chosen.command) == "table" then
- if action_chosen.edit then
- util.apply_workspace_edit(action_chosen.edit)
- end
- if type(action_chosen.command) == "table" then
- buf.execute_command(action_chosen.command)
- end
- else
- buf.execute_command(action_chosen)
- end
-end
-
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_applyEdit
-M['workspace/applyEdit'] = function(_, _, workspace_edit)
+--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_applyEdit
+M['workspace/applyEdit'] = function(_, workspace_edit)
if not workspace_edit then return end
-- TODO(ashkan) Do something more with label?
if workspace_edit.label then
@@ -157,30 +122,30 @@ M['workspace/applyEdit'] = function(_, _, workspace_edit)
}
end
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_configuration
-M['workspace/configuration'] = function(err, _, params, client_id)
+--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_configuration
+M['workspace/configuration'] = function(_, result, ctx)
+ local client_id = ctx.client_id
local client = vim.lsp.get_client_by_id(client_id)
if not client then
err_message("LSP[id=", client_id, "] client has shut down after sending the message")
return
end
- if err then error(vim.inspect(err)) end
- if not params.items then
+ if not result.items then
return {}
end
- local result = {}
- for _, item in ipairs(params.items) do
+ local response = {}
+ for _, item in ipairs(result.items) do
if item.section then
local value = util.lookup_section(client.config.settings, item.section) or vim.NIL
-- For empty sections with no explicit '' key, return settings as is
if value == vim.NIL and item.section == '' then
value = client.config.settings or vim.NIL
end
- table.insert(result, value)
+ table.insert(response, value)
end
end
- return result
+ return response
end
M['textDocument/publishDiagnostics'] = function(...)
@@ -191,51 +156,71 @@ M['textDocument/codeLens'] = function(...)
return require('vim.lsp.codelens').on_codelens(...)
end
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_references
-M['textDocument/references'] = function(_, _, result)
- if not result then return end
- util.set_qflist(util.locations_to_items(result))
- api.nvim_command("copen")
-end
---@private
---- Prints given list of symbols to the quickfix list.
---@param _ (not used)
---@param _ (not used)
---@param result (list of Symbols) LSP method name
---@param result (table) result of LSP method; a location or a list of locations.
----(`textDocument/definition` can return `Location` or `Location[]`
-local symbol_handler = function(_, _, result, _, bufnr)
- if not result or vim.tbl_isempty(result) then return end
- util.set_qflist(util.symbols_to_items(result, bufnr))
- api.nvim_command("copen")
+---@private
+--- Return a function that converts LSP responses to list items and opens the list
+---
+--- The returned function has an optional {config} parameter that accepts a table
+--- with the following keys:
+---
+--- loclist: (boolean) use the location list (default is to use the quickfix list)
+---
+---@param map_result function `((resp, bufnr) -> list)` to convert the response
+---@param entity name of the resource used in a `not found` error message
+local function response_to_list(map_result, entity)
+ return function(_,result, ctx, config)
+ if not result or vim.tbl_isempty(result) then
+ vim.notify('No ' .. entity .. ' found')
+ else
+ config = config or {}
+ if config.loclist then
+ vim.fn.setloclist(0, {}, ' ', {
+ title = 'Language Server';
+ items = map_result(result, ctx.bufnr);
+ })
+ api.nvim_command("lopen")
+ else
+ vim.fn.setqflist({}, ' ', {
+ title = 'Language Server';
+ items = map_result(result, ctx.bufnr);
+ })
+ api.nvim_command("copen")
+ end
+ end
+ end
end
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_documentSymbol
-M['textDocument/documentSymbol'] = symbol_handler
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_symbol
-M['workspace/symbol'] = symbol_handler
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_rename
-M['textDocument/rename'] = function(_, _, result)
+
+--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_references
+M['textDocument/references'] = response_to_list(util.locations_to_items, 'references')
+
+--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_documentSymbol
+M['textDocument/documentSymbol'] = response_to_list(util.symbols_to_items, 'document symbols')
+
+--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_symbol
+M['workspace/symbol'] = response_to_list(util.symbols_to_items, 'symbols')
+
+--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_rename
+M['textDocument/rename'] = function(_, result, _)
if not result then return end
util.apply_workspace_edit(result)
end
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_rangeFormatting
-M['textDocument/rangeFormatting'] = function(_, _, result)
+--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_rangeFormatting
+M['textDocument/rangeFormatting'] = function(_, result, ctx, _)
if not result then return end
- util.apply_text_edits(result)
+ util.apply_text_edits(result, ctx.bufnr)
end
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_formatting
-M['textDocument/formatting'] = function(_, _, result)
+--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_formatting
+M['textDocument/formatting'] = function(_, result, ctx, _)
if not result then return end
- util.apply_text_edits(result)
+ util.apply_text_edits(result, ctx.bufnr)
end
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion
-M['textDocument/completion'] = function(_, _, result)
+--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion
+M['textDocument/completion'] = function(_, result, _, _)
if vim.tbl_isempty(result or {}) then return end
local row, col = unpack(api.nvim_win_get_cursor(0))
local line = assert(api.nvim_buf_get_lines(0, row-1, row, false)[1])
@@ -260,9 +245,9 @@ end
--- - border: (default=nil)
--- - Add borders to the floating window
--- - See |vim.api.nvim_open_win()|
-function M.hover(_, method, result, _, _, config)
+function M.hover(_, result, ctx, config)
config = config or {}
- config.focus_id = method
+ config.focus_id = ctx.method
if not (result and result.contents) then
-- return { 'No information available' }
return
@@ -276,18 +261,18 @@ function M.hover(_, method, result, _, _, config)
return util.open_floating_preview(markdown_lines, "markdown", config)
end
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_hover
+--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_hover
M['textDocument/hover'] = M.hover
---@private
+---@private
--- Jumps to a location. Used as a handler for multiple LSP methods.
---@param _ (not used)
---@param method (string) LSP method name
---@param result (table) result of LSP method; a location or a list of locations.
+---@param _ (not used)
+---@param result (table) result of LSP method; a location or a list of locations.
+---@param ctx (table) table containing the context of the request, including the method
---(`textDocument/definition` can return `Location` or `Location[]`
-local function location_handler(_, method, result)
+local function location_handler(_, result, ctx, _)
if result == nil or vim.tbl_isempty(result) then
- local _ = log.info() and log.info(method, 'No location found')
+ local _ = log.info() and log.info(ctx.method, 'No location found')
return nil
end
@@ -306,16 +291,17 @@ local function location_handler(_, method, result)
end
end
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_declaration
+--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_declaration
M['textDocument/declaration'] = location_handler
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_definition
+--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_definition
M['textDocument/definition'] = location_handler
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_typeDefinition
+--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_typeDefinition
M['textDocument/typeDefinition'] = location_handler
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_implementation
+--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_implementation
M['textDocument/implementation'] = location_handler
---- |lsp-handler| for the method "textDocument/signatureHelp"
+--- |lsp-handler| for the method "textDocument/signatureHelp".
+--- The active parameter is highlighted with |hl-LspSignatureActiveParameter|.
--- <pre>
--- vim.lsp.handlers["textDocument/signatureHelp"] = vim.lsp.with(
--- vim.lsp.handlers.signature_help, {
@@ -328,43 +314,53 @@ M['textDocument/implementation'] = location_handler
--- - border: (default=nil)
--- - Add borders to the floating window
--- - See |vim.api.nvim_open_win()|
-function M.signature_help(_, method, result, _, bufnr, config)
+function M.signature_help(_, result, ctx, config)
config = config or {}
- config.focus_id = method
+ config.focus_id = ctx.method
-- When use `autocmd CompleteDone <silent><buffer> lua vim.lsp.buf.signature_help()` to call signatureHelp handler
-- If the completion item doesn't have signatures It will make noise. Change to use `print` that can use `<silent>` to ignore
if not (result and result.signatures and result.signatures[1]) then
- print('No signature help available')
+ if config.silent ~= true then
+ print('No signature help available')
+ end
return
end
- local ft = api.nvim_buf_get_option(bufnr, 'filetype')
- local lines = util.convert_signature_help_to_markdown_lines(result, ft)
+ local client = vim.lsp.get_client_by_id(ctx.client_id)
+ local triggers = client.resolved_capabilities.signature_help_trigger_characters
+ local ft = api.nvim_buf_get_option(ctx.bufnr, 'filetype')
+ local lines, hl = util.convert_signature_help_to_markdown_lines(result, ft, triggers)
lines = util.trim_empty_lines(lines)
if vim.tbl_isempty(lines) then
- print('No signature help available')
+ if config.silent ~= true then
+ print('No signature help available')
+ end
return
end
- return util.open_floating_preview(lines, "markdown", config)
+ local fbuf, fwin = util.open_floating_preview(lines, "markdown", config)
+ if hl then
+ api.nvim_buf_add_highlight(fbuf, -1, "LspSignatureActiveParameter", 0, unpack(hl))
+ end
+ return fbuf, fwin
end
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_signatureHelp
+--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_signatureHelp
M['textDocument/signatureHelp'] = M.signature_help
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_documentHighlight
-M['textDocument/documentHighlight'] = function(_, _, result, _, bufnr, _)
+--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_documentHighlight
+M['textDocument/documentHighlight'] = function(_, result, ctx, _)
if not result then return end
- util.buf_highlight_references(bufnr, result)
+ util.buf_highlight_references(ctx.bufnr, result)
end
---@private
+---@private
---
--- Displays call hierarchy in the quickfix window.
---
---@param direction `"from"` for incoming calls and `"to"` for outgoing calls
---@returns `CallHierarchyIncomingCall[]` if {direction} is `"from"`,
---@returns `CallHierarchyOutgoingCall[]` if {direction} is `"to"`,
+---@param direction `"from"` for incoming calls and `"to"` for outgoing calls
+---@returns `CallHierarchyIncomingCall[]` if {direction} is `"from"`,
+---@returns `CallHierarchyOutgoingCall[]` if {direction} is `"to"`,
local make_call_hierarchy_handler = function(direction)
- return function(_, _, result)
+ return function(_, result)
if not result then return end
local items = {}
for _, call_hierarchy_call in pairs(result) do
@@ -383,16 +379,17 @@ local make_call_hierarchy_handler = function(direction)
end
end
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#callHierarchy/incomingCalls
+--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#callHierarchy_incomingCalls
M['callHierarchy/incomingCalls'] = make_call_hierarchy_handler('from')
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#callHierarchy/outgoingCalls
+--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#callHierarchy_outgoingCalls
M['callHierarchy/outgoingCalls'] = make_call_hierarchy_handler('to')
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window/logMessage
-M['window/logMessage'] = function(_, _, result, client_id)
+--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window_logMessage
+M['window/logMessage'] = function(_, result, ctx, _)
local message_type = result.type
local message = result.message
+ local client_id = ctx.client_id
local client = vim.lsp.get_client_by_id(client_id)
local client_name = client and client.name or string.format("id=%d", client_id)
if not client then
@@ -402,7 +399,7 @@ M['window/logMessage'] = function(_, _, result, client_id)
log.error(message)
elseif message_type == protocol.MessageType.Warning then
log.warn(message)
- elseif message_type == protocol.MessageType.Info then
+ elseif message_type == protocol.MessageType.Info or message_type == protocol.MessageType.Log then
log.info(message)
else
log.debug(message)
@@ -410,10 +407,11 @@ M['window/logMessage'] = function(_, _, result, client_id)
return result
end
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window/showMessage
-M['window/showMessage'] = function(_, _, result, client_id)
+--see: https://microsoft.github.io/language-server-protocol/specifications/specification-current/#window_showMessage
+M['window/showMessage'] = function(_, result, ctx, _)
local message_type = result.type
local message = result.message
+ local client_id = ctx.client_id
local client = vim.lsp.get_client_by_id(client_id)
local client_name = client and client.name or string.format("id=%d", client_id)
if not client then
@@ -430,16 +428,23 @@ end
-- Add boilerplate error validation and logging for all of these.
for k, fn in pairs(M) do
- M[k] = function(err, method, params, client_id, bufnr, config)
- local _ = log.debug() and log.debug('default_handler', method, {
- params = params, client_id = client_id, err = err, bufnr = bufnr, config = config
+ M[k] = function(err, result, ctx, config)
+ local _ = log.trace() and log.trace('default_handler', ctx.method, {
+ err = err, result = result, ctx=vim.inspect(ctx), config = config
})
if err then
- return err_message(tostring(err))
+ local client = vim.lsp.get_client_by_id(ctx.client_id)
+ local client_name = client and client.name or string.format("client_id=%d", ctx.client_id)
+ -- LSP spec:
+ -- interface ResponseError:
+ -- code: integer;
+ -- message: string;
+ -- data?: string | number | boolean | array | object | null;
+ return err_message(client_name .. ': ' .. tostring(err.code) .. ': ' .. err.message)
end
- return fn(err, method, params, client_id, bufnr, config)
+ return fn(err, result, ctx, config)
end
end
diff --git a/runtime/lua/vim/lsp/health.lua b/runtime/lua/vim/lsp/health.lua
new file mode 100644
index 0000000000..855679a2df
--- /dev/null
+++ b/runtime/lua/vim/lsp/health.lua
@@ -0,0 +1,27 @@
+local M = {}
+
+--- Performs a healthcheck for LSP
+function M.check_health()
+ local report_info = vim.fn['health#report_info']
+ local report_warn = vim.fn['health#report_warn']
+
+ local log = require('vim.lsp.log')
+ local current_log_level = log.get_level()
+ local log_level_string = log.levels[current_log_level]
+ report_info(string.format("LSP log level : %s", log_level_string))
+
+ if current_log_level < log.levels.WARN then
+ report_warn(string.format("Log level %s will cause degraded performance and high disk usage", log_level_string))
+ end
+
+ local log_path = vim.lsp.get_log_path()
+ report_info(string.format("Log path: %s", log_path))
+
+ local log_size = vim.loop.fs_stat(log_path).size
+
+ local report_fn = (log_size / 1000000 > 100 and report_warn or report_info)
+ report_fn(string.format("Log size: %d KB", log_size / 1000 ))
+end
+
+return M
+
diff --git a/runtime/lua/vim/lsp/log.lua b/runtime/lua/vim/lsp/log.lua
index 471a311c16..4597f1919a 100644
--- a/runtime/lua/vim/lsp/log.lua
+++ b/runtime/lua/vim/lsp/log.lua
@@ -14,26 +14,38 @@ log.levels = vim.deepcopy(vim.log.levels)
-- Default log level is warn.
local current_log_level = log.levels.WARN
-local log_date_format = "%FT%H:%M:%S%z"
+local log_date_format = "%F %H:%M:%S"
+local format_func = function(arg) return vim.inspect(arg, {newline=''}) end
do
- local path_sep = vim.loop.os_uname().sysname == "Windows" and "\\" or "/"
- --@private
+ local path_sep = vim.loop.os_uname().version:match("Windows") and "\\" or "/"
+ ---@private
local function path_join(...)
return table.concat(vim.tbl_flatten{...}, path_sep)
end
local logfilename = path_join(vim.fn.stdpath('cache'), 'lsp.log')
--- Returns the log filename.
- --@returns (string) log filename
+ ---@returns (string) log filename
function log.get_filename()
return logfilename
end
vim.fn.mkdir(vim.fn.stdpath('cache'), "p")
local logfile = assert(io.open(logfilename, "a+"))
+
+ local log_info = vim.loop.fs_stat(logfilename)
+ if log_info and log_info.size > 1e9 then
+ local warn_msg = string.format(
+ "LSP client log is large (%d MB): %s",
+ log_info.size / (1000 * 1000),
+ logfilename
+ )
+ vim.notify(warn_msg)
+ end
+
-- Start message for logging
- logfile:write(string.format("[ START ] %s ] LSP logging initiated\n", os.date(log_date_format)))
+ logfile:write(string.format("[START][%s] LSP logging initiated\n", os.date(log_date_format)))
for level, levelnr in pairs(log.levels) do
-- Also export the log level on the root object.
log[level] = levelnr
@@ -56,14 +68,14 @@ do
if levelnr < current_log_level then return false end
if argc == 0 then return true end
local info = debug.getinfo(2, "Sl")
- local fileinfo = string.format("%s:%s", info.short_src, info.currentline)
- local parts = { table.concat({"[", level, "]", os.date(log_date_format), "]", fileinfo, "]"}, " ") }
+ local header = string.format("[%s][%s] ...%s:%s", level, os.date(log_date_format), string.sub(info.short_src, #info.short_src - 15), info.currentline)
+ local parts = { header }
for i = 1, argc do
local arg = select(i, ...)
if arg == nil then
table.insert(parts, "nil")
else
- table.insert(parts, vim.inspect(arg, {newline=''}))
+ table.insert(parts, format_func(arg))
end
end
logfile:write(table.concat(parts, '\t'), "\n")
@@ -77,7 +89,7 @@ end
vim.tbl_add_reverse_lookup(log.levels)
--- Sets the current log level.
---@param level (string or number) One of `vim.lsp.log.levels`
+---@param level (string or number) One of `vim.lsp.log.levels`
function log.set_level(level)
if type(level) == 'string' then
current_log_level = assert(log.levels[level:upper()], string.format("Invalid log level: %q", level))
@@ -88,9 +100,21 @@ function log.set_level(level)
end
end
+--- Gets the current log level.
+function log.get_level()
+ return current_log_level
+end
+
+--- Sets formatting function used to format logs
+---@param handle function function to apply to logging arguments, pass vim.inspect for multi-line formatting
+function log.set_format_func(handle)
+ assert(handle == vim.inspect or type(handle) == 'function', "handle must be a function")
+ format_func = handle
+end
+
--- Checks whether the level is sufficient for logging.
---@param level number log level
---@returns (bool) true if would log, false if not
+---@param level number log level
+---@returns (bool) true if would log, false if not
function log.should_log(level)
return level >= current_log_level
end
diff --git a/runtime/lua/vim/lsp/protocol.lua b/runtime/lua/vim/lsp/protocol.lua
index 7e43eb84de..b3aa8b934f 100644
--- a/runtime/lua/vim/lsp/protocol.lua
+++ b/runtime/lua/vim/lsp/protocol.lua
@@ -5,14 +5,14 @@ local if_nil = vim.F.if_nil
local protocol = {}
--[=[
---@private
+---@private
--- Useful for interfacing with:
--- https://github.com/microsoft/language-server-protocol/raw/gh-pages/_specifications/specification-3-14.md
function transform_schema_comments()
nvim.command [[silent! '<,'>g/\/\*\*\|\*\/\|^$/d]]
nvim.command [[silent! '<,'>s/^\(\s*\) \* \=\(.*\)/\1--\2/]]
end
---@private
+---@private
function transform_schema_to_table()
transform_schema_comments()
nvim.command [[silent! '<,'>s/: \S\+//]]
@@ -645,6 +645,10 @@ function protocol.make_client_capabilities()
end)();
};
};
+ dataSupport = true;
+ resolveSupport = {
+ properties = { 'edit', }
+ };
};
completion = {
dynamicRegistration = false;
@@ -691,10 +695,11 @@ function protocol.make_client_capabilities()
signatureHelp = {
dynamicRegistration = false;
signatureInformation = {
+ activeParameterSupport = true;
documentationFormat = { protocol.MarkupKind.Markdown; protocol.MarkupKind.PlainText };
- -- parameterInformation = {
- -- labelOffsetSupport = false;
- -- };
+ parameterInformation = {
+ labelOffsetSupport = true;
+ };
};
};
references = {
@@ -1002,8 +1007,7 @@ function protocol.resolve_capabilities(server_capabilities)
elseif type(server_capabilities.declarationProvider) == 'boolean' then
general_properties.declaration = server_capabilities.declarationProvider
elseif type(server_capabilities.declarationProvider) == 'table' then
- -- TODO: support more detailed declarationProvider options.
- general_properties.declaration = false
+ general_properties.declaration = server_capabilities.declarationProvider
else
error("The server sent invalid declarationProvider")
end
@@ -1013,8 +1017,7 @@ function protocol.resolve_capabilities(server_capabilities)
elseif type(server_capabilities.typeDefinitionProvider) == 'boolean' then
general_properties.type_definition = server_capabilities.typeDefinitionProvider
elseif type(server_capabilities.typeDefinitionProvider) == 'table' then
- -- TODO: support more detailed typeDefinitionProvider options.
- general_properties.type_definition = false
+ general_properties.type_definition = server_capabilities.typeDefinitionProvider
else
error("The server sent invalid typeDefinitionProvider")
end
@@ -1024,8 +1027,7 @@ function protocol.resolve_capabilities(server_capabilities)
elseif type(server_capabilities.implementationProvider) == 'boolean' then
general_properties.implementation = server_capabilities.implementationProvider
elseif type(server_capabilities.implementationProvider) == 'table' then
- -- TODO(ashkan) support more detailed implementation options.
- general_properties.implementation = false
+ general_properties.implementation = server_capabilities.implementationProvider
else
error("The server sent invalid implementationProvider")
end
diff --git a/runtime/lua/vim/lsp/rpc.lua b/runtime/lua/vim/lsp/rpc.lua
index 4c5f02af9d..255eb65dfe 100644
--- a/runtime/lua/vim/lsp/rpc.lua
+++ b/runtime/lua/vim/lsp/rpc.lua
@@ -4,38 +4,10 @@ local log = require('vim.lsp.log')
local protocol = require('vim.lsp.protocol')
local validate, schedule, schedule_wrap = vim.validate, vim.schedule, vim.schedule_wrap
--- TODO replace with a better implementation.
---@private
---- Encodes to JSON.
----
---@param data (table) Data to encode
---@returns (string) Encoded object
-local function json_encode(data)
- local status, result = pcall(vim.fn.json_encode, data)
- if status then
- return result
- else
- return nil, result
- end
-end
---@private
---- Decodes from JSON.
----
---@param data (string) Data to decode
---@returns (table) Decoded JSON object
-local function json_decode(data)
- local status, result = pcall(vim.fn.json_decode, data)
- if status then
- return result
- else
- return nil, result
- end
-end
-
---@private
+---@private
--- Checks whether a given path exists and is a directory.
---@param filename (string) path to check
---@returns (bool)
+---@param filename (string) path to check
+---@returns (bool)
local function is_dir(filename)
local stat = vim.loop.fs_stat(filename)
return stat and stat.type == 'directory' or false
@@ -43,7 +15,7 @@ end
local NIL = vim.NIL
---@private
+---@private
local recursive_convert_NIL
recursive_convert_NIL = function(v, tbl_processed)
if v == NIL then
@@ -63,15 +35,15 @@ recursive_convert_NIL = function(v, tbl_processed)
return v
end
---@private
+---@private
--- Returns its argument, but converts `vim.NIL` to Lua `nil`.
---@param v (any) Argument
---@returns (any)
+---@param v (any) Argument
+---@returns (any)
local function convert_NIL(v)
return recursive_convert_NIL(v, {})
end
---@private
+---@private
--- Merges current process env with the given env and returns the result as
--- a list of "k=v" strings.
---
@@ -81,8 +53,8 @@ end
--- in: { PRODUCTION="false", PATH="/usr/bin/", PORT=123, HOST="0.0.0.0", }
--- out: { "PRODUCTION=false", "PATH=/usr/bin/", "PORT=123", "HOST=0.0.0.0", }
--- </pre>
---@param env (table) table of environment variable assignments
---@returns (table) list of `"k=v"` strings
+---@param env (table) table of environment variable assignments
+---@returns (table) list of `"k=v"` strings
local function env_merge(env)
if env == nil then
return env
@@ -97,11 +69,11 @@ local function env_merge(env)
return final_env
end
---@private
+---@private
--- Embeds the given string into a table and correctly computes `Content-Length`.
---
---@param encoded_message (string)
---@returns (table) table containing encoded message and `Content-Length` attribute
+---@param encoded_message (string)
+---@returns (table) table containing encoded message and `Content-Length` attribute
local function format_message_with_content_length(encoded_message)
return table.concat {
'Content-Length: '; tostring(#encoded_message); '\r\n\r\n';
@@ -109,11 +81,11 @@ local function format_message_with_content_length(encoded_message)
}
end
---@private
+---@private
--- Parses an LSP Message's header
---
---@param header: The header to parse.
---@returns Parsed headers
+---@param header: The header to parse.
+---@returns Parsed headers
local function parse_headers(header)
if type(header) ~= 'string' then
return nil
@@ -141,7 +113,7 @@ end
-- case insensitive pattern.
local header_start_pattern = ("content"):gsub("%w", function(c) return "["..c..c:upper().."]" end)
---@private
+---@private
--- The actual workhorse.
local function request_parser_loop()
local buffer = '' -- only for header part
@@ -203,8 +175,8 @@ local client_errors = vim.tbl_add_reverse_lookup {
--- Constructs an error message from an LSP error object.
---
---@param err (table) The error object
---@returns (string) The formatted error message
+---@param err (table) The error object
+---@returns (string) The formatted error message
local function format_rpc_error(err)
validate {
err = { err, 't' };
@@ -233,9 +205,9 @@ end
--- Creates an RPC response object/table.
---
---@param code RPC error code defined in `vim.lsp.protocol.ErrorCodes`
---@param message (optional) arbitrary message to send to server
---@param data (optional) arbitrary data to send to server
+---@param code RPC error code defined in `vim.lsp.protocol.ErrorCodes`
+---@param message (optional) arbitrary message to send to server
+---@param data (optional) arbitrary data to send to server
local function rpc_response_error(code, message, data)
-- TODO should this error or just pick a sane error (like InternalError)?
local code_name = assert(protocol.ErrorCodes[code], 'Invalid RPC error code')
@@ -250,38 +222,38 @@ end
local default_dispatchers = {}
---@private
+---@private
--- Default dispatcher for notifications sent to an LSP server.
---
---@param method (string) The invoked LSP method
---@param params (table): Parameters for the invoked LSP method
+---@param method (string) The invoked LSP method
+---@param params (table): Parameters for the invoked LSP method
function default_dispatchers.notification(method, params)
local _ = log.debug() and log.debug('notification', method, params)
end
---@private
+---@private
--- Default dispatcher for requests sent to an LSP server.
---
---@param method (string) The invoked LSP method
---@param params (table): Parameters for the invoked LSP method
---@returns `nil` and `vim.lsp.protocol.ErrorCodes.MethodNotFound`.
+---@param method (string) The invoked LSP method
+---@param params (table): Parameters for the invoked LSP method
+---@returns `nil` and `vim.lsp.protocol.ErrorCodes.MethodNotFound`.
function default_dispatchers.server_request(method, params)
local _ = log.debug() and log.debug('server_request', method, params)
return nil, rpc_response_error(protocol.ErrorCodes.MethodNotFound)
end
---@private
+---@private
--- Default dispatcher for when a client exits.
---
---@param code (number): Exit code
---@param signal (number): Number describing the signal used to terminate (if
+---@param code (number): Exit code
+---@param signal (number): Number describing the signal used to terminate (if
---any)
function default_dispatchers.on_exit(code, signal)
local _ = log.info() and log.info("client_exit", { code = code, signal = signal })
end
---@private
+---@private
--- Default dispatcher for client errors.
---
---@param code (number): Error code
---@param err (any): Details about the error
+---@param code (number): Error code
+---@param err (any): Details about the error
---any)
function default_dispatchers.on_error(code, err)
local _ = log.error() and log.error('client_error:', client_errors[code], err)
@@ -290,25 +262,25 @@ end
--- Starts an LSP server process and create an LSP RPC client object to
--- interact with it.
---
---@param cmd (string) Command to start the LSP server.
---@param cmd_args (table) List of additional string arguments to pass to {cmd}.
---@param dispatchers (table, optional) Dispatchers for LSP message types. Valid
+---@param cmd (string) Command to start the LSP server.
+---@param cmd_args (table) List of additional string arguments to pass to {cmd}.
+---@param dispatchers (table, optional) Dispatchers for LSP message types. Valid
---dispatcher names are:
--- - `"notification"`
--- - `"server_request"`
--- - `"on_error"`
--- - `"on_exit"`
---@param extra_spawn_params (table, optional) Additional context for the LSP
+---@param extra_spawn_params (table, optional) Additional context for the LSP
--- server process. May contain:
--- - {cwd} (string) Working directory for the LSP server process
--- - {env} (table) Additional environment variables for LSP server process
---@returns Client RPC object.
+---@returns Client RPC object.
---
---@returns Methods:
+---@returns Methods:
--- - `notify()` |vim.lsp.rpc.notify()|
--- - `request()` |vim.lsp.rpc.request()|
---
---@returns Members:
+---@returns Members:
--- - {pid} (number) The LSP server's PID.
--- - {handle} A handle for low-level interaction with the LSP server process
--- |vim.loop|.
@@ -358,10 +330,10 @@ local function start(cmd, cmd_args, dispatchers, extra_spawn_params)
local handle, pid
do
- --@private
+ ---@private
--- Callback for |vim.loop.spawn()| Closes all streams and runs the `on_exit` dispatcher.
- --@param code (number) Exit code
- --@param signal (number) Signal that was used to terminate (if any)
+ ---@param code (number) Exit code
+ ---@param signal (number) Signal that was used to terminate (if any)
local function onexit(code, signal)
stdin:close()
stdout:close()
@@ -385,20 +357,17 @@ local function start(cmd, cmd_args, dispatchers, extra_spawn_params)
end
end
- --@private
+ ---@private
--- Encodes {payload} into a JSON-RPC message and sends it to the remote
--- process.
---
- --@param payload (table) Converted into a JSON string, see |json_encode()|
- --@returns true if the payload could be scheduled, false if the main event-loop is in the process of closing.
+ ---@param payload table
+ ---@returns true if the payload could be scheduled, false if the main event-loop is in the process of closing.
local function encode_and_send(payload)
- local _ = log.debug() and log.debug("rpc.send.payload", payload)
+ local _ = log.debug() and log.debug("rpc.send", payload)
if handle == nil or handle:is_closing() then return false end
- -- TODO(ashkan) remove this once we have a Lua json_encode
- schedule(function()
- local encoded = assert(json_encode(payload))
- stdin:write(format_message_with_content_length(encoded))
- end)
+ local encoded = vim.json.encode(payload)
+ stdin:write(format_message_with_content_length(encoded))
return true
end
@@ -406,9 +375,9 @@ local function start(cmd, cmd_args, dispatchers, extra_spawn_params)
-- `start()`
--
--- Sends a notification to the LSP server.
- --@param method (string) The invoked LSP method
- --@param params (table): Parameters for the invoked LSP method
- --@returns (bool) `true` if notification could be sent, `false` if not
+ ---@param method (string) The invoked LSP method
+ ---@param params (table): Parameters for the invoked LSP method
+ ---@returns (bool) `true` if notification could be sent, `false` if not
local function notify(method, params)
return encode_and_send {
jsonrpc = "2.0";
@@ -417,7 +386,7 @@ local function start(cmd, cmd_args, dispatchers, extra_spawn_params)
}
end
- --@private
+ ---@private
--- sends an error object to the remote LSP process.
local function send_response(request_id, err, result)
return encode_and_send {
@@ -433,10 +402,10 @@ local function start(cmd, cmd_args, dispatchers, extra_spawn_params)
--
--- Sends a request to the LSP server and runs {callback} upon response.
---
- --@param method (string) The invoked LSP method
- --@param params (table) Parameters for the invoked LSP method
- --@param callback (function) Callback to invoke
- --@returns (bool, number) `(true, message_id)` if request could be sent, `false` if not
+ ---@param method (string) The invoked LSP method
+ ---@param params (table) Parameters for the invoked LSP method
+ ---@param callback (function) Callback to invoke
+ ---@returns (bool, number) `(true, message_id)` if request could be sent, `false` if not
local function request(method, params, callback)
validate {
callback = { callback, 'f' };
@@ -463,13 +432,13 @@ local function start(cmd, cmd_args, dispatchers, extra_spawn_params)
end
end)
- --@private
+ ---@private
local function on_error(errkind, ...)
assert(client_errors[errkind])
-- TODO what to do if this fails?
pcall(dispatchers.on_error, errkind, ...)
end
- --@private
+ ---@private
local function pcall_handler(errkind, status, head, ...)
if not status then
on_error(errkind, head, ...)
@@ -477,7 +446,7 @@ local function start(cmd, cmd_args, dispatchers, extra_spawn_params)
end
return status, head, ...
end
- --@private
+ ---@private
local function try_call(errkind, fn, ...)
return pcall_handler(errkind, pcall(fn, ...))
end
@@ -486,16 +455,17 @@ local function start(cmd, cmd_args, dispatchers, extra_spawn_params)
-- time and log them. This would require storing the timestamp. I could call
-- them with an error then, perhaps.
- --@private
+ ---@private
local function handle_body(body)
- local decoded, err = json_decode(body)
- if not decoded then
- -- on_error(client_errors.INVALID_SERVER_JSON, err)
+ local ok, decoded = pcall(vim.json.decode, body)
+ if not ok then
+ on_error(client_errors.INVALID_SERVER_JSON, decoded)
return
end
- local _ = log.debug() and log.debug("decoded", decoded)
+ local _ = log.debug() and log.debug("rpc.receive", decoded)
if type(decoded.method) == 'string' and decoded.id then
+ local err
-- Server Request
decoded.params = convert_NIL(decoded.params)
-- Schedule here so that the users functions don't trigger an error and
@@ -582,8 +552,6 @@ local function start(cmd, cmd_args, dispatchers, extra_spawn_params)
on_error(client_errors.INVALID_SERVER_MESSAGE, decoded)
end
end
- -- TODO(ashkan) remove this once we have a Lua json_decode
- handle_body = schedule_wrap(handle_body)
local request_parser = coroutine.wrap(request_parser_loop)
request_parser()
diff --git a/runtime/lua/vim/lsp/util.lua b/runtime/lua/vim/lsp/util.lua
index 195e3a0e65..e95f170427 100644
--- a/runtime/lua/vim/lsp/util.lua
+++ b/runtime/lua/vim/lsp/util.lua
@@ -1,4 +1,5 @@
local protocol = require 'vim.lsp.protocol'
+local snippet = require 'vim.lsp._snippet'
local vim = vim
local validate = vim.validate
local api = vim.api
@@ -30,20 +31,12 @@ local default_border = {
{" ", "NormalFloat"},
}
-
-local DiagnosticSeverity = protocol.DiagnosticSeverity
-local loclist_type_map = {
- [DiagnosticSeverity.Error] = 'E',
- [DiagnosticSeverity.Warning] = 'W',
- [DiagnosticSeverity.Information] = 'I',
- [DiagnosticSeverity.Hint] = 'I',
-}
-
-
---@private
--- Check the border given by opts or the default border for the additional
--- size it adds to a float.
---@returns size of border in height and width
+---@private
+--- Check the border given by opts or the default border for the additional
+--- size it adds to a float.
+---@param opts (table, optional) options for the floating window
+--- - border (string or table) the border
+---@returns (table) size of border in the form of { height = height, width = width }
local function get_border_size(opts)
local border = opts and opts.border or default_border
local height = 0
@@ -52,12 +45,16 @@ local function get_border_size(opts)
if type(border) == 'string' then
local border_size = {none = {0, 0}, single = {2, 2}, double = {2, 2}, rounded = {2, 2}, solid = {2, 2}, shadow = {1, 1}}
if border_size[border] == nil then
- error("floating preview border is not correct. Please refer to the docs |vim.api.nvim_open_win()|"
- .. vim.inspect(border))
+ error(string.format("invalid floating preview border: %s. :help vim.api.nvim_open_win()", vim.inspect(border)))
end
height, width = unpack(border_size[border])
else
+ if 8 % #border ~= 0 then
+ error(string.format("invalid floating preview border: %s. :help vim.api.nvim_open_win()", vim.inspect(border)))
+ end
+ ---@private
local function border_width(id)
+ id = (id - 1) % #border + 1
if type(border[id]) == "table" then
-- border specified as a table of <character, highlight group>
return vim.fn.strdisplaywidth(border[id][1])
@@ -65,9 +62,11 @@ local function get_border_size(opts)
-- border specified as a list of border characters
return vim.fn.strdisplaywidth(border[id])
end
- error("floating preview border is not correct. Please refer to the docs |vim.api.nvim_open_win()|" .. vim.inspect(border))
+ error(string.format("invalid floating preview border: %s. :help vim.api.nvim_open_win()", vim.inspect(border)))
end
+ ---@private
local function border_height(id)
+ id = (id - 1) % #border + 1
if type(border[id]) == "table" then
-- border specified as a table of <character, highlight group>
return #border[id][1] > 0 and 1 or 0
@@ -75,7 +74,7 @@ local function get_border_size(opts)
-- border specified as a list of border characters
return #border[id] > 0 and 1 or 0
end
- error("floating preview border is not correct. Please refer to the docs |vim.api.nvim_open_win()|" .. vim.inspect(border))
+ error(string.format("invalid floating preview border: %s. :help vim.api.nvim_open_win()", vim.inspect(border)))
end
height = height + border_height(2) -- top
height = height + border_height(6) -- bottom
@@ -86,7 +85,7 @@ local function get_border_size(opts)
return { height = height, width = width }
end
---@private
+---@private
local function split_lines(value)
return split(value, '\n', true)
end
@@ -95,11 +94,11 @@ end
---
--- CAUTION: Changes in-place!
---
---@param lines (table) Original list of strings
---@param A (table) Start position; a 2-tuple of {line, col} numbers
---@param B (table) End position; a 2-tuple of {line, col} numbers
---@param new_lines A list of strings to replace the original
---@returns (table) The modified {lines} object
+---@param lines (table) Original list of strings
+---@param A (table) Start position; a 2-tuple of {line, col} numbers
+---@param B (table) End position; a 2-tuple of {line, col} numbers
+---@param new_lines A list of strings to replace the original
+---@returns (table) The modified {lines} object
function M.set_lines(lines, A, B, new_lines)
-- 0-indexing to 1-indexing
local i_0 = A[1] + 1
@@ -133,7 +132,7 @@ function M.set_lines(lines, A, B, new_lines)
return lines
end
---@private
+---@private
local function sort_by_key(fn)
return function(a,b)
local ka, kb = fn(a), fn(b)
@@ -147,12 +146,8 @@ local function sort_by_key(fn)
return false
end
end
---@private
-local edit_sort_key = sort_by_key(function(e)
- return {e.A[1], e.A[2], e.i}
-end)
---@private
+---@private
--- Position is a https://microsoft.github.io/language-server-protocol/specifications/specification-current/#position
--- Returns a zero-indexed column, since set_lines() does the conversion to
--- 1-indexed
@@ -175,6 +170,7 @@ local function get_line_byte_from_position(bufnr, position)
if ok then
return result
end
+ return math.min(#lines[1], col)
end
end
return col
@@ -238,53 +234,119 @@ function M.get_progress_messages()
end
--- Applies a list of text edits to a buffer.
---@param text_edits (table) list of `TextEdit` objects
---@param buf_nr (number) Buffer id
+---@param text_edits table list of `TextEdit` objects
+---@param bufnr number Buffer id
+---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textEdit
function M.apply_text_edits(text_edits, bufnr)
if not next(text_edits) then return end
if not api.nvim_buf_is_loaded(bufnr) then
vim.fn.bufload(bufnr)
end
api.nvim_buf_set_option(bufnr, 'buflisted', true)
- local start_line, finish_line = math.huge, -1
- local cleaned = {}
- for i, e in ipairs(text_edits) do
- -- adjust start and end column for UTF-16 encoding of non-ASCII characters
- local start_row = e.range.start.line
- local start_col = get_line_byte_from_position(bufnr, e.range.start)
- local end_row = e.range["end"].line
- local end_col = get_line_byte_from_position(bufnr, e.range['end'])
- start_line = math.min(e.range.start.line, start_line)
- finish_line = math.max(e.range["end"].line, finish_line)
- -- TODO(ashkan) sanity check ranges for overlap.
- table.insert(cleaned, {
- i = i;
- A = {start_row; start_col};
- B = {end_row; end_col};
- lines = vim.split(e.newText, '\n', true);
- })
- end
- -- Reverse sort the orders so we can apply them without interfering with
- -- eachother. Also add i as a sort key to mimic a stable sort.
- table.sort(cleaned, edit_sort_key)
- local lines = api.nvim_buf_get_lines(bufnr, start_line, finish_line + 1, false)
- local fix_eol = api.nvim_buf_get_option(bufnr, 'fixeol')
- local set_eol = fix_eol and api.nvim_buf_line_count(bufnr) <= finish_line + 1
- if set_eol and (#lines == 0 or #lines[#lines] ~= 0) then
- table.insert(lines, '')
+ -- Fix reversed range and indexing each text_edits
+ local index = 0
+ text_edits = vim.tbl_map(function(text_edit)
+ index = index + 1
+ text_edit._index = index
+
+ if text_edit.range.start.line > text_edit.range['end'].line or text_edit.range.start.line == text_edit.range['end'].line and text_edit.range.start.character > text_edit.range['end'].character then
+ local start = text_edit.range.start
+ text_edit.range.start = text_edit.range['end']
+ text_edit.range['end'] = start
+ end
+ return text_edit
+ end, text_edits)
+
+ -- Sort text_edits
+ table.sort(text_edits, function(a, b)
+ if a.range.start.line ~= b.range.start.line then
+ return a.range.start.line > b.range.start.line
+ end
+ if a.range.start.character ~= b.range.start.character then
+ return a.range.start.character > b.range.start.character
+ end
+ if a._index ~= b._index then
+ return a._index > b._index
+ end
+ end)
+
+ -- Some LSP servers may return +1 range of the buffer content but nvim_buf_set_text can't accept it so we should fix it here.
+ local has_eol_text_edit = false
+ local max = vim.api.nvim_buf_line_count(bufnr)
+ local len = vim.str_utfindex(vim.api.nvim_buf_get_lines(bufnr, -2, -1, false)[1] or '')
+ text_edits = vim.tbl_map(function(text_edit)
+ if max <= text_edit.range.start.line then
+ text_edit.range.start.line = max - 1
+ text_edit.range.start.character = len
+ text_edit.newText = '\n' .. text_edit.newText
+ has_eol_text_edit = true
+ end
+ if max <= text_edit.range['end'].line then
+ text_edit.range['end'].line = max - 1
+ text_edit.range['end'].character = len
+ has_eol_text_edit = true
+ end
+ return text_edit
+ end, text_edits)
+
+ -- Some LSP servers are depending on the VSCode behavior.
+ -- The VSCode will re-locate the cursor position after applying TextEdit so we also do it.
+ local is_current_buf = vim.api.nvim_get_current_buf() == bufnr
+ local cursor = (function()
+ if not is_current_buf then
+ return {
+ row = -1,
+ col = -1,
+ }
+ end
+ local cursor = vim.api.nvim_win_get_cursor(0)
+ return {
+ row = cursor[1] - 1,
+ col = cursor[2],
+ }
+ end)()
+
+ -- Apply text edits.
+ local is_cursor_fixed = false
+ for _, text_edit in ipairs(text_edits) do
+ local e = {
+ start_row = text_edit.range.start.line,
+ start_col = get_line_byte_from_position(bufnr, text_edit.range.start),
+ end_row = text_edit.range['end'].line,
+ end_col = get_line_byte_from_position(bufnr, text_edit.range['end']),
+ text = vim.split(text_edit.newText, '\n', true),
+ }
+ vim.api.nvim_buf_set_text(bufnr, e.start_row, e.start_col, e.end_row, e.end_col, e.text)
+
+ local row_count = (e.end_row - e.start_row) + 1
+ if e.end_row < cursor.row then
+ cursor.row = cursor.row + (#e.text - row_count)
+ is_cursor_fixed = true
+ elseif e.end_row == cursor.row and e.end_col <= cursor.col then
+ cursor.row = cursor.row + (#e.text - row_count)
+ cursor.col = #e.text[#e.text] + (cursor.col - e.end_col)
+ if #e.text == 1 then
+ cursor.col = cursor.col + e.start_col
+ end
+ is_cursor_fixed = true
+ end
end
- for i = #cleaned, 1, -1 do
- local e = cleaned[i]
- local A = {e.A[1] - start_line, e.A[2]}
- local B = {e.B[1] - start_line, e.B[2]}
- lines = M.set_lines(lines, A, B, e.lines)
+ if is_cursor_fixed then
+ vim.api.nvim_win_set_cursor(0, {
+ cursor.row + 1,
+ math.min(cursor.col, #(vim.api.nvim_buf_get_lines(bufnr, cursor.row, cursor.row + 1, false)[1] or ''))
+ })
end
- if set_eol and #lines[#lines] == 0 then
- table.remove(lines)
+
+ -- Remove final line if needed
+ local fix_eol = has_eol_text_edit
+ fix_eol = fix_eol and api.nvim_buf_get_option(bufnr, 'fixeol')
+ fix_eol = fix_eol and (vim.api.nvim_buf_get_lines(bufnr, -2, -1, false)[1] or '') == ''
+ if fix_eol then
+ vim.api.nvim_buf_set_lines(bufnr, -2, -1, false, {})
end
- api.nvim_buf_set_lines(bufnr, start_line, finish_line + 1, false, lines)
end
-- local valid_windows_path_characters = "[^<>:\"/\\|?*]"
@@ -294,11 +356,11 @@ end
-- function M.glob_to_regex(glob)
-- end
---@private
+---@private
--- Finds the first line and column of the difference between old and new lines
---@param old_lines table list of lines
---@param new_lines table list of lines
---@returns (int, int) start_line_idx and start_col_idx of range
+---@param old_lines table list of lines
+---@param new_lines table list of lines
+---@returns (int, int) start_line_idx and start_col_idx of range
local function first_difference(old_lines, new_lines, start_line_idx)
local line_count = math.min(#old_lines, #new_lines)
if line_count == 0 then return 1, 1 end
@@ -324,12 +386,12 @@ local function first_difference(old_lines, new_lines, start_line_idx)
end
---@private
+---@private
--- Finds the last line and column of the differences between old and new lines
---@param old_lines table list of lines
---@param new_lines table list of lines
---@param start_char integer First different character idx of range
---@returns (int, int) end_line_idx and end_col_idx of range
+---@param old_lines table list of lines
+---@param new_lines table list of lines
+---@param start_char integer First different character idx of range
+---@returns (int, int) end_line_idx and end_col_idx of range
local function last_difference(old_lines, new_lines, start_char, end_line_idx)
local line_count = math.min(#old_lines, #new_lines)
if line_count == 0 then return 0,0 end
@@ -368,14 +430,14 @@ local function last_difference(old_lines, new_lines, start_char, end_line_idx)
end
---@private
+---@private
--- Get the text of the range defined by start and end line/column
---@param lines table list of lines
---@param start_char integer First different character idx of range
---@param end_char integer Last different character idx of range
---@param start_line integer First different line idx of range
---@param end_line integer Last different line idx of range
---@returns string text extracted from defined region
+---@param lines table list of lines
+---@param start_char integer First different character idx of range
+---@param end_char integer Last different character idx of range
+---@param start_line integer First different line idx of range
+---@param end_line integer Last different line idx of range
+---@returns string text extracted from defined region
local function extract_text(lines, start_line, start_char, end_line, end_char)
if start_line == #lines + end_line + 1 then
if end_line == 0 then return '' end
@@ -395,14 +457,14 @@ local function extract_text(lines, start_line, start_char, end_line, end_char)
return result
end
---@private
+---@private
--- Compute the length of the substituted range
---@param lines table list of lines
---@param start_char integer First different character idx of range
---@param end_char integer Last different character idx of range
---@param start_line integer First different line idx of range
---@param end_line integer Last different line idx of range
---@returns (int, int) end_line_idx and end_col_idx of range
+---@param lines table list of lines
+---@param start_char integer First different character idx of range
+---@param end_char integer Last different character idx of range
+---@param start_line integer First different line idx of range
+---@param end_line integer Last different line idx of range
+---@returns (int, int) end_line_idx and end_col_idx of range
local function compute_length(lines, start_line, start_char, end_line, end_char)
local adj_end_line = #lines + end_line + 1
local adj_end_char
@@ -423,12 +485,12 @@ local function compute_length(lines, start_line, start_char, end_line, end_char)
end
--- Returns the range table for the difference between old and new lines
---@param old_lines table list of lines
---@param new_lines table list of lines
---@param start_line_idx int line to begin search for first difference
---@param end_line_idx int line to begin search for last difference
---@param offset_encoding string encoding requested by language server
---@returns table start_line_idx and start_col_idx of range
+---@param old_lines table list of lines
+---@param new_lines table list of lines
+---@param start_line_idx int line to begin search for first difference
+---@param end_line_idx int line to begin search for last difference
+---@param offset_encoding string encoding requested by language server
+---@returns table start_line_idx and start_col_idx of range
function M.compute_diff(old_lines, new_lines, start_line_idx, end_line_idx, offset_encoding)
local start_line, start_char = first_difference(old_lines, new_lines, start_line_idx)
local end_line, end_char = last_difference(vim.list_slice(old_lines, start_line, #old_lines),
@@ -468,9 +530,9 @@ end
--- Can be used to extract the completion items from a
--- `textDocument/completion` request, which may return one of
--- `CompletionItem[]`, `CompletionList` or null.
---@param result (table) The result of a `textDocument/completion` request
---@returns (table) List of completion items
---@see https://microsoft.github.io/language-server-protocol/specification#textDocument_completion
+---@param result (table) The result of a `textDocument/completion` request
+---@returns (table) List of completion items
+---@see https://microsoft.github.io/language-server-protocol/specification#textDocument_completion
function M.extract_completion_items(result)
if type(result) == 'table' and result.items then
-- result is a `CompletionList`
@@ -514,90 +576,34 @@ function M.apply_text_document_edit(text_document_edit, index)
M.apply_text_edits(text_document_edit.edits, bufnr)
end
---@private
---- Recursively parses snippets in a completion entry.
----
---@param input (string) Snippet text to parse for snippets
---@param inner (bool) Whether this function is being called recursively
---@returns 2-tuple of strings: The first is the parsed result, the second is the
----unparsed rest of the input
-local function parse_snippet_rec(input, inner)
- local res = ""
-
- local close, closeend = nil, nil
- if inner then
- close, closeend = input:find("}", 1, true)
- while close ~= nil and input:sub(close-1,close-1) == "\\" do
- close, closeend = input:find("}", closeend+1, true)
- end
- end
-
- local didx = input:find('$', 1, true)
- if didx == nil and close == nil then
- return input, ""
- elseif close ~=nil and (didx == nil or close < didx) then
- -- No inner placeholders
- return input:sub(0, close-1), input:sub(closeend+1)
- end
-
- res = res .. input:sub(0, didx-1)
- input = input:sub(didx+1)
-
- local tabstop, tabstopend = input:find('^%d+')
- local placeholder, placeholderend = input:find('^{%d+:')
- local choice, choiceend = input:find('^{%d+|')
-
- if tabstop then
- input = input:sub(tabstopend+1)
- elseif choice then
- input = input:sub(choiceend+1)
- close, closeend = input:find("|}", 1, true)
-
- res = res .. input:sub(0, close-1)
- input = input:sub(closeend+1)
- elseif placeholder then
- -- TODO: add support for variables
- input = input:sub(placeholderend+1)
-
- -- placeholders and variables are recursive
- while input ~= "" do
- local r, tail = parse_snippet_rec(input, true)
- r = r:gsub("\\}", "}")
-
- res = res .. r
- input = tail
- end
- else
- res = res .. "$"
- end
-
- return res, input
-end
-
--- Parses snippets in a completion entry.
---
---@param input (string) unparsed snippet
---@returns (string) parsed snippet
+---@param input string unparsed snippet
+---@returns string parsed snippet
function M.parse_snippet(input)
- local res, _ = parse_snippet_rec(input, false)
-
- return res
+ local ok, parsed = pcall(function()
+ return tostring(snippet.parse(input))
+ end)
+ if not ok then
+ return input
+ end
+ return parsed
end
---@private
+---@private
--- Sorts by CompletionItem.sortText.
---
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion
+--see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion
local function sort_completion_items(items)
table.sort(items, function(a, b)
return (a.sortText or a.label) < (b.sortText or b.label)
end)
end
---@private
+---@private
--- Returns text that should be inserted when selecting completion item. The
--- precedence is as follows: textEdit.newText > insertText > label
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion
+--see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion
local function get_completion_word(item)
if item.textEdit ~= nil and item.textEdit.newText ~= nil and item.textEdit.newText ~= "" then
local insert_text_format = protocol.InsertTextFormat[item.insertTextFormat]
@@ -617,7 +623,7 @@ local function get_completion_word(item)
return item.label
end
---@private
+---@private
--- Some language servers return complementary candidates whose prefixes do not
--- match are also returned. So we exclude completion candidates whose prefix
--- does not match.
@@ -632,9 +638,9 @@ end
--- the client must handle it properly even if it receives a value outside the
--- specification.
---
---@param completion_item_kind (`vim.lsp.protocol.completionItemKind`)
---@returns (`vim.lsp.protocol.completionItemKind`)
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion
+---@param completion_item_kind (`vim.lsp.protocol.completionItemKind`)
+---@returns (`vim.lsp.protocol.completionItemKind`)
+---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion
function M._get_completion_item_kind_name(completion_item_kind)
return protocol.CompletionItemKind[completion_item_kind] or "Unknown"
end
@@ -642,12 +648,12 @@ end
--- Turns the result of a `textDocument/completion` request into vim-compatible
--- |complete-items|.
---
---@param result The result of a `textDocument/completion` call, e.g. from
+---@param result The result of a `textDocument/completion` call, e.g. from
---|vim.lsp.buf.completion()|, which may be one of `CompletionItem[]`,
--- `CompletionList` or `null`
---@param prefix (string) the prefix to filter the completion items
---@returns { matches = complete-items table, incomplete = bool }
---@see |complete-items|
+---@param prefix (string) the prefix to filter the completion items
+---@returns { matches = complete-items table, incomplete = bool }
+---@see |complete-items|
function M.text_document_completion_list_to_complete_items(result, prefix)
local items = M.extract_completion_items(result)
if vim.tbl_isempty(items) then
@@ -697,8 +703,8 @@ end
--- Rename old_fname to new_fname
---
---@param opts (table)
+---
+---@param opts (table)
-- overwrite? bool
-- ignoreIfExists? bool
function M.rename(old_fname, new_fname, opts)
@@ -753,8 +759,8 @@ end
--- Applies a `WorkspaceEdit`.
---
---@param workspace_edit (table) `WorkspaceEdit`
--- @see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_applyEdit
+---@param workspace_edit (table) `WorkspaceEdit`
+--see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#workspace_applyEdit
function M.apply_workspace_edit(workspace_edit)
if workspace_edit.documentChanges then
for idx, change in ipairs(workspace_edit.documentChanges) do
@@ -793,10 +799,10 @@ end
--- window for `textDocument/hover`, for parsing the result of
--- `textDocument/signatureHelp`, and potentially others.
---
---@param input (`MarkedString` | `MarkedString[]` | `MarkupContent`)
---@param contents (table, optional, default `{}`) List of strings to extend with converted lines
---@returns {contents}, extended with lines of converted markdown.
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_hover
+---@param input (`MarkedString` | `MarkedString[]` | `MarkupContent`)
+---@param contents (table, optional, default `{}`) List of strings to extend with converted lines
+---@returns {contents}, extended with lines of converted markdown.
+---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_hover
function M.convert_input_to_markdown_lines(input, contents)
contents = contents or {}
-- MarkedString variation 1
@@ -810,16 +816,16 @@ function M.convert_input_to_markdown_lines(input, contents)
-- If it's plaintext, then wrap it in a <text></text> block
-- Some servers send input.value as empty, so let's ignore this :(
- input.value = input.value or ''
+ local value = input.value or ''
if input.kind == "plaintext" then
-- wrap this in a <text></text> block so that stylize_markdown
-- can properly process it as plaintext
- input.value = string.format("<text>\n%s\n</text>", input.value or "")
+ value = string.format("<text>\n%s\n</text>", value)
end
- -- assert(type(input.value) == 'string')
- list_extend(contents, split_lines(input.value))
+ -- assert(type(value) == 'string')
+ list_extend(contents, split_lines(value))
-- MarkupString variation 2
elseif input.language then
-- Some servers send input.value as empty, so let's ignore this :(
@@ -843,11 +849,12 @@ end
--- Converts `textDocument/SignatureHelp` response to markdown lines.
---
---@param signature_help Response of `textDocument/SignatureHelp`
---@param ft optional filetype that will be use as the `lang` for the label markdown code block
---@returns list of lines of converted markdown.
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_signatureHelp
-function M.convert_signature_help_to_markdown_lines(signature_help, ft)
+---@param signature_help Response of `textDocument/SignatureHelp`
+---@param ft optional filetype that will be use as the `lang` for the label markdown code block
+---@param triggers optional list of trigger characters from the lsp server. used to better determine parameter offsets
+---@returns list of lines of converted markdown.
+---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_signatureHelp
+function M.convert_signature_help_to_markdown_lines(signature_help, ft, triggers)
if not signature_help.signatures then
return
end
@@ -856,6 +863,7 @@ function M.convert_signature_help_to_markdown_lines(signature_help, ft)
--=== 0`. Whenever possible implementors should make an active decision about
--the active signature and shouldn't rely on a default value.
local contents = {}
+ local active_hl
local active_signature = signature_help.activeSignature or 0
-- If the activeSignature is not inside the valid range, then clip it.
if active_signature >= #signature_help.signatures then
@@ -875,11 +883,17 @@ function M.convert_signature_help_to_markdown_lines(signature_help, ft)
M.convert_input_to_markdown_lines(signature.documentation, contents)
end
if signature.parameters and #signature.parameters > 0 then
- local active_parameter = signature_help.activeParameter or 0
- -- If the activeParameter is not inside the valid range, then clip it.
+ local active_parameter = (signature.activeParameter or signature_help.activeParameter or 0)
+ if active_parameter < 0
+ then active_parameter = 0
+ end
+
+ -- If the activeParameter is > #parameters, then set it to the last
+ -- NOTE: this is not fully according to the spec, but a client-side interpretation
if active_parameter >= #signature.parameters then
- active_parameter = 0
+ active_parameter = #signature.parameters - 1
end
+
local parameter = signature.parameters[active_parameter + 1]
if parameter then
--[=[
@@ -900,22 +914,44 @@ function M.convert_signature_help_to_markdown_lines(signature_help, ft)
documentation?: string | MarkupContent;
}
--]=]
- -- TODO highlight parameter
+ if parameter.label then
+ if type(parameter.label) == "table" then
+ active_hl = parameter.label
+ else
+ local offset = 1
+ -- try to set the initial offset to the first found trigger character
+ for _, t in ipairs(triggers or {}) do
+ local trigger_offset = signature.label:find(t, 1, true)
+ if trigger_offset and (offset == 1 or trigger_offset < offset) then
+ offset = trigger_offset
+ end
+ end
+ for p, param in pairs(signature.parameters) do
+ offset = signature.label:find(param.label, offset, true)
+ if not offset then break end
+ if p == active_parameter + 1 then
+ active_hl = {offset - 1, offset + #parameter.label - 1}
+ break
+ end
+ offset = offset + #param.label + 1
+ end
+ end
+ end
if parameter.documentation then
M.convert_input_to_markdown_lines(parameter.documentation, contents)
end
end
end
- return contents
+ return contents, active_hl
end
--- Creates a table with sensible default options for a floating window. The
--- table can be passed to |nvim_open_win()|.
---
---@param width (number) window width (in character cells)
---@param height (number) window height (in character cells)
---@param opts (table, optional)
---@returns (table) Options
+---@param width (number) window width (in character cells)
+---@param height (number) window height (in character cells)
+---@param opts (table, optional)
+---@returns (table) Options
function M.make_floating_popup_options(width, height, opts)
validate {
opts = { opts, 't', true };
@@ -942,7 +978,7 @@ function M.make_floating_popup_options(width, height, opts)
row = -get_border_size(opts).height
end
- if vim.fn.wincol() + width <= api.nvim_get_option('columns') then
+ if vim.fn.wincol() + width + (opts.offset_x or 0) <= api.nvim_get_option('columns') then
anchor = anchor..'W'
col = 0
else
@@ -960,13 +996,14 @@ function M.make_floating_popup_options(width, height, opts)
style = 'minimal',
width = width,
border = opts.border or default_border,
+ zindex = opts.zindex or 50,
}
end
--- Jumps to a location.
---
---@param location (`Location`|`LocationLink`)
---@returns `true` if the jump succeeded
+---@param location (`Location`|`LocationLink`)
+---@returns `true` if the jump succeeded
function M.jump_to_location(location)
-- location may be Location or LocationLink
local uri = location.uri or location.targetUri
@@ -996,8 +1033,8 @@ end
--- - for Location, range is shown (e.g., function definition)
--- - for LocationLink, targetRange is shown (e.g., body of function definition)
---
---@param location a single `Location` or `LocationLink`
---@returns (bufnr,winnr) buffer and window number of floating window or nil
+---@param location a single `Location` or `LocationLink`
+---@returns (bufnr,winnr) buffer and window number of floating window or nil
function M.preview_location(location, opts)
-- location may be LocationLink or Location (more useful for the former)
local uri = location.targetUri or location.uri
@@ -1020,7 +1057,7 @@ function M.preview_location(location, opts)
return M.open_floating_preview(contents, syntax, opts)
end
---@private
+---@private
local function find_window_by_var(name, value)
for _, win in ipairs(api.nvim_list_wins()) do
if npcall(api.nvim_win_get_var, win, name) == value then
@@ -1056,10 +1093,10 @@ function M._trim(contents, opts)
return contents
end
--- Generates a table mapping markdown code block lang to vim syntax,
--- based on g:markdown_fenced_languages
--- @return a table of lang -> syntax mappings
--- @private
+--- Generates a table mapping markdown code block lang to vim syntax,
+--- based on g:markdown_fenced_languages
+---@return a table of lang -> syntax mappings
+---@private
local function get_markdown_fences()
local fences = {}
for _, fence in pairs(vim.g.markdown_fenced_languages or {}) do
@@ -1129,6 +1166,8 @@ function M.stylize_markdown(bufnr, contents, opts)
-- Clean up
contents = M._trim(contents, opts)
+ -- Insert blank line separator after code block?
+ local add_sep = opts.separator == nil and true or opts.separator
local stripped = {}
local highlights = {}
-- keep track of lnums that contain markdown
@@ -1155,9 +1194,24 @@ function M.stylize_markdown(bufnr, contents, opts)
start = start + 1;
finish = #stripped;
})
+ -- add a separator, but not on the last line
+ if add_sep and i < #contents then
+ table.insert(stripped, "---")
+ markdown_lines[#stripped] = true
+ end
else
- table.insert(stripped, line)
- markdown_lines[#stripped] = true
+ -- strip any emty lines or separators prior to this separator in actual markdown
+ if line:match("^---+$") then
+ while markdown_lines[#stripped] and (stripped[#stripped]:match("^%s*$") or stripped[#stripped]:match("^---+$")) do
+ markdown_lines[#stripped] = false
+ table.remove(stripped, #stripped)
+ end
+ end
+ -- add the line if its not an empty line following a separator
+ if not (line:match("^%s*$") and markdown_lines[#stripped] and stripped[#stripped]:match("^---+$")) then
+ table.insert(stripped, line)
+ markdown_lines[#stripped] = true
+ end
i = i + 1
end
end
@@ -1165,7 +1219,7 @@ function M.stylize_markdown(bufnr, contents, opts)
-- Compute size of float needed to show (wrapped) lines
opts.wrap_at = opts.wrap_at or (vim.wo["wrap"] and api.nvim_win_get_width(0))
- local width, height = M._make_floating_popup_size(stripped, opts)
+ local width = M._make_floating_popup_size(stripped, opts)
local sep_line = string.rep("─", math.min(width, opts.wrap_at or width))
@@ -1175,30 +1229,10 @@ function M.stylize_markdown(bufnr, contents, opts)
end
end
- -- Insert blank line separator after code block
- local insert_separator = opts.separator
- if insert_separator == nil then insert_separator = true end
- if insert_separator then
- local offset = 0
- for _, h in ipairs(highlights) do
- h.start = h.start + offset
- h.finish = h.finish + offset
- -- check if a seperator already exists and use that one instead of creating a new one
- if h.finish + 1 <= #stripped then
- if stripped[h.finish + 1] ~= sep_line then
- table.insert(stripped, h.finish + 1, sep_line)
- offset = offset + 1
- height = height + 1
- end
- end
- end
- end
-
-
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, stripped)
local idx = 1
- --@private
+ ---@private
-- keep track of syntaxes we already inlcuded.
-- no need to include the same syntax more than once
local langs = {}
@@ -1247,26 +1281,26 @@ end
--- Creates autocommands to close a preview window when events happen.
---
---@param events (table) list of events
---@param winnr (number) window id of preview window
---@see |autocmd-events|
+---@param events (table) list of events
+---@param winnr (number) window id of preview window
+---@see |autocmd-events|
function M.close_preview_autocmd(events, winnr)
if #events > 0 then
api.nvim_command("autocmd "..table.concat(events, ',').." <buffer> ++once lua pcall(vim.api.nvim_win_close, "..winnr..", true)")
end
end
---@internal
+---@internal
--- Computes size of float needed to show contents (with optional wrapping)
---
---@param contents table of lines to show in window
---@param opts dictionary with optional fields
--- - height of floating window
--- - width of floating window
--- - wrap_at character to wrap at for computing height
--- - max_width maximal width of floating window
--- - max_height maximal height of floating window
---@returns width,height size of float
+---@param contents table of lines to show in window
+---@param opts dictionary with optional fields
+--- - height of floating window
+--- - width of floating window
+--- - wrap_at character to wrap at for computing height
+--- - max_width maximal width of floating window
+--- - max_height maximal height of floating window
+---@returns width,height size of float
function M._make_floating_popup_size(contents, opts)
validate {
contents = { contents, 't' };
@@ -1333,9 +1367,9 @@ end
--- Shows contents in a floating window.
---
---@param contents table of lines to show in window
---@param syntax string of syntax to set for opened buffer
---@param opts dictionary with optional fields
+---@param contents table of lines to show in window
+---@param syntax string of syntax to set for opened buffer
+---@param opts dictionary with optional fields
--- - height of floating window
--- - width of floating window
--- - wrap boolean enable wrapping of long lines (defaults to true)
@@ -1349,7 +1383,7 @@ end
--- - focus_id if a popup with this id is opened, then focus it
--- - close_events list of events that closes the floating window
--- - focusable (boolean, default true): Make float focusable
---@returns bufnr,winnr buffer and window number of the newly created floating
+---@returns bufnr,winnr buffer and window number of the newly created floating
---preview window
function M.open_floating_preview(contents, syntax, opts)
validate {
@@ -1445,7 +1479,7 @@ do --[[ References ]]
--- Removes document highlights from a buffer.
---
- --@param bufnr buffer id
+ ---@param bufnr buffer id
function M.buf_clear_references(bufnr)
validate { bufnr = {bufnr, 'n', true} }
api.nvim_buf_clear_namespace(bufnr, reference_ns, 0, -1)
@@ -1453,8 +1487,9 @@ do --[[ References ]]
--- Shows a list of document highlights for a certain buffer.
---
- --@param bufnr buffer id
- --@param references List of `DocumentHighlight` objects to highlight
+ ---@param bufnr buffer id
+ ---@param references List of `DocumentHighlight` objects to highlight
+ ---@see https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/#documentHighlight
function M.buf_highlight_references(bufnr, references)
validate { bufnr = {bufnr, 'n', true} }
for _, reference in ipairs(references) do
@@ -1475,24 +1510,24 @@ local position_sort = sort_by_key(function(v)
return {v.start.line, v.start.character}
end)
--- Gets the zero-indexed line from the given uri.
+--- Gets the zero-indexed line from the given uri.
+---@param uri string uri of the resource to get the line from
+---@param row number zero-indexed line number
+---@return string the line at row in filename
-- For non-file uris, we load the buffer and get the line.
-- If a loaded buffer exists, then that is used.
-- Otherwise we get the line using libuv which is a lot faster than loading the buffer.
---@param uri string uri of the resource to get the line from
---@param row number zero-indexed line number
---@return string the line at row in filename
function M.get_line(uri, row)
return M.get_lines(uri, { row })[row]
end
--- Gets the zero-indexed lines from the given uri.
+--- Gets the zero-indexed lines from the given uri.
+---@param uri string uri of the resource to get the lines from
+---@param rows number[] zero-indexed line numbers
+---@return table<number string> a table mapping rows to lines
-- For non-file uris, we load the buffer and get the lines.
-- If a loaded buffer exists, then that is used.
-- Otherwise we get the lines using libuv which is a lot faster than loading the buffer.
---@param uri string uri of the resource to get the lines from
---@param rows number[] zero-indexed line numbers
---@return table<number string> a table mapping rows to lines
function M.get_lines(uri, rows)
rows = type(rows) == "table" and rows or { rows }
@@ -1560,8 +1595,11 @@ end
--- Returns the items with the byte position calculated correctly and in sorted
--- order, for display in quickfix and location lists.
---
---@param locations (table) list of `Location`s or `LocationLink`s
---@returns (table) list of items
+--- The result can be passed to the {list} argument of |setqflist()| or
+--- |setloclist()|.
+---
+---@param locations (table) list of `Location`s or `LocationLink`s
+---@returns (table) list of items
function M.locations_to_items(locations)
local items = {}
local grouped = setmetatable({}, {
@@ -1618,7 +1656,9 @@ end
--- Can be obtained with e.g. |vim.lsp.util.locations_to_items()|.
--- Defaults to current window.
---
---@param items (table) list of items
+---@deprecated Use |setloclist()|
+---
+---@param items (table) list of items
function M.set_loclist(items, win_id)
vim.fn.setloclist(win_id or 0, {}, ' ', {
title = 'Language Server';
@@ -1629,7 +1669,9 @@ end
--- Fills quickfix list with given list of items.
--- Can be obtained with e.g. |vim.lsp.util.locations_to_items()|.
---
---@param items (table) list of items
+---@deprecated Use |setqflist()|
+---
+---@param items (table) list of items
function M.set_qflist(items)
vim.fn.setqflist({}, ' ', {
title = 'Language Server';
@@ -1646,9 +1688,9 @@ end
--- Converts symbols to quickfix list items.
---
---@param symbols DocumentSymbol[] or SymbolInformation[]
+---@param symbols DocumentSymbol[] or SymbolInformation[]
function M.symbols_to_items(symbols, bufnr)
- --@private
+ ---@private
local function _symbols_to_items(_symbols, _items, _bufnr)
for _, symbol in ipairs(_symbols) do
if symbol.location then -- SymbolInformation type
@@ -1684,19 +1726,19 @@ function M.symbols_to_items(symbols, bufnr)
end
--- Removes empty lines from the beginning and end.
---@param lines (table) list of lines to trim
---@returns (table) trimmed list of lines
+---@param lines (table) list of lines to trim
+---@returns (table) trimmed list of lines
function M.trim_empty_lines(lines)
local start = 1
for i = 1, #lines do
- if #lines[i] > 0 then
+ if lines[i] ~= nil and #lines[i] > 0 then
start = i
break
end
end
local finish = 1
for i = #lines, 1, -1 do
- if #lines[i] > 0 then
+ if lines[i] ~= nil and #lines[i] > 0 then
finish = i
break
end
@@ -1709,8 +1751,8 @@ end
---
--- CAUTION: Modifies the input in-place!
---
---@param lines (table) list of lines
---@returns (string) filetype or 'markdown' if it was unchanged.
+---@param lines (table) list of lines
+---@returns (string) filetype or 'markdown' if it was unchanged.
function M.try_trim_markdown_code_blocks(lines)
local language_id = lines[1]:match("^```(.*)")
if language_id then
@@ -1733,7 +1775,7 @@ function M.try_trim_markdown_code_blocks(lines)
end
local str_utfindex = vim.str_utfindex
---@private
+---@private
local function make_position_param()
local row, col = unpack(api.nvim_win_get_cursor(0))
row = row - 1
@@ -1747,8 +1789,8 @@ end
--- Creates a `TextDocumentPositionParams` object for the current buffer and cursor position.
---
---@returns `TextDocumentPositionParams` object
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentPositionParams
+---@returns `TextDocumentPositionParams` object
+---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentPositionParams
function M.make_position_params()
return {
textDocument = M.make_text_document_params();
@@ -1761,7 +1803,7 @@ end
--- `textDocument/codeAction`, `textDocument/colorPresentation`,
--- `textDocument/rangeFormatting`.
---
---@returns { textDocument = { uri = `current_file_uri` }, range = { start =
+---@returns { textDocument = { uri = `current_file_uri` }, range = { start =
---`current_position`, end = `current_position` } }
function M.make_range_params()
local position = make_position_param()
@@ -1774,11 +1816,11 @@ end
--- Using the given range in the current buffer, creates an object that
--- is similar to |vim.lsp.util.make_range_params()|.
---
---@param start_pos ({number, number}, optional) mark-indexed position.
+---@param start_pos ({number, number}, optional) mark-indexed position.
---Defaults to the start of the last visual selection.
---@param end_pos ({number, number}, optional) mark-indexed position.
+---@param end_pos ({number, number}, optional) mark-indexed position.
---Defaults to the end of the last visual selection.
---@returns { textDocument = { uri = `current_file_uri` }, range = { start =
+---@returns { textDocument = { uri = `current_file_uri` }, range = { start =
---`start_position`, end = `end_position` } }
function M.make_given_range_params(start_pos, end_pos)
validate {
@@ -1814,23 +1856,23 @@ end
--- Creates a `TextDocumentIdentifier` object for the current buffer.
---
---@returns `TextDocumentIdentifier`
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentIdentifier
+---@returns `TextDocumentIdentifier`
+---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocumentIdentifier
function M.make_text_document_params()
return { uri = vim.uri_from_bufnr(0) }
end
--- Create the workspace params
---@param added
---@param removed
+---@param added
+---@param removed
function M.make_workspace_params(added, removed)
return { event = { added = added; removed = removed; } }
end
--- Returns visual width of tabstop.
---
---@see |softtabstop|
---@param bufnr (optional, number): Buffer handle, defaults to current
---@returns (number) tabstop visual width
+---@see |softtabstop|
+---@param bufnr (optional, number): Buffer handle, defaults to current
+---@returns (number) tabstop visual width
function M.get_effective_tabstop(bufnr)
validate { bufnr = {bufnr, 'n', true} }
local bo = bufnr and vim.bo[bufnr] or vim.bo
@@ -1838,11 +1880,11 @@ function M.get_effective_tabstop(bufnr)
return (sts > 0 and sts) or (sts < 0 and bo.shiftwidth) or bo.tabstop
end
---- Creates a `FormattingOptions` object for the current buffer and cursor position.
+--- Creates a `DocumentFormattingParams` object for the current buffer and cursor position.
---
---@param options Table with valid `FormattingOptions` entries
---@returns `FormattingOptions object
---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_formatting
+---@param options Table with valid `FormattingOptions` entries
+---@returns `DocumentFormattingParams` object
+---@see https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_formatting
function M.make_formatting_params(options)
validate { options = {options, 't', true} }
options = vim.tbl_extend('keep', options or {}, {
@@ -1857,10 +1899,10 @@ end
--- Returns the UTF-32 and UTF-16 offsets for a position in a certain buffer.
---
---@param buf buffer id (0 for current)
---@param row 0-indexed line
---@param col 0-indexed byte offset in line
---@returns (number, number) UTF-32 and UTF-16 index of the character in line {row} column {col} in buffer {buf}
+---@param buf buffer id (0 for current)
+---@param row 0-indexed line
+---@param col 0-indexed byte offset in line
+---@returns (number, number) UTF-32 and UTF-16 index of the character in line {row} column {col} in buffer {buf}
function M.character_offset(bufnr, row, col)
local uri = vim.uri_from_bufnr(bufnr)
local line = M.get_line(uri, row)
@@ -1873,9 +1915,9 @@ end
--- Helper function to return nested values in language server settings
---
---@param settings a table of language server settings
---@param section a string indicating the field of the settings table
---@returns (table or string) The value of settings accessed via section
+---@param settings a table of language server settings
+---@param section a string indicating the field of the settings table
+---@returns (table or string) The value of settings accessed via section
function M.lookup_section(settings, section)
for part in vim.gsplit(section, '.', true) do
settings = settings[part]
@@ -1886,40 +1928,6 @@ function M.lookup_section(settings, section)
return settings
end
-
---- Convert diagnostics grouped by bufnr to a list of items for use in the
---- quickfix or location list.
----
---@param diagnostics_by_bufnr table bufnr -> Diagnostic[]
---@param predicate an optional function to filter the diagnostics.
--- If present, only diagnostic items matching will be included.
---@return table (A list of items)
-function M.diagnostics_to_items(diagnostics_by_bufnr, predicate)
- local items = {}
- for bufnr, diagnostics in pairs(diagnostics_by_bufnr or {}) do
- for _, d in pairs(diagnostics) do
- if not predicate or predicate(d) then
- table.insert(items, {
- bufnr = bufnr,
- lnum = d.range.start.line + 1,
- col = d.range.start.character + 1,
- text = d.message,
- type = loclist_type_map[d.severity or DiagnosticSeverity.Error] or 'E'
- })
- end
- end
- end
- table.sort(items, function(a, b)
- if a.bufnr == b.bufnr then
- return a.lnum < b.lnum
- else
- return a.bufnr < b.bufnr
- end
- end)
- return items
-end
-
-
M._get_line_byte_from_position = get_line_byte_from_position
M._warn_once = warn_once
diff --git a/runtime/lua/vim/shared.lua b/runtime/lua/vim/shared.lua
index 0a663628a5..18c1e21049 100644
--- a/runtime/lua/vim/shared.lua
+++ b/runtime/lua/vim/shared.lua
@@ -12,8 +12,8 @@ local vim = vim or {}
--- same functions as those in the input table. Userdata and threads are not
--- copied and will throw an error.
---
---@param orig Table to copy
---@returns New table of copied keys and (nested) values.
+---@param orig Table to copy
+---@returns New table of copied keys and (nested) values.
function vim.deepcopy(orig) end -- luacheck: no unused
vim.deepcopy = (function()
local function _id(v)
@@ -52,14 +52,14 @@ end)()
--- Splits a string at each instance of a separator.
---
---@see |vim.split()|
---@see https://www.lua.org/pil/20.2.html
---@see http://lua-users.org/wiki/StringLibraryTutorial
+---@see |vim.split()|
+---@see https://www.lua.org/pil/20.2.html
+---@see http://lua-users.org/wiki/StringLibraryTutorial
---
---@param s String to split
---@param sep Separator string or pattern
---@param plain If `true` use `sep` literally (passed to String.find)
---@returns Iterator over the split components
+---@param s String to split
+---@param sep Separator string or pattern
+---@param plain If `true` use `sep` literally (passed to String.find)
+---@returns Iterator over the split components
function vim.gsplit(s, sep, plain)
vim.validate{s={s,'s'},sep={sep,'s'},plain={plain,'b',true}}
@@ -101,12 +101,12 @@ end
--- split(x*yz*o, "*", true) --> {'x','yz','o'}
--- </pre>
--
---@see |vim.gsplit()|
+---@see |vim.gsplit()|
---
---@param s String to split
---@param sep Separator string or pattern
---@param plain If `true` use `sep` literally (passed to String.find)
---@returns List-like table of the split components.
+---@param s String to split
+---@param sep Separator string or pattern
+---@param plain If `true` use `sep` literally (passed to String.find)
+---@returns List-like table of the split components.
function vim.split(s,sep,plain)
local t={} for c in vim.gsplit(s, sep, plain) do table.insert(t,c) end
return t
@@ -115,10 +115,10 @@ end
--- Return a list of all keys used in a table.
--- However, the order of the return table of keys is not guaranteed.
---
---@see From https://github.com/premake/premake-core/blob/master/src/base/table.lua
+---@see From https://github.com/premake/premake-core/blob/master/src/base/table.lua
---
---@param t Table
---@returns list of keys
+---@param t Table
+---@returns list of keys
function vim.tbl_keys(t)
assert(type(t) == 'table', string.format("Expected table, got %s", type(t)))
@@ -132,8 +132,8 @@ end
--- Return a list of all values used in a table.
--- However, the order of the return table of values is not guaranteed.
---
---@param t Table
---@returns list of values
+---@param t Table
+---@returns list of values
function vim.tbl_values(t)
assert(type(t) == 'table', string.format("Expected table, got %s", type(t)))
@@ -146,8 +146,8 @@ end
--- Apply a function to all values of a table.
---
---@param func function or callable table
---@param t table
+---@param func function or callable table
+---@param t table
function vim.tbl_map(func, t)
vim.validate{func={func,'c'},t={t,'t'}}
@@ -160,8 +160,8 @@ end
--- Filter a table using a predicate function
---
---@param func function or callable table
---@param t table
+---@param func function or callable table
+---@param t table
function vim.tbl_filter(func, t)
vim.validate{func={func,'c'},t={t,'t'}}
@@ -176,9 +176,9 @@ end
--- Checks if a list-like (vector) table contains `value`.
---
---@param t Table to check
---@param value Value to compare
---@returns true if `t` contains `value`
+---@param t Table to check
+---@param value Value to compare
+---@returns true if `t` contains `value`
function vim.tbl_contains(t, value)
vim.validate{t={t,'t'}}
@@ -192,14 +192,20 @@ end
--- Checks if a table is empty.
---
---@see https://github.com/premake/premake-core/blob/master/src/base/table.lua
+---@see https://github.com/premake/premake-core/blob/master/src/base/table.lua
---
---@param t Table to check
+---@param t Table to check
function vim.tbl_isempty(t)
assert(type(t) == 'table', string.format("Expected table, got %s", type(t)))
return next(t) == nil
end
+--- we only merge empty tables or tables that are not a list
+---@private
+local function can_merge(v)
+ return type(v) == "table" and (vim.tbl_isempty(v) or not vim.tbl_islist(v))
+end
+
local function tbl_extend(behavior, deep_extend, ...)
if (behavior ~= 'error' and behavior ~= 'keep' and behavior ~= 'force') then
error('invalid "behavior": '..tostring(behavior))
@@ -219,8 +225,8 @@ local function tbl_extend(behavior, deep_extend, ...)
vim.validate{["after the second argument"] = {tbl,'t'}}
if tbl then
for k, v in pairs(tbl) do
- if type(v) == 'table' and deep_extend and not vim.tbl_islist(v) then
- ret[k] = tbl_extend(behavior, true, ret[k] or vim.empty_dict(), v)
+ if deep_extend and can_merge(v) and can_merge(ret[k]) then
+ ret[k] = tbl_extend(behavior, true, ret[k], v)
elseif behavior ~= 'force' and ret[k] ~= nil then
if behavior == 'error' then
error('key found in more than one map: '..k)
@@ -236,43 +242,48 @@ end
--- Merges two or more map-like tables.
---
---@see |extend()|
+---@see |extend()|
---
---@param behavior Decides what to do if a key is found in more than one map:
+---@param behavior Decides what to do if a key is found in more than one map:
--- - "error": raise an error
--- - "keep": use value from the leftmost map
--- - "force": use value from the rightmost map
---@param ... Two or more map-like tables.
+---@param ... Two or more map-like tables.
function vim.tbl_extend(behavior, ...)
return tbl_extend(behavior, false, ...)
end
--- Merges recursively two or more map-like tables.
---
---@see |tbl_extend()|
+---@see |tbl_extend()|
---
---@param behavior Decides what to do if a key is found in more than one map:
+---@param behavior Decides what to do if a key is found in more than one map:
--- - "error": raise an error
--- - "keep": use value from the leftmost map
--- - "force": use value from the rightmost map
---@param ... Two or more map-like tables.
+---@param ... Two or more map-like tables.
function vim.tbl_deep_extend(behavior, ...)
return tbl_extend(behavior, true, ...)
end
--- Deep compare values for equality
+---
+--- Tables are compared recursively unless they both provide the `eq` methamethod.
+--- All other types are compared using the equality `==` operator.
+---@param a first value
+---@param b second value
+---@returns `true` if values are equals, else `false`.
function vim.deep_equal(a, b)
if a == b then return true end
if type(a) ~= type(b) then return false end
if type(a) == 'table' then
- -- TODO improve this algorithm's performance.
for k, v in pairs(a) do
if not vim.deep_equal(v, b[k]) then
return false
end
end
- for k, v in pairs(b) do
- if not vim.deep_equal(v, a[k]) then
+ for k, _ in pairs(b) do
+ if a[k] == nil then
return false
end
end
@@ -286,7 +297,7 @@ end
--- `tbl_add_reverse_lookup { A = 1 } == { [1] = 'A', A = 1 }`
--
--Do note that it *modifies* the input.
---@param o table The table to add the reverse to.
+---@param o table The table to add the reverse to.
function vim.tbl_add_reverse_lookup(o)
local keys = vim.tbl_keys(o)
for _, k in ipairs(keys) do
@@ -303,13 +314,13 @@ end
---
--- NOTE: This mutates dst!
---
---@see |vim.tbl_extend()|
+---@see |vim.tbl_extend()|
---
---@param dst list which will be modified and appended to.
---@param src list from which values will be inserted.
---@param start Start index on src. defaults to 1
---@param finish Final index on src. defaults to #src
---@returns dst
+---@param dst list which will be modified and appended to.
+---@param src list from which values will be inserted.
+---@param start Start index on src. defaults to 1
+---@param finish Final index on src. defaults to #src
+---@returns dst
function vim.list_extend(dst, src, start, finish)
vim.validate {
dst = {dst, 't'};
@@ -326,10 +337,10 @@ end
--- Creates a copy of a list-like table such that any nested tables are
--- "unrolled" and appended to the result.
---
---@see From https://github.com/premake/premake-core/blob/master/src/base/table.lua
+---@see From https://github.com/premake/premake-core/blob/master/src/base/table.lua
---
---@param t List-like table
---@returns Flattened copy of the given list-like table.
+---@param t List-like table
+---@returns Flattened copy of the given list-like table.
function vim.tbl_flatten(t)
local result = {}
local function _tbl_flatten(_t)
@@ -353,8 +364,8 @@ end
--- |vim.empty_dict()| or returned as a dict-like |API| or Vimscript result,
--- for example from |rpcrequest()| or |vim.fn|.
---
---@param t Table
---@returns `true` if array-like table, else `false`.
+---@param t Table
+---@returns `true` if array-like table, else `false`.
function vim.tbl_islist(t)
if type(t) ~= 'table' then
return false
@@ -389,9 +400,9 @@ end
--- vim.tbl_count({ 1, 2 }) => 2
--- </pre>
---
---@see https://github.com/Tieske/Penlight/blob/master/lua/pl/tablex.lua
---@param t Table
---@returns Number that is the number of the value in table
+---@see https://github.com/Tieske/Penlight/blob/master/lua/pl/tablex.lua
+---@param t Table
+---@returns Number that is the number of the value in table
function vim.tbl_count(t)
vim.validate{t={t,'t'}}
@@ -402,10 +413,10 @@ end
--- Creates a copy of a table containing only elements from start to end (inclusive)
---
---@param list table table
---@param start integer Start range of slice
---@param finish integer End range of slice
---@returns Copy of table sliced from start to finish (inclusive)
+---@param list table table
+---@param start integer Start range of slice
+---@param finish integer End range of slice
+---@returns Copy of table sliced from start to finish (inclusive)
function vim.list_slice(list, start, finish)
local new_list = {}
for i = start or 1, finish or #list do
@@ -416,9 +427,9 @@ end
--- Trim whitespace (Lua pattern "%s") from both sides of a string.
---
---@see https://www.lua.org/pil/20.2.html
---@param s String to trim
---@returns String with whitespace removed from its beginning and end
+---@see https://www.lua.org/pil/20.2.html
+---@param s String to trim
+---@returns String with whitespace removed from its beginning and end
function vim.trim(s)
vim.validate{s={s,'s'}}
return s:match('^%s*(.*%S)') or ''
@@ -426,9 +437,9 @@ end
--- Escapes magic chars in a Lua pattern.
---
---@see https://github.com/rxi/lume
---@param s String to escape
---@returns %-escaped pattern string
+---@see https://github.com/rxi/lume
+---@param s String to escape
+---@returns %-escaped pattern string
function vim.pesc(s)
vim.validate{s={s,'s'}}
return s:gsub('[%(%)%.%%%+%-%*%?%[%]%^%$]', '%%%1')
@@ -436,9 +447,9 @@ end
--- Tests if `s` starts with `prefix`.
---
---@param s (string) a string
---@param prefix (string) a prefix
---@return (boolean) true if `prefix` is a prefix of s
+---@param s (string) a string
+---@param prefix (string) a prefix
+---@return (boolean) true if `prefix` is a prefix of s
function vim.startswith(s, prefix)
vim.validate { s = {s, 's'}; prefix = {prefix, 's'}; }
return s:sub(1, #prefix) == prefix
@@ -446,9 +457,9 @@ end
--- Tests if `s` ends with `suffix`.
---
---@param s (string) a string
---@param suffix (string) a suffix
---@return (boolean) true if `suffix` is a suffix of s
+---@param s (string) a string
+---@param suffix (string) a suffix
+---@return (boolean) true if `suffix` is a suffix of s
function vim.endswith(s, suffix)
vim.validate { s = {s, 's'}; suffix = {suffix, 's'}; }
return #suffix == 0 or s:sub(-#suffix) == suffix
@@ -480,7 +491,7 @@ end
--- => error('arg1: expected even number, got 3')
--- </pre>
---
---@param opt Map of parameter names to validations. Each key is a parameter
+---@param opt Map of parameter names to validations. Each key is a parameter
--- name; each value is a tuple in one of these forms:
--- 1. (arg_value, type_name, optional)
--- - arg_value: argument value
@@ -564,8 +575,8 @@ do
end
--- Returns true if object `f` can be called as a function.
---
---@param f Any object
---@return true if `f` is callable, else false
+---@param f Any object
+---@return true if `f` is callable, else false
function vim.is_callable(f)
if type(f) == 'function' then return true end
local m = getmetatable(f)
diff --git a/runtime/lua/vim/treesitter.lua b/runtime/lua/vim/treesitter.lua
index de997b2d86..66999c5f7f 100644
--- a/runtime/lua/vim/treesitter.lua
+++ b/runtime/lua/vim/treesitter.lua
@@ -20,6 +20,9 @@ setmetatable(M, {
elseif k == "language" then
t[k] = require"vim.treesitter.language"
return t[k]
+ elseif k == "query" then
+ t[k] = require"vim.treesitter.query"
+ return t[k]
end
end
})
@@ -28,9 +31,9 @@ setmetatable(M, {
---
--- It is not recommended to use this, use vim.treesitter.get_parser() instead.
---
---- @param bufnr The buffer the parser will be tied to
---- @param lang The language of the parser
---- @param opts Options to pass to the created language tree
+---@param bufnr The buffer the parser will be tied to
+---@param lang The language of the parser
+---@param opts Options to pass to the created language tree
function M._create_parser(bufnr, lang, opts)
language.require_language(lang)
if bufnr == 0 then
@@ -71,11 +74,11 @@ end
--- If needed this will create the parser.
--- Unconditionnally attach the provided callback
---
---- @param bufnr The buffer the parser should be tied to
---- @param lang The filetype of this parser
---- @param opts Options object to pass to the created language tree
+---@param bufnr The buffer the parser should be tied to
+---@param lang The filetype of this parser
+---@param opts Options object to pass to the created language tree
---
---- @returns The parser
+---@returns The parser
function M.get_parser(bufnr, lang, opts)
opts = opts or {}
@@ -97,9 +100,9 @@ end
--- Gets a string parser
---
---- @param str The string to parse
---- @param lang The language of this string
---- @param opts Options to pass to the created language tree
+---@param str The string to parse
+---@param lang The language of this string
+---@param opts Options to pass to the created language tree
function M.get_string_parser(str, lang, opts)
vim.validate {
str = { str, 'string' },
diff --git a/runtime/lua/vim/treesitter/highlighter.lua b/runtime/lua/vim/treesitter/highlighter.lua
index 84b6a5f135..22b528838c 100644
--- a/runtime/lua/vim/treesitter/highlighter.lua
+++ b/runtime/lua/vim/treesitter/highlighter.lua
@@ -22,8 +22,6 @@ local _link_default_highlight_once = function(from, to)
return from
end
--- These are conventions defined by nvim-treesitter, though it
--- needs to be user extensible also.
TSHighlighter.hl_map = {
["error"] = "Error",
@@ -87,8 +85,10 @@ function TSHighlighterQuery.new(lang, query_string)
hl = _link_default_highlight_once(lang .. hl, hl)
end
- rawset(table, capture, hl)
- return hl
+ local id = a.nvim_get_hl_id_by_name(hl)
+
+ rawset(table, capture, id)
+ return id
end
})
@@ -116,14 +116,14 @@ function TSHighlighterQuery:_get_hl_from_capture(capture)
-- From "Normal.left" only keep "Normal"
return vim.split(name, '.', true)[1], true
else
- return TSHighlighter.hl_map[name] or name, false
+ return TSHighlighter.hl_map[name] or 0, false
end
end
--- Creates a new highlighter using @param tree
---
---- @param tree The language tree to use for highlighting
---- @param opts Table used to configure the highlighter
+---@param tree The language tree to use for highlighting
+---@param opts Table used to configure the highlighter
--- - queries: Table to overwrite queries used by the highlighter
function TSHighlighter.new(tree, opts)
local self = setmetatable({}, TSHighlighter)
@@ -217,7 +217,7 @@ end
--- Gets the query used for @param lang
---
---- @param lang A language used by the highlighter.
+---@param lang A language used by the highlighter.
function TSHighlighter:get_query(lang)
if not self._queries[lang] then
self._queries[lang] = TSHighlighterQuery.new(lang)
@@ -248,7 +248,7 @@ local function on_line_impl(self, buf, line)
end
while line >= state.next_row do
- local capture, node = state.iter()
+ local capture, node, metadata = state.iter()
if capture == nil then break end
@@ -260,7 +260,7 @@ local function on_line_impl(self, buf, line)
{ end_line = end_row, end_col = end_col,
hl_group = hl,
ephemeral = true,
- priority = 100 -- Low but leaves room below
+ priority = tonumber(metadata.priority) or 100 -- Low but leaves room below
})
end
if start_row > line then
diff --git a/runtime/lua/vim/treesitter/language.lua b/runtime/lua/vim/treesitter/language.lua
index 6dc37c7848..89ddd6cd5a 100644
--- a/runtime/lua/vim/treesitter/language.lua
+++ b/runtime/lua/vim/treesitter/language.lua
@@ -6,9 +6,9 @@ local M = {}
---
--- Parsers are searched in the `parser` runtime directory.
---
---- @param lang The language the parser should parse
---- @param path Optional path the parser is located at
---- @param silent Don't throw an error if language not found
+---@param lang The language the parser should parse
+---@param path Optional path the parser is located at
+---@param silent Don't throw an error if language not found
function M.require_language(lang, path, silent)
if vim._ts_has_language(lang) then
return true
@@ -40,7 +40,7 @@ end
---
--- Inspecting provides some useful informations on the language like node names, ...
---
---- @param lang The language.
+---@param lang The language.
function M.inspect_language(lang)
M.require_language(lang)
return vim._ts_inspect_language(lang)
diff --git a/runtime/lua/vim/treesitter/languagetree.lua b/runtime/lua/vim/treesitter/languagetree.lua
index 899d90e464..7e392f72a4 100644
--- a/runtime/lua/vim/treesitter/languagetree.lua
+++ b/runtime/lua/vim/treesitter/languagetree.lua
@@ -9,12 +9,12 @@ LanguageTree.__index = LanguageTree
--- The language can contain child languages with in its range,
--- hence the tree.
---
---- @param source Can be a bufnr or a string of text to parse
---- @param lang The language this tree represents
---- @param opts Options table
---- @param opts.injections A table of language to injection query strings.
---- This is useful for overriding the built-in runtime file
---- searching for the injection language query per language.
+---@param source Can be a bufnr or a string of text to parse
+---@param lang The language this tree represents
+---@param opts Options table
+---@param opts.injections A table of language to injection query strings.
+--- This is useful for overriding the built-in runtime file
+--- searching for the injection language query per language.
function LanguageTree.new(source, lang, opts)
language.require_language(lang)
opts = opts or {}
@@ -171,8 +171,8 @@ end
--- Invokes the callback for each LanguageTree and it's children recursively
---
---- @param fn The function to invoke. This is invoked with arguments (tree: LanguageTree, lang: string)
---- @param include_self Whether to include the invoking tree in the results.
+---@param fn The function to invoke. This is invoked with arguments (tree: LanguageTree, lang: string)
+---@param include_self Whether to include the invoking tree in the results.
function LanguageTree:for_each_child(fn, include_self)
if include_self then
fn(self, self._lang)
@@ -187,8 +187,8 @@ end
---
--- Note, this includes the invoking language tree's trees as well.
---
---- @param fn The callback to invoke. The callback is invoked with arguments
---- (tree: TSTree, languageTree: LanguageTree)
+---@param fn The callback to invoke. The callback is invoked with arguments
+--- (tree: TSTree, languageTree: LanguageTree)
function LanguageTree:for_each_tree(fn)
for _, tree in ipairs(self._trees) do
fn(tree, self)
@@ -203,7 +203,7 @@ end
---
--- If the language already exists as a child, it will first be removed.
---
---- @param lang The language to add.
+---@param lang The language to add.
function LanguageTree:add_child(lang)
if self._children[lang] then
self:remove_child(lang)
@@ -219,7 +219,7 @@ end
--- Removes a child language from this tree.
---
---- @param lang The language to remove.
+---@param lang The language to remove.
function LanguageTree:remove_child(lang)
local child = self._children[lang]
@@ -259,7 +259,7 @@ end
---
--- Note, this call invalidates the tree and requires it to be parsed again.
---
---- @param regions A list of regions this tree should manage and parse.
+---@param regions A list of regions this tree should manage and parse.
function LanguageTree:set_included_regions(regions)
-- TODO(vigoux): I don't think string parsers are useful for now
if type(self._source) == "number" then
@@ -299,7 +299,7 @@ end
---
--- TODO: Allow for an offset predicate to tailor the injection range
--- instead of using the entire nodes range.
---- @private
+---@private
function LanguageTree:_get_injections()
if not self._injection_query then return {} end
@@ -449,7 +449,7 @@ function LanguageTree:_on_detach(...)
end
--- Registers callbacks for the parser
---- @param cbs An `nvim_buf_attach`-like table argument with the following keys :
+---@param cbs An `nvim_buf_attach`-like table argument with the following keys :
--- `on_bytes` : see `nvim_buf_attach`, but this will be called _after_ the parsers callback.
--- `on_changedtree` : a callback that will be called every time the tree has syntactical changes.
--- it will only be passed one argument, that is a table of the ranges (as node ranges) that
@@ -497,7 +497,7 @@ end
---
--- This goes down the tree to recursively check childs.
---
---- @param range A range, that is a `{ start_line, start_col, end_line, end_col }` table.
+---@param range A range, that is a `{ start_line, start_col, end_line, end_col }` table.
function LanguageTree:contains(range)
for _, tree in pairs(self._trees) do
if tree_contains(tree, range) then
@@ -510,7 +510,7 @@ end
--- Gets the appropriate language that contains @param range
---
---- @param range A text range, see |LanguageTree:contains|
+---@param range A text range, see |LanguageTree:contains|
function LanguageTree:language_for_range(range)
for _, child in pairs(self._children) do
if child:contains(range) then
diff --git a/runtime/lua/vim/treesitter/query.lua b/runtime/lua/vim/treesitter/query.lua
index b81eb18945..66da179ea3 100644
--- a/runtime/lua/vim/treesitter/query.lua
+++ b/runtime/lua/vim/treesitter/query.lua
@@ -36,9 +36,9 @@ end
--- Gets the list of files used to make up a query
---
---- @param lang The language
---- @param query_name The name of the query to load
---- @param is_included Internal parameter, most of the time left as `nil`
+---@param lang The language
+---@param query_name The name of the query to load
+---@param is_included Internal parameter, most of the time left as `nil`
function M.get_query_files(lang, query_name, is_included)
local query_path = string.format('queries/%s/%s.scm', lang, query_name)
local lang_files = dedupe_files(a.nvim_get_runtime_file(query_path, true))
@@ -112,19 +112,19 @@ local explicit_queries = setmetatable({}, {
--- This allows users to override any runtime files and/or configuration
--- set by plugins.
---
---- @param lang string: The language to use for the query
---- @param query_name string: The name of the query (i.e. "highlights")
---- @param text string: The query text (unparsed).
+---@param lang string: The language to use for the query
+---@param query_name string: The name of the query (i.e. "highlights")
+---@param text string: The query text (unparsed).
function M.set_query(lang, query_name, text)
explicit_queries[lang][query_name] = M.parse_query(lang, text)
end
--- Returns the runtime query {query_name} for {lang}.
---
---- @param lang The language to use for the query
---- @param query_name The name of the query (i.e. "highlights")
+---@param lang The language to use for the query
+---@param query_name The name of the query (i.e. "highlights")
---
---- @return The corresponding query, parsed.
+---@return The corresponding query, parsed.
function M.get_query(lang, query_name)
if explicit_queries[lang][query_name] then
return explicit_queries[lang][query_name]
@@ -151,10 +151,10 @@ end
--- -` info.captures` also points to `captures`.
--- - `info.patterns` contains information about predicates.
---
---- @param lang The language
---- @param query A string containing the query (s-expr syntax)
+---@param lang The language
+---@param query A string containing the query (s-expr syntax)
---
---- @returns The query
+---@returns The query
function M.parse_query(lang, query)
language.require_language(lang)
local self = setmetatable({}, Query)
@@ -168,8 +168,8 @@ end
--- Gets the text corresponding to a given node
---
---- @param node the node
---- @param bsource The buffer or string from which the node is extracted
+---@param node the node
+---@param bsource The buffer or string from which the node is extracted
function M.get_node_text(node, source)
local start_row, start_col, start_byte = node:start()
local end_row, end_col, end_byte = node:end_()
@@ -327,9 +327,9 @@ local directive_handlers = {
--- Adds a new predicate to be used in queries
---
---- @param name the name of the predicate, without leading #
---- @param handler the handler function to be used
---- signature will be (match, pattern, bufnr, predicate)
+---@param name the name of the predicate, without leading #
+---@param handler the handler function to be used
+--- signature will be (match, pattern, bufnr, predicate)
function M.add_predicate(name, handler, force)
if predicate_handlers[name] and not force then
error(string.format("Overriding %s", name))
@@ -340,9 +340,9 @@ end
--- Adds a new directive to be used in queries
---
---- @param name the name of the directive, without leading #
---- @param handler the handler function to be used
---- signature will be (match, pattern, bufnr, predicate)
+---@param name the name of the directive, without leading #
+---@param handler the handler function to be used
+--- signature will be (match, pattern, bufnr, predicate)
function M.add_directive(name, handler, force)
if directive_handlers[name] and not force then
error(string.format("Overriding %s", name))
@@ -351,7 +351,12 @@ function M.add_directive(name, handler, force)
directive_handlers[name] = handler
end
---- Returns the list of currently supported predicates
+---@return The list of supported directives.
+function M.list_directives()
+ return vim.tbl_keys(directive_handlers)
+end
+
+---@return The list of supported predicates.
function M.list_predicates()
return vim.tbl_keys(predicate_handlers)
end
@@ -460,13 +465,13 @@ end
--- end
--- </pre>
---
---- @param node The node under which the search will occur
---- @param source The source buffer or string to exctract text from
---- @param start The starting line of the search
---- @param stop The stopping line of the search (end-exclusive)
+---@param node The node under which the search will occur
+---@param source The source buffer or string to exctract text from
+---@param start The starting line of the search
+---@param stop The stopping line of the search (end-exclusive)
---
---- @returns The matching capture id
---- @returns The captured node
+---@returns The matching capture id
+---@returns The captured node
function Query:iter_captures(node, source, start, stop)
if type(source) == "number" and source == 0 then
source = vim.api.nvim_get_current_buf()
@@ -517,13 +522,13 @@ end
--- end
--- </pre>
---
---- @param node The node under which the search will occur
---- @param source The source buffer or string to search
---- @param start The starting line of the search
---- @param stop The stopping line of the search (end-exclusive)
+---@param node The node under which the search will occur
+---@param source The source buffer or string to search
+---@param start The starting line of the search
+---@param stop The stopping line of the search (end-exclusive)
---
---- @returns The matching pattern id
---- @returns The matching match
+---@returns The matching pattern id
+---@returns The matching match
function Query:iter_matches(node, source, start, stop)
if type(source) == "number" and source == 0 then
source = vim.api.nvim_get_current_buf()
diff --git a/runtime/lua/vim/ui.lua b/runtime/lua/vim/ui.lua
new file mode 100644
index 0000000000..5eab20fc54
--- /dev/null
+++ b/runtime/lua/vim/ui.lua
@@ -0,0 +1,36 @@
+local M = {}
+
+--- Prompts the user to pick a single item from a collection of entries
+---
+---@param items table Arbitrary items
+---@param opts table Additional options
+--- - prompt (string|nil)
+--- Text of the prompt. Defaults to `Select one of:`
+--- - format_item (function item -> text)
+--- Function to format an
+--- individual item from `items`. Defaults to `tostring`.
+---@param on_choice function ((item|nil, idx|nil) -> ())
+--- Called once the user made a choice.
+--- `idx` is the 1-based index of `item` within `item`.
+--- `nil` if the user aborted the dialog.
+function M.select(items, opts, on_choice)
+ vim.validate {
+ items = { items, 'table', false },
+ on_choice = { on_choice, 'function', false },
+ }
+ opts = opts or {}
+ local choices = {opts.prompt or 'Select one of:'}
+ local format_item = opts.format_item or tostring
+ for i, item in pairs(items) do
+ table.insert(choices, string.format('%d: %s', i, format_item(item)))
+ end
+ local choice = vim.fn.inputlist(choices)
+ if choice < 1 or choice > #items then
+ on_choice(nil, nil)
+ else
+ on_choice(items[choice], choice)
+ end
+end
+
+
+return M
diff --git a/runtime/lua/vim/uri.lua b/runtime/lua/vim/uri.lua
index f1a12c72ec..a3e79a0f2b 100644
--- a/runtime/lua/vim/uri.lua
+++ b/runtime/lua/vim/uri.lua
@@ -9,7 +9,7 @@ do
local schar = string.char
--- Convert hex to char
- --@private
+ ---@private
local function hex_to_char(hex)
return schar(tonumber(hex, 16))
end
@@ -38,7 +38,7 @@ do
tohex = function(b) return string.format("%02x", b) end
end
- --@private
+ ---@private
local function percent_encode_char(char)
return "%"..tohex(sbyte(char), 2)
end
@@ -50,14 +50,14 @@ do
end
---@private
+---@private
local function is_windows_file_uri(uri)
- return uri:match('^file:///[a-zA-Z]:') ~= nil
+ return uri:match('^file:/+[a-zA-Z]:') ~= nil
end
--- Get a URI from a file path.
---@param path (string): Path to file
---@return URI
+---@param path (string): Path to file
+---@return URI
local function uri_from_fname(path)
local volume_path, fname = path:match("^([a-zA-Z]:)(.*)")
local is_windows = volume_path ~= nil
@@ -74,11 +74,11 @@ local function uri_from_fname(path)
return table.concat(uri_parts)
end
-local URI_SCHEME_PATTERN = '^([a-zA-Z]+[a-zA-Z0-9+-.]*)://.*'
+local URI_SCHEME_PATTERN = '^([a-zA-Z]+[a-zA-Z0-9+-.]*):.*'
--- Get a URI from a bufnr
---@param bufnr (number): Buffer number
---@return URI
+---@param bufnr (number): Buffer number
+---@return URI
local function uri_from_bufnr(bufnr)
local fname = vim.api.nvim_buf_get_name(bufnr)
local scheme = fname:match(URI_SCHEME_PATTERN)
@@ -90,8 +90,8 @@ local function uri_from_bufnr(bufnr)
end
--- Get a filename from a URI
---@param uri (string): The URI
---@return Filename
+---@param uri (string): The URI
+---@return Filename
local function uri_to_fname(uri)
local scheme = assert(uri:match(URI_SCHEME_PATTERN), 'URI must contain a scheme: ' .. uri)
if scheme ~= 'file' then
@@ -100,18 +100,18 @@ local function uri_to_fname(uri)
uri = uri_decode(uri)
-- TODO improve this.
if is_windows_file_uri(uri) then
- uri = uri:gsub('^file:///', '')
+ uri = uri:gsub('^file:/+', '')
uri = uri:gsub('/', '\\')
else
- uri = uri:gsub('^file://', '')
+ uri = uri:gsub('^file:/+', '/')
end
return uri
end
--- Return or create a buffer for a uri.
---@param uri (string): The URI
---@return bufnr.
---@note Creates buffer but does not load it
+---@param uri (string): The URI
+---@return bufnr.
+---@note Creates buffer but does not load it
local function uri_to_bufnr(uri)
local scheme = assert(uri:match(URI_SCHEME_PATTERN), 'URI must contain a scheme: ' .. uri)
if scheme == 'file' then
diff --git a/runtime/nvim.appdata.xml b/runtime/nvim.appdata.xml
index e99c76a930..099c9a57c0 100644
--- a/runtime/nvim.appdata.xml
+++ b/runtime/nvim.appdata.xml
@@ -26,6 +26,7 @@
</screenshots>
<releases>
+ <release date="2021-07-02" version="0.5.0"/>
<release date="2020-08-04" version="0.4.4"/>
<release date="2019-11-06" version="0.4.3"/>
<release date="2019-09-15" version="0.4.2"/>
diff --git a/runtime/optwin.vim b/runtime/optwin.vim
index 633cb9e509..d4c10f7afa 100644
--- a/runtime/optwin.vim
+++ b/runtime/optwin.vim
@@ -440,6 +440,9 @@ if has("syntax")
call append("$", "cursorline\thighlight the screen line of the cursor")
call append("$", "\t(local to window)")
call <SID>BinOptionL("cul")
+ call append("$", "cursorlineopt\tspecifies which area 'cursorline' highlights")
+ call append("$", "\t(local to window)")
+ call <SID>OptionL("culopt")
call append("$", "colorcolumn\tcolumns to highlight")
call append("$", "\t(local to window)")
call <SID>OptionL("cc")
diff --git a/runtime/pack/dist/opt/matchit/doc/matchit.txt b/runtime/pack/dist/opt/matchit/doc/matchit.txt
index 3cd2c8e2a7..58a47780ef 100644
--- a/runtime/pack/dist/opt/matchit/doc/matchit.txt
+++ b/runtime/pack/dist/opt/matchit/doc/matchit.txt
@@ -4,7 +4,7 @@ For instructions on installing this file, type
`:help matchit-install`
inside Vim.
-For Vim version 8.1. Last change: 2020 Mar 01
+For Vim version 8.1. Last change: 2021 May 17
VIM REFERENCE MANUAL by Benji Fisher et al
@@ -322,7 +322,7 @@ should work (and have the same effect as "foobar:barfoo:endfoobar"), although
this has not been thoroughly tested.
You can use |zero-width| patterns such as |\@<=| and |\zs|. (The latter has
-not been thouroughly tested in matchit.vim.) For example, if the keyword "if"
+not been thoroughly tested in matchit.vim.) For example, if the keyword "if"
must occur at the start of the line, with optional white space, you might use
the pattern "\(^\s*\)\@<=if" so that the cursor will end on the "i" instead of
at the start of the line. For another example, if HTML had only one tag then
diff --git a/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim b/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim
index ae1274f81f..8057d7f284 100644
--- a/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim
+++ b/runtime/pack/dist/opt/termdebug/plugin/termdebug.vim
@@ -2,7 +2,7 @@
"
" Author: Bram Moolenaar
" Copyright: Vim license applies, see ":help license"
-" Last Change: 2021 May 16
+" Last Change: 2021 Aug 23
"
" WORK IN PROGRESS - Only the basics work
" Note: On MS-Windows you need a recent version of gdb. The one included with
@@ -127,6 +127,10 @@ func s:StartDebug_internal(dict)
let s:pid = 0
let s:asmwin = 0
+ if exists('#User#TermdebugStartPre')
+ doauto <nomodeline> User TermdebugStartPre
+ endif
+
" Uncomment this line to write logging in "debuglog".
" call ch_logfile('debuglog', 'w')
@@ -173,6 +177,10 @@ func s:StartDebug_internal(dict)
call win_gotoid(curwinid)
endif
endif
+
+ if exists('#User#TermdebugStartPost')
+ doauto <nomodeline> User TermdebugStartPost
+ endif
endfunc
" Use when debugger didn't start or ended.
@@ -181,6 +189,15 @@ func s:CloseBuffers()
unlet! s:gdbwin
endfunc
+func s:CheckGdbRunning()
+ if nvim_get_chan_info(s:gdb_job_id) == {}
+ echoerr string(g:termdebugger) . ' exited unexpectedly'
+ call s:CloseBuffers()
+ return ''
+ endif
+ return 'ok'
+endfunc
+
func s:StartDebug_term(dict)
" Open a terminal window without a job, to run the debugged program in.
execute s:vertical ? 'vnew' : 'new'
@@ -229,7 +246,7 @@ func s:StartDebug_term(dict)
let gdb_args = get(a:dict, 'gdb_args', [])
let proc_args = get(a:dict, 'proc_args', [])
- let cmd = [g:termdebugger, '-quiet', '-tty', pty] + gdb_args
+ let cmd = [g:termdebugger, '-quiet', '-tty', pty, '--eval-command', 'echo startupdone\n'] + gdb_args
"call ch_log('executing "' . join(cmd) . '"')
execute 'new'
let s:gdb_job_id = termopen(cmd, {'on_exit': function('s:EndTermDebug')})
@@ -246,9 +263,28 @@ func s:StartDebug_term(dict)
let s:gdbbuf = gdb_job_info['buffer']
let s:gdbwin = win_getid(winnr())
- " Set arguments to be run. First wait a bit to make detecting gdb a bit
- " more reliable.
- sleep 200m
+ " Wait for the "startupdone" message before sending any commands.
+ let try_count = 0
+ while 1
+ if s:CheckGdbRunning() != 'ok'
+ return
+ endif
+
+ for lnum in range(1, 200)
+ if get(getbufline(s:gdbbuf, lnum), 0, '') =~ 'startupdone'
+ let try_count = 9999
+ break
+ endif
+ endfor
+ let try_count += 1
+ if try_count > 300
+ " done or give up after five seconds
+ break
+ endif
+ sleep 10m
+ endwhile
+
+ " Set arguments to be run.
if len(proc_args)
call chansend(s:gdb_job_id, 'set args ' . join(proc_args) . "\r")
endif
@@ -260,9 +296,7 @@ func s:StartDebug_term(dict)
" why the debugger doesn't work.
let try_count = 0
while 1
- if nvim_get_chan_info(s:gdb_job_id) == {}
- echoerr string(g:termdebugger) . ' exited unexpectedly'
- call s:CloseBuffers()
+ if s:CheckGdbRunning() != 'ok'
return
endif
@@ -309,6 +343,9 @@ func s:StartDebug_term(dict)
" "Type <return> to continue" prompt.
call s:SendCommand('set pagination off')
+ " Set the filetype, this can be used to add mappings.
+ set filetype=termdebug
+
call s:StartDebugCommon(a:dict)
endfunc
@@ -597,6 +634,10 @@ func s:GetAsmAddr(msg)
endfunc
function s:EndTermDebug(job_id, exit_code, event)
+ if exists('#User#TermdebugStopPre')
+ doauto <nomodeline> User TermdebugStopPre
+ endif
+
unlet s:gdbwin
call s:EndDebugCommon()
@@ -631,10 +672,18 @@ func s:EndDebugCommon()
let &columns = s:save_columns
endif
+ if exists('#User#TermdebugStopPost')
+ doauto <nomodeline> User TermdebugStopPost
+ endif
+
au! TermDebug
endfunc
func s:EndPromptDebug(job_id, exit_code, event)
+ if exists('#User#TermdebugStopPre')
+ doauto <nomodeline> User TermdebugStopPre
+ endif
+
let curwinid = win_getid(winnr())
call win_gotoid(s:gdbwin)
close
@@ -777,7 +826,14 @@ func s:InstallCommands()
command Winbar call s:InstallWinbar()
if !exists('g:termdebug_map_K') || g:termdebug_map_K
- let s:k_map_saved = maparg('K', 'n', 0, 1)
+ " let s:k_map_saved = maparg('K', 'n', 0, 1)
+ let s:k_map_saved = {}
+ for map in nvim_get_keymap('n')
+ if map.lhs ==# 'K'
+ let s:k_map_saved = map
+ break
+ endif
+ endfor
nnoremap K :Evaluate<CR>
endif
@@ -821,7 +877,15 @@ func s:DeleteCommands()
if empty(s:k_map_saved)
nunmap K
else
- call mapset('n', 0, s:k_map_saved)
+ " call mapset('n', 0, s:k_map_saved)
+ let mode = s:k_map_saved.mode !=# ' ' ? s:k_map_saved.mode : ''
+ call nvim_set_keymap(mode, 'K', s:k_map_saved.rhs, {
+ \ 'expr': s:k_map_saved.expr ? v:true : v:false,
+ \ 'noremap': s:k_map_saved.noremap ? v:true : v:false,
+ \ 'nowait': s:k_map_saved.nowait ? v:true : v:false,
+ \ 'script': s:k_map_saved.script ? v:true : v:false,
+ \ 'silent': s:k_map_saved.silent ? v:true : v:false,
+ \ })
endif
unlet s:k_map_saved
endif
diff --git a/runtime/plugin/diagnostic.vim b/runtime/plugin/diagnostic.vim
new file mode 100644
index 0000000000..2183623ac8
--- /dev/null
+++ b/runtime/plugin/diagnostic.vim
@@ -0,0 +1,26 @@
+" :help vim.diagnostic
+
+hi default DiagnosticError ctermfg=1 guifg=Red
+hi default DiagnosticWarn ctermfg=3 guifg=Orange
+hi default DiagnosticInfo ctermfg=4 guifg=LightBlue
+hi default DiagnosticHint ctermfg=7 guifg=LightGrey
+
+hi default DiagnosticUnderlineError cterm=underline gui=underline guisp=Red
+hi default DiagnosticUnderlineWarn cterm=underline gui=underline guisp=Orange
+hi default DiagnosticUnderlineInfo cterm=underline gui=underline guisp=LightBlue
+hi default DiagnosticUnderlineHint cterm=underline gui=underline guisp=LightGrey
+
+hi default link DiagnosticVirtualTextError DiagnosticError
+hi default link DiagnosticVirtualTextWarn DiagnosticWarn
+hi default link DiagnosticVirtualTextInfo DiagnosticInfo
+hi default link DiagnosticVirtualTextHint DiagnosticHint
+
+hi default link DiagnosticFloatingError DiagnosticError
+hi default link DiagnosticFloatingWarn DiagnosticWarn
+hi default link DiagnosticFloatingInfo DiagnosticInfo
+hi default link DiagnosticFloatingHint DiagnosticHint
+
+hi default link DiagnosticSignError DiagnosticError
+hi default link DiagnosticSignWarn DiagnosticWarn
+hi default link DiagnosticSignInfo DiagnosticInfo
+hi default link DiagnosticSignHint DiagnosticHint
diff --git a/runtime/plugin/man.vim b/runtime/plugin/man.vim
index 689aa32ef3..b10677593f 100644
--- a/runtime/plugin/man.vim
+++ b/runtime/plugin/man.vim
@@ -5,8 +5,8 @@ if exists('g:loaded_man')
endif
let g:loaded_man = 1
-command! -bang -bar -range=-1 -complete=customlist,man#complete -nargs=* Man
- \ if <bang>0 | set ft=man |
+command! -bang -bar -addr=other -complete=customlist,man#complete -nargs=* Man
+ \ if <bang>0 | call man#init_pager() |
\ else | call man#open_page(<count>, <q-mods>, <f-args>) | endif
augroup man
diff --git a/runtime/plugin/netrwPlugin.vim b/runtime/plugin/netrwPlugin.vim
index 217a7795c9..d309f81484 100644
--- a/runtime/plugin/netrwPlugin.vim
+++ b/runtime/plugin/netrwPlugin.vim
@@ -1,9 +1,9 @@
" netrwPlugin.vim: Handles file transfer and remote directory listing across a network
" PLUGIN SECTION
-" Date: Feb 08, 2016 - Jan 07, 2020
+" Date: Feb 09, 2021
" Maintainer: Charles E Campbell <NcampObell@SdrPchip.AorgM-NOSPAM>
" GetLatestVimScripts: 1075 1 :AutoInstall: netrw.vim
-" Copyright: Copyright (C) 1999-2013 Charles E. Campbell {{{1
+" Copyright: Copyright (C) 1999-2021 Charles E. Campbell {{{1
" Permission is hereby granted to use and distribute this code,
" with or without modifications, provided that this copyright
" notice is copied with it. Like anything else that's free,
@@ -20,7 +20,7 @@
if &cp || exists("g:loaded_netrwPlugin")
finish
endif
-let g:loaded_netrwPlugin = "v170"
+let g:loaded_netrwPlugin = "v171"
let s:keepcpo = &cpo
set cpo&vim
"DechoRemOn
@@ -83,11 +83,11 @@ if !exists("g:netrw_nogx")
endif
nno <silent> <Plug>NetrwBrowseX :call netrw#BrowseX(netrw#GX(),netrw#CheckIfRemote(netrw#GX()))<cr>
endif
- if maparg('gx','v') == ""
+ if maparg('gx','x') == ""
if !hasmapto('<Plug>NetrwBrowseXVis')
- vmap <unique> gx <Plug>NetrwBrowseXVis
+ xmap <unique> gx <Plug>NetrwBrowseXVis
endif
- vno <silent> <Plug>NetrwBrowseXVis :<c-u>call netrw#BrowseXVis()<cr>
+ xno <silent> <Plug>NetrwBrowseXVis :<c-u>call netrw#BrowseXVis()<cr>
endif
endif
if exists("g:netrw_usetab") && g:netrw_usetab
@@ -129,7 +129,9 @@ fun! s:LocalBrowse(dirname)
elseif isdirectory(a:dirname)
" call Decho("(LocalBrowse) dirname<".a:dirname."> ft=".&ft." (isdirectory, not amiga)")
" call Dredir("LocalBrowse ft last set: ","verbose set ft")
- sil! call netrw#LocalBrowseCheck(a:dirname)
+ " Jul 13, 2021: for whatever reason, preceding the following call with
+ " a sil! causes an unbalanced if-endif vim error
+ call netrw#LocalBrowseCheck(a:dirname)
if exists("w:netrw_bannercnt") && line('.') < w:netrw_bannercnt
exe w:netrw_bannercnt
endif
@@ -151,10 +153,22 @@ endfun
" has already been called.
fun! s:VimEnter(dirname)
" call Dfunc("s:VimEnter(dirname<".a:dirname.">) expand(%)<".expand("%").">")
+ if has('nvim') || v:version < 802
+ " Johann Höchtl: reported that the call range... line causes an E488: Trailing characters
+ " error with neovim. I suspect its because neovim hasn't updated with recent
+ " vim patches. As is, this code will have problems with popup terminals
+ " instantiated before the VimEnter event runs.
+ " Ingo Karkat : E488 also in Vim 8.1.1602
let curwin = winnr()
let s:vimentered = 1
windo call s:LocalBrowse(expand("%:p"))
exe curwin."wincmd w"
+ else
+ " the following complicated expression comes courtesy of lacygoill; largely does the same thing as the windo and
+ " wincmd which are commented out, but avoids some side effects. Allows popup terminal before VimEnter.
+ let s:vimentered = 1
+ call range(1, winnr('$'))->map({_, v -> win_execute(win_getid(v), 'call expand("%:p")->s:LocalBrowse()')})
+ endif
" call Dret("s:VimEnter")
endfun
diff --git a/runtime/plugin/tohtml.vim b/runtime/plugin/tohtml.vim
index 2c85b57529..08df19b4f9 100644
--- a/runtime/plugin/tohtml.vim
+++ b/runtime/plugin/tohtml.vim
@@ -62,7 +62,7 @@ let g:loaded_2html_plugin = 'vim8.1_v2'
" 7.3_v14 (Vim 7.3.1246): Allow suppressing line number anchors using
" g:html_line_ids=0. Allow customizing
" important IDs (like line IDs and fold IDs) using
-" g:html_id_expr evalutated when the buffer conversion
+" g:html_id_expr evaluated when the buffer conversion
" is started.
" 7.3_v13 (Vim 7.3.1088): Keep foldmethod at manual in the generated file and
" insert modeline to set it to manual.
diff --git a/runtime/syntax/2html.vim b/runtime/syntax/2html.vim
index 4afdff2899..8adbd76950 100644
--- a/runtime/syntax/2html.vim
+++ b/runtime/syntax/2html.vim
@@ -499,7 +499,7 @@ if s:settings.prevent_copy =~# 'n'
endif
elseif s:settings.line_ids
" if lines are not being numbered the only reason this function gets called
- " is to put the line IDs on each line; "text" will be emtpy but lnr will
+ " is to put the line IDs on each line; "text" will be empty but lnr will
" always be non-zero, however we don't want to use the <input> because that
" won't work as nice for empty text
function! s:HtmlFormat_n(text, style_id, diff_style_id, lnr)
@@ -1034,7 +1034,7 @@ if !s:settings.no_progress
" ProgressBar Indicator
let s:progressbar={}
- " Progessbar specific functions
+ " Progressbar specific functions
func! s:SetProgbarColor()
if hlID("TOhtmlProgress") != 0
diff --git a/runtime/syntax/8th.vim b/runtime/syntax/8th.vim
index ddc1084c9f..d543489b72 100644
--- a/runtime/syntax/8th.vim
+++ b/runtime/syntax/8th.vim
@@ -293,7 +293,7 @@ syn region eighthComment start="\zs\\" end="$" contains=eighthTodo
" Define the default highlighting.
if !exists("did_eighth_syntax_inits")
let did_eighth_syntax_inits=1
- " The default methods for highlighting. Can be overriden later.
+ " The default methods for highlighting. Can be overridden later.
hi def link eighthTodo Todo
hi def link eighthOperators Operator
hi def link eighthMath Number
diff --git a/runtime/syntax/abel.vim b/runtime/syntax/abel.vim
index 67d7e4f786..dbed541ba8 100644
--- a/runtime/syntax/abel.vim
+++ b/runtime/syntax/abel.vim
@@ -59,7 +59,7 @@ syn region abelSpecifier start='istype' end=';' contains=abelTypeIdChar,abelType
syn match abelTypeIdChar "[,']" contained
syn match abelTypeIdEnd ";" contained
-" string contstants and special characters within them
+" string constants and special characters within them
syn match abelSpecial contained "\\['\\]"
syn region abelString start=+'+ skip=+\\"+ end=+'+ contains=abelSpecial
diff --git a/runtime/syntax/ada.vim b/runtime/syntax/ada.vim
index c9d2b06e18..415c9522fb 100644
--- a/runtime/syntax/ada.vim
+++ b/runtime/syntax/ada.vim
@@ -159,7 +159,7 @@ endif
" Section: end {{{1
" Unless special ("end loop", "end if", etc.), "end" marks the end of a
-" begin, package, task etc. Assiging it to adaEnd.
+" begin, package, task etc. Assigning it to adaEnd.
syntax match adaEnd /\<end\>/
syntax keyword adaPreproc pragma
diff --git a/runtime/syntax/ahdl.vim b/runtime/syntax/ahdl.vim
index 664bd3837d..3a40dcfaea 100644
--- a/runtime/syntax/ahdl.vim
+++ b/runtime/syntax/ahdl.vim
@@ -38,7 +38,7 @@ syn keyword ahdlMegafunction lpm_rom lpm_dff lpm_tff clklock pll ntsc
syn keyword ahdlTodo contained TODO
-" String contstants
+" String constants
syn region ahdlString start=+"+ skip=+\\"+ end=+"+
" valid integer number formats (decimal, binary, octal, hex)
diff --git a/runtime/syntax/aptconf.vim b/runtime/syntax/aptconf.vim
index 8cb14321e2..d51e7bdfa9 100644
--- a/runtime/syntax/aptconf.vim
+++ b/runtime/syntax/aptconf.vim
@@ -1,7 +1,7 @@
" Vim syntax file
" Language: APT config file
" Maintainer: Yann Amar <quidame@poivron.org>
-" Last Change: 2015 Dec 22
+" Last Change: 2021 Jul 12
" quit when a syntax file was already loaded
if !exists("main_syntax")
@@ -396,10 +396,13 @@ syn cluster aptconfSynaptic_ contains=aptconfSynaptic,
" }}}
" Unattended Upgrade: {{{
syn keyword aptconfUnattendedUpgrade contained
- \ AutoFixInterruptedDpkg Automatic-Reboot Automatic-Reboot-Time
- \ Automatic-Reboot-WithUsers InstallOnShutdown Mail MailOnlyOnError
- \ MinimalSteps Origins-Pattern Package-Blacklist
- \ Remove-Unused-Dependencies
+ \ Allow-APT-Mark-Fallback Allow-downgrade AutoFixInterruptedDpkg
+ \ Automatic-Reboot Automatic-Reboot-Time Automatic-Reboot-WithUsers
+ \ Debug InstallOnShutdown Mail MailOnlyOnError MailReport MinimalSteps
+ \ OnlyOnACPower Origins-Pattern Package-Blacklist
+ \ Remove-New-Unused-Dependencies Remove-Unused-Dependencies
+ \ Remove-Unused-Kernel-Packages Skip-Updates-On-Metered-Connections
+ \ SyslogEnable SyslogFacility Verbose
syn cluster aptconfUnattendedUpgrade_ contains=aptconfUnattendedUpgrade
" }}}
diff --git a/runtime/syntax/aspvbs.vim b/runtime/syntax/aspvbs.vim
index f0861d8b5a..08db416ef9 100644
--- a/runtime/syntax/aspvbs.vim
+++ b/runtime/syntax/aspvbs.vim
@@ -108,7 +108,7 @@ syn match AspVBSMethods contained "Response\.\w*"
" Colorize boolean constants:
syn keyword AspVBSMethods contained true false
-" AspVBScript Number Contstants
+" AspVBScript Number Constants
" Integer number, or floating point number without a dot.
syn match AspVBSNumber contained "\<\d\+\>"
" Floating point number, with dot
@@ -116,7 +116,7 @@ syn match AspVBSNumber contained "\<\d\+\.\d*\>"
" Floating point number, starting with a dot
syn match AspVBSNumber contained "\.\d\+\>"
-" String and Character Contstants
+" String and Character Constants
" removed (skip=+\\\\\|\\"+) because VB doesn't have backslash escaping in
" strings (or does it?)
syn region AspVBSString contained start=+"+ end=+"+ keepend
@@ -143,7 +143,7 @@ syn cluster AspVBScriptTop contains=AspVBSStatement,AspVBSFunction,AspVBSMethods
syn region AspVBSFold start="^\s*\(class\)\s\+.*$" end="^\s*end\s\+\(class\)\>.*$" fold contained transparent keepend
syn region AspVBSFold start="^\s*\(private\|public\)\=\(\s\+default\)\=\s\+\(sub\|function\)\s\+.*$" end="^\s*end\s\+\(function\|sub\)\>.*$" fold contained transparent keepend
-" Define AspVBScript delimeters
+" Define AspVBScript delimiters
" <%= func("string_with_%>_in_it") %> This is illegal in ASP syntax.
syn region AspVBScriptInsideHtmlTags keepend matchgroup=Delimiter start=+<%=\=+ end=+%>+ contains=@AspVBScriptTop, AspVBSFold
syn region AspVBScriptInsideHtmlTags keepend matchgroup=Delimiter start=+<script\s\+language="\=vbscript"\=[^>]*\s\+runatserver[^>]*>+ end=+</script>+ contains=@AspVBScriptTop
diff --git a/runtime/syntax/c.vim b/runtime/syntax/c.vim
index d07aaf2658..20f8632006 100644
--- a/runtime/syntax/c.vim
+++ b/runtime/syntax/c.vim
@@ -1,7 +1,7 @@
" Vim syntax file
" Language: C
" Maintainer: Bram Moolenaar <Bram@vim.org>
-" Last Change: 2021 Jan 11
+" Last Change: 2021 May 24
" Quit when a (custom) syntax file was already loaded
if exists("b:current_syntax")
@@ -414,6 +414,9 @@ if exists("c_autodoc")
syn cluster cPreProcGroup add=cAutodocReal
endif
+" be able to fold #pragma regions
+syn region cPragma start="^\s*#pragma\s\+region\>" end="^\s*#pragma\s\+endregion\>" transparent keepend extend fold
+
" Highlight User Labels
syn cluster cMultiGroup contains=cIncluded,cSpecial,cCommentSkip,cCommentString,cComment2String,@cCommentGroup,cCommentStartError,cUserCont,cUserLabel,cBitField,cOctalZero,cCppOutWrapper,cCppInWrapper,@cCppOutInGroup,cFormat,cNumber,cFloat,cOctal,cOctalError,cNumbersCom,cCppParen,cCppBracket,cCppString
if s:ft ==# 'c' || exists("cpp_no_cpp11")
diff --git a/runtime/syntax/cfg.vim b/runtime/syntax/cfg.vim
index a50297d418..f347b1379f 100644
--- a/runtime/syntax/cfg.vim
+++ b/runtime/syntax/cfg.vim
@@ -32,7 +32,7 @@ syn match CfgComment "#.*"
syn match CfgComment ";.*"
syn match CfgComment "\/\/.*"
-" Define the default hightlighting.
+" Define the default highlighting.
" Only when an item doesn't have highlighting yet
hi def link CfgOnOff Label
hi def link CfgComment Comment
diff --git a/runtime/syntax/chicken.vim b/runtime/syntax/chicken.vim
index c3f949f823..806d08fbb7 100644
--- a/runtime/syntax/chicken.vim
+++ b/runtime/syntax/chicken.vim
@@ -1,8 +1,9 @@
" Vim syntax file
" Language: Scheme (CHICKEN)
-" Last Change: 2018-02-05
+" Last Change: 2021 Jul 30
" Author: Evan Hanson <evhan@foldling.org>
" Maintainer: Evan Hanson <evhan@foldling.org>
+" Repository: https://git.foldling.org/vim-scheme.git
" URL: https://foldling.org/vim/syntax/chicken.vim
" Notes: This is supplemental syntax, to be loaded after the core Scheme
" syntax file (syntax/scheme.vim). Enable it by setting b:is_chicken=1
@@ -36,9 +37,23 @@ if len(s:c)
syn region c matchgroup=schemeComment start=/#>/ end=/<#/ contains=@c
endif
+# SRFI 26
+syn match schemeSyntax /\(([ \t\n]*\)\@<=\(cut\|cute\)\>/
+
+syn keyword schemeSyntax and-let*
syn keyword schemeSyntax define-record
+syn keyword schemeSyntax set!-values
+syn keyword schemeSyntax fluid-let
+syn keyword schemeSyntax let-optionals
+syn keyword schemeSyntax let-optionals*
+syn keyword schemeSyntax letrec-values
+syn keyword schemeSyntax nth-value
+syn keyword schemeSyntax receive
syn keyword schemeLibrarySyntax declare
+syn keyword schemeLibrarySyntax define-interface
+syn keyword schemeLibrarySyntax functor
+syn keyword schemeLibrarySyntax include-relative
syn keyword schemeLibrarySyntax module
syn keyword schemeLibrarySyntax reexport
syn keyword schemeLibrarySyntax require-library
@@ -52,10 +67,12 @@ syn keyword schemeTypeSyntax define-specialization
syn keyword schemeTypeSyntax define-type
syn keyword schemeTypeSyntax the
-syn keyword schemeExtraSyntax and-let*
syn keyword schemeExtraSyntax match
syn keyword schemeExtraSyntax match-lambda
syn keyword schemeExtraSyntax match-lambda*
+syn keyword schemeExtraSyntax match-let
+syn keyword schemeExtraSyntax match-let*
+syn keyword schemeExtraSyntax match-letrec
syn keyword schemeSpecialSyntax define-compiler-syntax
syn keyword schemeSpecialSyntax define-constant
diff --git a/runtime/syntax/cpp.vim b/runtime/syntax/cpp.vim
index ed38913f29..5437580a0a 100644
--- a/runtime/syntax/cpp.vim
+++ b/runtime/syntax/cpp.vim
@@ -2,7 +2,7 @@
" Language: C++
" Current Maintainer: vim-jp (https://github.com/vim-jp/vim-cpp)
" Previous Maintainer: Ken Shan <ccshan@post.harvard.edu>
-" Last Change: 2021 Jan 12
+" Last Change: 2021 Aug 23
" quit when a syntax file was already loaded
if exists("b:current_syntax")
@@ -44,22 +44,54 @@ if !exists("cpp_no_cpp11")
syn keyword cppConstant ATOMIC_WCHAR_T_LOCK_FREE ATOMIC_SHORT_LOCK_FREE
syn keyword cppConstant ATOMIC_INT_LOCK_FREE ATOMIC_LONG_LOCK_FREE
syn keyword cppConstant ATOMIC_LLONG_LOCK_FREE ATOMIC_POINTER_LOCK_FREE
- syn region cppRawString matchgroup=cppRawStringDelimiter start=+\%(u8\|[uLU]\)\=R"\z([[:alnum:]_{}[\]#<>%:;.?*\+\-/\^&|~!=,"']\{,16}\)(+ end=+)\z1"+ contains=@Spell
+ syn region cppRawString matchgroup=cppRawStringDelimiter start=+\%(u8\|[uLU]\)\=R"\z([[:alnum:]_{}[\]#<>%:;.?*\+\-/\^&|~!=,"']\{,16}\)(+ end=+)\z1"\(sv\|s\|_[_a-zA-Z][_a-zA-Z0-9]*\)\=+ contains=@Spell
syn match cppCast "\<\(const\|static\|dynamic\)_pointer_cast\s*<"me=e-1
syn match cppCast "\<\(const\|static\|dynamic\)_pointer_cast\s*$"
endif
" C++ 14 extensions
if !exists("cpp_no_cpp14")
- syn case ignore
- syn match cppNumber display "\<0b[01]\('\=[01]\+\)*\(u\=l\{0,2}\|ll\=u\)\>"
- syn match cppNumber display "\<[1-9]\('\=\d\+\)*\(u\=l\{0,2}\|ll\=u\)\>" contains=cFloat
- syn match cppNumber display "\<0x\x\('\=\x\+\)*\(u\=l\{0,2}\|ll\=u\)\>"
- syn case match
+ syn match cppNumbers display transparent "\<\d\|\.\d" contains=cppNumber,cppFloat
+ syn match cppNumber display contained "\<0\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
+ syn match cppNumber display contained "\<[1-9]\('\=\d\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
+ syn match cppNumber display contained "\<0\o\+\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
+ syn match cppNumber display contained "\<0b[01]\('\=[01]\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
+ syn match cppNumber display contained "\<0x\x\('\=\x\+\)*\([Uu]\=\([Ll]\|LL\|ll\)\|\([Ll]\|LL\|ll\)\=[Uu]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
+ syn match cppFloat display contained "\<\d\+\.\d*\(e[-+]\=\d\+\)\=\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
+ syn match cppFloat display contained "\<\.\d\+\(e[-+]\=\d\+\)\=\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
+ syn match cppFloat display contained "\<\d\+e[-+]\=\d\+\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
+ syn region cppString start=+\(L\|u\|u8\|U\)\="+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"\(sv\|s\|_\i*\)\=+ end='$' contains=cSpecial,cFormat,@Spell
+endif
+
+" C++ 17 extensions
+if !exists("cpp_no_cpp17")
+ syn match cppCast "\<reinterpret_pointer_cast\s*<"me=e-1
+ syn match cppCast "\<reinterpret_pointer_cast\s*$"
+ syn match cppFloat display contained "\<0x\x*\.\x\+p[-+]\=\d\+\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
+ syn match cppFloat display contained "\<0x\x\+\.\=p[-+]\=\d\+\([FfLl]\|i[fl]\=\|h\|min\|s\|ms\|us\|ns\|_\i*\)\=\>"
+
+ " TODO: push this up to c.vim if/when supported in C23
+ syn match cppCharacter "u8'[^\\]'"
+ syn match cppCharacter "u8'[^']*'" contains=cSpecial
+ if exists("c_gnu")
+ syn match cppSpecialError "u8'\\[^'\"?\\abefnrtv]'"
+ syn match cppSpecialCharacter "u8'\\['\"?\\abefnrtv]'"
+ else
+ syn match cppSpecialError "u8'\\[^'\"?\\abfnrtv]'"
+ syn match cppSpecialCharacter "u8'\\['\"?\\abfnrtv]'"
+ endif
+ syn match cppSpecialCharacter display "u8'\\\o\{1,3}'"
+ syn match cppSpecialCharacter display "u8'\\x\x\+'"
+
endif
" C++ 20 extensions
if !exists("cpp_no_cpp20")
+ syn match cppNumber display contained "\<0\(y\|d\)\>"
+ syn match cppNumber display contained "\<[1-9]\('\=\d\+\)*\(y\|d\)\>"
+ syn match cppNumber display contained "\<0\o\+\(y\|d\)\>"
+ syn match cppNumber display contained "\<0b[01]\('\=[01]\+\)*\(y\|d\)\>"
+ syn match cppNumber display contained "\<0x\x\('\=\x\+\)*\(y\|d\)\>"
syn keyword cppStatement co_await co_return co_yield requires
syn keyword cppStorageClass consteval constinit
syn keyword cppStructure concept
@@ -67,12 +99,6 @@ if !exists("cpp_no_cpp20")
syn keyword cppModule import module export
endif
-" C++ 17 extensions
-if !exists("cpp_no_cpp17")
- syn match cppCast "\<reinterpret_pointer_cast\s*<"me=e-1
- syn match cppCast "\<reinterpret_pointer_cast\s*$"
-endif
-
" The minimum and maximum operators in GNU C++
syn match cppMinMax "[<>]?"
@@ -87,10 +113,15 @@ hi def link cppType Type
hi def link cppStorageClass StorageClass
hi def link cppStructure Structure
hi def link cppBoolean Boolean
+hi def link cppCharacter cCharacter
+hi def link cppSpecialCharacter cSpecialCharacter
+hi def link cppSpecialError cSpecialError
hi def link cppConstant Constant
hi def link cppRawStringDelimiter Delimiter
hi def link cppRawString String
+hi def link cppString String
hi def link cppNumber Number
+hi def link cppFloat Number
hi def link cppModule Include
let b:current_syntax = "cpp"
diff --git a/runtime/syntax/csc.vim b/runtime/syntax/csc.vim
index 6e5d8b9f37..b1bc4d6a7b 100644
--- a/runtime/syntax/csc.vim
+++ b/runtime/syntax/csc.vim
@@ -141,7 +141,7 @@ sy keyword cscBPMacro contained EndLoop AllMembers SelectedMembers If Else EndIf
sy match cscBPMacro contained "!"
sy match cscBPW "!\s*\a*" contains=cscBPmacro
-" when wanted, highlighting lhs members or erros in asignments (may lag the editing)
+" when wanted, highlighting lhs members or errors in assignments (may lag the editing)
if exists("csc_asignment")
sy match cscEqError '\("[^"]*"\s*\|[^][\t !%()*+,--/:;<=>{}~]\+\s*\|->\s*\)*=\([^=]\@=\|$\)'
sy region cscFormula transparent matchgroup=cscVarName start='\("[^"]*"\|[^][\t !%()*+,--/:;<=>{}~]\+\)\s*=\([^=]\@=\|\n\)' skip='"[^"]*"' end=';' contains=ALLBUT,cscFormula,cscFormulaIn,cscBPMacro,cscCondition
diff --git a/runtime/syntax/cupl.vim b/runtime/syntax/cupl.vim
index 5b93b0db93..54495f8ba5 100644
--- a/runtime/syntax/cupl.vim
+++ b/runtime/syntax/cupl.vim
@@ -23,7 +23,7 @@ syn keyword cuplTodo contained TODO XXX FIXME
" cuplHeaderContents uses default highlighting except for numbers
syn match cuplHeaderContents ".\+;"me=e-1 contains=cuplNumber contained
-" String contstants
+" String constants
syn region cuplString start=+'+ end=+'+
syn region cuplString start=+"+ end=+"+
diff --git a/runtime/syntax/debchangelog.vim b/runtime/syntax/debchangelog.vim
index 220f184bc0..93b03ae06d 100644
--- a/runtime/syntax/debchangelog.vim
+++ b/runtime/syntax/debchangelog.vim
@@ -3,7 +3,7 @@
" Maintainer: Debian Vim Maintainers
" Former Maintainers: Gerfried Fuchs <alfie@ist.org>
" Wichert Akkerman <wakkerma@debian.org>
-" Last Change: 2020 Nov 28
+" Last Change: 2021 Aug 03
" URL: https://salsa.debian.org/vim-team/vim-debian/blob/master/syntax/debchangelog.vim
" Standard syntax initialization
@@ -24,7 +24,7 @@ let s:supported = [
\ 'jessie', 'stretch', 'buster', 'bullseye', 'bookworm',
\ 'trixie', 'sid', 'rc-buggy',
\
- \ 'trusty', 'xenial', 'bionic', 'focal', 'groovy', 'hirsute', 'devel'
+ \ 'trusty', 'xenial', 'bionic', 'focal', 'hirsute', 'impish', 'devel'
\ ]
let s:unsupported = [
\ 'frozen', 'buzz', 'rex', 'bo', 'hamm', 'slink', 'potato',
@@ -34,7 +34,7 @@ let s:unsupported = [
\ 'gutsy', 'hardy', 'intrepid', 'jaunty', 'karmic', 'lucid',
\ 'maverick', 'natty', 'oneiric', 'precise', 'quantal', 'raring', 'saucy',
\ 'utopic', 'vivid', 'wily', 'yakkety', 'zesty', 'artful', 'cosmic',
- \ 'disco', 'eoan'
+ \ 'disco', 'eoan', 'groovy'
\ ]
let &cpo=s:cpo
diff --git a/runtime/syntax/debsources.vim b/runtime/syntax/debsources.vim
index 2352466a3b..8aa96fcb58 100644
--- a/runtime/syntax/debsources.vim
+++ b/runtime/syntax/debsources.vim
@@ -2,7 +2,7 @@
" Language: Debian sources.list
" Maintainer: Debian Vim Maintainers
" Former Maintainer: Matthijs Mohlmann <matthijs@cacholong.nl>
-" Last Change: 2020 Nov 28
+" Last Change: 2021 Aug 03
" URL: https://salsa.debian.org/vim-team/vim-debian/blob/master/syntax/debsources.vim
" Standard syntax initialization
@@ -26,7 +26,7 @@ let s:supported = [
\ 'jessie', 'stretch', 'buster', 'bullseye', 'bookworm',
\ 'trixie', 'sid', 'rc-buggy',
\
- \ 'trusty', 'xenial', 'bionic', 'focal', 'groovy', 'hirsute', 'devel'
+ \ 'trusty', 'xenial', 'bionic', 'focal', 'hirsute', 'impish', 'devel'
\ ]
let s:unsupported = [
\ 'buzz', 'rex', 'bo', 'hamm', 'slink', 'potato',
@@ -36,7 +36,7 @@ let s:unsupported = [
\ 'gutsy', 'hardy', 'intrepid', 'jaunty', 'karmic', 'lucid',
\ 'maverick', 'natty', 'oneiric', 'precise', 'quantal', 'raring', 'saucy',
\ 'utopic', 'vivid', 'wily', 'yakkety', 'zesty', 'artful', 'cosmic',
- \ 'disco', 'eoan'
+ \ 'disco', 'eoan', 'groovy'
\ ]
let &cpo=s:cpo
diff --git a/runtime/syntax/dosbatch.vim b/runtime/syntax/dosbatch.vim
index 249e6f7c46..f003a65909 100644
--- a/runtime/syntax/dosbatch.vim
+++ b/runtime/syntax/dosbatch.vim
@@ -1,5 +1,5 @@
" Vim syntax file
-" Language: MSDOS batch file (with NT command extensions)
+" Language: MS-DOS batch file (with NT command extensions)
" Maintainer: Mike Williams <mrw@eandem.co.uk>
" Filenames: *.bat
" Last Change: 6th September 2009
diff --git a/runtime/syntax/doxygen.vim b/runtime/syntax/doxygen.vim
index cfd5452ee4..167b17cd0f 100644
--- a/runtime/syntax/doxygen.vim
+++ b/runtime/syntax/doxygen.vim
@@ -1,4 +1,4 @@
-" DoxyGen syntax hilighting extension for c/c++/idl/java
+" DoxyGen syntax highlighting extension for c/c++/idl/java
" Language: doxygen on top of c, cpp, idl, java, php
" Maintainer: Michael Geddes <vimmer@frog.wheelycreek.net>
" Author: Michael Geddes
@@ -54,7 +54,7 @@ let s:cpo_save = &cpo
try
set cpo&vim
- " Start of Doxygen syntax hilighting:
+ " Start of Doxygen syntax highlighting:
"
" C/C++ Style line comments
@@ -256,7 +256,7 @@ endif
syn match doxygenLinkRest +[^*@\\]\|\*/\@!\|[@\\]\(endlink\>\)\@!+ contained skipnl nextgroup=doxygenLinkRest,doxygenContinueLinkComment
syn match doxygenContinueLinkComment contained +^\s*\*\=[^/]+me=e-1 nextgroup=doxygenLinkRest
syn match doxygenLinkError "\*/" contained
- " #Link hilighting.
+ " #Link highlighting.
syn match doxygenHashLink /\(\h\w*\)\?#\(\.\w\@=\|\w\+\|::\|()\)\+/ contained contains=doxygenHashSpecial
syn match doxygenHashSpecial /#/ contained
syn match doxygenHyperLink /\(\s\|^\s*\*\?\)\@<=\(http\|https\|ftp\):\/\/[-0-9a-zA-Z_?&=+#%/.!':;@~]\+/ contained
@@ -306,7 +306,7 @@ endif
syn region doxygenFormula contained matchgroup=doxygenFormulaEnds start=+f\[+ end=+[@\\]f]+ contains=doxygenFormulaSpecial,doxygenFormulaOperator,doxygenAtom
syn region doxygenAtom contained transparent matchgroup=doxygenFormulaOperator start=+{+ end=+}+ contains=doxygenAtom,doxygenFormulaSpecial,doxygenFormulaOperator
- " Add TODO hilighting.
+ " Add TODO highlighting.
syn keyword doxygenTODO contained TODO README XXX FIXME
" Supported HTML subset. Not perfect, but okay.
diff --git a/runtime/syntax/focexec.vim b/runtime/syntax/focexec.vim
index a75aed47cb..187fd50dbf 100644
--- a/runtime/syntax/focexec.vim
+++ b/runtime/syntax/focexec.vim
@@ -8,7 +8,7 @@
" this is a very simple syntax file - I will be improving it
" one thing is how to do computes
" I don't like that &vars and FUSE() functions highlight to the same color
-" I think some of these things should get different hilights -
+" I think some of these things should get different highlights -
" should MODIFY commands look different than TABLE?
" quit when a syntax file was already loaded
diff --git a/runtime/syntax/forth.vim b/runtime/syntax/forth.vim
index 9b39a7fd7d..721bceb367 100644
--- a/runtime/syntax/forth.vim
+++ b/runtime/syntax/forth.vim
@@ -181,7 +181,7 @@ syn keyword forthMath DECIMAL HEX BASE
syn match forthInteger '\<-\=[0-9]\+.\=\>'
syn match forthInteger '\<&-\=[0-9]\+.\=\>'
" recognize hex and binary numbers, the '$' and '%' notation is for gforth
-syn match forthInteger '\<\$\x*\x\+\>' " *1* --- dont't mess
+syn match forthInteger '\<\$\x*\x\+\>' " *1* --- don't mess
syn match forthInteger '\<\x*\d\x*\>' " *2* --- this order!
syn match forthInteger '\<%[0-1]*[0-1]\+\>'
syn match forthFloat '\<-\=\d*[.]\=\d\+[DdEe]\d\+\>'
diff --git a/runtime/syntax/gemtext.vim b/runtime/syntax/gemtext.vim
new file mode 100644
index 0000000000..8c2bd29928
--- /dev/null
+++ b/runtime/syntax/gemtext.vim
@@ -0,0 +1,24 @@
+" Vim syntax file
+" Language: Gemtext markup language
+" Maintainer: Suneel Freimuth <suneelfreimuth1@gmail.com>
+" Latest Revision: 2020-11-21
+" Filenames: *.gmi
+
+if exists('b:current_syntax')
+ finish
+endif
+
+syntax match Heading /^#\{1,3}.\+$/
+syntax match List /^\* /
+syntax match LinkURL /^=>\s*\S\+/
+syntax match Quote /^>.\+/
+syntax region Preformatted start=/^```/ end=/```/
+
+highlight default link Heading Special
+highlight default link List Statement
+highlight default link LinkURL Underlined
+highlight default link Quote Constant
+highlight default link Preformatted Identifier
+
+let b:current_syntax = 'gemtext'
+
diff --git a/runtime/syntax/go.vim b/runtime/syntax/go.vim
index e78f8cf27c..0c326254b8 100644
--- a/runtime/syntax/go.vim
+++ b/runtime/syntax/go.vim
@@ -1,58 +1,109 @@
-" Vim syntax file
-" Language: Go
-" Maintainer: David Barnett (https://github.com/google/vim-ft-go)
-" Last Change: 2014 Aug 16
-
-" Options:
-" There are some options for customizing the highlighting; the recommended
-" settings are the default values, but you can write:
-" let OPTION_NAME = 0
-" in your ~/.vimrc file to disable particular options. You can also write:
-" let OPTION_NAME = 1
-" to enable particular options. At present, all options default to on.
+" Copyright 2009 The Go Authors. All rights reserved.
+" Use of this source code is governed by a BSD-style
+" license that can be found in the LICENSE file.
"
-" - g:go_highlight_array_whitespace_error
-" Highlights white space after "[]".
-" - g:go_highlight_chan_whitespace_error
-" Highlights white space around the communications operator that don't
-" follow the standard style.
-" - g:go_highlight_extra_types
-" Highlights commonly used library types (io.Reader, etc.).
-" - g:go_highlight_space_tab_error
-" Highlights instances of tabs following spaces.
-" - g:go_highlight_trailing_whitespace_error
-" Highlights trailing white space.
+" go.vim: Vim syntax file for Go.
+" Language: Go
+" Maintainer: Billie Cleek <bhcleek@gmail.com>
+" Latest Revision: 2021-09-18
+" License: BSD-style. See LICENSE file in source repository.
+" Repository: https://github.com/fatih/vim-go
" Quit when a (custom) syntax file was already loaded
-if exists('b:current_syntax')
+if exists("b:current_syntax")
finish
endif
-if !exists('g:go_highlight_array_whitespace_error')
- let g:go_highlight_array_whitespace_error = 1
-endif
-if !exists('g:go_highlight_chan_whitespace_error')
- let g:go_highlight_chan_whitespace_error = 1
-endif
-if !exists('g:go_highlight_extra_types')
- let g:go_highlight_extra_types = 1
-endif
-if !exists('g:go_highlight_space_tab_error')
- let g:go_highlight_space_tab_error = 1
-endif
-if !exists('g:go_highlight_trailing_whitespace_error')
- let g:go_highlight_trailing_whitespace_error = 1
-endif
+let s:keepcpo = &cpo
+set cpo&vim
+
+function! s:FoldEnable(...) abort
+ if a:0 > 0
+ return index(s:FoldEnable(), a:1) > -1
+ endif
+ return get(g:, 'go_fold_enable', ['block', 'import', 'varconst', 'package_comment'])
+endfunction
+
+function! s:HighlightArrayWhitespaceError() abort
+ return get(g:, 'go_highlight_array_whitespace_error', 0)
+endfunction
+
+function! s:HighlightChanWhitespaceError() abort
+ return get(g:, 'go_highlight_chan_whitespace_error', 0)
+endfunction
+
+function! s:HighlightExtraTypes() abort
+ return get(g:, 'go_highlight_extra_types', 0)
+endfunction
+
+function! s:HighlightSpaceTabError() abort
+ return get(g:, 'go_highlight_space_tab_error', 0)
+endfunction
+
+function! s:HighlightTrailingWhitespaceError() abort
+ return get(g:, 'go_highlight_trailing_whitespace_error', 0)
+endfunction
+
+function! s:HighlightOperators() abort
+ return get(g:, 'go_highlight_operators', 0)
+endfunction
+
+function! s:HighlightFunctions() abort
+ return get(g:, 'go_highlight_functions', 0)
+endfunction
+
+function! s:HighlightFunctionParameters() abort
+ return get(g:, 'go_highlight_function_parameters', 0)
+endfunction
+
+function! s:HighlightFunctionCalls() abort
+ return get(g:, 'go_highlight_function_calls', 0)
+endfunction
+
+function! s:HighlightFields() abort
+ return get(g:, 'go_highlight_fields', 0)
+endfunction
+
+function! s:HighlightTypes() abort
+ return get(g:, 'go_highlight_types', 0)
+endfunction
+
+function! s:HighlightBuildConstraints() abort
+ return get(g:, 'go_highlight_build_constraints', 0)
+endfunction
+
+function! s:HighlightStringSpellcheck() abort
+ return get(g:, 'go_highlight_string_spellcheck', 1)
+endfunction
+
+function! s:HighlightFormatStrings() abort
+ return get(g:, 'go_highlight_format_strings', 1)
+endfunction
+
+function! s:HighlightGenerateTags() abort
+ return get(g:, 'go_highlight_generate_tags', 0)
+endfunction
+
+function! s:HighlightVariableAssignments() abort
+ return get(g:, 'go_highlight_variable_assignments', 0)
+endfunction
+
+function! s:HighlightVariableDeclarations() abort
+ return get(g:, 'go_highlight_variable_declarations', 0)
+endfunction
syn case match
-syn keyword goDirective package import
-syn keyword goDeclaration var const type
-syn keyword goDeclType struct interface
+syn keyword goPackage package
+syn keyword goImport import contained
+syn keyword goVar var contained
+syn keyword goConst const contained
-hi def link goDirective Statement
+hi def link goPackage Statement
+hi def link goImport Statement
+hi def link goVar Keyword
+hi def link goConst Keyword
hi def link goDeclaration Keyword
-hi def link goDeclType Keyword
" Keywords within functions
syn keyword goStatement defer go goto return break continue fallthrough
@@ -78,28 +129,38 @@ hi def link goUnsignedInts Type
hi def link goFloats Type
hi def link goComplexes Type
-" Treat func specially: it's a declaration at the start of a line, but a type
-" elsewhere. Order matters here.
-syn match goType /\<func\>/
-syn match goDeclaration /^func\>/
-
" Predefined functions and values
-syn keyword goBuiltins append cap close complex copy delete imag len
-syn keyword goBuiltins make new panic print println real recover
-syn keyword goConstants iota true false nil
+syn keyword goBuiltins append cap close complex copy delete imag len
+syn keyword goBuiltins make new panic print println real recover
+syn keyword goBoolean true false
+syn keyword goPredefinedIdentifiers nil iota
-hi def link goBuiltins Keyword
-hi def link goConstants Keyword
+hi def link goBuiltins Identifier
+hi def link goBoolean Boolean
+hi def link goPredefinedIdentifiers goBoolean
" Comments; their contents
syn keyword goTodo contained TODO FIXME XXX BUG
syn cluster goCommentGroup contains=goTodo
-syn region goComment start="/\*" end="\*/" contains=@goCommentGroup,@Spell
-syn region goComment start="//" end="$" contains=@goCommentGroup,@Spell
+
+syn region goComment start="//" end="$" contains=goGenerate,@goCommentGroup,@Spell
+if s:FoldEnable('comment')
+ syn region goComment start="/\*" end="\*/" contains=@goCommentGroup,@Spell fold
+ syn match goComment "\v(^\s*//.*\n)+" contains=goGenerate,@goCommentGroup,@Spell fold
+else
+ syn region goComment start="/\*" end="\*/" contains=@goCommentGroup,@Spell
+endif
hi def link goComment Comment
hi def link goTodo Todo
+if s:HighlightGenerateTags()
+ syn match goGenerateVariables contained /\%(\$GOARCH\|\$GOOS\|\$GOFILE\|\$GOLINE\|\$GOPACKAGE\|\$DOLLAR\)\>/
+ syn region goGenerate start="^\s*//go:generate" end="$" contains=goGenerateVariables
+ hi def link goGenerate PreProc
+ hi def link goGenerateVariables Special
+endif
+
" Go escapes
syn match goEscapeOctal display contained "\\[0-7]\{3}"
syn match goEscapeC display contained +\\[abfnrtv\\'"]+
@@ -118,8 +179,30 @@ hi def link goEscapeError Error
" Strings and their contents
syn cluster goStringGroup contains=goEscapeOctal,goEscapeC,goEscapeX,goEscapeU,goEscapeBigU,goEscapeError
-syn region goString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@goStringGroup
-syn region goRawString start=+`+ end=+`+
+if s:HighlightStringSpellcheck()
+ syn region goString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@goStringGroup,@Spell
+ syn region goRawString start=+`+ end=+`+ contains=@Spell
+else
+ syn region goString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=@goStringGroup
+ syn region goRawString start=+`+ end=+`+
+endif
+
+if s:HighlightFormatStrings()
+ " [n] notation is valid for specifying explicit argument indexes
+ " 1. Match a literal % not preceded by a %.
+ " 2. Match any number of -, #, 0, space, or +
+ " 3. Match * or [n]* or any number or nothing before a .
+ " 4. Match * or [n]* or any number or nothing after a .
+ " 5. Match [n] or nothing before a verb
+ " 6. Match a formatting verb
+ syn match goFormatSpecifier /\
+ \%([^%]\%(%%\)*\)\
+ \@<=%[-#0 +]*\
+ \%(\%(\%(\[\d\+\]\)\=\*\)\|\d\+\)\=\
+ \%(\.\%(\%(\%(\[\d\+\]\)\=\*\)\|\d\+\)\=\)\=\
+ \%(\[\d\+\]\)\=[vTtbcdoqxXUeEfFgGspw]/ contained containedin=goString,goRawString
+ hi def link goFormatSpecifier goSpecialString
+endif
hi def link goString String
hi def link goRawString String
@@ -131,71 +214,263 @@ syn region goCharacter start=+'+ skip=+\\\\\|\\'+ end=+'+ contains=
hi def link goCharacter Character
" Regions
-syn region goBlock start="{" end="}" transparent fold
syn region goParen start='(' end=')' transparent
+if s:FoldEnable('block')
+ syn region goBlock start="{" end="}" transparent fold
+else
+ syn region goBlock start="{" end="}" transparent
+endif
+
+" import
+if s:FoldEnable('import')
+ syn region goImport start='import (' end=')' transparent fold contains=goImport,goString,goComment
+else
+ syn region goImport start='import (' end=')' transparent contains=goImport,goString,goComment
+endif
+
+" var, const
+if s:FoldEnable('varconst')
+ syn region goVar start='var (' end='^\s*)$' transparent fold
+ \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar,goParamName,goParamType,goSimpleParams,goPointerOperator
+ syn region goConst start='const (' end='^\s*)$' transparent fold
+ \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar,goParamName,goParamType,goSimpleParams,goPointerOperator
+else
+ syn region goVar start='var (' end='^\s*)$' transparent
+ \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar,goParamName,goParamType,goSimpleParams,goPointerOperator
+ syn region goConst start='const (' end='^\s*)$' transparent
+ \ contains=ALLBUT,goParen,goBlock,goFunction,goTypeName,goReceiverType,goReceiverVar,goParamName,goParamType,goSimpleParams,goPointerOperator
+endif
+
+" Single-line var, const, and import.
+syn match goSingleDecl /\%(import\|var\|const\) [^(]\@=/ contains=goImport,goVar,goConst
" Integers
-syn match goDecimalInt "\<\d\+\([Ee]\d\+\)\?\>"
-syn match goHexadecimalInt "\<0x\x\+\>"
-syn match goOctalInt "\<0\o\+\>"
-syn match goOctalError "\<0\o*[89]\d*\>"
+syn match goDecimalInt "\<-\=\(0\|[1-9]_\?\(\d\|\d\+_\?\d\+\)*\)\%([Ee][-+]\=\d\+\)\=\>"
+syn match goDecimalError "\<-\=\(_\(\d\+_*\)\+\|\([1-9]\d*_*\)\+__\(\d\+_*\)\+\|\([1-9]\d*_*\)\+_\+\)\%([Ee][-+]\=\d\+\)\=\>"
+syn match goHexadecimalInt "\<-\=0[xX]_\?\(\x\+_\?\)\+\>"
+syn match goHexadecimalError "\<-\=0[xX]_\?\(\x\+_\?\)*\(\([^ \t0-9A-Fa-f_)]\|__\)\S*\|_\)\>"
+syn match goOctalInt "\<-\=0[oO]\?_\?\(\o\+_\?\)\+\>"
+syn match goOctalError "\<-\=0[0-7oO_]*\(\([^ \t0-7oOxX_/)\]\}\:;]\|[oO]\{2,\}\|__\)\S*\|_\|[oOxX]\)\>"
+syn match goBinaryInt "\<-\=0[bB]_\?\([01]\+_\?\)\+\>"
+syn match goBinaryError "\<-\=0[bB]_\?[01_]*\([^ \t01_)]\S*\|__\S*\|_\)\>"
hi def link goDecimalInt Integer
+hi def link goDecimalError Error
hi def link goHexadecimalInt Integer
+hi def link goHexadecimalError Error
hi def link goOctalInt Integer
+hi def link goOctalError Error
+hi def link goBinaryInt Integer
+hi def link goBinaryError Error
hi def link Integer Number
" Floating point
-syn match goFloat "\<\d\+\.\d*\([Ee][-+]\d\+\)\?\>"
-syn match goFloat "\<\.\d\+\([Ee][-+]\d\+\)\?\>"
-syn match goFloat "\<\d\+[Ee][-+]\d\+\>"
+syn match goFloat "\<-\=\d\+\.\d*\%([Ee][-+]\=\d\+\)\=\>"
+syn match goFloat "\<-\=\.\d\+\%([Ee][-+]\=\d\+\)\=\>"
hi def link goFloat Float
" Imaginary literals
-syn match goImaginary "\<\d\+i\>"
-syn match goImaginary "\<\d\+\.\d*\([Ee][-+]\d\+\)\?i\>"
-syn match goImaginary "\<\.\d\+\([Ee][-+]\d\+\)\?i\>"
-syn match goImaginary "\<\d\+[Ee][-+]\d\+i\>"
+syn match goImaginary "\<-\=\d\+i\>"
+syn match goImaginary "\<-\=\d\+[Ee][-+]\=\d\+i\>"
+syn match goImaginaryFloat "\<-\=\d\+\.\d*\%([Ee][-+]\=\d\+\)\=i\>"
+syn match goImaginaryFloat "\<-\=\.\d\+\%([Ee][-+]\=\d\+\)\=i\>"
hi def link goImaginary Number
+hi def link goImaginaryFloat Float
" Spaces after "[]"
-if go_highlight_array_whitespace_error != 0
- syn match goSpaceError display "\(\[\]\)\@<=\s\+"
+if s:HighlightArrayWhitespaceError()
+ syn match goSpaceError display "\%(\[\]\)\@<=\s\+"
endif
" Spacing errors around the 'chan' keyword
-if go_highlight_chan_whitespace_error != 0
+if s:HighlightChanWhitespaceError()
" receive-only annotation on chan type
- syn match goSpaceError display "\(<-\)\@<=\s\+\(chan\>\)\@="
+ "
+ " \(\<chan\>\)\@<!<- (only pick arrow when it doesn't come after a chan)
+ " this prevents picking up 'chan<- chan<-' but not '<- chan'
+ syn match goSpaceError display "\%(\%(\<chan\>\)\@<!<-\)\@<=\s\+\%(\<chan\>\)\@="
+
" send-only annotation on chan type
- syn match goSpaceError display "\(\<chan\)\@<=\s\+\(<-\)\@="
+ "
+ " \(<-\)\@<!\<chan\> (only pick chan when it doesn't come after an arrow)
+ " this prevents picking up '<-chan <-chan' but not 'chan <-'
+ syn match goSpaceError display "\%(\%(<-\)\@<!\<chan\>\)\@<=\s\+\%(<-\)\@="
+
" value-ignoring receives in a few contexts
- syn match goSpaceError display "\(\(^\|[={(,;]\)\s*<-\)\@<=\s\+"
+ syn match goSpaceError display "\%(\%(^\|[={(,;]\)\s*<-\)\@<=\s\+"
endif
" Extra types commonly seen
-if go_highlight_extra_types != 0
- syn match goExtraType /\<bytes\.\(Buffer\)\>/
- syn match goExtraType /\<io\.\(Reader\|Writer\|ReadWriter\|ReadWriteCloser\)\>/
- syn match goExtraType /\<reflect\.\(Kind\|Type\|Value\)\>/
+if s:HighlightExtraTypes()
+ syn match goExtraType /\<bytes\.\%(Buffer\)\>/
+ syn match goExtraType /\<context\.\%(Context\)\>/
+ syn match goExtraType /\<io\.\%(Reader\|ReadSeeker\|ReadWriter\|ReadCloser\|ReadWriteCloser\|Writer\|WriteCloser\|Seeker\)\>/
+ syn match goExtraType /\<reflect\.\%(Kind\|Type\|Value\)\>/
syn match goExtraType /\<unsafe\.Pointer\>/
endif
" Space-tab error
-if go_highlight_space_tab_error != 0
+if s:HighlightSpaceTabError()
syn match goSpaceError display " \+\t"me=e-1
endif
" Trailing white space error
-if go_highlight_trailing_whitespace_error != 0
+if s:HighlightTrailingWhitespaceError()
syn match goSpaceError display excludenl "\s\+$"
endif
hi def link goExtraType Type
hi def link goSpaceError Error
+
+
+" included from: https://github.com/athom/more-colorful.vim/blob/master/after/syntax/go.vim
+"
+" Comments; their contents
+syn keyword goTodo contained NOTE
+hi def link goTodo Todo
+
+syn match goVarArgs /\.\.\./
+
+" Operators;
+if s:HighlightOperators()
+ " match single-char operators: - + % < > ! & | ^ * =
+ " and corresponding two-char operators: -= += %= <= >= != &= |= ^= *= ==
+ syn match goOperator /[-+%<>!&|^*=]=\?/
+ " match / and /=
+ syn match goOperator /\/\%(=\|\ze[^/*]\)/
+ " match two-char operators: << >> &^
+ " and corresponding three-char operators: <<= >>= &^=
+ syn match goOperator /\%(<<\|>>\|&^\)=\?/
+ " match remaining two-char operators: := && || <- ++ --
+ syn match goOperator /:=\|||\|<-\|++\|--/
+ " match ...
+
+ hi def link goPointerOperator goOperator
+ hi def link goVarArgs goOperator
+endif
+hi def link goOperator Operator
+
+" Functions;
+if s:HighlightFunctions() || s:HighlightFunctionParameters()
+ syn match goDeclaration /\<func\>/ nextgroup=goReceiver,goFunction,goSimpleParams skipwhite skipnl
+ syn match goReceiverVar /\w\+\ze\s\+\%(\w\|\*\)/ nextgroup=goPointerOperator,goReceiverType skipwhite skipnl contained
+ syn match goPointerOperator /\*/ nextgroup=goReceiverType contained skipwhite skipnl
+ syn match goFunction /\w\+/ nextgroup=goSimpleParams contained skipwhite skipnl
+ syn match goReceiverType /\w\+/ contained
+ if s:HighlightFunctionParameters()
+ syn match goSimpleParams /(\%(\w\|\_s\|[*\.\[\],\{\}<>-]\)*)/ contained contains=goParamName,goType nextgroup=goFunctionReturn skipwhite skipnl
+ syn match goFunctionReturn /(\%(\w\|\_s\|[*\.\[\],\{\}<>-]\)*)/ contained contains=goParamName,goType skipwhite skipnl
+ syn match goParamName /\w\+\%(\s*,\s*\w\+\)*\ze\s\+\%(\w\|\.\|\*\|\[\)/ contained nextgroup=goParamType skipwhite skipnl
+ syn match goParamType /\%([^,)]\|\_s\)\+,\?/ contained nextgroup=goParamName skipwhite skipnl
+ \ contains=goVarArgs,goType,goSignedInts,goUnsignedInts,goFloats,goComplexes,goDeclType,goBlock
+ hi def link goReceiverVar goParamName
+ hi def link goParamName Identifier
+ endif
+ syn match goReceiver /(\s*\w\+\%(\s\+\*\?\s*\w\+\)\?\s*)\ze\s*\w/ contained nextgroup=goFunction contains=goReceiverVar skipwhite skipnl
+else
+ syn keyword goDeclaration func
+endif
+hi def link goFunction Function
+
+" Function calls;
+if s:HighlightFunctionCalls()
+ syn match goFunctionCall /\w\+\ze(/ contains=goBuiltins,goDeclaration
+endif
+hi def link goFunctionCall Type
+
+" Fields;
+if s:HighlightFields()
+ " 1. Match a sequence of word characters coming after a '.'
+ " 2. Require the following but dont match it: ( \@= see :h E59)
+ " - The symbols: / - + * % OR
+ " - The symbols: [] {} <> ) OR
+ " - The symbols: \n \r space OR
+ " - The symbols: , : .
+ " 3. Have the start of highlight (hs) be the start of matched
+ " pattern (s) offsetted one to the right (+1) (see :h E401)
+ syn match goField /\.\w\+\
+ \%(\%([\/\-\+*%]\)\|\
+ \%([\[\]{}<\>\)]\)\|\
+ \%([\!=\^|&]\)\|\
+ \%([\n\r\ ]\)\|\
+ \%([,\:.]\)\)\@=/hs=s+1
+endif
+hi def link goField Identifier
+
+" Structs & Interfaces;
+if s:HighlightTypes()
+ syn match goTypeConstructor /\<\w\+{\@=/
+ syn match goTypeDecl /\<type\>/ nextgroup=goTypeName skipwhite skipnl
+ syn match goTypeName /\w\+/ contained nextgroup=goDeclType skipwhite skipnl
+ syn match goDeclType /\<\%(interface\|struct\)\>/ skipwhite skipnl
+ hi def link goReceiverType Type
+else
+ syn keyword goDeclType struct interface
+ syn keyword goDeclaration type
+endif
+hi def link goTypeConstructor Type
+hi def link goTypeName Type
+hi def link goTypeDecl Keyword
+hi def link goDeclType Keyword
+
+" Variable Assignments
+if s:HighlightVariableAssignments()
+ syn match goVarAssign /\v[_.[:alnum:]]+(,\s*[_.[:alnum:]]+)*\ze(\s*([-^+|^\/%&]|\*|\<\<|\>\>|\&\^)?\=[^=])/
+ hi def link goVarAssign Special
+endif
+
+" Variable Declarations
+if s:HighlightVariableDeclarations()
+ syn match goVarDefs /\v\w+(,\s*\w+)*\ze(\s*:\=)/
+ hi def link goVarDefs Special
+endif
+
+" Build Constraints
+if s:HighlightBuildConstraints()
+ syn match goBuildKeyword display contained "+build\|go:build"
+ " Highlight the known values of GOOS, GOARCH, and other +build options.
+ syn keyword goBuildDirectives contained
+ \ android darwin dragonfly freebsd linux nacl netbsd openbsd plan9
+ \ solaris windows 386 amd64 amd64p32 arm armbe arm64 arm64be ppc64
+ \ ppc64le mips mipsle mips64 mips64le mips64p32 mips64p32le ppc
+ \ s390 s390x sparc sparc64 cgo ignore race
+
+ " Other words in the build directive are build tags not listed above, so
+ " avoid highlighting them as comments by using a matchgroup just for the
+ " start of the comment.
+ " The rs=s+2 option lets the \s*+build portion be part of the inner region
+ " instead of the matchgroup so it will be highlighted as a goBuildKeyword.
+ syn region goBuildComment matchgroup=goBuildCommentStart
+ \ start="//\s*+build\s"rs=s+2 end="$"
+ \ contains=goBuildKeyword,goBuildDirectives
+ hi def link goBuildCommentStart Comment
+ hi def link goBuildDirectives Type
+ hi def link goBuildKeyword PreProc
+endif
+
+if s:HighlightBuildConstraints() || s:FoldEnable('package_comment')
+ " One or more line comments that are followed immediately by a "package"
+ " declaration are treated like package documentation, so these must be
+ " matched as comments to avoid looking like working build constraints.
+ " The he, me, and re options let the "package" itself be highlighted by
+ " the usual rules.
+ exe 'syn region goPackageComment start=/\v(\/\/.*\n)+\s*package/'
+ \ . ' end=/\v\n\s*package/he=e-7,me=e-7,re=e-7'
+ \ . ' contains=@goCommentGroup,@Spell'
+ \ . (s:FoldEnable('package_comment') ? ' fold' : '')
+ exe 'syn region goPackageComment start=/\v^\s*\/\*.*\n(.*\n)*\s*\*\/\npackage/'
+ \ . ' end=/\v\*\/\n\s*package/he=e-7,me=e-7,re=e-7'
+ \ . ' contains=@goCommentGroup,@Spell'
+ \ . (s:FoldEnable('package_comment') ? ' fold' : '')
+ hi def link goPackageComment Comment
+endif
+
+" :GoCoverage commands
+hi def link goCoverageNormalText Comment
+
" Search backwards for a global declaration to start processing the syntax.
"syn sync match goSync grouphere NONE /^\(const\|var\|type\|func\)\>/
@@ -203,6 +478,9 @@ hi def link goSpaceError Error
" following as a more expensive/less precise workaround.
syn sync minlines=500
-let b:current_syntax = 'go'
+let b:current_syntax = "go"
+
+let &cpo = s:keepcpo
+unlet s:keepcpo
" vim: sw=2 sts=2 et
diff --git a/runtime/syntax/gprof.vim b/runtime/syntax/gprof.vim
index 880452a84b..d2c5cb4cab 100644
--- a/runtime/syntax/gprof.vim
+++ b/runtime/syntax/gprof.vim
@@ -1,15 +1,16 @@
" Vim syntax file
" Language: Syntax for Gprof Output
" Maintainer: Dominique Pelle <dominique.pelle@gmail.com>
-" Last Change: 2021 Apr 08
+" Last Change: 2021 Sep 19
" Quit when a syntax file was already loaded
if exists("b:current_syntax")
- finish
+ finish
endif
let s:keepcpo= &cpo
set cpo&vim
+syn spell notoplevel
syn case match
syn sync minlines=100
diff --git a/runtime/syntax/gvpr.vim b/runtime/syntax/gvpr.vim
new file mode 100644
index 0000000000..a7378916f9
--- /dev/null
+++ b/runtime/syntax/gvpr.vim
@@ -0,0 +1,85 @@
+" Vim syntax file
+" Language: Graphviz program
+" Maintainer: Matthew Fernandez <matthew.fernandez@gmail.com>
+" Last Change: Tue, 28 Jul 2020 17:20:44 -0700
+
+if exists("b:current_syntax")
+ finish
+endif
+
+let s:cpo_save = &cpo
+set cpo&vim
+
+syn keyword gvArg ARGC ARGV
+syn keyword gvBeg BEGIN BEG_G N E END END_G
+syn keyword gvFunc
+ \ graph fstsubg isDirect isStrict isSubg nEdges nNodes nxtsubg subg
+ \ degreeOf fstnode indegreeOf isNode isSubnode node nxtnode nxtnode_sg
+ \ outDegreeOf subnode
+ \ edge edge_sg fstedge fstedge_sg fstin fstin_sg fstout fstout_sg isEdge
+ \ isEdge_sg isSubedge nxtedge nxtedge_sg nxtin nxtin_sg nxtout nxtout_sg opp
+ \ subedge
+ \ freadG fwriteG readG write[] writeG
+ \ aget aset clone cloneG compOf copy[] copyA delete[] fstAttr getDflt hasAttr
+ \ induce isAttr isIn kindOf lock[] nxtAttr setDflt
+ \ canon gsub html index ishtml length llOf match[] rindex split[] sprintf
+ \ sscanf strcmp sub substr tokens tolower toupper urOf xOf yOf
+ \ closeF openF print[] printf scanf readL
+ \ atan2 cos exp log MAX MIN pow sin[] sqrt
+ \ in[] unset
+ \ colorx exit[] rand srand system
+syn keyword gvCons
+ \ NULL TV_bfs TV_dfs TV_en TV_flat TV_fwd TV_ne TV_prepostdfs TV_prepostfwd
+ \ TV_prepostrev TV_postdfs TV_postfwd tv_postrev TV_rev
+syn keyword gvType char double float int long unsigned void
+ \ string
+ \ edge_t graph_t node_t obj_t
+syn match gvVar
+ \ "\$\(\(F\|G\|NG\|O\|T\|tgtname\|tvedge\|tvnext\|tvroot\|tvtype\)\>\)\?\(\<\)\@!"
+syn keyword gvWord break continue else for forr if return switch while
+
+" numbers adapted from c.vim's cNumbers and friends
+syn match gvNums transparent "\<\d\|\.\d" contains=gvNumber,gvFloat,gvOctal
+syn match gvNumber contained "\d\+\(u\=l\{0,2}\|ll\=u\)\>"
+syn match gvNumber contained "0x\x\+\(u\=l\{0,2}\|ll\=u\)\>"
+syn match gvOctal contained "0\o\+\(u\=l\{0,2}\|ll\=u\)\>" contains=gvOctalZero
+syn match gvOctalZero contained "\<0"
+syn match gvFloat contained "\d\+f"
+syn match gvFloat contained "\d\+\.\d*\(e[-+]\=\d\+\)\=[fl]\="
+syn match gvFloat contained "\.\d\+\(e[-+]\=\d\+\)\=[fl]\=\>"
+syn match gvFloat contained "\d\+e[-+]\=\d\+[fl]\=\>"
+
+syn region gvString start=+"+ skip=+\\\\\|\\"+ end=+"+ contains=gvFormat,gvSpecial extend
+syn region gvString start="'" skip="\\\\\|\\'" end="'" contains=gvFormat,gvSpecial extend
+
+" adapted from c.vim's cFormat for c_no_c99
+syn match gvFormat "%\(\d\+\$\)\=[-+' #0*]*\(\d*\|\*\|\*\d\+\$\)\(\.\(\d*\|\*\|\*\d\+\$\)\)\=\([hlL]\|ll\)\=\([bdiuoxXDOUfeEgGcCsSpn]\|\[\^\=.[^]]*\]\)" contained
+
+syn match gvSpecial "\\." contained
+
+syn region gvCComment start="//" skip="\\$" end="$" keepend
+syn region gvCPPComment start="#" skip="\\$" end="$" keepend
+syn region gvCXXComment start="/\*" end="\*/" fold
+
+hi def link gvArg Identifier
+hi def link gvBeg Keyword
+hi def link gvFloat Number
+hi def link gvFunc Identifier
+hi def link gvCons Number
+hi def link gvNumber Number
+hi def link gvType Type
+hi def link gvVar Statement
+hi def link gvWord Keyword
+
+hi def link gvString String
+hi def link gvFormat Special
+hi def link gvSpecial Special
+
+hi def link gvCComment Comment
+hi def link gvCPPComment Comment
+hi def link gvCXXComment Comment
+
+let b:current_syntax = "gvpr"
+
+let &cpo = s:cpo_save
+unlet s:cpo_save
diff --git a/runtime/syntax/hamster.vim b/runtime/syntax/hamster.vim
index 64d9598a71..975562da0f 100644
--- a/runtime/syntax/hamster.vim
+++ b/runtime/syntax/hamster.vim
@@ -9,7 +9,7 @@
" It allows the use of multiple news- and mailserver and combines them to one
" mail- and newsserver for the news/mail-client. It load faster than a normal
" newsreader because many threads can run simultaneous. It contains scorefile
-" for news and mail, a build-in script language, the GUI allows translation to
+" for news and mail, a built-in script language, the GUI allows translation to
" other languages, it can be used in a network and that's not all features...
"
" quit when a syntax file was already loaded
diff --git a/runtime/syntax/help.vim b/runtime/syntax/help.vim
index d3d8f4f435..01915d23d7 100644
--- a/runtime/syntax/help.vim
+++ b/runtime/syntax/help.vim
@@ -1,7 +1,7 @@
" Vim syntax file
" Language: Vim help file
" Maintainer: Bram Moolenaar (Bram@vim.org)
-" Last Change: 2020 Jul 28
+" Last Change: 2021 Jun 13
" Quit when a (custom) syntax file was already loaded
if exists("b:current_syntax")
diff --git a/runtime/syntax/idl.vim b/runtime/syntax/idl.vim
index 6a4ce7e087..2f20dec2d7 100644
--- a/runtime/syntax/idl.vim
+++ b/runtime/syntax/idl.vim
@@ -7,7 +7,7 @@
" This is an experiment. IDL's structure is simple enough to permit a full
" grammar based approach to rather than using a few heuristics. The result
-" is large and somewhat repetative but seems to work.
+" is large and somewhat repetitive but seems to work.
" There are some Microsoft extensions to idl files that are here. Some of
" them are disabled by defining idl_no_ms_extensions.
diff --git a/runtime/syntax/iss.vim b/runtime/syntax/iss.vim
index e41de5db5a..34bb698368 100644
--- a/runtime/syntax/iss.vim
+++ b/runtime/syntax/iss.vim
@@ -2,10 +2,10 @@
" Language: Inno Setup File (iss file) and My InnoSetup extension
" Maintainer: Jason Mills (jmills@cs.mun.ca)
" Previous Maintainer: Dominique Stéphan (dominique@mggen.com)
-" Last Change: 2019 Sep 27
+" Last Change: 2021 Aug 30
"
" Todo:
-" - The paramter String: is matched as flag string (because of case ignore).
+" - The parameter String: is matched as flag string (because of case ignore).
" - Pascal scripting syntax is not recognized.
" - Embedded double quotes confuse string matches. e.g. "asfd""asfa"
diff --git a/runtime/syntax/jsonc.vim b/runtime/syntax/jsonc.vim
new file mode 100644
index 0000000000..d0df16bbf1
--- /dev/null
+++ b/runtime/syntax/jsonc.vim
@@ -0,0 +1,44 @@
+" Vim syntax file
+" Language: JSONC (JSON with Comments)
+" Original Author: Izhak Jakov <izhak724@gmail.com>
+" Acknowledgement: Based off of vim-jsonc maintained by Kevin Locke <kevin@kevinlocke.name>
+" https://github.com/kevinoid/vim-jsonc
+" License: MIT
+" Last Change: 2021-07-01
+
+" Ensure syntax is loaded once, unless nested inside another (main) syntax
+" For description of main_syntax, see https://stackoverflow.com/q/16164549
+if !exists('g:main_syntax')
+ if exists('b:current_syntax') && b:current_syntax ==# 'jsonc'
+ finish
+ endif
+ let g:main_syntax = 'jsonc'
+endif
+
+" Based on vim-json syntax
+runtime! syntax/json.vim
+
+" Remove syntax group for comments treated as errors
+if !exists("g:vim_json_warnings") || g:vim_json_warnings
+ syn clear jsonCommentError
+endif
+
+syn match jsonStringMatch /"\([^"]\|\\\"\)\+"\ze\(\_s*\/\/.*\_s*\)*[}\]]/ contains=jsonString
+syn match jsonStringMatch /"\([^"]\|\\\"\)\+"\ze\_s*\/\*\_.*\*\/\_s*[}\]]/ contains=jsonString
+syn match jsonTrailingCommaError /\(,\)\+\ze\(\_s*\/\/.*\_s*\)*[}\]]/
+syn match jsonTrailingCommaError /\(,\)\+\ze\_s*\/\*\_.*\*\/\_s*[}\]]/
+
+" Define syntax matching comments and their contents
+syn keyword jsonCommentTodo FIXME NOTE TBD TODO XXX
+syn region jsonLineComment start=+\/\/+ end=+$+ contains=@Spell,jsonCommentTodo keepend
+syn region jsonComment start='/\*' end='\*/' contains=@Spell,jsonCommentTodo fold
+
+" Link comment syntax comment to highlighting
+hi! def link jsonLineComment Comment
+hi! def link jsonComment Comment
+
+" Set/Unset syntax to avoid duplicate inclusion and correctly handle nesting
+let b:current_syntax = 'jsonc'
+if g:main_syntax ==# 'jsonc'
+ unlet g:main_syntax
+endif
diff --git a/runtime/syntax/julia.vim b/runtime/syntax/julia.vim
new file mode 100644
index 0000000000..2c2d36a97a
--- /dev/null
+++ b/runtime/syntax/julia.vim
@@ -0,0 +1,550 @@
+" Vim syntax file
+" Language: julia
+" Maintainer: Carlo Baldassi <carlobaldassi@gmail.com>
+" Homepage: https://github.com/JuliaEditorSupport/julia-vim
+" Last Change: 2013 feb 11
+
+if version < 600
+ syntax clear
+elseif exists("b:current_syntax")
+ finish
+endif
+
+let s:cpo_save = &cpo
+set cpo&vim
+
+if version < 704
+ " this is used to disable regex syntax like `\@3<='
+ " on older vim versions
+ function! s:d(x)
+ return ''
+ endfunction
+else
+ function! s:d(x)
+ return string(a:x)
+ endfunction
+endif
+
+scriptencoding utf-8
+
+let s:julia_spellcheck_strings = get(g:, "julia_spellcheck_strings", 0)
+let s:julia_spellcheck_docstrings = get(g:, "julia_spellcheck_docstrings", 1)
+let s:julia_spellcheck_comments = get(g:, "julia_spellcheck_comments", 1)
+
+let s:julia_highlight_operators = get(g:, "julia_highlight_operators", 1)
+
+" List of characters, up to \UFF, which cannot be used in identifiers.
+" (It includes operator characters; we don't consider them identifiers.)
+" This is used mostly in lookbehinds with `\@<=`, e.g. when we need to check
+" that that we're not in the middle of an identifier.
+" It doesn't include a few characters (spaces and all closing parentheses)
+" because those may or may not be valid in the lookbehind on a case-by-case
+" basis.
+let s:nonid_chars = '\U00-\U08' . '\U0A-\U1F'
+ \ . '\U21-\U28' . '\U2A-\U2F' . '\U3A-\U40' . '\U5B-\U5E' . '\U60' . '\U7B\U7C'
+ \ . '\U7E-\UA1' . '\UA7\UA8' . '\UAB-\UAD' . '\UAF\UB1\UB4' . '\UB6-\UB8' . '\UBB\UBF' . '\UD7\UF7'
+
+" The complete list
+let s:nonidS_chars = '[:space:])\U5D}' . s:nonid_chars
+
+
+" List of all valid operator chars up to \UFF (NOTE: they must all be included
+" in s:nonidS_chars, so that if we include that, then this is redundant)
+" It does not include '!' since it can be used in an identifier.
+" The list contains the following characters: '%&*+-/<=>\\^|~¬±×÷'
+let s:op_chars = '\U25\U26\U2A\U2B\U2D\U2F\U3C-\U3E\U5C\U5E\U7C\U7E\UAC\UB1\UD7\UF7'
+
+" List of all valid operator chars above \UFF
+" Written with ranges for performance reasons
+" The list contains the following characters: '…⁝⅋←↑→↓↔↚↛↜↝↞↠↢↣↤↦↩↪↫↬↮↶↷↺↻↼↽⇀⇁⇄⇆⇇⇉⇋⇌⇍⇎⇏⇐⇒⇔⇚⇛⇜⇝⇠⇢⇴⇵⇶⇷⇸⇹⇺⇻⇼⇽⇾⇿∈∉∊∋∌∍∓∔∗∘∙√∛∜∝∤∥∦∧∨∩∪∷∸∺∻∽∾≀≁≂≃≄≅≆≇≈≉≊≋≌≍≎≏≐≑≒≓≔≕≖≗≘≙≚≛≜≝≞≟≠≡≢≣≤≥≦≧≨≩≪≫≬≭≮≯≰≱≲≳≴≵≶≷≸≹≺≻≼≽≾≿⊀⊁⊂⊃⊄⊅⊆⊇⊈⊉⊊⊋⊍⊎⊏⊐⊑⊒⊓⊔⊕⊖⊗⊘⊙⊚⊛⊜⊞⊟⊠⊡⊢⊣⊩⊬⊮⊰⊱⊲⊳⊴⊵⊶⊷⊻⊼⊽⋄⋅⋆⋇⋉⋊⋋⋌⋍⋎⋏⋐⋑⋒⋓⋕⋖⋗⋘⋙⋚⋛⋜⋝⋞⋟⋠⋡⋢⋣⋤⋥⋦⋧⋨⋩⋪⋫⋬⋭⋮⋯⋰⋱⋲⋳⋴⋵⋶⋷⋸⋹⋺⋻⋼⋽⋾⋿⌿▷⟂⟈⟉⟑⟒⟕⟖⟗⟰⟱⟵⟶⟷⟹⟺⟻⟼⟽⟾⟿⤀⤁⤂⤃⤄⤅⤆⤇⤈⤉⤊⤋⤌⤍⤎⤏⤐⤑⤒⤓⤔⤕⤖⤗⤘⤝⤞⤟⤠⥄⥅⥆⥇⥈⥉⥊⥋⥌⥍⥎⥏⥐⥑⥒⥓⥔⥕⥖⥗⥘⥙⥚⥛⥜⥝⥞⥟⥠⥡⥢⥣⥤⥥⥦⥧⥨⥩⥪⥫⥬⥭⥮⥯⥰⦷⦸⦼⦾⦿⧀⧁⧡⧣⧤⧥⧴⧶⧷⧺⧻⨇⨈⨝⨟⨢⨣⨤⨥⨦⨧⨨⨩⨪⨫⨬⨭⨮⨰⨱⨲⨳⨴⨵⨶⨷⨸⨹⨺⨻⨼⨽⩀⩁⩂⩃⩄⩅⩊⩋⩌⩍⩎⩏⩐⩑⩒⩓⩔⩕⩖⩗⩘⩚⩛⩜⩝⩞⩟⩠⩡⩢⩣⩦⩧⩪⩫⩬⩭⩮⩯⩰⩱⩲⩳⩴⩵⩶⩷⩸⩹⩺⩻⩼⩽⩾⩿⪀⪁⪂⪃⪄⪅⪆⪇⪈⪉⪊⪋⪌⪍⪎⪏⪐⪑⪒⪓⪔⪕⪖⪗⪘⪙⪚⪛⪜⪝⪞⪟⪠⪡⪢⪣⪤⪥⪦⪧⪨⪩⪪⪫⪬⪭⪮⪯⪰⪱⪲⪳⪴⪵⪶⪷⪸⪹⪺⪻⪼⪽⪾⪿⫀⫁⫂⫃⫄⫅⫆⫇⫈⫉⫊⫋⫌⫍⫎⫏⫐⫑⫒⫓⫔⫕⫖⫗⫘⫙⫛⫷⫸⫹⫺⬰⬱⬲⬳⬴⬵⬶⬷⬸⬹⬺⬻⬼⬽⬾⬿⭀⭁⭂⭃⭄⭇⭈⭉⭊⭋⭌←↑→↓'
+let s:op_chars_wc = '\U2026\U205D\U214B\U2190-\U2194\U219A-\U219E\U21A0\U21A2-\U21A4\U21A6\U21A9-\U21AC\U21AE\U21B6\U21B7\U21BA-\U21BD\U21C0\U21C1\U21C4\U21C6\U21C7\U21C9\U21CB-\U21D0\U21D2\U21D4\U21DA-\U21DD\U21E0\U21E2\U21F4-\U21FF\U2208-\U220D\U2213\U2214\U2217-\U221D\U2224-\U222A\U2237\U2238\U223A\U223B\U223D\U223E\U2240-\U228B\U228D-\U229C\U229E-\U22A3\U22A9\U22AC\U22AE\U22B0-\U22B7\U22BB-\U22BD\U22C4-\U22C7\U22C9-\U22D3\U22D5-\U22FF\U233F\U25B7\U27C2\U27C8\U27C9\U27D1\U27D2\U27D5-\U27D7\U27F0\U27F1\U27F5-\U27F7\U27F9-\U27FF\U2900-\U2918\U291D-\U2920\U2944-\U2970\U29B7\U29B8\U29BC\U29BE-\U29C1\U29E1\U29E3-\U29E5\U29F4\U29F6\U29F7\U29FA\U29FB\U2A07\U2A08\U2A1D\U2A1F\U2A22-\U2A2E\U2A30-\U2A3D\U2A40-\U2A45\U2A4A-\U2A58\U2A5A-\U2A63\U2A66\U2A67\U2A6A-\U2AD9\U2ADB\U2AF7-\U2AFA\U2B30-\U2B44\U2B47-\U2B4C\UFFE9-\UFFEC'
+
+" Full operators regex
+let s:operators = '\%(' . '\.\%([-+*/^÷%|&⊻]\|//\|\\\|>>\|>>>\?\)\?=' .
+ \ '\|' . '[:<>]=\|||\|&&\||>\|<|\|[<>:]:\|<<\|>>>\?\|//\|[-=]>\|\.\.\.\?' .
+ \ '\|' . '\.\?[!' . s:op_chars . s:op_chars_wc . ']' .
+ \ '\)'
+
+
+" Characters that can be used to start an identifier. Above \UBF we don't
+" bother checking. (If a UTF8 operator is used, it will take precedence anyway.)
+let s:id_charsH = '\%([A-Za-z_\UA2-\UA6\UA9\UAA\UAE\UB0\UB5\UBA]\|[^\U00-\UBF]\)'
+" Characters that can appear in an identifier, starting in 2nd position. Above
+" \UBF we check for operators since we need to stop the identifier if one
+" appears. We don't check for invalid characters though.
+let s:id_charsW = '\%([0-9A-Za-z_!\UA2-\UA6\UA9\UAA\UAE-\UB0\UB2-\UB5\UB8-\UBA\UBC-\UBE]\|[^\U00-\UBF]\@=[^' . s:op_chars_wc . ']\)'
+
+" A valid julia identifier, more or less
+let s:idregex = '\%(' . s:id_charsH . s:id_charsW . '*\)'
+
+
+
+syn case match
+
+syntax cluster juliaExpressions contains=@juliaParItems,@juliaStringItems,@juliaKeywordItems,@juliaBlocksItems,@juliaTypesItems,@juliaConstItems,@juliaMacroItems,@juliaSymbolItems,@juliaOperatorItems,@juliaNumberItems,@juliaCommentItems,@juliaErrorItems,@juliaSyntaxRegions
+syntax cluster juliaExprsPrintf contains=@juliaExpressions,@juliaPrintfItems
+syntax cluster juliaExprsNodot contains=@juliaParItems,@juliaStringItems,@juliaMacroItems,@juliaSymbolItems,@juliaOperatorItems,@juliaCommentItems,juliaIdSymbol
+
+syntax cluster juliaParItems contains=juliaParBlock,juliaSqBraIdxBlock,juliaSqBraBlock,juliaCurBraBlock,juliaQuotedParBlock,juliaQuotedQMarkPar
+syntax cluster juliaKeywordItems contains=juliaKeyword,juliaWhereKeyword,juliaImportLine,juliaInfixKeyword,juliaRepKeyword
+syntax cluster juliaBlocksItems contains=juliaConditionalBlock,juliaWhileBlock,juliaForBlock,juliaBeginBlock,juliaFunctionBlock,juliaMacroBlock,juliaQuoteBlock,juliaTypeBlock,juliaImmutableBlock,juliaExceptionBlock,juliaLetBlock,juliaDoBlock,juliaModuleBlock,juliaStructBlock,juliaMutableStructBlock,juliaAbstractBlock,juliaPrimitiveBlock
+syntax cluster juliaTypesItems contains=juliaBaseTypeBasic,juliaBaseTypeNum,juliaBaseTypeC,juliaBaseTypeError,juliaBaseTypeIter,juliaBaseTypeString,juliaBaseTypeArray,juliaBaseTypeDict,juliaBaseTypeSet,juliaBaseTypeIO,juliaBaseTypeProcess,juliaBaseTypeRange,juliaBaseTypeRegex,juliaBaseTypeFact,juliaBaseTypeFact,juliaBaseTypeSort,juliaBaseTypeRound,juliaBaseTypeSpecial,juliaBaseTypeRandom,juliaBaseTypeDisplay,juliaBaseTypeTime,juliaBaseTypeOther
+
+syntax cluster juliaConstItems contains=juliaConstNum,juliaConstBool,juliaConstEnv,juliaConstMMap,juliaConstC,juliaConstGeneric,juliaConstIO,juliaPossibleEuler
+
+syntax cluster juliaMacroItems contains=juliaPossibleMacro,juliaDollarVar,juliaDollarPar,juliaDollarSqBra
+syntax cluster juliaSymbolItems contains=juliaPossibleSymbol
+syntax cluster juliaNumberItems contains=juliaNumbers
+syntax cluster juliaStringItems contains=juliaChar,juliaString,juliabString,juliasString,juliaShellString,juliaDocString,juliaRegEx
+syntax cluster juliaPrintfItems contains=juliaPrintfParBlock,juliaPrintfString
+syntax cluster juliaOperatorItems contains=juliaOperator,juliaRangeOperator,juliaCTransOperator,juliaTernaryRegion,juliaColon,juliaSemicolon,juliaComma
+syntax cluster juliaCommentItems contains=juliaCommentL,juliaCommentM
+syntax cluster juliaErrorItems contains=juliaErrorPar,juliaErrorEnd,juliaErrorElse,juliaErrorCatch,juliaErrorFinally
+
+syntax cluster juliaSyntaxRegions contains=juliaIdSymbol,juliaTypeOperatorR2,juliaTypeOperatorR3,juliaWhereR,juliaDotted
+
+syntax cluster juliaSpellcheckStrings contains=@spell
+syntax cluster juliaSpellcheckDocStrings contains=@spell
+syntax cluster juliaSpellcheckComments contains=@spell
+
+if !s:julia_spellcheck_docstrings
+ syntax cluster juliaSpellcheckDocStrings remove=@spell
+endif
+if !s:julia_spellcheck_strings
+ syntax cluster juliaSpellcheckStrings remove=@spell
+endif
+if !s:julia_spellcheck_comments
+ syntax cluster juliaSpellcheckComments remove=@spell
+endif
+
+syntax match juliaSemicolon display ";"
+syntax match juliaComma display ","
+syntax match juliaColon display ":"
+
+" A dot can introduce a sort of 'environment' such that words after it are not
+" recognized as keywords. This has low precedence so that it can be overridden
+" by operators
+syntax match juliaDotted transparent "\.\s*[^])}.]" contains=@juliaExprsNodot
+syntax match juliaDottedT contained transparent "\.\s*[^])}.]" contains=@juliaExprsNodot,juliaType
+
+syntax match juliaErrorPar display "[])}]"
+syntax match juliaErrorEnd display "\<end\>"
+syntax match juliaErrorElse display "\<\%(else\|elseif\)\>"
+syntax match juliaErrorCatch display "\<catch\>"
+syntax match juliaErrorFinally display "\<finally\>"
+syntax match juliaErrorSemicol display contained ";"
+
+syntax region juliaParBlock matchgroup=juliaParDelim start="(" end=")" contains=@juliaExpressions,juliaComprehensionFor
+syntax region juliaParBlockInRange matchgroup=juliaParDelim contained start="(" end=")" contains=@juliaExpressions,juliaParBlockInRange,juliaRangeKeyword,juliaComprehensionFor
+syntax region juliaSqBraIdxBlock matchgroup=juliaParDelim start="\[" end="\]" contains=@juliaExpressions,juliaParBlockInRange,juliaRangeKeyword,juliaComprehensionFor,juliaSymbolS,juliaQuotedParBlockS,juliaQuotedQMarkParS
+exec 'syntax region juliaSqBraBlock matchgroup=juliaParDelim start="\%(^\|\s\|' . s:operators . '\)\@'.s:d(3).'<=\[" end="\]" contains=@juliaExpressions,juliaComprehensionFor,juliaSymbolS,juliaQuotedParBlockS,juliaQuotedQMarkParS'
+syntax region juliaCurBraBlock matchgroup=juliaParDelim start="{" end="}" contains=juliaType,juliaDottedT,@juliaExpressions
+
+exec 'syntax match juliaType contained "\%(' . s:idregex . '\.\)*\zs' . s:idregex . '"'
+
+" This is a generic identifier followed by some symbol, either a type
+" operator (<: or >:), or an open parenthesis, or an open curly bracket.
+" It's used to recognize one of the contained regions looking for identifiers
+" only once. Once recognized, those regions no longer need to use the
+" expensive s:idregex.
+exec 'syntax match juliaIdSymbol transparent "' . s:idregex . '\%(\s*[<>]:\|\.\?(\|{\|\"\)\@=" contains=juliaFunctionCall,juliaParamType,juliaStringPrefixed,juliaTypeOperatorR1'
+
+syntax match juliaFunctionCall contained "[^{([:space:]<>\"]\+(\@=" nextgroup=juliaParBlock
+
+exec 'syntax match juliaFunctionDef contained transparent "\%(\<\%(function\|macro\)\)\@'.s:d(8).'<=\s\+\zs' . s:idregex . '\%(\.' . s:idregex . '\)*\ze\s*\%((\|\send\>\|$\)" contains=juliaFunctionName'
+exec 'syntax match juliaFunctionName contained "\%(\<\%(function\|macro\)\s\+\)\@'.s:d(20).'<=\%(' . s:idregex . '\.\)*\zs' . s:idregex . '"'
+
+exec 'syntax match juliaStructR contained transparent "\%(\<\%(\%(mutable\s\+\)\?struct\|\%(abstract\|primitive\)\s\+type\)\s\+\)\@'.s:d(20).'<=\%(' . s:idregex . '\.\)*' . s:idregex . '\>\(\s*(\)\@!" contains=juliaType'
+
+syntax match juliaKeyword display "\<\%(return\|local\|global\|const\)\>"
+syntax match juliaInfixKeyword display "\%(=\s*\)\@<!\<\%(in\|isa\)\>\S\@!\%(\s*=\)\@!"
+
+" The import/export/using keywords introduce a sort of special parsing
+" environment with its own rules
+exec 'syntax region juliaImportLine matchgroup=juliaKeyword excludenl start="\<\%(import\|using\|export\)\>" skip="\%(\%(\<\%(import\|using\|export\)\>\)\|^\)\@'.s:d(6).'<=$" end="$" end="\%([])}]\)\@=" contains=@juliaExpressions,juliaAsKeyword,@juliaContinuationItems,juliaMacroName'
+syntax match juliaAsKeyword display contained "\<as\>"
+
+syntax match juliaRepKeyword display "\<\%(break\|continue\)\>"
+syntax region juliaConditionalBlock matchgroup=juliaConditional start="\<if\>" end="\<end\>" contains=@juliaExpressions,juliaConditionalEIBlock,juliaConditionalEBlock fold
+syntax region juliaConditionalEIBlock matchgroup=juliaConditional transparent contained start="\<elseif\>" end="\<\%(end\|else\|elseif\)\>"me=s-1 contains=@juliaExpressions,juliaConditionalEIBlock,juliaConditionalEBlock
+syntax region juliaConditionalEBlock matchgroup=juliaConditional transparent contained start="\<else\>" end="\<end\>"me=s-1 contains=@juliaExpressions
+syntax region juliaWhileBlock matchgroup=juliaRepeat start="\<while\>" end="\<end\>" contains=@juliaExpressions fold
+syntax region juliaForBlock matchgroup=juliaRepeat start="\<for\>" end="\<end\>" contains=@juliaExpressions,juliaOuter fold
+syntax region juliaBeginBlock matchgroup=juliaBlKeyword start="\<begin\>" end="\<end\>" contains=@juliaExpressions fold
+syntax region juliaFunctionBlock matchgroup=juliaBlKeyword start="\<function\>" end="\<end\>" contains=@juliaExpressions,juliaFunctionDef fold
+syntax region juliaMacroBlock matchgroup=juliaBlKeyword start="\<macro\>" end="\<end\>" contains=@juliaExpressions,juliaFunctionDef fold
+syntax region juliaQuoteBlock matchgroup=juliaBlKeyword start="\<quote\>" end="\<end\>" contains=@juliaExpressions fold
+syntax region juliaStructBlock matchgroup=juliaBlKeyword start="\<struct\>" end="\<end\>" contains=@juliaExpressions,juliaStructR fold
+syntax region juliaMutableStructBlock matchgroup=juliaBlKeyword start="\<mutable\s\+struct\>" end="\<end\>" contains=@juliaExpressions,juliaStructR fold
+syntax region juliaLetBlock matchgroup=juliaBlKeyword start="\<let\>" end="\<end\>" contains=@juliaExpressions fold
+syntax region juliaDoBlock matchgroup=juliaBlKeyword start="\<do\>" end="\<end\>" contains=@juliaExpressions fold
+syntax region juliaModuleBlock matchgroup=juliaBlKeyword start="\<\%(bare\)\?module\>" end="\<end\>" contains=@juliaExpressions fold
+syntax region juliaExceptionBlock matchgroup=juliaException start="\<try\>" end="\<end\>" contains=@juliaExpressions,juliaCatchBlock,juliaFinallyBlock fold
+syntax region juliaCatchBlock matchgroup=juliaException transparent contained start="\<catch\>" end="\<end\>"me=s-1 contains=@juliaExpressions,juliaFinallyBlock
+syntax region juliaFinallyBlock matchgroup=juliaException transparent contained start="\<finally\>" end="\<end\>"me=s-1 contains=@juliaExpressions
+syntax region juliaAbstractBlock matchgroup=juliaBlKeyword start="\<abstract\s\+type\>" end="\<end\>" fold contains=@juliaExpressions,juliaStructR
+syntax region juliaPrimitiveBlock matchgroup=juliaBlKeyword start="\<primitive\s\+type\>" end="\<end\>" fold contains=@juliaExpressions,juliaStructR
+
+exec 'syntax region juliaComprehensionFor matchgroup=juliaComprehensionFor transparent contained start="\%([^[:space:],;:({[]\_s*\)\@'.s:d(80).'<=\<for\>" end="\ze[]);]" contains=@juliaExpressions,juliaComprehensionIf,juliaComprehensionFor'
+syntax match juliaComprehensionIf contained "\<if\>"
+
+exec 'syntax match juliaOuter contained "\<outer\ze\s\+' . s:idregex . '\>"'
+
+syntax match juliaRangeKeyword contained "\<\%(begin\|end\)\>"
+
+syntax match juliaBaseTypeBasic display "\<\%(\%(N\|Named\)\?Tuple\|Symbol\|Function\|Union\%(All\)\?\|Type\%(Name\|Var\)\?\|Any\|ANY\|Vararg\|Ptr\|Exception\|Module\|Expr\|DataType\|\%(LineNumber\|Quote\)Node\|\%(Weak\|Global\)\?Ref\|Method\|Pair\|Val\|Nothing\|Some\|Missing\)\>"
+syntax match juliaBaseTypeNum display "\<\%(U\?Int\%(8\|16\|32\|64\|128\)\?\|Float\%(16\|32\|64\)\|Complex\|Bool\|Char\|Number\|Signed\|Unsigned\|Integer\|AbstractFloat\|Real\|Rational\|\%(Abstract\)\?Irrational\|Enum\|BigInt\|BigFloat\|MathConst\|ComplexF\%(16\|32\|64\)\)\>"
+syntax match juliaBaseTypeC display "\<\%(FileOffset\|C\%(u\?\%(char\|short\|int\|long\(long\)\?\|w\?string\)\|float\|double\|\%(ptrdiff\|s\?size\|wchar\|off\|u\?intmax\)_t\|void\)\)\>"
+syntax match juliaBaseTypeError display "\<\%(\%(Bounds\|Divide\|Domain\|\%(Stack\)\?Overflow\|EOF\|Undef\%(Ref\|Var\)\|System\|Type\|Parse\|Argument\|Key\|Load\|Method\|Inexact\|OutOfMemory\|Init\|Assertion\|ReadOnlyMemory\|StringIndex\)Error\|\%(Interrupt\|Error\|ProcessExited\|Captured\|Composite\|InvalidState\|Missing\|\%(Process\|Task\)Failed\)Exception\|DimensionMismatch\|SegmentationFault\)\>"
+syntax match juliaBaseTypeIter display "\<\%(EachLine\|Enumerate\|Cartesian\%(Index\|Range\)\|LinSpace\|CartesianIndices\)\>"
+syntax match juliaBaseTypeString display "\<\%(DirectIndex\|Sub\|Rep\|Rev\|Abstract\|Substitution\)\?String\>"
+syntax match juliaBaseTypeArray display "\<\%(\%(Sub\)\?Array\|\%(Abstract\|Dense\|Strided\)\?\%(Array\|Matrix\|Vec\%(tor\|OrMat\)\)\|SparseMatrixCSC\|\%(AbstractSparse\|Bit\|Shared\)\%(Array\|Vector\|Matrix\)\|\%\(D\|Bid\|\%(Sym\)\?Trid\)iagonal\|Hermitian\|Symmetric\|UniformScaling\|\%(Lower\|Upper\)Triangular\|\%(Sparse\|Row\)Vector\|VecElement\|Conj\%(Array\|Matrix\|Vector\)\|Index\%(Cartesian\|Linear\|Style\)\|PermutedDimsArray\|Broadcasted\|Adjoint\|Transpose\|LinearIndices\)\>"
+syntax match juliaBaseTypeDict display "\<\%(WeakKey\|Id\|Abstract\)\?Dict\>"
+syntax match juliaBaseTypeSet display "\<\%(\%(Abstract\|Bit\)\?Set\)\>"
+syntax match juliaBaseTypeIO display "\<\%(IO\%(Stream\|Buffer\|Context\)\?\|RawFD\|StatStruct\|FileMonitor\|PollingFileWatcher\|Timer\|Base64\%(Decode\|Encode\)Pipe\|\%(UDP\|TCP\)Socket\|\%(Abstract\)\?Channel\|BufferStream\|ReentrantLock\|GenericIOBuffer\)\>"
+syntax match juliaBaseTypeProcess display "\<\%(Pipe\|Cmd\|PipeBuffer\)\>"
+syntax match juliaBaseTypeRange display "\<\%(Dims\|RangeIndex\|\%(Abstract\|Lin\|Ordinal\|Step\|\%(Abstract\)\?Unit\)Range\|Colon\|ExponentialBackOff\|StepRangeLen\)\>"
+syntax match juliaBaseTypeRegex display "\<Regex\%(Match\)\?\>"
+syntax match juliaBaseTypeFact display "\<\%(Factorization\|BunchKaufman\|\%(Cholesky\|QR\)\%(Pivoted\)\?\|\%(Generalized\)\?\%(Eigen\|SVD\|Schur\)\|Hessenberg\|LDLt\|LQ\|LU\)\>"
+syntax match juliaBaseTypeSort display "\<\%(Insertion\|\(Partial\)\?Quick\|Merge\)Sort\>"
+syntax match juliaBaseTypeRound display "\<Round\%(ingMode\|FromZero\|Down\|Nearest\%(Ties\%(Away\|Up\)\)\?\|ToZero\|Up\)\>"
+syntax match juliaBaseTypeSpecial display "\<\%(LocalProcess\|ClusterManager\)\>"
+syntax match juliaBaseTypeRandom display "\<\%(AbstractRNG\|MersenneTwister\|RandomDevice\)\>"
+syntax match juliaBaseTypeDisplay display "\<\%(Text\(Display\)\?\|\%(Abstract\)\?Display\|MIME\|HTML\)\>"
+syntax match juliaBaseTypeTime display "\<\%(Date\%(Time\)\?\|DateFormat\)\>"
+syntax match juliaBaseTypeOther display "\<\%(RemoteRef\|Task\|Condition\|VersionNumber\|IPv[46]\|SerializationState\|WorkerConfig\|Future\|RemoteChannel\|IPAddr\|Stack\%(Trace\|Frame\)\|\(Caching\|Worker\)Pool\|AbstractSerializer\)\>"
+
+syntax match juliaConstNum display "\%(\<\%(\%(NaN\|Inf\)\%(16\|32\|64\)\?\|pi\|π\)\>\)"
+" Note: recognition of ℯ, which Vim does not consider a valid identifier, is
+" complicated. We detect possible uses by just looking for the character (for
+" performance) and then check that it's actually used by its own.
+" (This also tries to detect preceding number constants; it does so in a crude
+" way.)
+syntax match juliaPossibleEuler "ℯ" contains=juliaEuler
+exec 'syntax match juliaEuler contained "\%(\%(^\|[' . s:nonidS_chars . s:op_chars_wc . ']\)\%(.\?[0-9][.0-9eEf_]*\d\)\?\)\@'.s:d(80).'<=ℯ\ze[' . s:nonidS_chars . s:op_chars_wc . ']"'
+syntax match juliaConstBool display "\<\%(true\|false\)\>"
+syntax match juliaConstEnv display "\<\%(ARGS\|ENV\|ENDIAN_BOM\|LOAD_PATH\|VERSION\|PROGRAM_FILE\|DEPOT_PATH\)\>"
+syntax match juliaConstIO display "\<\%(std\%(out\|in\|err\)\|devnull\)\>"
+syntax match juliaConstC display "\<\%(C_NULL\)\>"
+syntax match juliaConstGeneric display "\<\%(nothing\|Main\|undef\|missing\)\>"
+
+syntax match juliaParamType contained "[^{([:space:]<>\"]\+\ze{" nextgroup=juliaCurBraBlock
+
+syntax match juliaPossibleMacro transparent "@" contains=juliaMacroCall,juliaMacroCallP,juliaPrintfMacro,juliaDocMacro,juliaDocMacroPre
+
+exec 'syntax match juliaMacro contained "@' . s:idregex . '\%(\.' . s:idregex . '\)*"'
+syntax match juliaMacro contained "@[!.~$%^*/\\|<>+-]\ze[^0-9]"
+exec 'syntax region juliaMacroCall contained transparent start="\(@' . s:idregex . '\%(\.' . s:idregex . '\)*\)\@=\1\%([^(]\|$\)" end="\ze\%([])};#]\|$\|\<for\>\|\<end\>\)" contains=@juliaExpressions,juliaMacro,juliaSymbolS,juliaQuotedParBlockS'
+exec 'syntax region juliaMacroCall contained transparent start="\(@.\)\@=\1\%([^(]\|$\)" end="\ze\%([])};#]\|$\|\<for\>\|\<end\>\)" contains=@juliaExpressions,juliaMacro,juliaSymbolS,juliaQuotedParBlockS'
+exec 'syntax region juliaMacroCallP contained transparent start="@' . s:idregex . '\%(\.' . s:idregex . '\)*(" end=")\@'.s:d(1).'<=" contains=juliaMacro,juliaParBlock'
+exec 'syntax region juliaMacroCallP contained transparent start="@.(" end=")\@'.s:d(1).'<=" contains=juliaMacro,juliaParBlock'
+
+exec 'syntax match juliaNumbers transparent "\%(^\|[' . s:nonidS_chars . s:op_chars_wc . ']\)\@'.s:d(1).'<=\d\|\.\d\|im\>" contains=juliaNumber,juliaFloat,juliaComplexUnit'
+
+"integer regexes
+let s:dec_regex = '\d\%(_\?\d\)*\%(\>\|im\>\|\ze\D\)'
+let s:hex_regex = '0x\x\%(_\?\x\)*\%(\>\|im\>\|\ze\X\)'
+let s:bin_regex = '0b[01]\%(_\?[01]\)*\%(\>\|im\>\|\ze[^01]\)'
+let s:oct_regex = '0o\o\%(_\?\o\)*\%(\>\|im\>\|\ze\O\)'
+
+let s:int_regex = '\%(' . s:hex_regex .
+ \ '\|' . s:bin_regex .
+ \ '\|' . s:oct_regex .
+ \ '\|' . s:dec_regex .
+ \ '\)'
+
+"floating point regexes
+" starting with a dot, optional exponent
+let s:float_regex1 = '\.\d\%(_\?\d\)*\%([eEf][-+]\?\d\+\)\?\%(\>\|im\>\|\ze\D\)'
+" with dot, optional exponent
+let s:float_regex2 = '\d\%(_\?\d\)*\.\%(\d\%(_\?\d\)*\)\?\%([eEf][-+]\?\d\+\)\?\%(\>\|im\>\|\ze\D\)'
+" without dot, with exponent
+let s:float_regex3 = '\d\%(_\?\d\)*[eEf][-+]\?\d\+\%(\>\|im\>\|\ze\D\)'
+
+"hex floating point numbers
+" starting with a dot
+let s:hexfloat_regex1 = '0x\.\%\(\x\%(_\?\x\)*\)\?[pP][-+]\?\d\+\%(\>\|im\>\|\ze\X\)'
+" starting with a digit
+let s:hexfloat_regex2 = '0x\x\%(_\?\x\)*\%\(\.\%\(\x\%(_\?\x\)*\)\?\)\?[pP][-+]\?\d\+\%(\>\|im\>\|\ze\X\)'
+
+let s:float_regex = '\%(' . s:float_regex3 .
+ \ '\|' . s:float_regex2 .
+ \ '\|' . s:float_regex1 .
+ \ '\|' . s:hexfloat_regex2 .
+ \ '\|' . s:hexfloat_regex1 .
+ \ '\)'
+
+exec 'syntax match juliaNumber contained "' . s:int_regex . '" contains=juliaComplexUnit'
+exec 'syntax match juliaFloat contained "' . s:float_regex . '" contains=juliaComplexUnit'
+syntax match juliaComplexUnit display contained "\<im\>"
+
+syntax match juliaRangeOperator display ":"
+exec 'syntax match juliaOperator "' . s:operators . '"'
+
+exec 'syntax region juliaTernaryRegion matchgroup=juliaTernaryOperator start="\s\zs?\ze\s" skip="\%(:\(:\|[^:[:space:]'."'".'"({[]\+\s*\ze:\)\|\%(?\s*\)\@'.s:d(6).'<=:(\)" end=":" contains=@juliaExpressions,juliaErrorSemicol'
+
+let s:interp_dollar = '\([' . s:nonidS_chars . s:op_chars_wc . '!]\|^\)\@'.s:d(1).'<=\$'
+
+exec 'syntax match juliaDollarVar display contained "' . s:interp_dollar . s:idregex . '"'
+exec 'syntax region juliaDollarPar matchgroup=juliaDollarVar contained start="' .s:interp_dollar . '(" end=")" contains=@juliaExpressions'
+exec 'syntax region juliaDollarSqBra matchgroup=juliaDollarVar contained start="' .s:interp_dollar . '\[" end="\]" contains=@juliaExpressions,juliaComprehensionFor,juliaSymbolS,juliaQuotedParBlockS'
+
+syntax match juliaChar "'\\\?.'" contains=juliaSpecialChar
+syntax match juliaChar display "'\\\o\{3\}'" contains=juliaOctalEscapeChar
+syntax match juliaChar display "'\\x\x\{2\}'" contains=juliaHexEscapeChar
+syntax match juliaChar display "'\\u\x\{1,4\}'" contains=juliaUniCharSmall
+syntax match juliaChar display "'\\U\x\{1,8\}'" contains=juliaUniCharLarge
+
+exec 'syntax match juliaCTransOperator "[[:space:]}' . s:nonid_chars . s:op_chars_wc . '!]\@'.s:d(1).'<!\.\?' . "'" . 'ᵀ\?"'
+
+" TODO: some of these might be specialized; the rest could be just left to the
+" generic juliaStringPrefixed fallback
+syntax region juliaString matchgroup=juliaStringDelim start=+\z("\(""\)\?\)+ skip=+\%(\\\\\)*\\"+ end=+\z1+ contains=@juliaStringVars,@juliaSpecialChars,@juliaSpellcheckStrings
+syntax region juliaStringPrefixed contained matchgroup=juliaStringDelim start=+[^{([:space:]<>"]\+\z("\(""\)\?\)+ skip=+\%(\\\\\)*\\"+ end=+\z1+ contains=@juliaSpecialCharsRaw
+syntax region juliabString matchgroup=juliaStringDelim start=+\<b\z("\(""\)\?\)+ skip=+\%(\\\\\)*\\"+ end=+\z1+ contains=@juliaSpecialChars
+syntax region juliasString matchgroup=juliaStringDelim start=+\<s\z("\(""\)\?\)+ skip=+\%(\\\\\)*\\"+ end=+\z1+ contains=@juliaSpecialChars
+
+syntax region juliaDocString matchgroup=juliaDocStringDelim fold start=+^"""+ skip=+\%(\\\\\)*\\"+ end=+"""+ contains=@juliaStringVars,@juliaSpecialChars,@juliaSpellcheckDocStrings
+
+exec 'syntax region juliaPrintfMacro contained transparent start="@s\?printf(" end=")\@'.s:d(1).'<=" contains=juliaMacro,juliaPrintfParBlock'
+syntax region juliaPrintfMacro contained transparent start="@s\?printf\s\+" end="\ze\%([])};#]\|$\|\<for\>\)" contains=@juliaExprsPrintf,juliaMacro,juliaSymbolS,juliaQuotedParBlockS
+syntax region juliaPrintfParBlock contained matchgroup=juliaParDelim start="(" end=")" contains=@juliaExprsPrintf
+syntax region juliaPrintfString contained matchgroup=juliaStringDelim start=+"+ skip=+\%(\\\\\)*\\"+ end=+"+ contains=@juliaSpecialChars,@juliaPrintfChars
+
+exec 'syntax region juliaDocMacroPre contained transparent start=+@doc\s\+\%(' . s:idregex . '\%(\.' . s:idregex . '\)*\)\z("\%(""\)\?\)+ skip=+\%(\\\\\)*\\"+ end=+\(\z1\)\@'.s:d(3).'<=+ contains=juliaMacro,juliaDocStringMRaw'
+exec 'syntax region juliaDocMacro contained transparent start=+@doc\s\+\z("\%(""\)\?\)+ skip=+\%(\\\\\)*\\"+ end=+\(\z1\)\@'.s:d(3).'<=+ contains=juliaMacro,juliaDocStringM'
+syntax region juliaDocStringMRaw contained fold matchgroup=juliaDocStringDelim fold start=+\z\("\(""\)\?\)+ skip=+\%(\\\\\)*\\"+ end=+\z1+ contains=@juliaSpellcheckDocStrings
+syntax region juliaDocStringM contained fold matchgroup=juliaDocStringDelim fold start=+\z\("\(""\)\?\)+ skip=+\%(\\\\\)*\\"+ end=+\z1+ contains=@juliaStringVars,@juliaSpecialChars,@juliaSpellcheckDocStrings
+
+syntax region juliaShellString matchgroup=juliaStringDelim start=+`+ skip=+\%(\\\\\)*\\`+ end=+`+ contains=@juliaStringVars,juliaSpecialChar
+
+syntax cluster juliaStringVars contains=juliaStringVarsPar,juliaStringVarsSqBra,juliaStringVarsCurBra,juliaStringVarsPla
+syntax region juliaStringVarsPar contained matchgroup=juliaStringVarDelim start="$(" end=")" contains=@juliaExpressions
+syntax region juliaStringVarsSqBra contained matchgroup=juliaStringVarDelim start="$\[" end="\]" contains=@juliaExpressions,juliaComprehensionFor,juliaSymbolS,juliaQuotedParBlockS
+syntax region juliaStringVarsCurBra contained matchgroup=juliaStringVarDelim start="${" end="}" contains=@juliaExpressions
+exec 'syntax match juliaStringVarsPla contained "\$' . s:idregex . '"'
+
+" TODO improve RegEx
+syntax region juliaRegEx matchgroup=juliaStringDelim start=+\<r\z("\(""\)\?\)+ skip=+\%(\\\\\)*\\"+ end=+\z1[imsx]*+
+
+syntax cluster juliaSpecialChars contains=juliaSpecialChar,juliaDoubleBackslash,juliaEscapedQuote,juliaOctalEscapeChar,juliaHexEscapeChar,juliaUniCharSmall,juliaUniCharLarge
+syntax match juliaSpecialChar display contained "\\."
+syntax match juliaOctalEscapeChar display contained "\\\o\{3\}"
+syntax match juliaHexEscapeChar display contained "\\x\x\{2\}"
+syntax match juliaUniCharSmall display contained "\\u\x\{1,4\}"
+syntax match juliaUniCharLarge display contained "\\U\x\{1,8\}"
+syntax cluster juliaSpecialCharsRaw contains=juliaDoubleBackslash,juliaEscapedQuote
+syntax match juliaDoubleBackslash contained "\\\\"
+syntax match juliaEscapedQuote contained "\\\""
+
+syntax cluster juliaPrintfChars contains=juliaErrorPrintfFmt,juliaPrintfFmt
+syntax match juliaErrorPrintfFmt display contained "\\\?%."
+syntax match juliaPrintfFmt display contained "%\%(\d\+\$\)\=[-+' #0]*\%(\d*\|\*\|\*\d\+\$\)\%(\.\%(\d*\|\*\|\*\d\+\$\)\)\=\%([hlLjqzt]\|ll\|hh\)\=[aAbdiuoxXDOUfFeEgGcCsSpn]"
+syntax match juliaPrintfFmt display contained "%%"
+syntax match juliaPrintfFmt display contained "\\%\%(\d\+\$\)\=[-+' #0]*\%(\d*\|\*\|\*\d\+\$\)\%(\.\%(\d*\|\*\|\*\d\+\$\)\)\=\%([hlLjqzt]\|ll\|hh\)\=[aAbdiuoxXDOUfFeEgGcCsSpn]"hs=s+1
+syntax match juliaPrintfFmt display contained "\\%%"hs=s+1
+
+" this is used to restrict the search for Symbols to when colons appear at all
+" (for performance reasons)
+syntax match juliaPossibleSymbol transparent ":\ze[^:]" contains=juliaSymbol,juliaQuotedParBlock,juliaQuotedQMarkPar,juliaColon
+
+let s:quotable = '\%(' . s:idregex . '\|' . s:operators . '\|[?.]\|' . s:float_regex . '\|' . s:int_regex . '\)'
+let s:quoting_colon = '\%(\%(^\s*\|\s\{6,\}\|[' . s:nonid_chars . s:op_chars_wc . ']\s*\)\@'.s:d(6).'<=\|\%(\<\%(return\|if\|else\%(if\)\?\|while\|try\|begin\)\s\+\)\@'.s:d(9).'<=\)\zs:'
+let s:quoting_colonS = '\s\@'.s:d(1).'<=:'
+
+" note: juliaSymbolS only works within whitespace-sensitive contexts,
+" such as in macro calls without parentheses, or within square brackets.
+" It is used to override the recognition of expressions like `a :b` as
+" ranges rather than symbols in those contexts.
+" (Note that such `a :b` expressions only allows at most 5 spaces between
+" the identifier and the colon anyway.)
+
+exec 'syntax match juliaSymbol contained "' . s:quoting_colon . s:quotable . '"'
+exec 'syntax match juliaSymbolS contained "' . s:quoting_colonS . s:quotable . '"'
+
+" same as above for quoted expressions such as :(expr)
+exec 'syntax region juliaQuotedParBlock matchgroup=juliaQParDelim start="' . s:quoting_colon . '(" end=")" contains=@juliaExpressions'
+exec 'syntax match juliaQuotedQMarkPar "' . s:quoting_colon . '(\s*?\s*)" contains=juliaQuotedQMark'
+exec 'syntax region juliaQuotedParBlockS matchgroup=juliaQParDelim contained start="' . s:quoting_colonS . '(" end=")" contains=@juliaExpressions'
+
+
+syntax match juliaTypeOperatorR1 contained "[^{([:space:]<>\"]\+\%(\s*[<>]:\)\@="
+
+" force precedence over Symbols
+syntax match juliaTypeOperator contained "[<>:]:"
+exec 'syntax match juliaTypeOperatorR2 transparent "[<>:]:\s*\%(' . s:idregex . '\.\)*' . s:idregex . '" contains=juliaTypeOperator,juliaType,juliaDottedT,@juliaExpressions nextgroup=juliaTypeOperator'
+syntax match juliaIsaKeyword contained "\<isa\>"
+exec 'syntax match juliaTypeOperatorR3 transparent "\<isa\s\+\%(' . s:idregex . '\.\)*' . s:idregex . '" contains=juliaIsaKeyword,juliaType,juliaDottedT,@juliaExpressions nextgroup=juliaIsaKeyword'
+
+syntax match juliaWhereKeyword "\<where\>"
+exec 'syntax match juliaWhereR transparent "\<where\s\+' . s:idregex . '" contains=juliaWhereKeyword,juliaType,juliaDottedT,juliaIdSymbol'
+
+syntax region juliaCommentL matchgroup=juliaCommentDelim excludenl start="#\ze\%([^=]\|$\)" end="$" contains=juliaTodo,@juliaSpellcheckComments
+syntax region juliaCommentM matchgroup=juliaCommentDelim fold start="#=\ze\%([^#]\|$\)" end="=#" contains=juliaTodo,juliaCommentM,@juliaSpellcheckComments
+syntax keyword juliaTodo contained TODO FIXME XXX
+
+" detect an end-of-line with only whitespace or comments before it
+let s:eol = '\s*\%(\%(\%(#=\%(=#\@!\|[^=]\|\n\)\{-}=#\)\s*\)\+\)\?\%(#=\@!.*\)\?\n'
+
+" a trailing comma, or colon, or an empty line in an import/using/export
+" multi-line command. Used to recognize the as keyword, and for indentation
+" (this needs to take precedence over normal commas and colons, and comments)
+syntax cluster juliaContinuationItems contains=juliaContinuationComma,juliaContinuationColon,juliaContinuationNone
+exec 'syntax region juliaContinuationComma matchgroup=juliaComma contained start=",\ze'.s:eol.'" end="\n\+\ze." contains=@juliaCommentItems'
+exec 'syntax region juliaContinuationColon matchgroup=juliaColon contained start=":\ze'.s:eol.'" end="\n\+\ze." contains=@juliaCommentItems'
+exec 'syntax region juliaContinuationNone matchgroup=NONE contained start="\%(\<\%(import\|using\|export\)\>\|^\)\@'.s:d(6).'<=\ze'.s:eol.'" end="\n\+\ze." contains=@juliaCommentItems,juliaAsKeyword'
+exec 'syntax match juliaMacroName contained "@' . s:idregex . '\%(\.' . s:idregex . '\)*"'
+
+" the following are disabled by default, but
+" can be enabled by entering e.g.
+" :hi link juliaParDelim Delimiter
+hi def link juliaParDelim juliaNone
+hi def link juliaSemicolon juliaNone
+hi def link juliaComma juliaNone
+hi def link juliaFunctionCall juliaNone
+
+hi def link juliaColon juliaOperator
+
+hi def link juliaFunctionName juliaFunction
+hi def link juliaFunctionName1 juliaFunction
+hi def link juliaMacroName juliaMacro
+
+
+hi def link juliaKeyword Keyword
+hi def link juliaWhereKeyword Keyword
+hi def link juliaInfixKeyword Keyword
+hi def link juliaIsaKeyword Keyword
+hi def link juliaAsKeyword Keyword
+hi def link juliaRepKeyword Keyword
+hi def link juliaBlKeyword Keyword
+hi def link juliaConditional Conditional
+hi def link juliaRepeat Repeat
+hi def link juliaException Exception
+hi def link juliaOuter Keyword
+hi def link juliaBaseTypeBasic Type
+hi def link juliaBaseTypeNum Type
+hi def link juliaBaseTypeC Type
+hi def link juliaBaseTypeError Type
+hi def link juliaBaseTypeIter Type
+hi def link juliaBaseTypeString Type
+hi def link juliaBaseTypeArray Type
+hi def link juliaBaseTypeDict Type
+hi def link juliaBaseTypeSet Type
+hi def link juliaBaseTypeIO Type
+hi def link juliaBaseTypeProcess Type
+hi def link juliaBaseTypeRange Type
+hi def link juliaBaseTypeRegex Type
+hi def link juliaBaseTypeFact Type
+hi def link juliaBaseTypeSort Type
+hi def link juliaBaseTypeRound Type
+hi def link juliaBaseTypeSpecial Type
+hi def link juliaBaseTypeRandom Type
+hi def link juliaBaseTypeDisplay Type
+hi def link juliaBaseTypeTime Type
+hi def link juliaBaseTypeOther Type
+
+hi def link juliaType Type
+hi def link juliaParamType Type
+hi def link juliaTypeOperatorR1 Type
+
+" NOTE: deprecated constants are not highlighted as such. For once,
+" one can still legitimately use them by importing Base.MathConstants.
+" Plus, one-letter variables like `e` and `γ` can be used with other
+" meanings.
+hi def link juliaConstNum Constant
+hi def link juliaEuler Constant
+
+hi def link juliaConstEnv Constant
+hi def link juliaConstC Constant
+hi def link juliaConstLimits Constant
+hi def link juliaConstGeneric Constant
+hi def link juliaRangeKeyword Constant
+hi def link juliaConstBool Boolean
+hi def link juliaConstIO Boolean
+
+hi def link juliaComprehensionFor Keyword
+hi def link juliaComprehensionIf Keyword
+
+hi def link juliaDollarVar Identifier
+
+hi def link juliaFunction Function
+hi def link juliaMacro Macro
+hi def link juliaSymbol Identifier
+hi def link juliaSymbolS Identifier
+hi def link juliaQParDelim Identifier
+hi def link juliaQuotedQMarkPar Identifier
+hi def link juliaQuotedQMark juliaOperatorHL
+
+hi def link juliaNumber Number
+hi def link juliaFloat Float
+hi def link juliaComplexUnit Constant
+
+hi def link juliaChar Character
+
+hi def link juliaString String
+hi def link juliaStringPrefixed juliaString
+hi def link juliabString juliaString
+hi def link juliasString juliaString
+hi def link juliavString juliaString
+hi def link juliarString juliaString
+hi def link juliaipString juliaString
+hi def link juliabigString juliaString
+hi def link juliaMIMEString juliaString
+hi def link juliarawString juliaString
+hi def link juliatestString juliaString
+hi def link juliahtmlString juliaString
+hi def link juliaint128String juliaString
+hi def link juliaPrintfString juliaString
+hi def link juliaShellString juliaString
+hi def link juliaDocString juliaString
+hi def link juliaDocStringM juliaDocString
+hi def link juliaDocStringMRaw juliaDocString
+hi def link juliaStringDelim juliaString
+hi def link juliaDocStringDelim juliaDocString
+hi def link juliaStringVarsPla Identifier
+hi def link juliaStringVarDelim Identifier
+
+hi def link juliaRegEx String
+
+hi def link juliaSpecialChar SpecialChar
+hi def link juliaOctalEscapeChar SpecialChar
+hi def link juliaHexEscapeChar SpecialChar
+hi def link juliaUniCharSmall SpecialChar
+hi def link juliaUniCharLarge SpecialChar
+hi def link juliaDoubleBackslash SpecialChar
+hi def link juliaEscapedQuote SpecialChar
+
+hi def link juliaPrintfFmt SpecialChar
+
+if s:julia_highlight_operators
+ hi! def link juliaOperatorHL Operator
+else
+ hi! def link juliaOperatorHL juliaNone
+endif
+hi def link juliaOperator juliaOperatorHL
+hi def link juliaRangeOperator juliaOperatorHL
+hi def link juliaCTransOperator juliaOperatorHL
+hi def link juliaTernaryOperator juliaOperatorHL
+hi def link juliaTypeOperator juliaOperatorHL
+
+hi def link juliaCommentL Comment
+hi def link juliaCommentM Comment
+hi def link juliaCommentDelim Comment
+hi def link juliaTodo Todo
+
+hi def link juliaErrorPar juliaError
+hi def link juliaErrorEnd juliaError
+hi def link juliaErrorElse juliaError
+hi def link juliaErrorCatch juliaError
+hi def link juliaErrorFinally juliaError
+hi def link juliaErrorSemicol juliaError
+hi def link juliaErrorPrintfFmt juliaError
+
+hi def link juliaError Error
+
+syntax sync fromstart
+
+let b:current_syntax = "julia"
+
+let &cpo = s:cpo_save
+unlet s:cpo_save
diff --git a/runtime/syntax/man.vim b/runtime/syntax/man.vim
index a01bd1c0e7..55b0e16de9 100644
--- a/runtime/syntax/man.vim
+++ b/runtime/syntax/man.vim
@@ -6,7 +6,7 @@ if exists('b:current_syntax')
endif
syntax case ignore
-syntax match manReference display '[^()[:space:]]\+([0-9nx][a-z]*)'
+syntax match manReference display '[^()[:space:]]\+(\%([0-9][a-z]*\|[nlpox]\))'
syntax match manSectionHeading display '^\S.*$'
syntax match manHeader display '^\%1l.*$'
syntax match manSubHeading display '^ \{3\}\S.*$'
@@ -27,11 +27,7 @@ if &filetype != 'man'
finish
endif
-if !exists('b:man_sect')
- call man#init_pager()
-endif
-
-if b:man_sect =~# '^[023]'
+if get(b:, 'man_sect', '') =~# '^[023]'
syntax case match
syntax include @c $VIMRUNTIME/syntax/c.vim
syntax match manCFuncDefinition display '\<\h\w*\>\ze\(\s\|\n\)*(' contained
diff --git a/runtime/syntax/mma.vim b/runtime/syntax/mma.vim
index 0683adc573..d2f22e9be5 100644
--- a/runtime/syntax/mma.vim
+++ b/runtime/syntax/mma.vim
@@ -12,7 +12,7 @@
"
" let filetype_m="mma"
"
-" I also recommend setting the default 'Comment' hilighting to something
+" I also recommend setting the default 'Comment' highlighting to something
" other than the color used for 'Function', since both are plentiful in
" most mathematica files, and they are often the same color (when using
" background=dark).
@@ -109,7 +109,7 @@ syntax match mmaemPHAsis "\%(^\|\s\)(\@<!\*[a-zA-Z0-9]\+\%([- \t':]\+[a-zA-Z0-9]
syntax region mmaComment start=+(\*+ end=+\*)+ skipempty contains=@mmaNotes,mmaItem,@mmaCommentStrings,mmaemPHAsis,mmaComment
" Function Comments:
-" just like a normal comment except the first sentance is Special ala Java
+" just like a normal comment except the first sentence is Special ala Java
" (** *)
" TODO - fix this for nesting, or not...
syntax region mmaFunctionComment start="(\*\*\+" end="\*\+)" contains=@mmaNotes,mmaItem,mmaFunctionTitle,@mmaCommentStrings,mmaemPHAsis,mmaComment
diff --git a/runtime/syntax/objc.vim b/runtime/syntax/objc.vim
index b29313a3cf..7c6e2d5128 100644
--- a/runtime/syntax/objc.vim
+++ b/runtime/syntax/objc.vim
@@ -64,7 +64,7 @@ syn keyword objcStorageClass nullable nonnull null_unspecified
" ObjC type specifier
syn keyword objcTypeSpecifier __kindof __covariant
-" ObjC Type Infomation Parameters
+" ObjC Type Information Parameters
syn keyword objcTypeInfoParams ObjectType KeyType
" shorthand
diff --git a/runtime/syntax/pascal.vim b/runtime/syntax/pascal.vim
index 3ab5c2e661..206df213a6 100644
--- a/runtime/syntax/pascal.vim
+++ b/runtime/syntax/pascal.vim
@@ -3,7 +3,7 @@
" Maintainer: Doug Kearns <dougkearns@gmail.com>
" Previous Maintainers: Xavier Crégut <xavier.cregut@enseeiht.fr>
" Mario Eusebio <bio@dq.fct.unl.pt>
-" Last Change: 2021 Apr 23
+" Last Change: 2021 May 20
" Contributors: Tim Chase <tchase@csc.com>,
" Stas Grabois <stsi@vtrails.com>,
diff --git a/runtime/syntax/php.vim b/runtime/syntax/php.vim
index 7b0085cd6e..80662d6750 100644
--- a/runtime/syntax/php.vim
+++ b/runtime/syntax/php.vim
@@ -1,7 +1,7 @@
" Vim syntax file
" Language: php PHP 3/4/5/7/8
" Maintainer: Tyson Andre <tysonandre775@hotmail.com>
-" Last Change: Dec 22, 2020
+" Last Change: Sep 18, 2021
" URL: https://github.com/TysonAndre/php-vim-syntax
" Former Maintainers:
" Jason Woofenden <jason@jasonwoof.com>
@@ -13,10 +13,32 @@
" than the default colourscheme, because elflord's colours will better
" highlight the break-points (Statements) in your code.
"
+" Note: This embeds a modified copy of the html.vim with (mostly) different symbols,
+" in order to implement php_htmlInStrings=2 can work as expected and correctly parse
+" `<?php $phpStartTag = '<?php';`.
+"
+" Credits for the original version of html.vim prior to modifications
+"
+" Previous Maintainer Jorge Maldonado Ventura <jorgesumle@freakspot.net>
+" Previous Maintainer Claudio Fleiner <claudio@fleiner.com>
+" Repository https://notabug.org/jorgesumle/vim-html-syntax
+" Last Change 2021 Mar 02
+" Included patch #7900 to fix comments
+" Included patch #7916 to fix a few more things
+"
" Options:
" Set to anything to enable:
" php_sql_query SQL syntax highlighting inside strings
" php_htmlInStrings HTML syntax highlighting inside strings
+"
+" By setting this to 2, this will use a local copy of
+" HTML syntax highlighting instead of the official
+" HTML syntax highlighting, and properly highlight
+" `<?php $startTag = '<?php';`.
+" This may become the new default in the future.
+"
+" By setting this to 3 (or any unrecognized value),
+" this will use the official installed top level html syntax highlighting rules.
" php_baselib highlighting baselib functions
" php_asp_tags highlighting ASP-style short tags
" php_parent_error_close highlighting parent error ] or )
@@ -62,6 +84,214 @@ if !exists("main_syntax")
let main_syntax = 'php'
endif
+" Start of copy of html for embedding in strings with {{{
+" This is a clone of https://notabug.org/jorgesumle/vim-html-syntax
+" from 2021 Mar 02 with changed symbols and modifications to rules. See the Note in the file header.
+"
+" The default behavior of php_htmlInStrings causes a bug
+" when you're working with code that contains the string literal `'<?php'`.
+" E.g. code that reads php files or generates the contents of php files or
+" generates snippets to `eval()`.
+"
+" When php_htmlInStrings was set to any value,
+" it would cause the html syntax rules to be embedded inside of the string
+" contents.
+"
+" However, php.vim extends html.vim by allowing the php start tag to be
+" included, meaning that this is parsed as `<?php';`, i.e. the start of a
+" new string literal.
+"
+" Work around that by using a different set of rules that don't allow
+" embedding php in most places (phpInnerHtmlPreProc).
+"
+" The default behavior may be changed to this in the future for constants other
+" than 2 or 3 if there are no issues.
+"
+" Many, but not all syntax rules were changed from html* to phpInnerHtml*
+if exists("php_htmlInStrings") && php_htmlInStrings==2
+ " mark illegal characters
+ syn match phpInnerHtmlError contained "[<>&]"
+
+ " tags
+ syn region phpInnerHtmlString contained start=+"+ end=+"+ contains=phpInnerHtmlSpecialChar,javaScriptExpression,@phpInnerHtmlPreproc
+ syn region phpInnerHtmlString contained start=+'+ end=+'+ contains=phpInnerHtmlSpecialChar,javaScriptExpression,@phpInnerHtmlPreproc
+ syn match phpInnerHtmlValue contained "=[\t ]*[^'" \t>][^ \t>]*"hs=s+1 contains=javaScriptExpression,@phpInnerHtmlPreproc
+ syn region phpInnerHtmlEndTag contained start=+</+ end=+>+ contains=phpInnerHtmlTagN,phpInnerHtmlTagError
+ syn region phpInnerHtmlTag contained start=+<[^/]+ end=+>+ fold contains=phpInnerHtmlTagN,phpInnerHtmlString,htmlArg,phpInnerHtmlValue,phpInnerHtmlTagError,phpInnerHtmlEvent,phpInnerHtmlCssDefinition,@phpInnerHtmlPreproc,@phpInnerHtmlArgCluster
+ syn match phpInnerHtmlTagN contained +<\s*[-a-zA-Z0-9]\++hs=s+1 contains=htmlTagName,htmlSpecialTagName,@phpInnerHtmlTagNameCluster
+ syn match phpInnerHtmlTagN contained +</\s*[-a-zA-Z0-9]\++hs=s+2 contains=htmlTagName,htmlSpecialTagName,@phpInnerHtmlTagNameCluster
+ syn match phpInnerHtmlTagError contained "[^>]<"ms=s+1
+
+
+ " special characters
+ syn match phpInnerHtmlSpecialChar "&#\=[0-9A-Za-z]\{1,8};"
+
+ " Comments (the real ones or the old netscape ones)
+ if exists("html_wrong_comments")
+ syn region phpInnerHtmlComment start=+<!--+ end=+--\s*>+ contains=@Spell
+ else
+ " The HTML 5.2 syntax 8.2.4.41: bogus comment is parser error; browser skips until next &gt
+ syn region phpInnerHtmlComment start=+<!+ end=+>+ contains=phpInnerHtmlCommentError keepend
+ " Idem 8.2.4.42,51: Comment starts with <!-- and ends with -->
+ " Idem 8.2.4.43,44: Except <!--> and <!---> are parser errors
+ " Idem 8.2.4.52: dash-dash-bang (--!>) is error ignored by parser, also closes comment
+ syn region phpInnerHtmlComment matchgroup=phpInnerHtmlComment start=+<!--\%(-\?>\)\@!+ end=+--!\?>+ contains=phpInnerHtmlCommentNested,@phpInnerHtmlPreProc,@Spell keepend
+ " Idem 8.2.4.49: nested comment is parser error, except <!--> is all right
+ syn match phpInnerHtmlCommentNested contained "<!-->\@!"
+ syn match phpInnerHtmlCommentError contained "[^><!]"
+ endif
+ syn region phpInnerHtmlComment start=+<!DOCTYPE+ end=+>+ keepend
+
+ " server-parsed commands
+ syn region phpInnerHtmlPreProc start=+<!--#+ end=+-->+ contains=phpInnerHtmlPreStmt,phpInnerHtmlPreError,phpInnerHtmlPreAttr
+ syn match phpInnerHtmlPreStmt contained "<!--#\(config\|echo\|exec\|fsize\|flastmod\|include\|printenv\|set\|if\|elif\|else\|endif\|geoguide\)\>"
+ syn match phpInnerHtmlPreError contained "<!--#\S*"ms=s+4
+ syn match phpInnerHtmlPreAttr contained "\w\+=[^"]\S\+" contains=phpInnerHtmlPreProcAttrError,phpInnerHtmlPreProcAttrName
+ syn region phpInnerHtmlPreAttr contained start=+\w\+="+ skip=+\\\\\|\\"+ end=+"+ contains=phpInnerHtmlPreProcAttrName keepend
+ syn match phpInnerHtmlPreProcAttrError contained "\w\+="he=e-1
+ syn match phpInnerHtmlPreProcAttrName contained "\(expr\|errmsg\|sizefmt\|timefmt\|var\|cgi\|cmd\|file\|virtual\|value\)="he=e-1
+
+ if !exists("html_no_rendering")
+ " rendering
+ syn cluster phpInnerHtmlTop contains=@Spell,phpInnerHtmlTag,phpInnerHtmlEndTag,phpInnerHtmlSpecialChar,phpInnerHtmlPreProc,phpInnerHtmlComment,phpInnerHtmlLink,javaScript,@phpInnerHtmlPreproc
+
+ syn region phpInnerHtmlStrike start="<del\>" end="</del\_s*>"me=s-1 contains=@phpInnerHtmlTop
+ syn region phpInnerHtmlStrike start="<strike\>" end="</strike\_s*>"me=s-1 contains=@phpInnerHtmlTop
+
+ syn region phpInnerHtmlBold start="<b\>" end="</b\_s*>"me=s-1 contains=@phpInnerHtmlTop,phpInnerHtmlBoldUnderline,phpInnerHtmlBoldItalic
+ syn region phpInnerHtmlBold start="<strong\>" end="</strong\_s*>"me=s-1 contains=@phpInnerHtmlTop,phpInnerHtmlBoldUnderline,phpInnerHtmlBoldItalic
+ syn region phpInnerHtmlBoldUnderline contained start="<u\>" end="</u\_s*>"me=s-1 contains=@phpInnerHtmlTop,phpInnerHtmlBoldUnderlineItalic
+ syn region phpInnerHtmlBoldItalic contained start="<i\>" end="</i\_s*>"me=s-1 contains=@phpInnerHtmlTop,phpInnerHtmlBoldItalicUnderline
+ syn region phpInnerHtmlBoldItalic contained start="<em\>" end="</em\_s*>"me=s-1 contains=@phpInnerHtmlTop,phpInnerHtmlBoldItalicUnderline
+ syn region phpInnerHtmlBoldUnderlineItalic contained start="<i\>" end="</i\_s*>"me=s-1 contains=@phpInnerHtmlTop
+ syn region phpInnerHtmlBoldUnderlineItalic contained start="<em\>" end="</em\_s*>"me=s-1 contains=@phpInnerHtmlTop
+ syn region phpInnerHtmlBoldItalicUnderline contained start="<u\>" end="</u\_s*>"me=s-1 contains=@phpInnerHtmlTop,phpInnerHtmlBoldUnderlineItalic
+
+ syn region phpInnerHtmlUnderline start="<u\>" end="</u\_s*>"me=s-1 contains=@phpInnerHtmlTop,phpInnerHtmlUnderlineBold,phpInnerHtmlUnderlineItalic
+ syn region phpInnerHtmlUnderlineBold contained start="<b\>" end="</b\_s*>"me=s-1 contains=@phpInnerHtmlTop,phpInnerHtmlUnderlineBoldItalic
+ syn region phpInnerHtmlUnderlineBold contained start="<strong\>" end="</strong\_s*>"me=s-1 contains=@phpInnerHtmlTop,phpInnerHtmlUnderlineBoldItalic
+ syn region phpInnerHtmlUnderlineItalic contained start="<i\>" end="</i\_s*>"me=s-1 contains=@phpInnerHtmlTop,phpInnerHtmlUnderlineItalicBold
+ syn region phpInnerHtmlUnderlineItalic contained start="<em\>" end="</em\_s*>"me=s-1 contains=@phpInnerHtmlTop,phpInnerHtmlUnderlineItalicBold
+ syn region phpInnerHtmlUnderlineItalicBold contained start="<b\>" end="</b\_s*>"me=s-1 contains=@phpInnerHtmlTop
+ syn region phpInnerHtmlUnderlineItalicBold contained start="<strong\>" end="</strong\_s*>"me=s-1 contains=@phpInnerHtmlTop
+ syn region phpInnerHtmlUnderlineBoldItalic contained start="<i\>" end="</i\_s*>"me=s-1 contains=@phpInnerHtmlTop
+ syn region phpInnerHtmlUnderlineBoldItalic contained start="<em\>" end="</em\_s*>"me=s-1 contains=@phpInnerHtmlTop
+
+ syn region phpInnerHtmlItalic start="<i\>" end="</i\_s*>"me=s-1 contains=@phpInnerHtmlTop,phpInnerHtmlItalicBold,phpInnerHtmlItalicUnderline
+ syn region phpInnerHtmlItalic start="<em\>" end="</em\_s*>"me=s-1 contains=@phpInnerHtmlTop
+ syn region phpInnerHtmlItalicBold contained start="<b\>" end="</b\_s*>"me=s-1 contains=@phpInnerHtmlTop,phpInnerHtmlItalicBoldUnderline
+ syn region phpInnerHtmlItalicBold contained start="<strong\>" end="</strong\_s*>"me=s-1 contains=@phpInnerHtmlTop,phpInnerHtmlItalicBoldUnderline
+ syn region phpInnerHtmlItalicBoldUnderline contained start="<u\>" end="</u\_s*>"me=s-1 contains=@phpInnerHtmlTop
+ syn region phpInnerHtmlItalicUnderline contained start="<u\>" end="</u\_s*>"me=s-1 contains=@phpInnerHtmlTop,phpInnerHtmlItalicUnderlineBold
+ syn region phpInnerHtmlItalicUnderlineBold contained start="<b\>" end="</b\_s*>"me=s-1 contains=@phpInnerHtmlTop
+ syn region phpInnerHtmlItalicUnderlineBold contained start="<strong\>" end="</strong\_s*>"me=s-1 contains=@phpInnerHtmlTop
+
+ syn match phpInnerHtmlLeadingSpace "^\s\+" contained
+ syn region phpInnerHtmlLink start="<a\>\_[^>]*\<href\>" end="</a\_s*>"me=s-1 contains=@Spell,phpInnerHtmlTag,phpInnerHtmlEndTag,phpInnerHtmlSpecialChar,phpInnerHtmlPreProc,phpInnerHtmlComment,phpInnerHtmlLeadingSpace,phpInnerJavaScript,@phpInnerHtmlPreproc
+ syn region phpInnerHtmlH1 start="<h1\>" end="</h1\_s*>"me=s-1 contains=@phpInnerHtmlTop
+ syn region phpInnerHtmlH2 start="<h2\>" end="</h2\_s*>"me=s-1 contains=@phpInnerHtmlTop
+ syn region phpInnerHtmlH3 start="<h3\>" end="</h3\_s*>"me=s-1 contains=@phpInnerHtmlTop
+ syn region phpInnerHtmlH4 start="<h4\>" end="</h4\_s*>"me=s-1 contains=@phpInnerHtmlTop
+ syn region phpInnerHtmlH5 start="<h5\>" end="</h5\_s*>"me=s-1 contains=@phpInnerHtmlTop
+ syn region phpInnerHtmlH6 start="<h6\>" end="</h6\_s*>"me=s-1 contains=@phpInnerHtmlTop
+ syn region phpInnerHtmlHead start="<head\>" end="</head\_s*>"me=s-1 end="<body\>"me=s-1 end="<h[1-6]\>"me=s-1 contains=phpInnerHtmlTag,phpInnerHtmlEndTag,phpInnerHtmlSpecialChar,phpInnerHtmlPreProc,phpInnerHtmlComment,phpInnerHtmlLink,phpInnerHtmlTitle,phpInnerJavaScript,phpInnerCssStyle,@phpInnerHtmlPreproc
+ syn region phpInnerHtmlTitle start="<title\>" end="</title\_s*>"me=s-1 contains=phpInnerHtmlTag,phpInnerHtmlEndTag,phpInnerHtmlSpecialChar,phpInnerHtmlPreProc,phpInnerHtmlComment,phpInnerJavaScript,@phpInnerHtmlPreproc
+ endif
+
+ if main_syntax != 'java' || exists("javascript")
+ " JAVA SCRIPT
+ " For example, $phpVar = '<img onload="foo()" />';
+ syn include @phpInnerHtmlJavaScript syntax/javascript.vim
+ unlet b:current_syntax
+ syn region phpInnerHtmlScriptTag contained start=+<script+ end=+>+ fold contains=phpInnerHtmlTagN,phpInnerHtmlString,phpInnerHtmlArg,phpInnerHtmlValue,phpInnerHtmlTagError,phpInnerHtmlEvent
+ hi def link phpInnerHtmlScriptTag phpInnerHtmlTag
+
+ " phpInnerHtml events (i.e. arguments that include phpInnerJavascript commands)
+ if exists("html_extended_events")
+ syn region phpInnerHtmlEvent contained start=+\<on\a\+\s*=[\t ]*'+ end=+'+ contains=phpInnerHtmlEventSQ
+ syn region phpInnerHtmlEvent contained start=+\<on\a\+\s*=[\t ]*"+ end=+"+ contains=phpInnerHtmlEventDQ
+ else
+ syn region phpInnerHtmlEvent contained start=+\<on\a\+\s*=[\t ]*'+ end=+'+ keepend contains=phpInnerHtmlEventSQ
+ syn region phpInnerHtmlEvent contained start=+\<on\a\+\s*=[\t ]*"+ end=+"+ keepend contains=phpInnerHtmlEventDQ
+ endif
+ syn region phpInnerHtmlEventSQ contained start=+'+ms=s+1 end=+'+me=s-1 contains=@phpInnerHtmlJavaScript
+ syn region phpInnerHtmlEventDQ contained start=+"+ms=s+1 end=+"+me=s-1 contains=@phpInnerHtmlJavaScript
+ hi def link phpInnerHtmlEventSQ phpInnerHtmlEvent
+ hi def link phpInnerHtmlEventDQ phpInnerHtmlEvent
+
+ " a phpInnerJavascript expression is used as an arg value
+ " syn region phpInnerJavaScriptExpression contained start=+&{+ keepend end=+};+ contains=@phpInnerHtmlJavaScript,@phpInnerHtmlPreproc
+ endif
+
+ syn cluster phpInnerHtmlJavaScript add=@phpInnerHtmlPreproc
+
+ " The default highlighting.
+ " NOTE: For now, this deliberately copies the definitions from html rather than link
+ " to the corresponding html tag name. If html is refactored to rename any
+ " keywords then html highlighting would unexpectedly be cleared.
+ hi def link phpInnerHtmlTag Function
+ hi def link phpInnerHtmlEndTag Identifier
+ hi def link phpInnerHtmlArg Type
+ hi def link phpInnerHtmlValue String
+ hi def link phpInnerHtmlSpecialChar Special
+
+ if !exists("html_no_rendering")
+ hi def link phpInnerHtmlH1 Title
+ hi def link phpInnerHtmlH2 phpInnerHtmlH1
+ hi def link phpInnerHtmlH3 phpInnerHtmlH2
+ hi def link phpInnerHtmlH4 phpInnerHtmlH3
+ hi def link phpInnerHtmlH5 phpInnerHtmlH4
+ hi def link phpInnerHtmlH6 phpInnerHtmlH5
+ hi def link phpInnerHtmlHead PreProc
+ hi def link phpInnerHtmlTitle Title
+ hi def link phpInnerHtmlBoldItalicUnderline phpInnerHtmlBoldUnderlineItalic
+ hi def link phpInnerHtmlUnderlineBold phpInnerHtmlBoldUnderline
+ hi def link phpInnerHtmlUnderlineItalicBold phpInnerHtmlBoldUnderlineItalic
+ hi def link phpInnerHtmlUnderlineBoldItalic phpInnerHtmlBoldUnderlineItalic
+ hi def link phpInnerHtmlItalicUnderline phpInnerHtmlUnderlineItalic
+ hi def link phpInnerHtmlItalicBold phpInnerHtmlBoldItalic
+ hi def link phpInnerHtmlItalicBoldUnderline phpInnerHtmlBoldUnderlineItalic
+ hi def link phpInnerHtmlItalicUnderlineBold phpInnerHtmlBoldUnderlineItalic
+ hi def link phpInnerHtmlLink Underlined
+ hi def link phpInnerHtmlLeadingSpace None
+ if !exists("html_my_rendering")
+ hi def phpInnerHtmlBold term=bold cterm=bold gui=bold
+ hi def phpInnerHtmlBoldUnderline term=bold,underline cterm=bold,underline gui=bold,underline
+ hi def phpInnerHtmlBoldItalic term=bold,italic cterm=bold,italic gui=bold,italic
+ hi def phpInnerHtmlBoldUnderlineItalic term=bold,italic,underline cterm=bold,italic,underline gui=bold,italic,underline
+ hi def phpInnerHtmlUnderline term=underline cterm=underline gui=underline
+ hi def phpInnerHtmlUnderlineItalic term=italic,underline cterm=italic,underline gui=italic,underline
+ hi def phpInnerHtmlItalic term=italic cterm=italic gui=italic
+ if v:version > 800 || v:version == 800 && has("patch1038")
+ hi def phpInnerHtmlStrike term=strikethrough cterm=strikethrough gui=strikethrough
+ else
+ hi def phpInnerHtmlStrike term=underline cterm=underline gui=underline
+ endif
+ endif
+ endif
+
+ hi def link phpInnerHtmlPreStmt PreProc
+ hi def link phpInnerHtmlPreError Error
+ hi def link phpInnerHtmlPreProc PreProc
+ hi def link phpInnerHtmlPreAttr String
+ hi def link phpInnerHtmlPreProcAttrName PreProc
+ hi def link phpInnerHtmlPreProcAttrError Error
+ hi def link phpInnerHtmlString String
+ hi def link phpInnerHtmlStatement Statement
+ hi def link phpInnerHtmlComment Comment
+ hi def link phpInnerHtmlCommentNested phpInnerHtmlError
+ hi def link phpInnerHtmlCommentError phpInnerHtmlError
+ hi def link phpInnerHtmlTagError phpInnerHtmlError
+ hi def link phpInnerHtmlEvent phpInnerJavaScript
+ hi def link phpInnerHtmlError Error
+
+ hi def link phpInnerJavaScript Special
+ hi def link phpInnerJavaScriptExpression phpInnerJavaScript
+ hi def link phpInnerHtmlCssStyleComment Comment
+ hi def link phpInnerHtmlCssDefinition Special
+endif
+
+
runtime! syntax/html.vim
unlet b:current_syntax
@@ -79,6 +309,8 @@ if exists("php_parentError") && !exists("php_parent_error_open") && !exists("php
let php_parent_error_open=1
endif
+" End of copy of html syntax for embedding in php strings }}}
+
syn cluster htmlPreproc add=phpRegion,phpRegionAsp,phpRegionSc
syn include @sqlTop syntax/sql.vim
@@ -90,7 +322,11 @@ if exists( "php_sql_query")
endif
if exists( "php_htmlInStrings")
- syn cluster phpAddStrings add=@htmlTop
+ if php_htmlInStrings==2
+ syn cluster phpAddStrings add=@phpInnerHtmlTop
+ else
+ syn cluster phpAddStrings add=@htmlTop
+ endif
endif
" make sure we can use \ at the beginning of the line to do a continuation
@@ -283,7 +519,7 @@ syn keyword phpStatement return break continue exit goto yield contained
syn keyword phpKeyword var const contained
" Type
-syn keyword phpType void bool boolean int integer real double float string array object NULL callable iterable mixed contained
+syn keyword phpType void bool boolean int integer real double float string array object NULL callable iterable mixed never contained
" Structure
syn keyword phpStructure namespace extends implements instanceof parent self contained
@@ -361,7 +597,7 @@ syn match phpFloatError "\%([eE.][0-9._+-]*\.\|__\|_\(\>\|[eE]\)\|\(\>\|[eE]\)_\
" Number
syn match phpNumber "\%(\.\)\@<!\<\%([1-9]\d*\|0\|0[xX]\(\x_\?\)*\x\)\>\%(\.\)\@!" contained display
-syn match phpNumber "\%(\.\)\@<!\<0\d\+\>\%(\.\)\@!" contained contains=phpOctalError display
+syn match phpNumber "\%(\.\)\@<!\<0\d\+\|0[oO]\d\+\>\%(\.\)\@!" contained contains=phpOctalError display
syn match phpBinaryError "[2-9]" contained display
syn match phpNumber "\%(\.\)\@<!\<0[bB]\(\d_\?\)*\d\>\%(\.\)\@!" contained contains=phpBinaryError display
@@ -446,7 +682,7 @@ syn cluster phpClTop contains=@phpClFunction,phpFoldFunction,phpFoldClass,phpFol
" Php Region
if exists("php_parent_error_open")
if exists("php_noShortTags")
- syn region phpRegion matchgroup=Delimiter start="<?php" end="?>" contains=@phpClTop
+ syn region phpRegion matchgroup=Delimiter start="<?\(php\|=\)" end="?>" contains=@phpClTop
else
syn region phpRegion matchgroup=Delimiter start="<?\(php\)\=" end="?>" contains=@phpClTop
endif
@@ -456,7 +692,7 @@ if exists("php_parent_error_open")
endif
else
if exists("php_noShortTags")
- syn region phpRegion matchgroup=Delimiter start="<?php" end="?>" contains=@phpClTop keepend
+ syn region phpRegion matchgroup=Delimiter start="<?\(php\|=\)" end="?>" contains=@phpClTop keepend
else
syn region phpRegion matchgroup=Delimiter start="<?\(php\)\=" end="?>" contains=@phpClTop keepend
endif
@@ -469,13 +705,13 @@ endif
" Fold
if exists("php_folding") && php_folding==1
" match one line constructs here and skip them at folding
- syn keyword phpSCKeyword abstract final private protected public static contained
+ syn keyword phpSCKeyword abstract final private protected public static readonly contained
syn keyword phpFCKeyword function contained
syn keyword phpDefine fn contained
syn keyword phpStorageClass global contained
syn match phpDefine "\(\s\|^\)\(abstract\s\+\|final\s\+\|private\s\+\|protected\s\+\|public\s\+\|static\s\+\)*function\(\s\+.*[;}]\)\@=" contained contains=phpSCKeyword
syn match phpStructure "\(\s\|^\)\(abstract\s\+\|final\s\+\)*\(trait\|class\)\(\s\+.*}\)\@=" contained
- syn match phpStructure "\(\s\|^\)interface\(\s\+.*}\)\@=" contained
+ syn match phpStructure "\(\s\|^\)\(interface\|enum\)\(\s\+.*}\)\@=" contained
syn match phpException "\(\s\|^\)try\(\s\+.*}\)\@=" contained
syn match phpException "\(\s\|^\)catch\(\s\+.*}\)\@=" contained
syn match phpException "\(\s\|^\)finally\(\s\+.*}\)\@=" contained
@@ -484,15 +720,15 @@ if exists("php_folding") && php_folding==1
syn region phpFoldHtmlInside matchgroup=Delimiter start="?>" end="<?\(php\)\=" contained transparent contains=@htmlTop
syn region phpFoldFunction matchgroup=Storageclass start="^\z(\s*\)\(abstract\s\+\|final\s\+\|private\s\+\|protected\s\+\|public\s\+\|static\s\+\)*function\s\([^};]*$\)\@="rs=e-9 matchgroup=Delimiter end="^\z1}" contains=@phpClFunction,phpFoldHtmlInside,phpFCKeyword contained transparent fold extend
syn region phpFoldFunction matchgroup=Define start="^function\s\([^};]*$\)\@=" matchgroup=Delimiter end="^}" contains=@phpClFunction,phpFoldHtmlInside contained transparent fold extend
- syn region phpFoldClass matchgroup=Structure start="^\z(\s*\)\(abstract\s\+\|final\s\+\)*\(trait\|class\)\s\+\([^}]*$\)\@=" matchgroup=Delimiter end="^\z1}" contains=@phpClFunction,phpFoldFunction,phpSCKeyword contained transparent fold extend
+ syn region phpFoldClass matchgroup=Structure start="^\z(\s*\)\(abstract\s\+\|final\s\+\)*\(trait\|class\|enum\)\s\+\([^}]*$\)\@=" matchgroup=Delimiter end="^\z1}" contains=@phpClFunction,phpFoldFunction,phpSCKeyword contained transparent fold extend
syn region phpFoldInterface matchgroup=Structure start="^\z(\s*\)interface\s\+\([^}]*$\)\@=" matchgroup=Delimiter end="^\z1}" contains=@phpClFunction,phpFoldFunction contained transparent fold extend
syn region phpFoldCatch matchgroup=Exception start="^\z(\s*\)catch\s\+\([^}]*$\)\@=" matchgroup=Delimiter end="^\z1}" contains=@phpClFunction,phpFoldFunction contained transparent fold extend
syn region phpFoldTry matchgroup=Exception start="^\z(\s*\)try\s\+\([^}]*$\)\@=" matchgroup=Delimiter end="^\z1}" contains=@phpClFunction,phpFoldFunction contained transparent fold extend
else
syn keyword phpDefine function fn contained
- syn keyword phpStructure abstract class trait interface contained
+ syn keyword phpStructure abstract class trait interface enum contained
syn keyword phpException catch throw try finally contained
- syn keyword phpStorageClass final global private protected public static contained
+ syn keyword phpStorageClass final global private protected public static readonly contained
if exists("php_folding") && php_folding==2
setlocal foldmethod=syntax
syn region phpFoldHtmlInside matchgroup=Delimiter start="?>" end="<?\(php\)\=" contained transparent contains=@htmlTop
@@ -512,9 +748,9 @@ syntax keyword phpStructure list contained
syntax keyword phpConditional switch contained
syntax keyword phpStatement die contained
-" Highlighting for PHP5's user-definable magic class methods
+" Highlighting for PHP's user-definable magic class methods
syntax keyword phpSpecialFunction containedin=ALLBUT,phpComment,phpStringDouble,phpStringSingle,phpIdentifier
- \ __construct __destruct __call __callStatic __get __set __isset __unset __sleep __wakeup __toString __invoke __set_state __clone __debugInfo
+ \ __construct __destruct __call __callStatic __get __set __isset __unset __sleep __wakeup __toString __invoke __set_state __clone __debugInfo __serialize __unserialize
" Highlighting for __autoload slightly different from line above
syntax keyword phpSpecialFunction containedin=ALLBUT,phpComment,phpStringDouble,phpStringSingle,phpIdentifier,phpMethodsVar
\ __autoload
@@ -638,7 +874,7 @@ endif
" Sync
if php_sync_method==-1
if exists("php_noShortTags")
- syn sync match phpRegionSync grouphere phpRegion "^\s*<?php\s*$"
+ syn sync match phpRegionSync grouphere phpRegion "^\s*<?\(php\|=\)\s*$"
else
syn sync match phpRegionSync grouphere phpRegion "^\s*<?\(php\)\=\s*$"
endif
@@ -658,7 +894,7 @@ endif
syntax match phpDocCustomTags "@[a-zA-Z]*\(\s\+\|\n\|\r\)" containedin=phpComment
syntax region phpDocTags start="{@\(example\|id\|internal\|inheritdoc\|link\|source\|toc\|tutorial\)" end="}" containedin=phpComment
-syntax match phpDocTags "@\(abstract\|access\|author\|category\|copyright\|deprecated\|example\|final\|global\|ignore\|internal\|license\|link\|method\|name\|package\|param\|property\|return\|see\|since\|static\|staticvar\|subpackage\|tutorial\|uses\|var\|version\|contributor\|modified\|filename\|description\|filesource\|throws\)\(\s\+\)\?" containedin=phpComment
+syntax match phpDocTags "@\(abstract\|access\|api\|author\|category\|copyright\|deprecated\|example\|final\|global\|ignore\|internal\|license\|link\|method\|name\|package\|param\|property\(-write\|-read\)\?\|return\|see\|since\|source\|static\|staticvar\|subpackage\|tutorial\|uses\|used-by\|var\|version\|contributor\|modified\|filename\|description\|filesource\|throws\)\(\s\+\)\?" containedin=phpComment
syntax match phpDocTodo "@\(todo\|fixme\|xxx\)\(\s\+\)\?" containedin=phpComment
" Define the default highlighting.
@@ -729,7 +965,6 @@ else
hi def link phpIdentifierSimply Identifier
endif
-
let b:current_syntax = "php"
if main_syntax == 'php'
diff --git a/runtime/syntax/postscr.vim b/runtime/syntax/postscr.vim
index d5dc9a22d6..5af57aa0b1 100644
--- a/runtime/syntax/postscr.vim
+++ b/runtime/syntax/postscr.vim
@@ -6,7 +6,7 @@
" URL: http://www.eandem.co.uk/mrw/vim
"
" Options Flags:
-" postscr_level - language level to use for highligting (1, 2, or 3)
+" postscr_level - language level to use for highlighting (1, 2, or 3)
" postscr_display - include display PS operators
" postscr_ghostscript - include GS extensions
" postscr_fonts - highlight standard font names (a lot for PS 3)
@@ -469,12 +469,12 @@ if postscr_level == 2 || postscr_level == 3
syn keyword postscrConstant contained SubsVector UnderlineThickness FamilyName FontBBox CurMID
syn keyword postscrConstant contained Weight
-" PS2 User paramters
+" PS2 User parameters
syn keyword postscrConstant contained MaxFontItem MinFontCompress MaxUPathItem MaxFormItem MaxPatternItem
syn keyword postscrConstant contained MaxScreenItem MaxOpStack MaxDictStack MaxExecStack MaxLocalVM
syn keyword postscrConstant contained VMReclaim VMThreshold
-" PS2 System paramters
+" PS2 System parameters
syn keyword postscrConstant contained SystemParamsPassword StartJobPassword BuildTime ByteOrder RealFormat
syn keyword postscrConstant contained MaxFontCache CurFontCache MaxOutlineCache CurOutlineCache
syn keyword postscrConstant contained MaxUPathCache CurUPathCache MaxFormCache CurFormCache
@@ -504,7 +504,7 @@ if postscr_level == 2 || postscr_level == 3
syn keyword postscrL2Operator accuratescreens checkscreen pagemargin pageparams setaccuratescreens setpage
syn keyword postscrL2Operator setpagemargin setpageparams
-" Misc compatability operators
+" Misc compatibility operators
syn keyword postscrL2Operator appletalktype buildtime byteorder checkpassword defaulttimeouts diskonline
syn keyword postscrL2Operator diskstatus manualfeed manualfeedtimeout margins mirrorprint pagecount
syn keyword postscrL2Operator pagestackorder printername processcolors sethardwareiomode setjobtimeout
diff --git a/runtime/syntax/redif.vim b/runtime/syntax/redif.vim
index 725067fd32..365192284b 100644
--- a/runtime/syntax/redif.vim
+++ b/runtime/syntax/redif.vim
@@ -1,7 +1,7 @@
" Vim syntax file
" Language: ReDIF
" Maintainer: Axel Castellane <axel.castellane@polytechnique.edu>
-" Last Change: 2013 April 17
+" Last Change: 2021 Jul 28
" Original Author: Axel Castellane
" Source: http://openlib.org/acmes/root/docu/redif_1.html
" File Extension: rdf
diff --git a/runtime/syntax/ruby.vim b/runtime/syntax/ruby.vim
index 0de63d0ef3..13d6d9efd8 100644
--- a/runtime/syntax/ruby.vim
+++ b/runtime/syntax/ruby.vim
@@ -3,7 +3,7 @@
" Maintainer: Doug Kearns <dougkearns@gmail.com>
" URL: https://github.com/vim-ruby/vim-ruby
" Release Coordinator: Doug Kearns <dougkearns@gmail.com>
-" Last Change: 2019 Jul 13
+" Last Change: 2021 Jun 06
" ----------------------------------------------------------------------------
"
" Previous Maintainer: Mirko Nasato
@@ -66,7 +66,7 @@ endfunction
com! -nargs=* SynFold call s:run_syntax_fold(<q-args>)
" Not-Top Cluster {{{1
-syn cluster rubyNotTop contains=@rubyCommentNotTop,@rubyStringNotTop,@rubyRegexpSpecial,@rubyDeclaration,@rubyExceptionHandler,@rubyClassOperator,rubyConditional,rubyModuleName,rubyClassName,rubySymbolDelimiter,rubyParentheses
+syn cluster rubyNotTop contains=@rubyCommentNotTop,@rubyStringNotTop,@rubyRegexpSpecial,@rubyDeclaration,@rubyExceptionHandler,@rubyClassOperator,rubyConditional,rubyModuleName,rubyClassName,rubySymbolDelimiter,rubyParentheses,@Spell
" Whitespace Errors {{{1
if exists("ruby_space_errors")
@@ -92,7 +92,7 @@ if exists("ruby_operators") || exists("ruby_pseudo_operators")
syn match rubyBooleanOperator "\%(\w\|[^\x00-\x7F]\)\@1<!!\|&&\|||"
syn match rubyRangeOperator "\.\.\.\="
syn match rubyAssignmentOperator "=>\@!\|-=\|/=\|\*\*=\|\*=\|&&=\|&=\|||=\||=\|%=\|+=\|>>=\|<<=\|\^="
- syn match rubyAssignmentOperator "=>\@!" containedin=rubyBlockParameterList " TODO: this is inelegant
+ syn match rubyAssignmentOperator "=>\@!" contained containedin=rubyBlockParameterList " TODO: this is inelegant
syn match rubyEqualityOperator "===\|==\|!=\|!\~\|=\~"
syn region rubyBracketOperator matchgroup=rubyOperator start="\%(\%(\w\|[^\x00-\x7F]\)[?!]\=\|[]})]\)\@2<=\[" end="]" contains=ALLBUT,@rubyNotTop
@@ -134,10 +134,10 @@ syn match rubyCurlyBraceEscape "\\[{}]" contained display
syn match rubyAngleBracketEscape "\\[<>]" contained display
syn match rubySquareBracketEscape "\\[[\]]" contained display
-syn region rubyNestedParentheses start="(" skip="\\\\\|\\)" matchgroup=rubyString end=")" transparent contained
-syn region rubyNestedCurlyBraces start="{" skip="\\\\\|\\}" matchgroup=rubyString end="}" transparent contained
-syn region rubyNestedAngleBrackets start="<" skip="\\\\\|\\>" matchgroup=rubyString end=">" transparent contained
-syn region rubyNestedSquareBrackets start="\[" skip="\\\\\|\\\]" matchgroup=rubyString end="\]" transparent contained
+syn region rubyNestedParentheses start="(" skip="\\\\\|\\)" end=")" transparent contained
+syn region rubyNestedCurlyBraces start="{" skip="\\\\\|\\}" end="}" transparent contained
+syn region rubyNestedAngleBrackets start="<" skip="\\\\\|\\>" end=">" transparent contained
+syn region rubyNestedSquareBrackets start="\[" skip="\\\\\|\\\]" end="\]" transparent contained
syn cluster rubySingleCharEscape contains=rubyBackslashEscape,rubyQuoteEscape,rubySpaceEscape,rubyParenthesisEscape,rubyCurlyBraceEscape,rubyAngleBracketEscape,rubySquareBracketEscape
syn cluster rubyNestedBrackets contains=rubyNested.\+
@@ -193,7 +193,7 @@ SynFold ':' syn region rubySymbol matchgroup=rubySymbolDelimiter start="[]})\"':
syn match rubyCapitalizedMethod "\%(\%(^\|[^.]\)\.\s*\)\@<!\<\u\%(\w\|[^\x00-\x7F]\)*\>\%(\s*(\)\@="
-syn region rubyParentheses start="(" end=")" contains=ALLBUT,@rubyNotTop containedin=rubyBlockParameterList
+syn region rubyParentheses start="(" end=")" contains=ALLBUT,@rubyNotTop contained containedin=rubyBlockParameterList
syn region rubyBlockParameterList start="\%(\%(\<do\>\|{\)\_s*\)\@32<=|" end="|" contains=ALLBUT,@rubyNotTop,@rubyProperOperator
if exists('ruby_global_variable_error')
@@ -332,7 +332,7 @@ SynFold '<<' syn region rubyString start=+\%(\%(class\|::\|\.\@1<!\.\)\_s*\|\%([
syn match rubyAliasDeclaration "[^[:space:];#.()]\+" contained contains=rubySymbol,@rubyGlobalVariable nextgroup=rubyAliasDeclaration2 skipwhite
syn match rubyAliasDeclaration2 "[^[:space:];#.()]\+" contained contains=rubySymbol,@rubyGlobalVariable
syn match rubyMethodDeclaration "[^[:space:];#(]\+" contained contains=rubyConstant,rubyBoolean,rubyPseudoVariable,rubyInstanceVariable,rubyClassVariable,rubyGlobalVariable
-syn match rubyClassDeclaration "[^[:space:];#<]\+" contained contains=rubyClassName,rubyScopeOperator nextgroup=rubySuperClassOperator skipwhite skipnl
+syn match rubyClassDeclaration "[^[:space:];#<]\+" contained contains=rubyClassName,rubyScopeOperator nextgroup=rubySuperClassOperator skipwhite
syn match rubyModuleDeclaration "[^[:space:];#<]\+" contained contains=rubyModuleName,rubyScopeOperator
syn match rubyMethodName "\<\%([_[:alpha:]]\|[^\x00-\x7F]\)\%([_[:alnum:]]\|[^\x00-\x7F]\)*[?!=]\=\%([[:alnum:]_.:?!=]\|[^\x00-\x7F]\)\@!" contained containedin=rubyMethodDeclaration
@@ -462,7 +462,7 @@ endif
syn match rubyDefinedOperator "\%#=1\<defined?" display
" 1.9-style Hash Keys and Keyword Parameters {{{1
-syn match rubySymbol "\%([{(|,]\_s*\)\@<=\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*[?!]\=::\@!"he=e-1
+syn match rubySymbol "\%(\w\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*[?!]\=::\@!"he=e-1 contained containedin=rubyBlockParameterList,rubyCurlyBlock
syn match rubySymbol "[]})\"':]\@1<!\<\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*[!?]\=:[[:space:],;]\@="he=e-1
syn match rubySymbol "[[:space:],{(]\%(\h\|[^\x00-\x7F]\)\%(\w\|[^\x00-\x7F]\)*[!?]\=:[[:space:],;]\@="hs=s+1,he=e-1
diff --git a/runtime/syntax/scala.vim b/runtime/syntax/scala.vim
index c5a175fd77..16e114778d 100644
--- a/runtime/syntax/scala.vim
+++ b/runtime/syntax/scala.vim
@@ -3,7 +3,7 @@
" Maintainer: Derek Wyatt
" URL: https://github.com/derekwyatt/vim-scala
" License: Same as Vim
-" Last Change: 20 May 2016
+" Last Change: 23 August 2021
" ----------------------------------------------------------------------------
if !exists('main_syntax')
@@ -66,7 +66,7 @@ syn match scalaChar /'\\u[A-Fa-f0-9]\{4}'/ contains=scalaUnicodeChar
syn match scalaEscapedChar /\\[\\"'ntbrf]/
syn match scalaUnicodeChar /\\u[A-Fa-f0-9]\{4}/
hi link scalaChar Character
-hi link scalaEscapedChar Function
+hi link scalaEscapedChar Special
hi link scalaUnicodeChar Special
syn match scalaOperator "||"
@@ -102,9 +102,9 @@ syn match scalaTypeTypeDeclaration /(/ contained nextgroup=scalaTypeTypeExtensio
syn match scalaTypeTypeDeclaration /\%(⇒\|=>\)\ze/ contained nextgroup=scalaTypeTypeDeclaration contains=scalaTypeTypeExtension skipwhite
syn match scalaTypeTypeDeclaration /\<[_\.A-Za-z0-9$]\+\>/ contained nextgroup=scalaTypeTypeExtension,scalaTypeTypeEquals skipwhite
syn match scalaTypeTypeEquals /=\ze[^>]/ contained nextgroup=scalaTypeTypePostDeclaration skipwhite
-syn match scalaTypeTypeExtension /)\?\_s*\zs\%(⇒\|=>\|<:\|:>\|=:=\|::\|#\)/ contained nextgroup=scalaTypeTypeDeclaration skipwhite
+syn match scalaTypeTypeExtension /)\?\_s*\zs\%(⇒\|=>\|<:\|:>\|=:=\|::\|#\)/ contained contains=scalaTypeOperator nextgroup=scalaTypeTypeDeclaration skipwhite
syn match scalaTypeTypePostDeclaration /\<[_\.A-Za-z0-9$]\+\>/ contained nextgroup=scalaTypeTypePostExtension skipwhite
-syn match scalaTypeTypePostExtension /\%(⇒\|=>\|<:\|:>\|=:=\|::\)/ contained nextgroup=scalaTypeTypePostDeclaration skipwhite
+syn match scalaTypeTypePostExtension /\%(⇒\|=>\|<:\|:>\|=:=\|::\)/ contained contains=scalaTypeOperator nextgroup=scalaTypeTypePostDeclaration skipwhite
hi link scalaTypeTypeDeclaration Type
hi link scalaTypeTypeExtension Keyword
hi link scalaTypeTypePostDeclaration Special
@@ -113,21 +113,23 @@ hi link scalaTypeTypePostExtension Keyword
syn match scalaTypeDeclaration /(/ contained nextgroup=scalaTypeExtension contains=scalaRoundBrackets skipwhite
syn match scalaTypeDeclaration /\%(⇒\|=>\)\ze/ contained nextgroup=scalaTypeDeclaration contains=scalaTypeExtension skipwhite
syn match scalaTypeDeclaration /\<[_\.A-Za-z0-9$]\+\>/ contained nextgroup=scalaTypeExtension skipwhite
-syn match scalaTypeExtension /)\?\_s*\zs\%(⇒\|=>\|<:\|:>\|=:=\|::\|#\)/ contained nextgroup=scalaTypeDeclaration skipwhite
+syn match scalaTypeExtension /)\?\_s*\zs\%(⇒\|=>\|<:\|:>\|=:=\|::\|#\)/ contained contains=scalaTypeOperator nextgroup=scalaTypeDeclaration skipwhite
hi link scalaTypeDeclaration Type
hi link scalaTypeExtension Keyword
hi link scalaTypePostExtension Keyword
syn match scalaTypeAnnotation /\%([_a-zA-Z0-9$\s]:\_s*\)\ze[_=(\.A-Za-z0-9$]\+/ skipwhite nextgroup=scalaTypeDeclaration contains=scalaRoundBrackets
syn match scalaTypeAnnotation /)\_s*:\_s*\ze[_=(\.A-Za-z0-9$]\+/ skipwhite nextgroup=scalaTypeDeclaration
-hi link scalaTypeAnnotation Normal
+hi clear scalaTypeAnnotation
-syn match scalaCaseFollowing /\<[_\.A-Za-z0-9$]\+\>/ contained
-syn match scalaCaseFollowing /`[^`]\+`/ contained
+syn match scalaCaseFollowing /\<[_\.A-Za-z0-9$]\+\>/ contained contains=scalaCapitalWord
+syn match scalaCaseFollowing /`[^`]\+`/ contained contains=scalaCapitalWord
hi link scalaCaseFollowing Special
-syn keyword scalaKeywordModifier abstract override final lazy implicit implicitly private protected sealed null require super
+syn keyword scalaKeywordModifier abstract override final lazy implicit private protected sealed null super
+syn keyword scalaSpecialFunction implicitly require
hi link scalaKeywordModifier Function
+hi link scalaSpecialFunction Function
syn keyword scalaSpecial this true false ne eq
syn keyword scalaSpecial new nextgroup=scalaInstanceDeclaration skipwhite
@@ -151,14 +153,14 @@ hi link scalaTripleIString String
syn match scalaInterpolation /\$[a-zA-Z0-9_$]\+/ contained
exe 'syn region scalaInterpolationB matchgroup=scalaInterpolationBoundary start=/\${/ end=/}/ contained contains=' . s:ContainedGroup()
hi link scalaInterpolation Function
-hi link scalaInterpolationB Normal
+hi clear scalaInterpolationB
syn region scalaFString matchgroup=scalaInterpolationBrackets start=/f"/ skip=/\\"/ end=/"/ contains=scalaFInterpolation,scalaFInterpolationB,scalaEscapedChar,scalaUnicodeChar
syn match scalaFInterpolation /\$[a-zA-Z0-9_$]\+\(%[-A-Za-z0-9\.]\+\)\?/ contained
exe 'syn region scalaFInterpolationB matchgroup=scalaInterpolationBoundary start=/${/ end=/}\(%[-A-Za-z0-9\.]\+\)\?/ contained contains=' . s:ContainedGroup()
hi link scalaFString String
hi link scalaFInterpolation Function
-hi link scalaFInterpolationB Normal
+hi clear scalaFInterpolationB
syn region scalaTripleString start=/"""/ end=/"""\%([^"]\|$\)/ contains=scalaEscapedChar,scalaUnicodeChar
syn region scalaTripleFString matchgroup=scalaInterpolationBrackets start=/f"""/ end=/"""\%([^"]\|$\)/ contains=scalaFInterpolation,scalaFInterpolationB,scalaEscapedChar,scalaUnicodeChar
@@ -199,7 +201,6 @@ hi link scalaDocLinks Function
hi link scalaParameterAnnotation Function
hi link scalaParamAnnotationValue Keyword
hi link scalaCommentAnnotation Function
-hi link scalaCommentCodeBlockBrackets String
hi link scalaCommentCodeBlock String
hi link scalaTodo Todo
diff --git a/runtime/syntax/scdoc.vim b/runtime/syntax/scdoc.vim
new file mode 100644
index 0000000000..25c9c5433b
--- /dev/null
+++ b/runtime/syntax/scdoc.vim
@@ -0,0 +1,52 @@
+" Syntax file for scdoc files
+" Maintainer: Gregory Anders <greg@gpanders.com>
+" Last Updated: 2021-08-04
+
+if exists('b:current_syntax')
+ finish
+endif
+let b:current_syntax = 'scdoc'
+
+syntax match scdocFirstLineError "\%^.*$"
+syntax match scdocFirstLineValid "\%^\S\+(\d[0-9A-Za-z]*)\%(\s\+\"[^"]*\"\%(\s\+\"[^"]*\"\)\=\)\=$"
+
+syntax region scdocCommentError start="^;\S" end="$" keepend
+syntax region scdocComment start="^; " end="$" keepend
+
+syntax region scdocHeaderError start="^#\{3,}" end="$" keepend
+syntax region scdocHeader start="^#\{1,2}" end="$" keepend
+
+syntax match scdocIndentError "^[ ]\+"
+
+syntax match scdocLineBreak "++$"
+
+syntax match scdocOrderedListMarker "^\s*\.\%(\s\+\S\)\@="
+syntax match scdocListMarker "^\s*-\%(\s\+\S\)\@="
+
+syntax match scdocTableStartMarker "^[\[|\]][\[\-\]]"
+syntax match scdocTableMarker "^[|:][\[\-\] ]"
+
+syntax region scdocBold concealends matchgroup=scdocBoldDelimiter start="\\\@<!\*" end="\\\@<!\*"
+syntax region scdocUnderline concealends matchgroup=scdocUnderlineDelimiter start="\<\\\@<!_" end="\\\@<!_\>"
+syntax region scdocPre matchgroup=scdocPreDelimiter start="^\t*```" end="^\t*```"
+
+hi link scdocFirstLineValid Comment
+hi link scdocComment Comment
+hi link scdocHeader Title
+hi link scdocOrderedListMarker Statement
+hi link scdocListMarker scdocOrderedListMarker
+hi link scdocLineBreak Special
+hi link scdocTableMarker Statement
+hi link scdocTableStartMarker scdocTableMarker
+
+hi link scdocFirstLineError Error
+hi link scdocCommentError Error
+hi link scdocHeaderError Error
+hi link scdocIndentError Error
+
+hi link scdocPreDelimiter Delimiter
+
+hi scdocBold term=bold cterm=bold gui=bold
+hi scdocUnderline term=underline cterm=underline gui=underline
+hi link scdocBoldDelimiter scdocBold
+hi link scdocUnderlineDelimiter scdocUnderline
diff --git a/runtime/syntax/scheme.vim b/runtime/syntax/scheme.vim
index e209729f57..c4454fc57c 100644
--- a/runtime/syntax/scheme.vim
+++ b/runtime/syntax/scheme.vim
@@ -1,10 +1,11 @@
" Vim syntax file
" Language: Scheme (R7RS)
-" Last Change: 2018-01-06
+" Last Change: 2021-01-03
" Author: Evan Hanson <evhan@foldling.org>
" Maintainer: Evan Hanson <evhan@foldling.org>
" Previous Author: Dirk van Deun <dirk@igwe.vub.ac.be>
" Previous Maintainer: Sergey Khorev <sergey.khorev@gmail.com>
+" Repository: https://git.foldling.org/vim-scheme.git
" URL: https://foldling.org/vim/syntax/scheme.vim
if exists('b:current_syntax')
@@ -14,6 +15,8 @@ endif
let s:cpo = &cpo
set cpo&vim
+syn spell notoplevel
+
syn match schemeParentheses "[^ '`\t\n()\[\]";]\+"
syn match schemeParentheses "[)\]]"
@@ -35,7 +38,7 @@ syn region schemeUnquote matchgroup=schemeParentheses start=/,@(/ end=/)/ contai
syn region schemeQuoteForm matchgroup=schemeData start=/(/ end=/)/ contained contains=ALLBUT,schemeQuasiquote,schemeQuasiquoteForm,schemeUnquote,schemeForm,schemeDatumCommentForm,schemeImport,@schemeImportCluster,@schemeSyntaxCluster
syn region schemeQuasiquoteForm matchgroup=schemeData start=/(/ end=/)/ contained contains=ALLBUT,schemeQuote,schemeForm,schemeDatumCommentForm,schemeImport,@schemeImportCluster,@schemeSyntaxCluster
-syn region schemeString start=/\(\\\)\@<!"/ skip=/\\[\\"]/ end=/"/
+syn region schemeString start=/\(\\\)\@<!"/ skip=/\\[\\"]/ end=/"/ contains=@Spell
syn region schemeSymbol start=/\(\\\)\@<!|/ skip=/\\[\\|]/ end=/|/
syn match schemeNumber /\(#[dbeio]\)*[+\-]*\([0-9]\+\|inf.0\|nan.0\)\(\/\|\.\)\?[0-9+\-@\ilns]*\>/
@@ -47,9 +50,9 @@ syn match schemeBoolean /#f\(alse\)\?/
syn match schemeCharacter /#\\.[^ `'\t\n\[\]()]*/
syn match schemeCharacter /#\\x[0-9a-fA-F]\+/
-syn match schemeComment /;.*$/
+syn match schemeComment /;.*$/ contains=@Spell
-syn region schemeMultilineComment start=/#|/ end=/|#/ contains=schemeMultilineComment
+syn region schemeMultilineComment start=/#|/ end=/|#/ contains=schemeMultilineComment,@Spell
syn region schemeForm matchgroup=schemeParentheses start="(" end=")" contains=ALLBUT,schemeUnquote,schemeDatumCommentForm,@schemeImportCluster
syn region schemeForm matchgroup=schemeParentheses start="\[" end="\]" contains=ALLBUT,schemeUnquote,schemeDatumCommentForm,@schemeImportCluster
@@ -63,7 +66,7 @@ else
syn region schemeImport matchgroup=schemeImport start="\(([ \t\n]*\)\@<=\(import\)\>" end=")"me=e-1 contained contains=schemeImportForm,schemeIdentifier,schemeComment,schemeDatumComment
endif
-syn match schemeImportKeyword "\(([ \t\n]*\)\@<=\(except\|only\|prefix\|rename\|srfi\)\>"
+syn match schemeImportKeyword "\(([ \t\n]*\)\@<=\(except\|only\|prefix\|rename\)\>"
syn region schemeImportForm matchgroup=schemeParentheses start="(" end=")" contained contains=schemeIdentifier,schemeComment,schemeDatumComment,@schemeImportCluster
syn cluster schemeImportCluster contains=schemeImportForm,schemeImportKeyword
diff --git a/runtime/syntax/sgml.vim b/runtime/syntax/sgml.vim
index d60040c5d9..00d58d11f2 100644
--- a/runtime/syntax/sgml.vim
+++ b/runtime/syntax/sgml.vim
@@ -174,7 +174,7 @@ syn match sgmlAbbrEndTag +/+
" SGML specific
" abbreviated regions
"
-" No highlighing, highlighing is done by contained elements.
+" No highlighting, highlighting is done by contained elements.
"
" PROVIDES: @sgmlRegionHook
"
@@ -192,7 +192,7 @@ syn match sgmlAbbrRegion
" real (non-empty) elements. We cannot do syntax folding
" as in xml, because end tags may be optional in sgml depending
" on the dtd.
-" No highlighing, highlighing is done by contained elements.
+" No highlighting, highlighting is done by contained elements.
"
" PROVIDES: @sgmlRegionHook
"
@@ -225,7 +225,7 @@ syn region sgmlRegion
"
" <tag id="lola"/>
"
-" TODO use sgmlEmptyTag intead of sgmlTag
+" TODO use sgmlEmptyTag instead of sgmlTag
syn match sgmlEmptyRegion
\ +<[^ /!?>"']\(\_[^"'<>]\|"\_[^"]*"\|'\_[^']*'\)*/>+
\ contains=sgmlEmptyTag
diff --git a/runtime/syntax/sh.vim b/runtime/syntax/sh.vim
index 48a0024b00..0ab9c0ad58 100644
--- a/runtime/syntax/sh.vim
+++ b/runtime/syntax/sh.vim
@@ -2,8 +2,8 @@
" Language: shell (sh) Korn shell (ksh) bash (sh)
" Maintainer: Charles E. Campbell <NcampObell@SdrPchip.AorgM-NOSPAM>
" Previous Maintainer: Lennart Schultz <Lennart.Schultz@ecmwf.int>
-" Last Change: Nov 24, 2020
-" Version: 196
+" Last Change: Feb 18, 2021
+" Version: 198
" URL: http://www.drchip.org/astronaut/vim/index.html#SYNTAX_SH
" For options and settings, please use: :help ft-sh-syntax
" This file includes many ideas from Eric Brunet (eric.brunet@ens.fr) and heredoc fixes from Felipe Contreras
@@ -13,33 +13,35 @@ if exists("b:current_syntax")
finish
endif
-" trying to answer the question: which shell is /bin/sh, really?
-" If the user has not specified any of g:is_kornshell, g:is_bash, g:is_posix, g:is_sh, then guess.
-if getline(1) =~ '\<ksh$'
+" If the shell script itself specifies which shell to use, use it
+if getline(1) =~ '\<ksh\>'
let b:is_kornshell = 1
-elseif getline(1) =~ '\<bash$'
+elseif getline(1) =~ '\<bash\>'
let b:is_bash = 1
-elseif getline(1) =~ '\<dash$'
+elseif getline(1) =~ '\<dash\>'
let b:is_dash = 1
elseif !exists("g:is_kornshell") && !exists("g:is_bash") && !exists("g:is_posix") && !exists("g:is_sh") && !exists("g:is_dash")
+ " user did not specify which shell to use, and
+ " the script itself does not specify which shell to use. FYI: /bin/sh is ambiguous.
+ " Assuming /bin/sh is executable, and if its a link, find out what it links to.
let s:shell = ""
if executable("/bin/sh")
let s:shell = resolve("/bin/sh")
elseif executable("/usr/bin/sh")
let s:shell = resolve("/usr/bin/sh")
endif
- if s:shell =~ 'ksh$'
+ if s:shell =~ '\<ksh\>'
let b:is_kornshell= 1
- elseif s:shell =~ 'bash$'
+ elseif s:shell =~ '\<bash\>'
let b:is_bash = 1
- elseif s:shell =~ 'dash$'
+ elseif s:shell =~ '\<dash\>'
let b:is_dash = 1
endif
unlet s:shell
endif
" handling /bin/sh with is_kornshell/is_sh {{{1
-" b:is_sh is set when "#! /bin/sh" is found;
+" b:is_sh will be set when "#! /bin/sh" is found;
" However, it often is just a masquerade by bash (typically Linux)
" or kornshell (typically workstations with Posix "sh").
" So, when the user sets "g:is_bash", "g:is_kornshell",
@@ -98,12 +100,14 @@ if g:sh_fold_enabled && &fdm == "manual"
setl fdm=syntax
endif
-" set up the syntax-highlighting iskeyword
+" set up the syntax-highlighting for iskeyword
if (v:version == 704 && has("patch-7.4.1142")) || v:version > 704
- if exists("b:is_bash")
- exe "syn iskeyword ".&iskeyword.",-,:"
- else
- exe "syn iskeyword ".&iskeyword.",-"
+ if !exists("g:sh_syntax_isk") || (exists("g:sh_syntax_isk") && g:sh_syntax_isk)
+ if exists("b:is_bash")
+ exe "syn iskeyword ".&iskeyword.",-,:"
+ else
+ exe "syn iskeyword ".&iskeyword.",-"
+ endif
endif
endif
@@ -374,12 +378,11 @@ elseif !exists("g:sh_no_error")
syn region shExDoubleQuote matchGroup=Error start=+\$"+ skip=+\\\\\|\\.+ end=+"+ contains=shStringSpecial
endif
syn region shSingleQuote matchgroup=shQuote start=+'+ end=+'+ contains=@Spell nextgroup=shSpecialStart,shSpecialSQ
-syn region shDoubleQuote matchgroup=shQuote start=+\%(\%(\\\\\)*\\\)\@<!"+ skip=+\\.+ end=+"+ contains=@shDblQuoteList,shStringSpecial,@Spell nextgroup=shSpecialStart
-syn region shDoubleQuote matchgroup=shQuote start=+"+ matchgroup=shSpecial skip=+\\"+ matchgroup=shQuote end=+"+ contained contains=@shDblQuoteList,shStringSpecial,@Spell nextgroup=shSpecialStart
+syn region shDoubleQuote matchgroup=shQuote start=+\%(\%(\\\\\)*\\\)\@<!"+ skip=+\\.+ end=+"+ contains=@shDblQuoteList,shStringSpecial,@Spell nextgroup=shSpecialStart
syn match shStringSpecial "[^[:print:] \t]" contained
-syn match shStringSpecial "[^\\]\zs\%(\\\\\)*\\[\\"'`$()#]" nextgroup=shComment
-syn match shSpecialSQ "[^\\]\zs\%(\\\\\)*\\[\\"'`$()#]" contained nextgroup=shBkslshSnglQuote,@shNoZSList
-syn match shSpecialDQ "[^\\]\zs\%(\\\\\)*\\[\\"'`$()#]" contained nextgroup=shBkslshDblQuote,@shNoZSList
+syn match shStringSpecial "[^\\]\zs\%(\\\\\)*\(\\[\\"'`$()#]\)\+" nextgroup=shComment
+syn match shSpecialSQ "[^\\]\zs\%(\\\\\)*\(\\[\\"'`$()#]\)\+" contained nextgroup=shBkslshSnglQuote,@shNoZSList
+syn match shSpecialDQ "[^\\]\zs\%(\\\\\)*\(\\[\\"'`$()#]\)\+" contained nextgroup=shBkslshDblQuote,@shNoZSList
syn match shSpecialStart "\%(\\\\\)*\\[\\"'`$()#]" contained nextgroup=shBkslshSnglQuote,shBkslshDblQuote,@shNoZSList
syn match shSpecial "^\%(\\\\\)*\\[\\"'`$()#]"
syn match shSpecialNoZS contained "\%(\\\\\)*\\[\\"'`$()#]"
@@ -402,6 +405,7 @@ syn match shQuickComment contained "#.*$"
syn match shBQComment contained "#.\{-}\ze`" contains=@shCommentGroup
" Here Documents: {{{1
+" (modified by Felipe Contreras)
" =========================================
ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc01 start="<<\s*\z([^ \t|>]\+\)" matchgroup=shHereDoc01 end="^\z1\s*$" contains=@shDblQuoteList
ShFoldHereDoc syn region shHereDoc matchgroup=shHereDoc02 start="<<-\s*\z([^ \t|>]\+\)" matchgroup=shHereDoc02 end="^\s*\z1\s*$" contains=@shDblQuoteList
diff --git a/runtime/syntax/spup.vim b/runtime/syntax/spup.vim
index 743c7b5711..9284abf63f 100644
--- a/runtime/syntax/spup.vim
+++ b/runtime/syntax/spup.vim
@@ -25,7 +25,7 @@ endif
let s:cpo_save = &cpo
set cpo&vim
-" don't hightlight several keywords like subsections
+" don't highlight several keywords like subsections
"let strict_subsections = 1
" highlight types usually found in DECLARE section
@@ -177,7 +177,7 @@ syn cluster spupOrdinary contains=spupNumber,spupIdentifier,spupSymbol
syn cluster spupOrdinary add=spupError,spupString,spupComment
syn cluster spupTextproc contains=spupTextprocGeneric,spupTextprocError
-" define syncronizing; especially OPERATION sections can become very large
+" define synchronizing; especially OPERATION sections can become very large
syn sync clear
syn sync minlines=100
syn sync maxlines=500
diff --git a/runtime/syntax/st.vim b/runtime/syntax/st.vim
index 8160c7704a..ffa7820fe8 100644
--- a/runtime/syntax/st.vim
+++ b/runtime/syntax/st.vim
@@ -44,7 +44,7 @@ syn match stCharacter "$."
syn case ignore
-" the symols prefixed by a '#'
+" the symbols prefixed by a '#'
syn match stSymbol "\(#\<[a-z_][a-z0-9_]*\>\)"
syn match stSymbol "\(#'[^']*'\)"
@@ -58,7 +58,7 @@ syn match stFloat "\<\d\+e[-+]\=\d\+[fl]\=\>"
syn case match
-" a try to higlight paren mismatches
+" a try to highlight paren mismatches
syn region stParen transparent start='(' end=')' contains=ALLBUT,stParenError
syn match stParenError ")"
syn region stBlock transparent start='\[' end='\]' contains=ALLBUT,stBlockError
diff --git a/runtime/syntax/structurizr.vim b/runtime/syntax/structurizr.vim
new file mode 100644
index 0000000000..73629b1495
--- /dev/null
+++ b/runtime/syntax/structurizr.vim
@@ -0,0 +1,76 @@
+" Vim syntax file
+" Language: Structurizr DSL
+" Maintainer: Bastian Venthur <venthur@debian.org>
+" Last Change: 2021-08-16
+" Remark: For a language reference, see
+" https://github.com/structurizr/dsl
+
+
+if exists("b:current_syntax")
+ finish
+endif
+
+syn case ignore
+
+" comments
+syn match scomment "#.*$"
+syn match scomment "//.*$"
+syn region scomment start="/\*" end="\*/"
+
+" keywords
+syn keyword skeyword animation
+syn keyword skeyword autoLayout
+syn keyword skeyword branding
+syn keyword skeyword component
+syn keyword skeyword configuration
+syn keyword skeyword container
+syn keyword skeyword containerinstance
+syn keyword skeyword custom
+syn keyword skeyword deployment
+syn keyword skeyword deploymentenvironment
+syn keyword skeyword deploymentgroup
+syn keyword skeyword deploymentnode
+syn keyword skeyword dynamic
+syn keyword skeyword element
+syn keyword skeyword enterprise
+syn keyword skeyword exclude
+syn keyword skeyword filtered
+syn keyword skeyword group
+syn keyword skeyword healthcheck
+syn keyword skeyword impliedrelationships
+syn keyword skeyword include
+syn keyword skeyword infrastructurenode
+syn keyword skeyword model
+syn keyword skeyword person
+syn keyword skeyword perspectives
+syn keyword skeyword properties
+syn keyword skeyword relationship
+syn keyword skeyword softwaresystem
+syn keyword skeyword softwaresysteminstance
+syn keyword skeyword styles
+syn keyword skeyword systemcontext
+syn keyword skeyword systemlandscape
+syn keyword skeyword tags
+syn keyword skeyword terminology
+syn keyword skeyword theme
+syn keyword skeyword title
+syn keyword skeyword url
+syn keyword skeyword users
+syn keyword skeyword views
+syn keyword skeyword workspace
+
+syn match skeyword "\!adrs\s\+"
+syn match skeyword "\!constant\s\+"
+syn match skeyword "\!docs\s\+"
+syn match skeyword "\!identifiers\s\+"
+syn match skeyword "\!include\s\+"
+
+syn region sstring oneline start='"' end='"'
+
+syn region sblock start='{' end='}' fold transparent
+
+hi def link sstring string
+hi def link scomment comment
+hi def link skeyword keyword
+
+let b:current_syntax = "structurizr"
diff --git a/runtime/syntax/syncolor.vim b/runtime/syntax/syncolor.vim
deleted file mode 100644
index 5b907a3b83..0000000000
--- a/runtime/syntax/syncolor.vim
+++ /dev/null
@@ -1,87 +0,0 @@
-" Vim syntax support file
-" Maintainer: Bram Moolenaar <Bram@vim.org>
-" Last Change: 2020 Feb 13
-
-" This file sets up the default methods for highlighting.
-" It is loaded from "synload.vim" and from Vim for ":syntax reset".
-" Also used from init_highlight().
-
-if !exists("syntax_cmd") || syntax_cmd == "on"
- " ":syntax on" works like in Vim 5.7: set colors but keep links
- command -nargs=* SynColor hi <args>
- command -nargs=* SynLink hi link <args>
-else
- if syntax_cmd == "enable"
- " ":syntax enable" keeps any existing colors
- command -nargs=* SynColor hi def <args>
- command -nargs=* SynLink hi def link <args>
- elseif syntax_cmd == "reset"
- " ":syntax reset" resets all colors to the default
- command -nargs=* SynColor hi <args>
- command -nargs=* SynLink hi! link <args>
- else
- " User defined syncolor file has already set the colors.
- finish
- endif
-endif
-
-" Many terminals can only use six different colors (plus black and white).
-" Therefore the number of colors used is kept low. It doesn't look nice with
-" too many colors anyway.
-" Careful with "cterm=bold", it changes the color to bright for some terminals.
-" There are two sets of defaults: for a dark and a light background.
-if &background == "dark"
- SynColor Comment term=bold cterm=NONE ctermfg=Cyan ctermbg=NONE gui=NONE guifg=#80a0ff guibg=NONE
- SynColor Constant term=underline cterm=NONE ctermfg=Magenta ctermbg=NONE gui=NONE guifg=#ffa0a0 guibg=NONE
- SynColor Special term=bold cterm=NONE ctermfg=LightRed ctermbg=NONE gui=NONE guifg=Orange guibg=NONE
- SynColor Identifier term=underline cterm=bold ctermfg=Cyan ctermbg=NONE gui=NONE guifg=#40ffff guibg=NONE
- SynColor Statement term=bold cterm=NONE ctermfg=Yellow ctermbg=NONE gui=bold guifg=#ffff60 guibg=NONE
- SynColor PreProc term=underline cterm=NONE ctermfg=LightBlue ctermbg=NONE gui=NONE guifg=#ff80ff guibg=NONE
- SynColor Type term=underline cterm=NONE ctermfg=LightGreen ctermbg=NONE gui=bold guifg=#60ff60 guibg=NONE
- SynColor Underlined term=underline cterm=underline ctermfg=LightBlue gui=underline guifg=#80a0ff
- SynColor Ignore term=NONE cterm=NONE ctermfg=black ctermbg=NONE gui=NONE guifg=bg guibg=NONE
-else
- SynColor Comment term=bold cterm=NONE ctermfg=DarkBlue ctermbg=NONE gui=NONE guifg=Blue guibg=NONE
- SynColor Constant term=underline cterm=NONE ctermfg=DarkRed ctermbg=NONE gui=NONE guifg=Magenta guibg=NONE
- " #6a5acd is SlateBlue
- SynColor Special term=bold cterm=NONE ctermfg=DarkMagenta ctermbg=NONE gui=NONE guifg=#6a5acd guibg=NONE
- SynColor Identifier term=underline cterm=NONE ctermfg=DarkCyan ctermbg=NONE gui=NONE guifg=DarkCyan guibg=NONE
- SynColor Statement term=bold cterm=NONE ctermfg=Brown ctermbg=NONE gui=bold guifg=Brown guibg=NONE
- " #6a0dad is Purple
- SynColor PreProc term=underline cterm=NONE ctermfg=DarkMagenta ctermbg=NONE gui=NONE guifg=#6a0dad guibg=NONE
- SynColor Type term=underline cterm=NONE ctermfg=DarkGreen ctermbg=NONE gui=bold guifg=SeaGreen guibg=NONE
- SynColor Underlined term=underline cterm=underline ctermfg=DarkMagenta gui=underline guifg=SlateBlue
- SynColor Ignore term=NONE cterm=NONE ctermfg=white ctermbg=NONE gui=NONE guifg=bg guibg=NONE
-endif
-SynColor Error term=reverse cterm=NONE ctermfg=White ctermbg=Red gui=NONE guifg=White guibg=Red
-SynColor Todo term=standout cterm=NONE ctermfg=Black ctermbg=Yellow gui=NONE guifg=Blue guibg=Yellow
-
-" Common groups that link to default highlighting.
-" You can specify other highlighting easily.
-SynLink String Constant
-SynLink Character Constant
-SynLink Number Constant
-SynLink Boolean Constant
-SynLink Float Number
-SynLink Function Identifier
-SynLink Conditional Statement
-SynLink Repeat Statement
-SynLink Label Statement
-SynLink Operator Statement
-SynLink Keyword Statement
-SynLink Exception Statement
-SynLink Include PreProc
-SynLink Define PreProc
-SynLink Macro PreProc
-SynLink PreCondit PreProc
-SynLink StorageClass Type
-SynLink Structure Type
-SynLink Typedef Type
-SynLink Tag Special
-SynLink SpecialChar Special
-SynLink Delimiter Special
-SynLink SpecialComment Special
-SynLink Debug Special
-
-delcommand SynColor
-delcommand SynLink
diff --git a/runtime/syntax/synload.vim b/runtime/syntax/synload.vim
index 3863a84c1a..bfcd3b06da 100644
--- a/runtime/syntax/synload.vim
+++ b/runtime/syntax/synload.vim
@@ -14,13 +14,6 @@ endif
" let others know that syntax has been switched on
let syntax_on = 1
-" Set the default highlighting colors. Use a color scheme if specified.
-if exists("colors_name")
- exe "colors " . colors_name
-else
- runtime! syntax/syncolor.vim
-endif
-
" Line continuation is used here, remove 'C' from 'cpoptions'
let s:cpo_save = &cpo
set cpo&vim
diff --git a/runtime/syntax/tmux.vim b/runtime/syntax/tmux.vim
index d5419982ad..4f435ab923 100644
--- a/runtime/syntax/tmux.vim
+++ b/runtime/syntax/tmux.vim
@@ -8,7 +8,7 @@ if exists("b:current_syntax")
finish
endif
-" Explicitly change compatiblity options to Vim's defaults because this file
+" Explicitly change compatibility options to Vim's defaults because this file
" uses line continuations.
let s:original_cpo = &cpo
set cpo&vim
diff --git a/runtime/syntax/vim.vim b/runtime/syntax/vim.vim
index 55c47aa34d..f695a1a1bf 100644
--- a/runtime/syntax/vim.vim
+++ b/runtime/syntax/vim.vim
@@ -12,7 +12,7 @@
if exists("b:current_syntax")
finish
endif
-let s:keepcpo= &cpo
+let s:keepcpo = &cpo
set cpo&vim
" vimTodo: contains common special-notices for comments {{{2
@@ -200,7 +200,7 @@ syn keyword vimAugroupKey contained aug[roup]
" Operators: {{{2
" =========
-syn cluster vimOperGroup contains=vimEnvvar,vimFunc,vimFuncVar,vimOper,vimOperParen,vimNumber,vimString,vimRegister,vimContinue,vim9Comment
+syn cluster vimOperGroup contains=vimEnvvar,vimFunc,vimFuncVar,vimOper,vimOperParen,vimNumber,vimString,vimType,vimRegister,vimContinue,vim9Comment
syn match vimOper "\%#=1\(==\|!=\|>=\|<=\|=\~\|!\~\|>\|<\|=\)[?#]\{0,2}" skipwhite nextgroup=vimString,vimSpecFile
syn match vimOper "\(\<is\|\<isnot\)[?#]\{0,2}\>" skipwhite nextgroup=vimString,vimSpecFile
syn match vimOper "||\|&&\|[-+.!]" skipwhite nextgroup=vimString,vimSpecFile
@@ -214,12 +214,13 @@ endif
" =========
syn cluster vimFuncList contains=vimCommand,vimFunctionError,vimFuncKey,Tag,vimFuncSID
syn cluster vimFuncBodyList contains=vimAbb,vimAddress,vimAugroupKey,vimAutoCmd,vimCmplxRepeat,vimComment,vim9Comment,vimContinue,vimCtrlChar,vimEcho,vimEchoHL,vimEnvvar,vimExecute,vimIsCommand,vimFBVar,vimFunc,vimFunction,vimFuncVar,vimGlobal,vimHighlight,vimIsCommand,vimLet,vimLetHereDoc,vimLineComment,vimMap,vimMark,vimNorm,vimNotation,vimNotFunc,vimNumber,vimOper,vimOperParen,vimRegion,vimRegister,vimSearch,vimSet,vimSpecFile,vimString,vimSubst,vimSynLine,vimUnmap,vimUserCommand
-syn match vimFunction "\<fu\%[nction]!\=\s\+\%(<[sS][iI][dD]>\|[sSgGbBwWtTlL]:\)\=\%(\i\|[#.]\|{.\{-1,}}\)*\ze\s*(" contains=@vimFuncList nextgroup=vimFuncBody
+syn match vimFunction "\<\(fu\%[nction]\)!\=\s\+\%(<[sS][iI][dD]>\|[sSgGbBwWtTlL]:\)\=\%(\i\|[#.]\|{.\{-1,}}\)*\ze\s*(" contains=@vimFuncList nextgroup=vimFuncBody
+ syn match vimFunction "\<def!\=\ze\s*(" contains=@vimFuncList nextgroup=vimFuncBody
if exists("g:vimsyn_folding") && g:vimsyn_folding =~# 'f'
syn region vimFuncBody contained fold start="\ze\s*(" matchgroup=vimCommand end="\<\(endf\>\|endfu\%[nction]\>\|enddef\>\)" contains=@vimFuncBodyList
else
- syn region vimFuncBody contained start="\ze\s*(" matchgroup=vimCommand end="\<\(endf\>\|endfu\%[nction]\>\|enddef\>\)" contains=@vimFuncBodyList
+ syn region vimFuncBody contained start="\ze\s*(" matchgroup=vimCommand end="\<\(endf\>\|endfu\%[nction]\>\|enddef\>\)" contains=@vimFuncBodyList
endif
syn match vimFuncVar contained "a:\(\K\k*\|\d\+\)"
syn match vimFuncSID contained "\c<sid>\|\<s:"
@@ -228,6 +229,9 @@ syn match vimFuncBlank contained "\s\+"
syn keyword vimPattern contained start skip end
+" vimTypes : new for vim9
+ syn match vimType ":\s*\zs\<\(bool\|number\|float\|string\|blob\|list<\|dict<\|job\|channel\|func\)\>"
+
" Special Filenames, Modifiers, Extension Removal: {{{2
" ===============================================
syn match vimSpecFile "<c\(word\|WORD\)>" nextgroup=vimSpecFileMod,vimSubst
@@ -355,7 +359,7 @@ syn match vimCmplxRepeat '[^a-zA-Z_/\\()]q[0-9a-zA-Z"]\>'lc=1
syn match vimCmplxRepeat '@[0-9a-z".=@:]\ze\($\|[^a-zA-Z]\>\)'
" Set command and associated set-options (vimOptions) with comment {{{2
-syn region vimSet matchgroup=vimCommand start="\<\%(setl\%[ocal]\|setg\%[lobal]\|se\%[t]\)\>" skip="\%(\\\\\)*\\." end="$" end="|" matchgroup=vimNotation end="<[cC][rR]>" oneline keepend contains=vimSetEqual,vimOption,vimErrSetting,vimComment,vim9Comment,vimSetString,vimSetMod
+syn region vimSet matchgroup=vimCommand start="\<\%(setl\%[ocal]\|setg\%[lobal]\|se\%[t]\)\>" skip="\%(\\\\\)*\\.\n\@!" end="$" end="|" matchgroup=vimNotation end="<[cC][rR]>" keepend contains=vimSetEqual,vimOption,vimErrSetting,vimComment,vim9Comment,vimSetString,vimSetMod
syn region vimSetEqual contained start="[=:]\|[-+^]=" skip="\\\\\|\\\s" end="[| \t]"me=e-1 end="$" contains=vimCtrlChar,vimSetSep,vimNotation,vimEnvvar
syn region vimSetString contained start=+="+hs=s+1 skip=+\\\\\|\\"+ end=+"+ contains=vimCtrlChar
syn match vimSetSep contained "[,:]"
@@ -390,7 +394,7 @@ syn case match
" Maps: {{{2
" ====
syn match vimMap "\<map\>!\=\ze\s*[^(]" skipwhite nextgroup=vimMapMod,vimMapLhs
-syn keyword vimMap cm[ap] cno[remap] im[ap] ino[remap] lm[ap] ln[oremap] nm[ap] nn[oremap] no[remap] om[ap] ono[remap] smap snor[emap] vm[ap] vn[oremap] xm[ap] xn[oremap] skipwhite nextgroup=vimMapBang,vimMapMod,vimMapLhs
+syn keyword vimMap cm[ap] cno[remap] im[ap] ino[remap] lm[ap] ln[oremap] nm[ap] nn[oremap] no[remap] om[ap] ono[remap] smap snor[emap] tno[remap] tm[ap] vm[ap] vmapc[lear] vn[oremap] xm[ap] xn[oremap] skipwhite nextgroup=vimMapBang,vimMapMod,vimMapLhs
syn keyword nvimMap tn[oremap] tm[ap] skipwhite nextgroup=vimMapBang,vimMapMod,vimMapLhs
syn keyword vimMap mapc[lear] smapc[lear]
syn keyword vimUnmap cu[nmap] iu[nmap] lu[nmap] nun[map] ou[nmap] sunm[ap] unm[ap] unm[ap] vu[nmap] xu[nmap] skipwhite nextgroup=vimMapBang,vimMapMod,vimMapLhs
@@ -981,6 +985,7 @@ if !exists("skip_vim_syntax_inits")
hi def link vimSyntax vimCommand
hi def link vimSynType vimSpecial
hi def link vimTodo Todo
+ hi def link vimType Type
hi def link vimUnmap vimMap
hi def link vimUserAttrbCmpltFunc Special
hi def link vimUserAttrbCmplt vimSpecial
diff --git a/runtime/tutor/en/vim-01-beginner.tutor b/runtime/tutor/en/vim-01-beginner.tutor
index 5ae0fde0da..7c0c357e80 100644
--- a/runtime/tutor/en/vim-01-beginner.tutor
+++ b/runtime/tutor/en/vim-01-beginner.tutor
@@ -1,4 +1,4 @@
-# Welcome to the VIM Tutor
+# Welcome to the VIM Tutor
Vim is a very powerful editor that has many commands, too many to explain in
a tutor such as this. This tutor is designed to describe enough of the
@@ -21,7 +21,9 @@ This tutorial is interactive, and there are a few things you should know.
- Type [<Enter>](<Enter>) on links [like this](holy-grail ) to open the linked help section.
- Or simply type [K](K) on any word to find its documentation!
- Sometimes you will be required to modify text like
-this here
+
+ this here
+
Once you have done the changes correctly, the ✗ sign at the left will change
to ✓. I imagine you can already see how neat Vim can be. ;)
Other times, you'll be prompted to run a command (I'll explain this later):
@@ -32,7 +34,6 @@ or press a sequence of keys
~~~ normal
<Esc>0f<Space>d3wP$P
~~~
-
Text within <'s and >'s (like `<Enter>`{normal}) describes a key to press
instead of text to type.
@@ -48,12 +49,12 @@ Now, move to the next lesson (use the `j`{normal} key to scroll down).
j The `j`{normal} key looks like a down arrow.
- 1. Move the cursor around the screen until you are comfortable.
+ 1. Move the cursor around the screen until you are comfortable.
- 2. Hold down the down key (`j`{normal}) until it repeats.
- Now you know how to move to the next lesson.
+ 2. Hold down the down key (`j`{normal}) until it repeats.
+ Now you know how to move to the next lesson.
- 3. Using the down key, move to Lesson 1.2.
+ 3. Using the down key, move to Lesson 1.2.
NOTE: If you are ever unsure about something you typed, press <Esc> to place
you in Normal mode. Then retype the command you wanted.
@@ -63,8 +64,7 @@ NOTE: The cursor keys should also work. But using hjkl you will be able to
# Lesson 1.2: EXITING VIM
-!! NOTE: Before executing any of the steps below,
-read this entire lesson !!
+!! NOTE: Before executing any of the steps below, read this entire lesson !!
1. Press the <Esc> key (to make sure you are in Normal mode).
@@ -72,18 +72,18 @@ read this entire lesson !!
`:q!`{vim} `<Enter>`{normal}.
- This exits the editor, DISCARDING any changes you have made.
+ This exits the editor, DISCARDING any changes you have made.
3. Open vim and get back here by executing the command that got you into
- this tutor. That might be:
+ this tutor. That might be:
- :Tutor <Enter>
+ :Tutor <Enter>
4. If you have these steps memorized and are confident, execute steps
- 1 through 3 to exit and re-enter the editor.
+ 1 through 3 to exit and re-enter the editor.
NOTE: [:q!](:q) <Enter> discards any changes you made. In a few lessons you
- will learn how to save the changes to a file.
+ will learn how to save the changes to a file.
5. Move the cursor down to Lesson 1.3.
@@ -94,7 +94,7 @@ NOTE: [:q!](:q) <Enter> discards any changes you made. In a few lessons you
1. Move the cursor to the line below marked ✗.
2. To fix the errors, move the cursor until it is on top of the
- character to be deleted.
+ character to be deleted.
3. Press [the x key](x) to delete the unwanted character.
@@ -104,8 +104,9 @@ The ccow jumpedd ovverr thhe mooon.
5. Now that the line is correct, go on to Lesson 1.4.
-NOTE: As you go through this tutor, do not try to memorize, learn by
- usage.
+NOTE: As you go through this tutor, do not try to memorize everything,
+ your Vim vocabulary will expand with usage. Consider returning to
+ this tutor periodically for a refresher.
# Lesson 1.4: TEXT EDITING: INSERTION
@@ -114,12 +115,12 @@ NOTE: As you go through this tutor, do not try to memorize, learn by
1. Move the cursor to the first line below marked ✗.
2. To make the first line the same as the second, move the cursor on top
- of the first character AFTER where the text is to be inserted.
+ of the first character AFTER where the text is to be inserted.
3. Press `i`{normal} and type in the necessary additions.
4. As each error is fixed press `<Esc>`{normal} to return to Normal mode.
- Repeat steps 2 through 4 to correct the sentence.
+ Repeat steps 2 through 4 to correct the sentence.
There is text misng this .
There is some text missing from this line.
@@ -136,7 +137,7 @@ There is some text missing from this line.
2. Press [A](A) and type in the necessary additions.
3. As the text has been appended press `<Esc>`{normal} to return to Normal
- mode.
+ mode.
4. Move the cursor to the second line marked ✗ and repeat
steps 2 and 3 to correct this sentence.
@@ -159,7 +160,7 @@ There is also some text missing here.
2. At the shell prompt type this command:
~~~ sh
- $ nvim tutor
+ $ nvim tutor
~~~
'nvim' is the command to start the Nvim editor, 'tutor' is the name of
the file you wish to edit. Use a file that may be changed.
@@ -168,13 +169,12 @@ There is also some text missing here.
4. Save the file with changes and exit Vim with:
~~~ cmd
- :wq
+ :wq
~~~
-
Note you'll need to press `<Enter>` to execute the command.
5. If you have quit vimtutor in step 1 restart the vimtutor and move down
- to the following summary.
+ to the following summary.
6. After reading the above steps and understanding them: do it.
@@ -184,15 +184,11 @@ There is also some text missing here.
h (left) j (down) k (up) l (right)
2. To start Vim from the shell prompt type:
-
~~~ sh
$ nvim FILENAME
~~~
-
- 3. To exit Vim type: `<Esc>`{normal} `:q!`{vim} `<Enter>`{normal} to trash
- all changes.
- OR type: `<Esc>`{normal} `:wq`{vim} `<Enter>`{normal} to save
- the changes.
+ 3. To exit Vim type: `<Esc>`{normal} `:q!`{vim} `<Enter>`{normal} to trash all changes.
+ OR type: `<Esc>`{normal} `:wq`{vim} `<Enter>`{normal} to save the changes.
4. To delete the character at the cursor type: `x`{normal}
@@ -239,8 +235,7 @@ Somebody typed the end of this line twice. end of this line twice.
# Lesson 2.3: ON OPERATORS AND MOTIONS
-Many commands that change text are made from an [operator](operator) and
-a [motion](navigation).
+Many commands that change text are made from an [operator](operator) and a [motion](navigation).
The format for a delete command with the [d](d) delete operator is as follows:
d motion
@@ -318,16 +313,13 @@ it would be easier to simply type two d's to delete a line.
** Press `u`{normal} to undo the last commands, `U`{normal} to fix a whole line. **
- 1. Move the cursor to the line below marked ✗ and place it on the
- first error.
+ 1. Move the cursor to the line below marked ✗ and place it on the first error.
2. Type `x`{normal} to delete the first unwanted character.
3. Now type `u`{normal} to undo the last command executed.
4. This time fix all the errors on the line using the `x`{normal} command.
5. Now type a capital `U`{normal} to return the line to its original state.
- 6. Now type `u`{normal} a few times to undo the `U`{normal} and preceding
- commands.
- 7. Now type `<C-r>`{normal} (Control + R) a few times to redo the commands
- (undo the undos).
+ 6. Now type `u`{normal} a few times to undo the `U`{normal} and preceding commands.
+ 7. Now type `<C-r>`{normal} (Control + R) a few times to redo the commands.
Fiix the errors oon thhis line and reeplace them witth undo.
@@ -341,11 +333,14 @@ Fiix the errors oon thhis line and reeplace them witth undo.
4. To repeat a motion prepend it with a number: `2w`{normal}
5. The format for a change command is:
- operator [number] motion
+
+ operator [number] motion
+
where:
- operator - is what to do, such as [d](d) for delete
- [number] - is an optional count to repeat the motion
- motion - moves over the text to operate on, such as:
+
+ operator - is what to do, such as [d](d) for delete
+ [number] - is an optional count to repeat the motion
+ motion - moves over the text to operate on, such as:
[w](w) (word),
[$]($) (to the end of line), etc.
@@ -403,8 +398,7 @@ NOTE: Remember that you should be learning by doing, not memorization.
3. Type `ce`{normal} and the correct word (in this case, type "ine" ).
- 4. Press `<Esc>`{normal} and move to the next character that needs to be
- changed.
+ 4. Press `<Esc>`{normal} and move to the next character that needs to be changed.
5. Repeat steps 3 and 4 until the first sentence is the same as the second.
@@ -419,7 +413,7 @@ Notice that [c](c)e deletes the word and places you in Insert mode.
1. The change operator works in the same way as delete. The format is:
- c [number] motion
+ c [number] motion
2. The motions are the same, such as `w`{normal} (word) and `$`{normal} (end of line).
@@ -449,7 +443,7 @@ NOTE: You can use the Backspace key to correct mistakes while typing.
4. The format for change is:
- c [number] motion
+ c [number] motion
Now go on to the next lesson.
@@ -460,13 +454,13 @@ Now go on to the next lesson.
NOTE: Read this entire lesson before executing any of the steps!!
- 1. Hold down the `<Ctrl>`{normal} key and press `g`{normal}. We call this
- `<C-g>`{normal}. A message will appear at the bottom of the page with the
- filename and the position in the file. Remember the line number for
- Step 3.
+ 1. Hold down the `<Ctrl>`{normal} key and press `g`{normal}. We call this `<C-g>`{normal}.
+ A message will appear at the bottom of the page with the filename and
+ the position in the file. Remember the line number for Step 3.
NOTE: You may see the cursor position in the lower right corner of the
screen. This happens when the ['ruler']('ruler') option is set.
+
2. Press [G](G) to move you to the bottom of the file.
Type [gg](gg) to move you to the start of the file.
@@ -482,17 +476,16 @@ NOTE: You may see the cursor position in the lower right corner of the
1. In Normal mode type the `/`{normal} character. Notice that it and the
cursor appear at the bottom of the screen as with the `:`{normal} command.
- 2. Now type 'errroor' `<Enter>`{normal}. This is the word you want to search
- for.
+ 2. Now type 'errroor' `<Enter>`{normal}. This is the word you want to search for.
3. To search for the same phrase again, simply type [n](n).
To search for the same phrase in the opposite direction, type [N](N).
- 4. To search for a phrase in the backward direction, use [?](?) instead
- of `/`{normal}.
+ 4. To search for a phrase in the backward direction, use [?](?) instead of `/`{normal}.
- 5. To go back to where you came from press `<C-o>`{normal} (keep `<Ctrl>`{normal} pressed down while pressing the letter `o`{normal}). Repeat to go back
- further. `<C-i>`{normal} goes forward.
+ 5. To go back to where you came from press `<C-o>`{normal}.
+ (keep `<Ctrl>`{normal} pressed down while pressing the letter `o`{normal}).
+ Repeat to go back further. `<C-i>`{normal} goes forward.
"errroor" is not the way to spell error; errroor is an error.
@@ -525,16 +518,14 @@ NOTE: This is very useful in debugging a program with unmatched parentheses!
2. Type
~~~ cmd
- :s/thee/the/
+ :s/thee/the/
~~~
-
- NOTE that the [:s](:s) command only changed the first occurrence of "thee" in the line.
+ NOTE: the [:s](:s) command only changed the first match of "thee" in the line.
3. Now type
~~~ cmd
- :s/thee/the/g
+ :s/thee/the/g
~~~
-
Adding the g [flag](:s_flags) means to substitute globally in the line,
change all occurrences of "thee" in the line.
@@ -542,20 +533,20 @@ Usually thee best time to see thee flowers is in thee spring.
4. To change every occurrence of a character string between two lines, type
~~~ cmd
- :#,#s/old/new/g
+ :#,#s/old/new/g
~~~
where #,# are the line numbers of the range of lines where the
substitution is to be done.
Type
~~~ cmd
- :%s/old/new/g
+ :%s/old/new/g
~~~
to change every occurrence in the whole file.
Type
~~~ cmd
- :%s/old/new/gc
+ :%s/old/new/gc
~~~
to find every occurrence in the whole file, with a prompt whether to
substitute or not.
@@ -564,7 +555,7 @@ Usually thee best time to see thee flowers is in thee spring.
1. `<C-g>`{normal} displays your location and the file status.
`G`{normal} moves to the end of the file.
- number `G`{normal} moves to that line number.
+ number `G`{normal} moves to that line number.
`gg`{normal} moves to the first line.
2. Typing `/`{normal} followed by a phrase searches FORWARD for the phrase.
@@ -643,7 +634,6 @@ NOTE: If you were to exit Vim and start it again with `nvim TEST`, the file
~~~ cmd
:!rm TEST
~~~
-
# Lesson 5.3: SELECTING TEXT TO WRITE
** To save part of the file, type `v`{normal} motion `:w FILENAME`{vim}. **
@@ -655,7 +645,7 @@ NOTE: If you were to exit Vim and start it again with `nvim TEST`, the file
3. Press the `:`{normal} character. At the bottom of the screen
- :'<,'>
+ `:'<,'>`{vim}
will appear.
@@ -669,12 +659,12 @@ NOTE: If you were to exit Vim and start it again with `nvim TEST`, the file
before you press `<Enter>`{normal}.
- 5. Vim will write the selected lines to the file TEST. Use `:!ls`{vim} to see it. Do not remove it yet! We will use it in the next lesson.
+ 5. Vim will write the selected lines to the file TEST. Use `:!ls`{vim} to see it.
+ Do not remove it yet! We will use it in the next lesson.
-NOTE: Pressing [v](v) starts [Visual selection](visual-mode). You can move
- the cursor around to make the selection bigger or smaller. Then you can
- use an operator to do something with the text. For example, `d`{normal}
- deletes the text.
+NOTE: Pressing [v](v) starts [Visual selection](visual-mode). You can move the cursor around to
+ make the selection bigger or smaller. Then you can use an operator to
+ do something with the text. For example, `d`{normal} deletes the text.
# Lesson 5.4: RETRIEVING AND MERGING FILES
@@ -689,8 +679,8 @@ NOTE: After executing Step 2 you will see text from Lesson 5.3. Then move
`:r TEST`{vim}
- where TEST is the name of the file you used.
- The file you retrieve is placed below the cursor line.
+ where TEST is the name of the file you used.
+ The file you retrieve is placed below the cursor line.
3. To verify that a file was retrieved, cursor back and notice that there
are now two copies of Lesson 5.3, the original and the file version.
@@ -706,20 +696,20 @@ NOTE: You can also read the output of an external command. For example,
1. [:!command](:!cmd) executes an external command.
Some useful examples are:
- `:!ls`{vim} - shows a directory listing
- `:!rm FILENAME`{vim} - removes file FILENAME
+ `:!ls`{vim} - shows a directory listing
+ `:!rm FILENAME`{vim} - removes file FILENAME
- 2. [:w](:w) FILENAME writes the current Vim file to disk with
- name FILENAME.
+ 2. [:w](:w) FILENAME writes the current Vim file to disk with
+ name FILENAME.
3. [v](v) motion :w FILENAME saves the Visually selected lines in file
FILENAME.
- 4. [:r](:r) FILENAME retrieves disk file FILENAME and puts it
- below the cursor position.
+ 4. [:r](:r) FILENAME retrieves disk file FILENAME and puts it
+ below the cursor position.
- 5. [:r !dir](:r!) reads the output of the dir command and
- puts it below the cursor position.
+ 5. [:r !dir](:r!) reads the output of the dir command and
+ puts it below the cursor position.
# Lesson 6.1: THE OPEN COMMAND
@@ -747,14 +737,11 @@ Open up a line above this by typing O while the cursor is on this line.
2. Press `e`{normal} until the cursor is on the end of "li".
- 3. Type the lowercase letter `a`{normal} to [append](a) text AFTER the
- cursor.
+ 3. Type the lowercase letter `a`{normal} to [append](a) text AFTER the cursor.
- 4. Complete the word like the line below it. Press `<Esc>`{normal} to exit
- Insert mode.
+ 4. Complete the word like the line below it. Press `<Esc>`{normal} to exit Insert mode.
- 5. Use `e`{normal} to move to the next incomplete word and repeat steps 3
- and 4.
+ 5. Use `e`{normal} to move to the next incomplete word and repeat steps 3 and 4.
This li will allow you to pract appendi text to a line.
This line will allow you to practice appending text to a line.
@@ -767,21 +754,21 @@ NOTE: [a](a), [i](i) and [A](A) all go to the same Insert mode, the only
** Type a capital `R`{normal} to replace more than one character. **
1. Move the cursor to the first line below marked ✗. Move the cursor to
- the beginning of the first "xxx".
+ the beginning of the first "xxx".
2. Now press `R`{normal} ([capital R](R)) and type the number below it in the
- second line, so that it replaces the "xxx".
+ second line, so that it replaces the "xxx".
3. Press `<Esc>`{normal} to leave [Replace mode](mode-replace). Notice that
- the rest of the line remains unmodified.
+ the rest of the line remains unmodified.
4. Repeat the steps to replace the remaining "xxx".
Adding 123 to xxx gives you xxx.
Adding 123 to 456 gives you 579.
-NOTE: Replace mode is like Insert mode, but every typed character deletes an
- existing character.
+NOTE: Replace mode is like Insert mode, but every typed character
+ deletes an existing character.
# Lesson 6.4: COPY AND PASTE TEXT
@@ -875,17 +862,17 @@ NOTE: If you want to ignore case for just one search command, use [\c](/\c)
~~~ cmd
:set invic
~~~
-
# Lesson 7.1: GETTING HELP
** Use the on-line help system. **
-Vim has a comprehensive on-line help system. To get started, try one of
-these three:
- - press the `<HELP>`{normal} key (if you have one)
- - press the `<F1>`{normal} key (if you have one)
- - type
- `:help`{vim}
+Vim has a comprehensive on-line help system.
+
+To get started, try one of these three:
+
+ - press the `<HELP>`{normal} key (if you have one)
+ - press the `<F1>`{normal} key (if you have one)
+ - type `:help`{vim}
Read the text in the help window to find out how the help works.
Type `<C-w><C-w>`{normal} to jump from one window to another.
@@ -907,10 +894,12 @@ Vim has many more features than Vi, but most of them are disabled by
default. To start using more features you have to create a "vimrc" file.
1. Start editing the "vimrc" file.
+
`:call mkdir(stdpath('config'),'p')`{vim}
`:exe 'edit' stdpath('config').'/init.vim'`{vim}
2. Write the file with:
+
`:w`{vim}
You can add all your preferred settings to this "vimrc" file.
@@ -924,17 +913,15 @@ default. To start using more features you have to create a "vimrc" file.
2. Type the start of a command: `:e`{vim}
- 3. Press `<C-d>`{normal} and Vim will show a list of commands that start
- with "e".
+ 3. Press `<C-d>`{normal} and Vim will show a list of commands beginning with "e".
4. Press `<Tab>`{normal} and Vim will complete the command name to ":edit".
5. Now add a space and the start of an existing file name: `:edit FIL`{vim}
- 6. Press `<Tab>`{normal}. Vim will complete the name (if it is unique).
+ 6. Press `<Tab>`{normal}. Vim will complete the name ("FIL" -> "FILE", if it is unique).
-NOTE: Completion works for many commands. It is especially useful for
- `:help`{vim}.
+NOTE: Completion works for many commands. It is especially useful for `:help`{vim}.
# Lesson 7 SUMMARY
@@ -950,7 +937,7 @@ NOTE: Completion works for many commands. It is especially useful for
5. Create a vimrc startup script to keep your preferred settings.
6. While in command mode, press `<C-d>`{normal} to see possible completions.
- Press `<Tab>`{normal} to use one completion.
+ Press `<Tab>`{normal} to use one completion.
# CONCLUSION
@@ -961,13 +948,20 @@ many many more commands. Consult the help often.
There are many resources online to learn more about vim. Here's a bunch of
them:
-- *Learn Vim Progressively*: http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/
-- *Learning Vim in 2014*: http://benmccormick.org/learning-vim-in-2014/
-- *Vimcasts*: http://vimcasts.org/
-- *Vim Video-Tutorials by Derek Wyatt*: http://derekwyatt.org/vim/tutorials/
-- *Learn Vimscript the Hard Way*: http://learnvimscriptthehardway.stevelosh.com/
-- *7 Habits of Effective Text Editing*: http://www.moolenaar.net/habits.html
-- *vim-galore*: https://github.com/mhinz/vim-galore
+- *Learn Vim Progressively*:
+ http://yannesposito.com/Scratch/en/blog/Learn-Vim-Progressively/
+- *Learning Vim in 2013*:
+ http://benmccormick.org/learning-vim-in-2014/
+- *Vimcasts*:
+ http://vimcasts.org/
+- *Vim Video-Tutorials by Derek Wyatt*:
+ http://derekwyatt.org/vim/tutorials/
+- *Learn Vimscript the Hard Way*:
+ http://learnvimscriptthehardway.stevelosh.com/
+- *7 Habits of Effective Text Editing*:
+ http://www.moolenaar.net/habits.html
+- *vim-galore*:
+ https://github.com/mhinz/vim-galore
If you prefer a book, *Practical Vim* by Drew Neil is recommended often
(the sequel, *Modern Vim*, includes material specific to nvim).
@@ -978,3 +972,5 @@ University. E-mail: bware@mines.colorado.edu.
Modified for Vim by Bram Moolenaar.
Modified for vim-tutor-mode by Felipe Morales.
+
+// vim: nowrap
diff --git a/runtime/tutor/en/vim-01-beginner.tutor.json b/runtime/tutor/en/vim-01-beginner.tutor.json
index af22cf2aca..e71ead976d 100644
--- a/runtime/tutor/en/vim-01-beginner.tutor.json
+++ b/runtime/tutor/en/vim-01-beginner.tutor.json
@@ -1,45 +1,45 @@
{
"expect": {
- "24": -1,
+ "25": -1,
"103": "The cow jumped over the moon.",
- "124": "There is some text missing from this line.",
"125": "There is some text missing from this line.",
- "144": "There is some text missing from this line.",
+ "126": "There is some text missing from this line.",
"145": "There is some text missing from this line.",
- "146": "There is also some text missing here.",
+ "146": "There is some text missing from this line.",
"147": "There is also some text missing here.",
- "220": "There are some words that don't belong in this sentence.",
- "236": "Somebody typed the end of this line twice.",
- "276": -1,
- "295": "This line of words is cleaned up.",
+ "148": "There is also some text missing here.",
+ "216": "There are some words that don't belong in this sentence.",
+ "232": "Somebody typed the end of this line twice.",
+ "271": -1,
+ "290": "This line of words is cleaned up.",
+ "304": -1,
+ "305": -1,
+ "306": -1,
+ "307": -1,
+ "308": -1,
"309": -1,
"310": -1,
- "311": -1,
- "312": -1,
- "313": -1,
- "314": -1,
- "315": -1,
- "332": "Fix the errors on this line and replace them with undo.",
- "372": -1,
- "373": -1,
- "374": -1,
- "375": -1,
- "389": "When this line was typed in, someone pressed some wrong keys!",
- "390": "When this line was typed in, someone pressed some wrong keys!",
- "411": "This line has a few words that need changing using the change operator.",
- "412": "This line has a few words that need changing using the change operator.",
- "432": "The end of this line needs to be corrected using the `c$` command.",
- "433": "The end of this line needs to be corrected using the `c$` command.",
- "497": -1,
- "516": -1,
- "541": "Usually the best time to see the flowers is in the spring.",
- "735": -1,
- "740": -1,
- "759": "This line will allow you to practice appending text to a line.",
- "760": "This line will allow you to practice appending text to a line.",
- "780": "Adding 123 to 456 gives you 579.",
- "781": "Adding 123 to 456 gives you 579.",
- "807": "a) This is the first item.",
- "808": "b) This is the second item."
+ "324": "Fix the errors on this line and replace them with undo.",
+ "367": -1,
+ "368": -1,
+ "369": -1,
+ "370": -1,
+ "384": "When this line was typed in, someone pressed some wrong keys!",
+ "385": "When this line was typed in, someone pressed some wrong keys!",
+ "405": "This line has a few words that need changing using the change operator.",
+ "406": "This line has a few words that need changing using the change operator.",
+ "426": "The end of this line needs to be corrected using the `c$` command.",
+ "427": "The end of this line needs to be corrected using the `c$` command.",
+ "490": -1,
+ "509": -1,
+ "532": "Usually the best time to see the flowers is in the spring.",
+ "725": -1,
+ "730": -1,
+ "746": "This line will allow you to practice appending text to a line.",
+ "747": "This line will allow you to practice appending text to a line.",
+ "767": "Adding 123 to 456 gives you 579.",
+ "768": "Adding 123 to 456 gives you 579.",
+ "794": "a) This is the first item.",
+ "795": "b) This is the second item."
}
}