Skip to content

Commit 61c7a71

Browse files
<leader>xs to switch between ts and html
1 parent 6d03ab8 commit 61c7a71

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

init.lua

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1112,5 +1112,27 @@ require('lspconfig').pylsp.setup {
11121112
vim.keymap.set('t', '<ESC>', '<C-\\><C-n>', {})
11131113
vim.keymap.set('n', '<leader>xt', ':Telescope colorscheme<CR>', {})
11141114
vim.keymap.set({ 'n', 'x' }, 's', '<Nop>')
1115+
vim.keymap.set('n', '<leader>xs', function()
1116+
local current_file = vim.fn.expand '%:p'
1117+
1118+
local base = vim.fn.expand '%:r' -- gets full path without extension
1119+
local ext = vim.fn.expand '%:e' -- gets the file extension
1120+
1121+
local target
1122+
if ext == 'ts' then
1123+
target = base .. '.html'
1124+
elseif ext == 'html' then
1125+
target = base .. '.ts'
1126+
else
1127+
print 'Not a .ts or .html file'
1128+
return
1129+
end
1130+
1131+
if vim.fn.filereadable(target) == 1 then
1132+
vim.cmd('edit ' .. target)
1133+
else
1134+
print('File does not exist: ' .. target)
1135+
end
1136+
end, { desc = 'Switch between .ts and .html files' })
11151137
-- The line beneath this is called `modeline`. See `:help modeline`
11161138
-- vim: ts=2 sts=2 sw=2 et

0 commit comments

Comments
 (0)