From f45414fe0eaf987025210a5d173a7890b7193d84 Mon Sep 17 00:00:00 2001 From: Cameron Reed Date: Wed, 28 Aug 2024 19:28:01 -0600 Subject: [PATCH] Special treatment for .txt and .md files --- after/plugin/lsp-zero.lua | 2 ++ lua/cam123/autocmd.lua | 18 ++++++++++++++++++ lua/cam123/init.lua | 1 + lua/cam123/remap.lua | 1 + 4 files changed, 22 insertions(+) create mode 100644 lua/cam123/autocmd.lua diff --git a/after/plugin/lsp-zero.lua b/after/plugin/lsp-zero.lua index 748cfe1..f3e9f1d 100644 --- a/after/plugin/lsp-zero.lua +++ b/after/plugin/lsp-zero.lua @@ -5,6 +5,8 @@ local lsp = require('lsp-zero').preset({}) lsp.on_attach(function(_, bufnr) lsp.default_keymaps({buffer = bufnr}) + local bufopts = { noremap = true, silent = true, buffer = bufnr } + vim.keymap.set("n", "rn", vim.lsp.buf.rename, bufopts) end) local lsp_config = require('lspconfig') diff --git a/lua/cam123/autocmd.lua b/lua/cam123/autocmd.lua new file mode 100644 index 0000000..9e37b0d --- /dev/null +++ b/lua/cam123/autocmd.lua @@ -0,0 +1,18 @@ +vim.api.nvim_create_autocmd({'BufNewFile', 'BufRead'}, { + pattern = "*.txt,*.md", + callback = function () + vim.api.nvim_set_option_value("spell", true, { scope = "local" }) + vim.api.nvim_set_option_value("wrap", true, { scope = "local" }) + vim.api.nvim_set_option_value("linebreak", true, { scope = "local" }) + end +}) + +vim.api.nvim_create_autocmd("BufWrite", { + callback = function (opts) + local filetype = vim.bo[opts.buf].filetype + if filetype == "text" or filetype == "markdown" then + return + end + vim.api.nvim_exec2("%s/[ \\t]\\+$//e", { output = false }) + end +}) diff --git a/lua/cam123/init.lua b/lua/cam123/init.lua index 3db766b..e38e5fa 100644 --- a/lua/cam123/init.lua +++ b/lua/cam123/init.lua @@ -1,4 +1,5 @@ require("cam123.set") +require("cam123.autocmd") require("cam123.remap") require("cam123.lazy") diff --git a/lua/cam123/remap.lua b/lua/cam123/remap.lua index 525fd22..f7a63d6 100644 --- a/lua/cam123/remap.lua +++ b/lua/cam123/remap.lua @@ -1 +1,2 @@ vim.keymap.set("n", "pv", vim.cmd.Ex) +vim.keymap.set("n", "", function () vim.opt.hlsearch = false end)