1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

wsl tmux neovim環境でneovimのundercurl(波線)と色を対応させる

Posted at

ubuntuのwsl, tmux上のnvimでhi SpellBadをしたところ、意図したハイライトになっていなかった。

GOOD: 赤い波線(undercurl)が出ている
image.png

BAD: undercurlも、色も出ない
image.png

今後チェックにはコマンドモードの:hi SpellBadを使用します。

*カラースキームはこちらです

TL;DR: tmux側の設定

下記で対応できました。だいぶネットの海から見つけにくいissueだったので備忘録

要するに、wslの時のみterminalの色を制御するコード方式を変えています。
Smulx=がundercurlを表示可能にし、
Setulc=が色のエンコード方式を変えているようです。
詳しいことはよくわかっていないので詳しい方いたらご教示願いたいです。

tmux.conf
set -g default-terminal "tmux-256color"
set -ag terminal-overrides ",xterm-256color:RGB"

# Undercurl
set -as terminal-overrides ',*:Smulx=\E[4::%p1%dm'  # undercurl support
set -as terminal-overrides ',*:Setulc=\E[58::2::%p1%{65536}%/%d::%p1%{256}%/%{255}%&%d::%p1%{255}%&%d%;m'  # underscore colours - needs tmux-3.0

# Check if we are in WSL
if-shell 'test -n "$WSL_DISTRO_NAME"' {
  set -as terminal-overrides ',*:Setulc=\E[58::2::::%p1%{65536}%/%d::%p1%{256}%/%{255}%&%d::%p1%{255}%&%d%;m' # underscore colours - needs tmux-3.0 (wsl2 in Windows Terminal)
}

破線を表示させる(wsl上の設定)

そもそもtmux上で下記を打っても、赤い波線(undercurl)が出ない場合がある。

printf "\x1b[58:2::255:0:0m\x1b[4:1msingle\x1b[4:2mdouble\x1b[4:3mcurly\x1b[4:4mdotted\x1b[4:5mdashed\x1b[0m\n"

image.png

波線(undercurl)を出すためにこちらの通りに行いました。大変参考になりました

波線を出すまでの手順

wsl(tmux外)で、下記の設定が下の線を出すために必要なので設定する。

Smulx=\E[4:%p1%dm

~/Myterm-256color.srcを作成する。

owlterm-256color|xterm with 256 colors with decorations,
	Smulx=\E[4:%p1%dm,
	use=xterm-256color,

ticでコンパイルします

tic -x ~/Myterm-256color.src
infocmp Myterm-256color -x | grep Smulx

smulxが以下のように出ればok!

output.sh
       RV=\E[>c, Se=\E[2 q, Smulx=\E[4:%p1%dm, Ss=\E[%p1%d q,

Neovimに読み込む方法

TERM=Myterm-256color nvim

課題: 環境ごとの違い

ここが環境ごとに差分があるので今後の課題です。
同じwsl, tmux, nvimのPC1とPC2で試したのですが

PC1では

echo $TERM 
xterm-256color
  • wsl上で赤い波線が出る(printf "\x1b[58:2::255:0:0m\x1b[4:1msingle\x1b[4:2mdouble\x1b[4:3mcurly\x1b[4:4mdotted\x1b[4:5mdashed\x1b[0m\n")

  • wslのNeovimでは赤い波線が出ないが、先のwsl上で波線を出す設定をし、TERM=Myterm-256color nvimで正常に色付きの波線が乗る

  • tmuxでは、先のtmuxで波線と色を出す設定を行い、赤い波線が出た

  • tmux上のNeovimでは、TERM=Myterm-256color nvimで正常に色付きの波線が乗る

PC2では

echo $TERM 
xterm-256color
  • wsl上でなにもしなくとも赤い波線が出る
  • wslのNeovimでもなにもしなくとも赤い波線が出る
  • tmuxでは、先のtmuxで波線と色を出す設定を行い、赤い波線が出た
  • tmuxのNeovimでも、先のtmuxで波線と色を出す設定を行い、赤い波線が出た
  • 逆にTERM=Myterm-256color nvimをした結果、バッファを閉じたときにコンソールにバッファが残るようになってしまった

など、だいぶばらつきがあります。
総括すると

  • tmuxの設定は間違いない
  • wsl上のneovimが何もしなくとも赤い波線が出る場合は、tmuxの設定だけ行い
  • wsl上のneovimで波線と色が出ない場合は、「破線を表示させる(wsl上の設定)」を行い、TERM=Myterm-256color nvimでnvimを起動させる

ということになりそうです。

走り書きなのでだいぶ雑ですが、ご容赦ください。

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?