From 61c7a717ee92ef1bef470ced1a48130d3c993496 Mon Sep 17 00:00:00 2001 From: Michael Wesolek Date: Mon, 7 Jul 2025 11:29:03 +0200 Subject: [PATCH] xs to switch between ts and html --- init.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/init.lua b/init.lua index 58a6cb49..626c5cea 100644 --- a/init.lua +++ b/init.lua @@ -1112,5 +1112,27 @@ require('lspconfig').pylsp.setup { vim.keymap.set('t', '', '', {}) vim.keymap.set('n', 'xt', ':Telescope colorscheme', {}) vim.keymap.set({ 'n', 'x' }, 's', '') +vim.keymap.set('n', 'xs', function() + local current_file = vim.fn.expand '%:p' + + local base = vim.fn.expand '%:r' -- gets full path without extension + local ext = vim.fn.expand '%:e' -- gets the file extension + + local target + if ext == 'ts' then + target = base .. '.html' + elseif ext == 'html' then + target = base .. '.ts' + else + print 'Not a .ts or .html file' + return + end + + if vim.fn.filereadable(target) == 1 then + vim.cmd('edit ' .. target) + else + print('File does not exist: ' .. target) + end +end, { desc = 'Switch between .ts and .html files' }) -- The line beneath this is called `modeline`. See `:help modeline` -- vim: ts=2 sts=2 sw=2 et