diff options
| author | Olivia Kinnear <git@superatomic.dev> | 2026-03-28 22:07:04 -0500 |
|---|---|---|
| committer | Olivia Kinnear <git@superatomic.dev> | 2026-04-10 11:08:26 -0500 |
| commit | 8715877417b5c5fee98e6cac9e4e60ca08050048 (patch) | |
| tree | c0283a005101a7507e9f78b28fd6eede384cf073 /runtime/lua/vim/_core/util.lua | |
| parent | 6bea0cdbdcb576fa9633521dbb560985e8f0076b (diff) | |
feat(ex): add `:log` command
Diffstat (limited to 'runtime/lua/vim/_core/util.lua')
| -rw-r--r-- | runtime/lua/vim/_core/util.lua | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/runtime/lua/vim/_core/util.lua b/runtime/lua/vim/_core/util.lua index b2d5f9ef0f..973cf1da2d 100644 --- a/runtime/lua/vim/_core/util.lua +++ b/runtime/lua/vim/_core/util.lua @@ -22,6 +22,17 @@ function M.space_below() add_blank() end +--- Gets a buffer by name +--- @param name string +--- @return integer? +function M.get_buf_by_name(name) + for _, buf in ipairs(vim.api.nvim_list_bufs()) do + if vim.api.nvim_buf_get_name(buf) == name then + return buf + end + end +end + --- Edit a file in a specific window --- @param winnr number --- @param file string @@ -49,6 +60,23 @@ M.edit_in = function(winnr, file) end) end +--- :edit, but it respects commands like :hor, :vert, :tab, etc. +--- @param file string +--- @param mods_str string +function M.wrapped_edit(file, mods_str) + local cmdline = table.concat({ mods_str, 'edit' }, ' ') + local mods = vim.api.nvim_parse_cmd(cmdline, {}).mods + --- @diagnostic disable-next-line: need-check-nil + if mods.tab > 0 or mods.split ~= '' or mods.horizontal or mods.vertical then + local buf = M.get_buf_by_name(file) + if buf == nil then + buf = vim.api.nvim_create_buf(true, false) + end + vim.cmd.sbuffer { buf, mods = mods } + end + vim.cmd.edit { file } +end + --- Read a chunk of data from a file --- @param file string --- @param size number |
