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.
\lcd
command doesn't work but\cd
works.\lcd
failure?~/Documents/cp
. If I want to change it to a temporary local directory. Then pressing\lcd
executes this commandtabdo lcd %:p:h
in all opened tabs. Mnemoniclcd
equal to Local Current Directory.