mirror of
https://github.com/pratiktri/dotfiles.git
synced 2026-02-04 08:41:43 +05:30
refactor(neovim): Convert file-autocmd to after-ftplugin
- Markdown, gitcommit, text: `lua/shared/text_settings.lua` - Javascript, Typescript, React, Vue: `lua/shared/javascript_settings.lua` - `after/ftplugin` files that `require` the above 2 shared configs
This commit is contained in:
1
common/.config/nvim/after/ftplugin/gitcommit.lua
Normal file
1
common/.config/nvim/after/ftplugin/gitcommit.lua
Normal file
@@ -0,0 +1 @@
|
|||||||
|
require("shared.text_settings").setup()
|
||||||
1
common/.config/nvim/after/ftplugin/javascript.jsx.lua
Normal file
1
common/.config/nvim/after/ftplugin/javascript.jsx.lua
Normal file
@@ -0,0 +1 @@
|
|||||||
|
require("shared.javascript_settings").setup()
|
||||||
1
common/.config/nvim/after/ftplugin/javascript.lua
Normal file
1
common/.config/nvim/after/ftplugin/javascript.lua
Normal file
@@ -0,0 +1 @@
|
|||||||
|
require("shared.javascript_settings").setup()
|
||||||
1
common/.config/nvim/after/ftplugin/javascriptreact.lua
Normal file
1
common/.config/nvim/after/ftplugin/javascriptreact.lua
Normal file
@@ -0,0 +1 @@
|
|||||||
|
require("shared.javascript_settings").setup()
|
||||||
1
common/.config/nvim/after/ftplugin/markdown.lua
Normal file
1
common/.config/nvim/after/ftplugin/markdown.lua
Normal file
@@ -0,0 +1 @@
|
|||||||
|
require("shared.text_settings").setup()
|
||||||
1
common/.config/nvim/after/ftplugin/text.lua
Normal file
1
common/.config/nvim/after/ftplugin/text.lua
Normal file
@@ -0,0 +1 @@
|
|||||||
|
require("shared.text_settings").setup()
|
||||||
1
common/.config/nvim/after/ftplugin/typescript.lua
Normal file
1
common/.config/nvim/after/ftplugin/typescript.lua
Normal file
@@ -0,0 +1 @@
|
|||||||
|
require("shared.javascript_settings").setup()
|
||||||
1
common/.config/nvim/after/ftplugin/typescript.tsx.lua
Normal file
1
common/.config/nvim/after/ftplugin/typescript.tsx.lua
Normal file
@@ -0,0 +1 @@
|
|||||||
|
require("shared.javascript_settings").setup()
|
||||||
1
common/.config/nvim/after/ftplugin/typescriptreact.lua
Normal file
1
common/.config/nvim/after/ftplugin/typescriptreact.lua
Normal file
@@ -0,0 +1 @@
|
|||||||
|
require("shared.javascript_settings").setup()
|
||||||
1
common/.config/nvim/after/ftplugin/vue.lua
Normal file
1
common/.config/nvim/after/ftplugin/vue.lua
Normal file
@@ -0,0 +1 @@
|
|||||||
|
require("shared.javascript_settings").setup()
|
||||||
@@ -1,57 +0,0 @@
|
|||||||
-- Enable keymaps that are specific to only a certain LSP
|
|
||||||
vim.api.nvim_create_autocmd("FileType", {
|
|
||||||
group = vim.api.nvim_create_augroup("keymaps-javascript", { clear = true }),
|
|
||||||
pattern = { "javascript", "javascriptreact", "javascript.jsx", "typescript", "typescriptreact", "typescript.tsx", "vue", "svelte", "astro" },
|
|
||||||
callback = function()
|
|
||||||
vim.keymap.set({ "n", "v" }, "<leader>co", function()
|
|
||||||
vim.lsp.buf.code_action({
|
|
||||||
apply = true,
|
|
||||||
context = {
|
|
||||||
only = { "source.organizeImports.ts" },
|
|
||||||
diagnostics = {},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
end, { desc = "Code: Typescript: Organize Imports" })
|
|
||||||
vim.keymap.set({ "n", "v" }, "<leader>cO", function()
|
|
||||||
vim.lsp.buf.code_action({
|
|
||||||
apply = true,
|
|
||||||
context = {
|
|
||||||
only = { "source.removeUnused.ts" },
|
|
||||||
diagnostics = {},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
end, { desc = "Code: Typescript: Remove Unused Imports" })
|
|
||||||
end,
|
|
||||||
nested = true,
|
|
||||||
})
|
|
||||||
|
|
||||||
-- Enable spell check on markdown and text files
|
|
||||||
vim.api.nvim_create_autocmd("FileType", {
|
|
||||||
group = vim.api.nvim_create_augroup("spell_check_text_files", { clear = true }),
|
|
||||||
pattern = { "markdown", "gitcommit", "text" },
|
|
||||||
callback = function()
|
|
||||||
vim.opt.spell = true
|
|
||||||
end,
|
|
||||||
nested = true,
|
|
||||||
})
|
|
||||||
|
|
||||||
vim.api.nvim_create_autocmd("FileType", {
|
|
||||||
group = vim.api.nvim_create_augroup("markdown-keymaps", { clear = true }),
|
|
||||||
pattern = { "markdown", "gitcommit", "text" },
|
|
||||||
callback = function()
|
|
||||||
vim.keymap.set("v", "<leader>ml", function()
|
|
||||||
-- Save visually selected text to register 'v'
|
|
||||||
vim.cmd('normal! "vy')
|
|
||||||
-- Delete the selected text
|
|
||||||
vim.cmd("normal! gvd")
|
|
||||||
-- Get the content of the system clipboard
|
|
||||||
local clipboard_content = vim.fn.getreg("+")
|
|
||||||
-- Insert the markdown link
|
|
||||||
local link = string.format("[%s](%s)", vim.fn.getreg("v"), clipboard_content)
|
|
||||||
vim.api.nvim_put({ link }, "c", false, true)
|
|
||||||
-- Move cursor inside the square brackets
|
|
||||||
vim.cmd("normal! F[l")
|
|
||||||
end, { desc = "Markdown: Make link" })
|
|
||||||
end,
|
|
||||||
nested = true,
|
|
||||||
})
|
|
||||||
@@ -49,11 +49,11 @@ return {
|
|||||||
indent = { enabled = false, skip_heading = true, icon = "" },
|
indent = { enabled = false, skip_heading = true, icon = "" },
|
||||||
completions = { blink = { enabled = true } },
|
completions = { blink = { enabled = true } },
|
||||||
},
|
},
|
||||||
ft = { "markdown", "norg", "rmd", "org" },
|
ft = { "markdown", "text", "gitcommit", "scratch" },
|
||||||
config = function(_, opts)
|
config = function(_, opts)
|
||||||
require("render-markdown").setup(opts)
|
require("render-markdown").setup(opts)
|
||||||
Snacks.toggle({
|
Snacks.toggle({
|
||||||
name = "Markdown Render",
|
name = "Markdown Rendering",
|
||||||
get = function()
|
get = function()
|
||||||
return require("render-markdown.state").enabled
|
return require("render-markdown.state").enabled
|
||||||
end,
|
end,
|
||||||
|
|||||||
24
common/.config/nvim/lua/shared/javascript_settings.lua
Normal file
24
common/.config/nvim/lua/shared/javascript_settings.lua
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
local M = {}
|
||||||
|
|
||||||
|
function M.setup()
|
||||||
|
vim.keymap.set({ "n", "v" }, "<leader>co", function()
|
||||||
|
vim.lsp.buf.code_action({
|
||||||
|
apply = true,
|
||||||
|
context = {
|
||||||
|
only = { "source.organizeimports.ts" },
|
||||||
|
diagnostics = {},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
end, { desc = "Typescript: organize imports" })
|
||||||
|
vim.keymap.set({ "n", "v" }, "<leader>co", function()
|
||||||
|
vim.lsp.buf.code_action({
|
||||||
|
apply = true,
|
||||||
|
context = {
|
||||||
|
only = { "source.removeunused.ts" },
|
||||||
|
diagnostics = {},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
end, { desc = "Typescript: remove unused imports" })
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
19
common/.config/nvim/lua/shared/text_settings.lua
Normal file
19
common/.config/nvim/lua/shared/text_settings.lua
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
local M = {}
|
||||||
|
|
||||||
|
function M.setup()
|
||||||
|
vim.opt_local.spell = true
|
||||||
|
|
||||||
|
vim.keymap.set("v", "<leader>ml", function()
|
||||||
|
vim.cmd('normal! "vygvc ') -- Save selected text to register 'v' & delete the text
|
||||||
|
|
||||||
|
-- Copy the system clipboard
|
||||||
|
local clipboard_content = vim.fn.getreg("+")
|
||||||
|
-- Insert the markdown link
|
||||||
|
local link = string.format("[%s](%s)", vim.fn.getreg("v"), clipboard_content)
|
||||||
|
|
||||||
|
vim.api.nvim_put({ link }, "c", false, true)
|
||||||
|
vim.cmd("normal! T[vt]") -- Move cursor inside the square brackets & visually select text
|
||||||
|
end, { desc = "Markdown: Create link from system clipboard" })
|
||||||
|
end
|
||||||
|
|
||||||
|
return M
|
||||||
Reference in New Issue
Block a user