Created
November 6, 2021 23:40
-
-
Save voyeg3r/9f5ede801560b3b0c4cf3a4c17a6a95f to your computer and use it in GitHub Desktop.
Flash neovim cursorline (just for a second)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- in your utils.lua | |
local M = {} | |
-- https://vi.stackexchange.com/questions/31206 | |
M.flash_cursorline = function() | |
vim.opt.cursorline = true | |
vim.cmd([[hi CursorLine guifg=#000000 guibg=#ffffff]]) | |
vim.fn.timer_start(200, function() | |
vim.cmd([[hi CursorLine guifg=NONE guibg=NONE]]) | |
vim.opt.cursorline = false | |
end) | |
end | |
return M | |
-- in your mappings.lua | |
-- map helper | |
local function map(mode, lhs, rhs, opts) | |
local options = {noremap = true} | |
if opts then options = vim.tbl_extend('force', options, opts) end | |
vim.api.nvim_set_keymap(mode, lhs, rhs, options) | |
end | |
map('n', 'n', 'nzz') | |
map('n', 'N', 'Nzz') | |
map('n', '<c-o>', '<c-o>zz:lua require("utils").flash_cursorline()<cr>', { silent = true}) | |
map('n', '<c-i>', '<c-i>zz:lua require("utils").flash_cursorline()<cr>', { silent = true}) | |
map('n', '}', '}zz') | |
map('n', '{', '{zz') | |
-- in your autocmd.lua | |
--- This function is taken from https://github.com/norcalli/nvim_utils | |
function nvim_create_augroups(definitions) | |
for group_name, definition in pairs(definitions) do | |
vim.api.nvim_command('augroup '..group_name) | |
vim.api.nvim_command('autocmd!') | |
for _, def in ipairs(definition) do | |
local command = table.concat(vim.tbl_flatten{'autocmd', def}, ' ') | |
vim.api.nvim_command(command) | |
end | |
vim.api.nvim_command('augroup END') | |
end | |
end | |
local autocmds = { | |
reload_vimrc = { | |
-- Reload vim config automatically | |
-- {"BufWritePost",[[$VIM_PATH/{*.vim,*.yaml,vimrc} nested source $MYVIMRC | redraw]]}; | |
{"BufWritePre", "$MYVIMRC", "lua require('utils').ReloadConfig()"}; | |
}; | |
-- a lot of autocommands | |
flash_cursor_line = { | |
{ "WinEnter", "*", [[lua require('utils').flash_cursorline()]]} | |
}; | |
} | |
nvim_create_augroups(autocmds) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment