]> git.madduck.net Git - etc/neovim.git/commitdiff

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

List mode handling how I like it
authormartin f. krafft <madduck@madduck.net>
Wed, 9 Apr 2025 08:44:50 +0000 (10:44 +0200)
committermartin f. krafft <madduck@madduck.net>
Fri, 11 Apr 2025 18:48:08 +0000 (20:48 +0200)
.config/nvim/plugin/listmode.lua [new file with mode: 0644]
.gitignore.d/neovim

diff --git a/.config/nvim/plugin/listmode.lua b/.config/nvim/plugin/listmode.lua
new file mode 100644 (file)
index 0000000..a0a4c05
--- /dev/null
@@ -0,0 +1,28 @@
+vim.opt.list = true
+vim.opt.listchars = { tab = '⇝·', trail = '·', nbsp = '␣' }
+
+-- disable list mode when inserting stuff, otherwise keep it enabled, it's
+-- useful (see also setting lcs)
+listinsert = vim.api.nvim_create_augroup('listinsert', { clear = true })
+vim.api.nvim_create_autocmd('InsertEnter', {
+       desc = 'Disable list mode when starting to insert',
+       group = listinsert,
+       callback = function() vim.opt.list = false end
+})
+vim.api.nvim_create_autocmd('InsertLeave', {
+       desc = 'Enable list mode when leaving insert mode',
+       group = listinsert,
+       callback = function() vim.opt.list = true end
+})
+-- flag trailing spaces as error only when not inserting
+tsperrorinsert = vim.api.nvim_create_augroup('tsperrorinsert', { clear = true })
+vim.api.nvim_create_autocmd('InsertEnter', {
+       desc = 'Disable highlighting trailing spaces in insert mode',
+       group = tsperrorinsert,
+       callback = function() vim.cmd([[match none /\s\+$/]]) end
+})
+vim.api.nvim_create_autocmd('InsertLeave', {
+       desc = 'Enable highlighting trailing spaces outside of insert mode',
+       group = tsperrorinsert,
+       callback = function() vim.cmd([[match Error /\s\+$/]]) end
+})
index 67f09bb304614351ecfb6cf8077168314bc281e2..b07238f7cac8851b478783eeb53d717698e988c0 100644 (file)
@@ -1,5 +1,6 @@
 *
 !/.config/nvim/autoload/plug.vim
 !/.config/nvim/init.lua
+!/.config/nvim/plugin/listmode.lua
 !/.config/nvim/plugin/vim-artesanal.lua
 !/.gitignore.d/neovim