Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitfdad865

Browse files
famiukraftwerk28
authored andcommitted
feat(lua): vim.cmd() with kwargs acts like nvim_cmd()neovim#18523
1 parent4a44d38 commitfdad865

File tree

2 files changed

+59
-18
lines changed

2 files changed

+59
-18
lines changed

‎runtime/doc/lua.txt‎

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,21 +1017,10 @@ vim.call({func}, {...}) *vim.call()*
10171017
See also|vim.fn|.
10181018
Equivalent to:>
10191019
vim.fn[func]({...})
1020-
<
1021-
vim.cmd({cmd})*vim.cmd()*
1022-
Executes multiple lines of Vimscript at once. It is an alias to
1023-
|nvim_exec()|, where`output` is set to false. Thus it works identical
1024-
to|:source|.
1025-
See also|ex-cmd-index|.
1026-
Example:>
1027-
vim.cmd('echo 42')
1028-
vim.cmd([[
1029-
augroup My_group
1030-
autocmd!
1031-
autocmd FileType c setlocal cindent
1032-
augroup END
1033-
]])
1034-
<
1020+
1021+
vim.cmd({command})
1022+
See|vim.cmd()|.
1023+
10351024
vim.fn.{func}({...})*vim.fn*
10361025
Invokes|vim-function| or|user-function|{func} with arguments{...}.
10371026
To call autoload functions, use the syntax:>
@@ -1296,6 +1285,34 @@ vim.wo *vim.wo*
12961285
==============================================================================
12971286
Lua module: vim*lua-vim*
12981287

1288+
cmd({command})*vim.cmd()*
1289+
Execute Vim script commands.
1290+
1291+
Example:>
1292+
1293+
vim.cmd('echo 42')
1294+
vim.cmd([[
1295+
augroup My_group
1296+
autocmd!
1297+
autocmd FileType c setlocal cindent
1298+
augroup END
1299+
]])
1300+
vim.cmd({ cmd = 'echo', args = { '"foo"' } })
1301+
<
1302+
1303+
Parameters:~
1304+
{command} string|table Command(s) to execute. If a
1305+
string, executes multiple lines of Vim script
1306+
at once. In this case, it is an alias to
1307+
|nvim_exec()|, where`output` is set to false.
1308+
Thus it works identical to|:source|. If a
1309+
table, executes a single command. In this case,
1310+
it is an alias to|nvim_cmd()| where`opts` is
1311+
empty.
1312+
1313+
See also:~
1314+
|ex-cmd-index|
1315+
12991316
*vim.connection_failure_errmsg()*
13001317
connection_failure_errmsg({consequence})
13011318
TODO: Documentation

‎runtime/lua/vim/_editor.lua‎

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -284,9 +284,33 @@ vim.funcref = function(viml_func_name)
284284
returnvim.fn[viml_func_name]
285285
end
286286

287-
-- An easier alias for commands.
288-
vim.cmd=function(command)
289-
returnvim.api.nvim_exec(command,false)
287+
--- Execute Vim script commands.
288+
---
289+
--- Example:
290+
--- <pre>
291+
--- vim.cmd('echo 42')
292+
--- vim.cmd([[
293+
--- augroup My_group
294+
--- autocmd!
295+
--- autocmd FileType c setlocal cindent
296+
--- augroup END
297+
--- ]])
298+
--- vim.cmd({ cmd = 'echo', args = { '"foo"' } })
299+
--- </pre>
300+
---
301+
---@paramcommandstring|table Command(s)to execute.
302+
--- If a string, executes multiple lines of Vim script at once. In this
303+
--- case, it is an alias to |nvim_exec()|, where `output` is set to
304+
--- false. Thus it works identical to |:source|.
305+
--- If a table, executes a single command. In this case, it is an alias
306+
--- to |nvim_cmd()| where `opts` is empty.
307+
---@see |ex-cmd-index|
308+
functionvim.cmd(command)
309+
iftype(command)=='table'then
310+
returnvim.api.nvim_cmd(command, {})
311+
else
312+
returnvim.api.nvim_exec(command,false)
313+
end
290314
end
291315

292316
-- These are the vim.env/v/g/o/bo/wo variable magic accessors.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp