0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【WezTerm】bindkeyで透明度をサクッと変えよう

0
Posted at

はじめに

ターミナルの背景を透明にしていますか?
背景を透明にすると、裏側の内容をサクッと確認できるので、筆者はとても気に入っています。
その一方で、見づらい場面に遭遇することもあります。
「バインドキーだけで透明度をサクッと切り替えられないかな」と思ったのがきっかけです。

実現したかったこと

Adobe Express - 画面収録 2026-06-06 11.46.58.gif

ここだけ変えればOK

以下のコードを追加するだけです。
bindkeyはお好みのキーに変更してください。

~/.config/wezterm/wezterm.lua
wezterm.on('toggle-blur', function(window)
  local overrides = window:get_config_overrides() or {}
  if (overrides.macos_window_background_blur or 20) > 0 then
    overrides.macos_window_background_blur = 0
  else
    overrides.macos_window_background_blur = 20
  end
  window:set_config_overrides(overrides)
end)

-- keybinds.luaを読み込めるようにする
config.keys = require("keybinds").keys
config.key_tables = require("keybinds").key_tables
config.disable_default_key_bindings = true
config.leader = { key = "q", mods = "CTRL", timeout_milliseconds = 2000 }
~/.config/wezterm/keybinds.lua
local wezterm = require 'wezterm'
local act = wezterm.action

return {
  keys = {
+     { key = 'b', mods = 'LEADER', action = act.EmitEvent 'toggle-blur' },
  },

操作方法

  1. WezTermを開く(設定は自動リロードされるので再起動不要)
  2. CTRL+q を押す(LEADERキー)
  3. b を押す

設定の背景

透明背景いいよね

ターミナルの背景を透明にすると、好きな画像をデスクトップ背景に設定したり、風景写真を使ったりできて気分が上がります。

背景にソースコードを表示したまま、ちょっとターミナルを開きたいときにも便利です。

image.png

透明だとたまに困るよね

透明背景は便利ですが、困る場面もあります。

例えば、ターミナルのスクリーンショットを撮りたいとき、背後に表示している内容まで見えてしまいます。
その都度背景のブラウザやウィンドウを閉じるのは少し面倒です。
また、背景に文字が多い画面の場合、ターミナルの文字が見づらく感じることもあります。

image.png

nvim(LazyVim)も同じようにできないかな

できました

Adobe Express - 画面収録 2026-06-06 12.12.07.gif

~/.config/nvim/lua/config/keymaps.lua
vim.keymap.set("n", "<leader>ub", function()
  local hl = vim.api.nvim_get_hl(0, { name = "Normal" })
  if hl.bg then
    vim.api.nvim_set_hl(0, "Normal", { bg = "none" })
    vim.api.nvim_set_hl(0, "NormalNC", { bg = "none" })
  else
    vim.cmd("colorscheme tokyonight")
  end
end, { desc = "Toggle background transparency" })

Spaceキー(LEADERキー)ubで切り替えられるようにしました。

おわりに

Weztermのカスタマイズ楽しいですね!今回はAIの力を借りて簡単に実現できました。
透明背景を使っている方の参考になれば幸いです。

参考記事

沼にハマるきっかけになった記事です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?