Lua format
function TabLcd()
local current_tab = vim.fn.tabpagenr()
vim.cmd("tabdo <commands>")
vim.cmd("execute 'tabnext' " .. current_tab)
end
vim.api.nvim_set_keymap('n', '<leader>lcd', ':lua TabLcd()<CR>', { noremap = true, silent = true })
function TabLcd() defines a Lua function named TabLcd.
local current_tab = vim.fn.tabpagenr(): It stores the current tab
page number in the current_tab variable using a Neovim built-in
function vim.fn.tabpagenr().
vim.cmd("tabdo <commands>"): This line executes <commands> in all open tabs. You would replace with the
specific commands you want to run in each tab. For example, if you
want to run :command1 in each tab, you would use vim.cmd("tabdo command1").
vim.cmd("execute 'tabnext' " .. current_tab): After executing the
commands in all tabs, it switches back to the original tab also defined as current_tab.
Set any keymap (in this case \lcd), And you're a go.
\lcdcommand doesn't work but\cdworks. – Mega Bang Oct 10 '23 at 13:28\lcdfailure? – Vivian De Smedt Oct 10 '23 at 13:30~/Documents/cp. If I want to change it to a temporary local directory. Then pressing\lcdexecutes this commandtabdo lcd %:p:hin all opened tabs. Mnemoniclcdequal to Local Current Directory. – Mega Bang Oct 10 '23 at 13:42