diff options
| author | Olivia Kinnear <git@superatomic.dev> | 2026-04-23 16:11:59 -0500 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-04-23 17:11:59 -0400 |
| commit | 645a588aa60f4e816a704c97685e2036958af176 (patch) | |
| tree | ddd9fb1d80b0c8b1f4e0ae54e86576492baf1acb /runtime/lua/vim/_core/ex_cmd.lua | |
| parent | c42aea3d37d96cd4275847ee0a71aa270596ba7f (diff) | |
feat(excmd): add :uptime command #39331
Problem
Nvim marks its v:starttime, but there is no user-friendly way to get Nvim's uptime.
Solution
Add :uptime (based loosely on uptime(1)).
Diffstat (limited to 'runtime/lua/vim/_core/ex_cmd.lua')
| -rw-r--r-- | runtime/lua/vim/_core/ex_cmd.lua | 14 |
1 files changed, 11 insertions, 3 deletions
diff --git a/runtime/lua/vim/_core/ex_cmd.lua b/runtime/lua/vim/_core/ex_cmd.lua index cd33a11662..bff960e39d 100644 --- a/runtime/lua/vim/_core/ex_cmd.lua +++ b/runtime/lua/vim/_core/ex_cmd.lua @@ -1,6 +1,8 @@ local api = vim.api local fs = vim.fs +local time = require('vim._core.time') local util = require('vim._core.util') +local uv = vim.uv local N_ = vim.fn.gettext --- Parsed ex command arguments for builtin commands, passed from C via `nlua_call_excmd`. @@ -157,7 +159,7 @@ local available_subcmds = vim.tbl_keys(actions) --- Implements command: `:lsp {subcmd} {name}?`. --- @param eap vim._core.ExCmdArgs -M.ex_lsp = function(eap) +function M.ex_lsp(eap) local fargs = api.nvim_parse_cmd('lsp ' .. eap.args, {}).args if not fargs then return @@ -198,7 +200,7 @@ local log_dir = vim.fn.stdpath('log') --- Implements command: `:log {file}`. --- @param eap vim._core.ExCmdArgs -M.ex_log = function(eap) +function M.ex_log(eap) local filename = eap.args if filename == '' then util.wrapped_edit(log_dir, eap.smods) @@ -236,7 +238,7 @@ end --- `:terminal [cmd]` --- @param eap vim._core.ExCmdArgs --- @param shell_argv? string[] Tokenized 'shell' from C (shell_build_argv), for the no-cmd case. -M.ex_terminal = function(eap, shell_argv) +function M.ex_terminal(eap, shell_argv) local smods = eap.smods local has_mods = (smods.tab or 0) > 0 or (smods.split or '') ~= '' @@ -256,4 +258,10 @@ M.ex_terminal = function(eap, shell_argv) end end +function M.ex_uptime() + local uptime = math.floor((uv.hrtime() - vim.v.starttime) / 1e9) + local uptime_display = time.fmt_rtime(uptime) + api.nvim_echo({ { N_('Up %s'):format(uptime_display) } }, true, {}) +end + return M |
