Replies: 1 comment
-
|
The easiest way to create a keymap for toggling the background in Neovim is like this: local toggle_background = function()
if vim.o.background == 'light' then
vim.o.background = 'dark'
else
vim.o.background = 'light'
end
end
vim.keymap.set('n', '<F2>', toggle_background)Alternatively, you can use neovim-remote to achieve the same result: Start Neovim with a listening socket: nvim --listen /tmp/nvimsocketSend commands remotely: nvr --remote-send ':set background=light<CR>'You can create a shell function to always open Neovim with the listening socket: function vim {
[[ -n "$1" ]] && nvim --listen /tmp/nvimsocket "$1" || nvim --listen /tmp/nvimsocket
}Now, you can create a Bash script to toggle Neovim's background. For testing, you could bind a shortcut to toggle the background: bind -x '"\C-b":toggle'
export NEOVIM_BACKGROUND=dark
function toggle {
[[ "$NEOVIM_BACKGROUND" = 'dark' ]] && NEOVIM_BACKGROUND=light || NEOVIM_BACKGROUND=dark
nvr --remote-send ":set background=${NEOVIM_BACKGROUND}<CR>"
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I am using WezTerm, and I have set up a custom event that allows me to change the overall color scheme of the terminal. When I switch the color scheme in WezTerm and then open Neovim, it correctly adjusts the background option for Vim based on the new color scheme. However, I’ve noticed that if I run the color scheme change event while I am already inside Neovim, it does not update the background of the Neovim color scheme accordingly. Is there a way to ensure that the background changes in Neovim when I trigger the event from within it?
Beta Was this translation helpful? Give feedback.
All reactions