diff options
| author | Justin M. Keyes <justinkz@gmail.com> | 2025-02-26 14:31:03 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-02-26 14:31:03 -0800 |
| commit | 4f42b69b4ad0d0034581d756ef9bcb0e55f3491d (patch) | |
| tree | 0c40b6f8c3569e339d375cb5842820590c5f3103 /runtime/doc | |
| parent | f4921e2b7deb4812414998a521c33f920f571c20 (diff) | |
| parent | 4a997a1732fdb7a1c99cadf780b789f1ac84d990 (diff) | |
| download | rneovim-4f42b69b4ad0d0034581d756ef9bcb0e55f3491d.tar.gz rneovim-4f42b69b4ad0d0034581d756ef9bcb0e55f3491d.tar.bz2 rneovim-4f42b69b4ad0d0034581d756ef9bcb0e55f3491d.zip | |
Merge #32601 vim.text.indent()
Diffstat (limited to 'runtime/doc')
| -rw-r--r-- | runtime/doc/lua.txt | 35 | ||||
| -rw-r--r-- | runtime/doc/news.txt | 1 |
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 |