voyeg3r

flash_cursorline

Mar 6th, 2022 (edited)
1,097
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.27 KB | None | 0 0
  1. local M = {} -- M stands for module (I think)
  2.  
  3. -- https://vi.stackexchange.com/questions/31206
  4. -- https://vi.stackexchange.com/a/36950/7339
  5. M.flash_cursorline = function()
  6.     local cursorline_state = lua print(vim.opt.cursorline:get())
  7.     vim.opt.cursorline = true
  8.     vim.cmd([[hi CursorLine guifg=#FFFFFF guibg=#FF9509]])
  9.     vim.fn.timer_start(200, function()
  10.         vim.cmd([[hi CursorLine guifg=NONE guibg=NONE]])
  11.         if cursorline_state == false then
  12.             vim.opt.cursorline = false
  13.         end
  14.     end)
  15. end
  16.  
  17. -- Below we can see the mappings using map helper
  18.  
  19. -- map helper
  20. -- Reference:  https://oroques.dev/notes/neovim-init/
  21. local function map(mode, lhs, rhs, opts)
  22.     local options = { noremap = true }
  23.     if opts then
  24.         options = vim.tbl_extend("force", options, opts)
  25.     end
  26.     vim.api.nvim_set_keymap(mode, lhs, rhs, options)
  27. end
  28.  
  29. map('n', 'n', 'nzz:lua require("user.utils").flash_cursorline()<CR>Nn')
  30. map('n', 'N', 'Nzz:lua require("user.utils").flash_cursorline()<CR>nN')
  31.  
  32. map("n", "<c-o>", '<c-o>zv:lua require("user.utils").flash_cursorline()<cr>', { silent = true })
  33. map("n", "<c-i>", '<c-i>zv:lua require("user.utils").flash_cursorline()<cr>', { silent = true })
  34.  
  35. -- Aditional ideas:
  36. -- 1 - each WinEnter event flashes the cursorline
  37.  
  38.  
  39.  
  40. return M
Add Comment
Please, Sign In to add comment