aboutsummaryrefslogtreecommitdiff
path: root/runtime/doc
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/doc')
-rw-r--r--runtime/doc/lua.txt35
-rw-r--r--runtime/doc/news.txt1
2 files changed, 36 insertions, 0 deletions
diff --git a/runtime/doc/lua.txt b/runtime/doc/lua.txt
index ef2125841d..300d809854 100644
--- a/runtime/doc/lua.txt
+++ b/runtime/doc/lua.txt
@@ -4624,6 +4624,41 @@ vim.text.hexencode({str}) *vim.text.hexencode()*
Return: ~
(`string`) Hex encoded string
+vim.text.indent({size}, {text}, {opts}) *vim.text.indent()*
+ Sets the indent (i.e. the common leading whitespace) of non-empty lines in
+ `text` to `size` spaces/tabs.
+
+ Indent is calculated by number of consecutive indent chars.
+ • The first indented, non-empty line decides the indent char (space/tab):
+ • `SPC SPC TAB …` = two-space indent.
+ • `TAB SPC …` = one-tab indent.
+ • Set `opts.expandtab` to treat tabs as spaces.
+
+ To "dedent" (remove the common indent), pass `size=0`: >lua
+ vim.print(vim.text.indent(0, ' a\n b\n'))
+<
+
+ To adjust relative-to an existing indent, call indent() twice: >lua
+ local indented, old_indent = vim.text.indent(0, ' a\n b\n')
+ indented = vim.text.indent(old_indent + 2, indented)
+ vim.print(indented)
+<
+
+ To ignore the final, blank line when calculating the indent, use gsub()
+ before calling indent(): >lua
+ local text = ' a\n b\n '
+ vim.print(vim.text.indent(0, (text:gsub('\n[\t ]+\n?$', '\n'))))
+<
+
+ Parameters: ~
+ • {size} (`integer`) Number of spaces.
+ • {text} (`string`) Text to indent.
+ • {opts} (`{ expandtab?: number }?`)
+
+ Return (multiple): ~
+ (`string`) Indented text.
+ (`integer`) Indent size before modification.
+
==============================================================================
Lua module: tohtml *vim.tohtml*
diff --git a/runtime/doc/news.txt b/runtime/doc/news.txt
index 17de99730a..0d47c7adb9 100644
--- a/runtime/doc/news.txt
+++ b/runtime/doc/news.txt
@@ -321,6 +321,7 @@ LUA
• |vim.fs.relpath()| gets relative path compared to base path.
• |vim.fs.dir()| and |vim.fs.find()| now follow symbolic links by default,
the behavior can be turn off using the new `follow` option.
+• |vim.text.indent()| indents/dedents text.
OPTIONS