✨ feat(nvim): add some new useful autocmds on ftplugin
This commit is contained in:
parent
038974661b
commit
60e69ab7d3
5 changed files with 58 additions and 1 deletions
16
.config/nvim/after/ftplugin/javascriptreact.lua
Normal file
16
.config/nvim/after/ftplugin/javascriptreact.lua
Normal file
|
@ -0,0 +1,16 @@
|
|||
-- Automatically end a self-closing tag when pressing /
|
||||
vim.keymap.set("i", "/", function()
|
||||
local node = vim.treesitter.get_node()
|
||||
if not node then
|
||||
return "/"
|
||||
end
|
||||
|
||||
if node:type() == "jsx_opening_element" then
|
||||
local char_at_cursor = vim.fn.strcharpart(vim.fn.strpart(vim.fn.getline("."), vim.fn.col(".") - 2), 0, 1)
|
||||
local already_have_space = char_at_cursor == " "
|
||||
|
||||
return already_have_space and "/>" or " />"
|
||||
end
|
||||
|
||||
return "/"
|
||||
end, { expr = true, buffer = true })
|
|
@ -1 +1,13 @@
|
|||
vim.opt.conceallevel = 0
|
||||
|
||||
-- When creating a new line with o, make sure there is a trailing comma on the current line
|
||||
vim.keymap.set("n", "o", function()
|
||||
local line = vim.api.nvim_get_current_line()
|
||||
|
||||
local should_add_comma = string.find(line, "[^,{[]$")
|
||||
if should_add_comma then
|
||||
return "A,<cr>"
|
||||
else
|
||||
return "o"
|
||||
end
|
||||
end, { buffer = true, expr = true })
|
||||
|
|
|
@ -1 +1,13 @@
|
|||
vim.opt.conceallevel = 0
|
||||
|
||||
-- When creating a new line with o, make sure there is a trailing comma on the current line
|
||||
vim.keymap.set("n", "o", function()
|
||||
local line = vim.api.nvim_get_current_line()
|
||||
|
||||
local should_add_comma = string.find(line, "[^,{[]$")
|
||||
if should_add_comma then
|
||||
return "A,<cr>"
|
||||
else
|
||||
return "o"
|
||||
end
|
||||
end, { buffer = true, expr = true })
|
||||
|
|
16
.config/nvim/after/ftplugin/typescriptreact.lua
Normal file
16
.config/nvim/after/ftplugin/typescriptreact.lua
Normal file
|
@ -0,0 +1,16 @@
|
|||
-- Automatically end a self-closing tag when pressing /
|
||||
vim.keymap.set("i", "/", function()
|
||||
local node = vim.treesitter.get_node()
|
||||
if not node then
|
||||
return "/"
|
||||
end
|
||||
|
||||
if node:type() == "jsx_opening_element" then
|
||||
local char_at_cursor = vim.fn.strcharpart(vim.fn.strpart(vim.fn.getline("."), vim.fn.col(".") - 2), 0, 1)
|
||||
local already_have_space = char_at_cursor == " "
|
||||
|
||||
return already_have_space and "/>" or " />"
|
||||
end
|
||||
|
||||
return "/"
|
||||
end, { expr = true, buffer = true })
|
|
@ -107,4 +107,5 @@
|
|||
"NEWS.md": "2123"
|
||||
},
|
||||
"version": 2
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue