Skip to content

Instantly share code, notes, and snippets.

@Schniz
Created May 27, 2016 10:25
Show Gist options
  • Save Schniz/5cfc225920486ffa2fb447545b9f6d24 to your computer and use it in GitHub Desktop.
Save Schniz/5cfc225920486ffa2fb447545b9f6d24 to your computer and use it in GitHub Desktop.
toggle background color for vim
if exists("*ToggleBackground") == 0
function ToggleBackground()
if &background == "dark"
set background=light
else
set background=dark
endif
endfunction
command BG call ToggleBackground()
endif
@sugiura-hiromichi
Copy link

nice

@surajitbasak109
Copy link

In lua the above can be writeen like:

local create_cmd = vim.api.nvim_create_user_command

create_cmd("ToggleBackground", function ()
    if vim.o.background == 'dark' then
        vim.cmd'set bg=light'
    else
        vim.cmd'set bg=dark'
    end
end, {})

@sugiura-hiromichi
Copy link

thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment