LoginSignup
3
5

More than 5 years have passed since last update.

VS Code@Windowsのターミナルで256色使えない問題に自分なりに対応してみた

Last updated at Posted at 2018-07-29

TL;DR

  • VS Code盛り上がってますね!
  • vimから乗り換えてみたら感動した!
  • Terraform拡張やGit Project検索等ええな!
  • からの、Windows版 Integrated Terminal(統合ターミナル)で256色使えない問題
  • わかった。VS Code@WindowsやめてLinux版使うわ。
  • XmingでX11 forward出来ねーーー!
  • VcXsrvなら出来るよって記事見つけるっ!
  • Putty使ったX11 forwardの記事よくあるけど、Putty入れたくない!
  • vagrant sshとVcXsrvだけでVS Code@LinuxをWindowsで使えるようになりました。

構成

ホスト OS etc
Local Windows10 Pro
Git for Windows
Vagrant
Oracle VirtualBox
VcXsrv
Remote Ubuntu 16.04 LTS (ubuntu/Xenial64)

やり方

Localホストへのツールのインストール手順は飛ばします。
特につまずくところはない...はず。

1. VcXsrvの起動

選択肢デフォルトのまま、次へ連打

image.png

image.png

image.png

image.png

2. Vagrantfileの用意

Vagrantfile
  config.ssh.forward_x11 = true
...
  config.vm.provision "shell", path: "provision/vscode.sh",    privileged: false
@git-bash
[you@local-machine]$ echo 'export DISPLAY=localhost:0.0' > ~/.profile
[you@local-machine]$ vagrant ssh-config > ~/.ssh/config 
[you@local-machine]$ cat ~/.ssh/config
Host default
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile {{your-vagrant-dir}}/.vagrant/machines/default/virtualbox/private_key
  IdentitiesOnly yes
  LogLevel FATAL
  ForwardX11 yes

3. Remoteホストへのプロビジョニング

provision/vscode.sh
#!/bin/bash

# VS Code installation
curl https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor > microsoft.gpg
sudo mv microsoft.gpg /etc/apt/trusted.gpg.d/microsoft.gpg
sudo sh -c 'echo "deb [arch=amd64] https://packages.microsoft.com/repos/vscode stable main" > /etc/apt/sources.list.d/vscode.list'
sudo apt-get update -y
sudo apt-get install -y code

# X11 for vscode
sudo apt-get install -y xauth libgtk2.0-0 libxss1 libasound2

# Japanese setting, font installation
sudo apt-get -y install language-pack-ja-base language-pack-ja
sudo localectl set-locale LANG=ja_JP.UTF-8 LANGUAGE="ja_JP.UTF-8"
sudo apt install -y fonts-migmix

4. Let's Provisioning!!!

[you@local-machine]$ vagrant up
...
(Reading database ... 78416 files and directories currently installed.)
    default: Preparing to unpack .../fonts-migmix_20150712-1_all.deb ...
    default: Unpacking fonts-migmix (20150712-1) ...
    default: Processing triggers for fontconfig (2.11.94-0ubuntu1.1) ...
    default: Setting up fonts-migmix (20150712-1) ...
(provisiong終わり)

[you@local-machine] $

5. Let's VS Coding!!!

[you@local-machine]$ vagrant ssh
$ vagrant ssh
Welcome to Ubuntu 16.04.5 LTS (GNU/Linux 4.4.0-131-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

  Get cloud support with Ubuntu Advantage Cloud Guest:
    http://www.ubuntu.com/business/services/cloud

0 packages can be updated.
0 updates are security updates.


/usr/bin/xauth:  file /home/vagrant/.Xauthority does not exist
[vagrant@remote-machine]$ code .
(VS Codeで日本語拡張パッケージをインストールするか聞かれるので、インストールして再起動)
(終わり)

結果、256色対応したterminalが使えるようになり、vimのcolorshceme:tenderがちゃんと表示されました!
image.png

6. 補足:Sync your Setting

既にVS Codeを使い始めていて、そちらの設定を取り込みたい場合、Setting Sync拡張パッケージを使用しましょう。
Githubのgistに設定ファイルをアップロードすることで設定を共有できるパッケージになります。
とても便利なのでおススメです!

ソース

3
5
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
3
5