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

Commitea75155

Browse files
committed
feat: makevim.cmd usenvim_cmd for table argument
1 parentcf68f0a commitea75155

File tree

2 files changed

+67
-18
lines changed

2 files changed

+67
-18
lines changed

‎runtime/doc/lua.txt‎

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,21 +1017,18 @@ 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+
Executes one or multiple Vim script commands, depending on the type of
1023+
{command}:
1024+
1025+
* if{command} is a string (possibly containing newlines), execute it
1026+
as if passed to`:source`.
1027+
* if{command} is a table, execute it directly as a single command
1028+
with arguments as returned by|nvim_parse_command|.
1029+
1030+
See|vim.cmd()| for details.
1031+
10351032
vim.fn.{func}({...})*vim.fn*
10361033
Invokes|vim-function| or|user-function|{func} with arguments{...}.
10371034
To call autoload functions, use the syntax:>
@@ -1296,6 +1293,34 @@ vim.wo *vim.wo*
12961293
==============================================================================
12971294
Lua module: vim*lua-vim*
12981295

1296+
cmd({command})*vim.cmd()*
1297+
Execute Vim script commands.
1298+
1299+
Example:>
1300+
1301+
vim.cmd('echo 42')
1302+
vim.cmd([[
1303+
augroup My_group
1304+
autocmd!
1305+
autocmd FileType c setlocal cindent
1306+
augroup END
1307+
]])
1308+
vim.cmd({ cmd = 'echo', args = { '"foo"' } })
1309+
<
1310+
1311+
Parameters:~
1312+
{command} string|table Command(s) to execute. If a
1313+
string, executes multiple lines of Vim script
1314+
at once. In this case, it is an alias to
1315+
|nvim_exec()|, where`output` is set to false.
1316+
Thus it works identical to|:source|. If a
1317+
table, executes a single command. In this case,
1318+
it is an alias to|nvim_cmd()| where`opts` is
1319+
empty.
1320+
1321+
See also:~
1322+
|ex-cmd-index|
1323+
12991324
*vim.connection_failure_errmsg()*
13001325
connection_failure_errmsg({consequence})
13011326
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