ターミナルがダサいとモテない。neovim + AstroNvim v4.0 紹介編

ターミナルがダサいとモテない。neovim + AstroNvim v4.0 紹介編

AstroNvim が v4.0に update していて大幅に変わっています。

ターミナルがダサいとモテない。neovim + AstroNvim v4.0 紹介編

Photo by Goran Ivos on Unsplash

恵比寿で IT企業をやっているとモテると聞いて創業しましたが早いことありがたいことに10年目に突入した長谷川です。

まだモテる成果は出ていません、、、これからです!(もうめんどくさいのでカウントやめました)

以前書いた「ターミナルがダサいとモテない。neovim + AstroNvim 紹介編」は古くなりました。

AstroNvim は v4.0になったので書き直します。

実はしばらく NvChad に浮気してました。

Neovim

neovim はさらっと行きます。

Home - Neovim

Install Neovim

Plain text
brew install neovim

さくっと入ります。

AstroNvim

AstroNvim

v4.0に update していて変更点はこちらに記載があります。

Migration to v4.0

めっちゃ変更されていて、もう Migration と書いてあるけど無理。
入れ直した方が早そうです。

主に以下の3個に分かれているみたいです。

  • KeyMapping や設定管理や更新などの機能が含まれる AstroCore

  • LSP 関連の AstroLSP

  • ColorTheme, Highlight, Icons など UserInterface 関連の AstroUI

変更箇所が多すぎるので諦めて入れ直しましょう!

Backup AstroNvim

オフィシャルには Backup の仕方が書かれています。

Getting Started

もし AstroNvim がもうすでに入ってるなら以下の Script に適当な名前をつけて実行してください。

Plain text
#!/usr/bin/env bash

declare -x nvim_dir=(
  ${HOME}/.config/nvim
  ${HOME}/.local/share/nvim
  ${HOME}/.local/state/nvim
  ${HOME}/.cache/nvim
)

for d in ${nvim_dir[@]}
do
  if [ -d ${d} ]; then
    echo "make backup: ${d}"
    mv ${d} ${d}.bak
  fi
done

Requirements

ここを参考にしてください。

Getting Started

Nerd Fonts

Nerd Fonts - Iconic font aggregator, glyphs/icons collection, & fonts patcher

macos であれば homebrew にたくさんあります。
以下のコマンドで検索できます。
Terminal で使うのは等幅フォント(monospaced font)の方が良いと思われるので勝手に mono で grep してます。

Plain text
brew search nerd-font | grep mono

自分はこれを使ってます。

GitHub - yuru7/moralerspace: Moralerspace は、欧文フォント Monaspace と日本語フォント IBM Plex Sans JP…

Install Tree-sitter

さくっと homebrew で入れちゃってください。

Plain text
brew install tree-sitter

Optional Requirements

Install ripgrep

こちらも homebrew で

Plain text
brew install ripgrep

Install lazygit

こちらも homebrew

Plain text
brew install lazygit

Install go DiskUsage()

こちらも homebrew

Plain text
brew install gdu

Install bottom

こちらも homebrew

Plain text
brew install bottom

Python & Node

これはなんでも良いです。

自分の場合は Python = Rye, Node = Volta で構成しています。

Install AstroNvim

Instalation の Clone the repository にあります。

Plain text
git clone --depth 1 https://github.com/AstroNvim/template ~/.config/nvim
rm -rf ~/.config/nvim/.git

1st Setup

まずは nvim を起動

Plain text
nvim

以下を実行してみましょう。

Plain text
:Lazy check

更新がいくつかあると思うので update しましょう。

Plain text
:Lazy update

Configuration

The Starter Template をみるとデフォルトのファイル Tree がわかります。

Getting Started

以下のような形になっています。

Plain text
${HOME}/.config/nvim
├── init.lua
├── lazy-lock.json
├── lazyvim.json
├── lua
│  ├── community.lua
│  ├── lazy_setup.lua
│  ├── plugins
│  │  ├── astrocore.lua
│  │  ├── astrolsp.lua
│  │  ├── astroui.lua
│  │  ├── mason.lua
│  │  ├── none-ls.lua
│  │  ├── treesitter.lua
│  │  └── user.lua
│  └── polish.lua
├── neovim.yml
├── README.md
└── selene.toml

AstroCommunity

ここにも記載がある通り、AstroCommunity という Repository がありこれを使って比較的簡単に拡張ができます。

Getting Started

AstroCommunity の GitHub は以下です。

GitHub - AstroNvim/astrocommunity: A community repository of common plugin specifications

lua/astrocommunity の下に体系化されてたくさんの neovim plugin が存在します。

後で使うので適当に Home Directory あたりに git clone しておきましょう。

Plain text
cd
git clone --depth 1 https://github.com/AstroNvim/astrocommunity

いくつか例を紹介します。

draclula.nvim

私は dracula theme が好きで、あるなら必ず設定しますが AstroNvim でも適応できます。

AstroCommunity にも lua/astrocommunity/colorscheme/dracula-nvim にあります。

astrocommunity/lua/astrocommunity/colorscheme/dracula-nvim at main · AstroNvim/astrocommunity

中にある init.lua を見てみるとこのようになっていて

Plain text
return { "Mofiqul/dracula.nvim", lazy = true }

これを ${HOME}/.config/nvim/lua/plugins/user.lua に追記すれば動作します。
私は管理しにくいので試しに ${HOME}/.config/nvim/lua/plugins/dracula-nvim.lua として書き込んだら動いたのでこの形で利用しています。

plugin の導入として別ファイルにするのではなく user.lua に追記すべきなんだと思いますが、backup や recovery などがしにくいので個別にファイルを投入しちゃってます。良いのか悪いのかわかりませんが、まあトラブったらこのやり方を廃止して patch作るしか無いかな。

Plain text
cp \
  ${HOME}/astrocommunity/lua/astrocommunity/colorscheme/dracula-nvim/init.lua \
  ${HOME}/.config/nvim/lua/plugins/dracula-nvim.lua

${HOME}/.config/nvim/lua/plugins/astroui.lua の colorscheme を dracula に変更したら dracula colorscheme になります。

Plain text
${HOME}/.config/nvim/lua/plugins/astroui.lua
  -- ~~ 省略 ~~
  opts = {
    -- change colorscheme
    -- colorscheme = "astrodark",
    colorscheme = "dracula", -- ← このように変更
    -- AstroUI allows you to easily modify highlight groups easily for any and all colorschemes
    highlights = {
  -- ~~ 省略 ~~

transparent.nvim

Terminal が透明なので neovim も透明にしたい。

astrocommunity/lua/astrocommunity/color/transparent-nvim at main · AstroNvim/astrocommunity

astrocommunity/lua/astrocommunity/color/transparent-nvim/init.lua at main ·…

init.lua は以下のようになっています。

Plain text
return {
  "xiyaowong/transparent.nvim",
  lazy = false,
  opts = {
    extra_groups = {
      "NormalFloat",
      "NvimTreeNormal",
    },
  },
  config = function(_, opts)
    local transparent = require "transparent"
    transparent.setup(opts)
    transparent.clear_prefix "BufferLine"
    transparent.clear_prefix "NeoTree"
    transparent.clear_prefix "lualine"
  end,
  dependencies = {
    {
      "AstroNvim/astrocore",
      opts = function(_, opts)
        opts.mappings.n["<Leader>uT"] = { "<Cmd>TransparentToggle<CR>", desc = "Toggle transparency" }
        if vim.tbl_get(opts, "autocmds", "heirline_colors") then
          table.insert(opts.autocmds.heirline_colors, {
            event = "User",
            pattern = "TransparentClear",
            desc = "Refresh heirline colors",
            callback = function()
              if package.loaded["heirline"] then require("astroui.status.heirline").refresh_colors() end
            end,
          })
        end
      end,
    },
  },
}

こちらを nvim の plugins にコピーします。

Plain text
cp \
  ${HOME}/astrocommunity/lua/astrocommunity/color/transparent-nvim/init.lua \
  ${HOME}/.config/nvim/lua/plugins/transparent-nvim.lua

:TransparentEnable で有効にできます。

GitHub - xiyaowong/transparent.nvim: Remove all background colors to make nvim transparent

im-select

im-select はとても便利で、これなくしては生活ができないくらい強力な plugin です。
編集モードから抜けると自動的に半角にしてくれます。

GitHub - keaising/im-select.nvim: Switch Input Method automatically depends on Neovim’s edit mode

Plain text
Install im-select

まず im-select を Install します。
普通に homebrew にあります。

Plain text
brew tap daipeihust/tap
brew install im-select

GitHub - keaising/im-select.nvim: Switch Input Method automatically depends on Neovim’s edit mode

自分は macos なので、ここに書いてあるとおり
${HOME}/.config/nvim/lua/plugins/im-select.lua として保存します。

Google Japanese Input を利用しているので default_im_select を以下にします。

Plain text
default_im_select = “com.google.inputmethod.Japanese.Roman”,
Plain text
{
    "keaising/im-select.nvim",
    config = function()
        require('im_select').setup({
            -- IM will be set to `default_im_select` in `normal` mode
            -- For Windows/WSL, default: "1033", aka: English US Keyboard
            -- For macOS, default: "com.apple.keylayout.ABC", aka: US
            -- For Linux, default:
            --               "keyboard-us" for Fcitx5
            --               "1" for Fcitx
            --               "xkb:us::eng" for ibus
            -- You can use `im-select` or `fcitx5-remote -n` to get the IM's name
            default_im_select  = "com.google.inputmethod.Japanese.Roman",

            -- Can be binary's name, binary's full path, or a table, e.g. 'im-select',
            -- '/usr/local/bin/im-select' for binary without extra arguments,
            -- or { "AIMSwitcher.exe", "--imm" } for binary need extra arguments to work.
            -- For Windows/WSL, default: "im-select.exe"
            -- For macOS, default: "im-select"
            -- For Linux, default: "fcitx5-remote" or "fcitx-remote" or "ibus"
            default_command = "im-select.exe",

            -- Restore the default input method state when the following events are triggered
            set_default_events = { "VimEnter", "FocusGained", "InsertLeave", "CmdlineLeave" },

            -- Restore the previous used input method state when the following events
            -- are triggered, if you don't want to restore previous used im in Insert mode,
            -- e.g. deprecated `disable_auto_restore = 1`, just let it empty
            -- as `set_previous_events = {}`
            set_previous_events = { "InsertEnter" },

            -- Show notification about how to install executable binary when binary missed
            keep_quiet_on_no_binary = false,

            -- Async run `default_command` to switch IM or not
            async_switch_im = true
        })
    end,
}

rendar-markdown.nvim

markdown viewer はいろいろありますが、今のところこれを使っています。
CLI で確認できる glow を利用したものもありますが、フローティング表示で lua の config に style で glow の style JSON を適応しても dracula theme が適応されないので使うのやめました。

astrocommunity/lua/astrocommunity/markdown-and-latex/render-markdown-nvim at main ·…

GitHub - MeanderingProgrammer/render-markdown.nvim: Plugin to improve viewing Markdown files in…

先程 clone した astrocommunity からコピーしてきます。

Plain text
cp \
  ${HOME}/astrocommunity/lua/astrocommunity/markdown-and-latex/render-markdown-nvim/init.lua \
  ${HOME}/.config/nvim/lua/plugins/render-markdown-nvim.lua

これで使えるようになります。

Commands は以下にあります。

GitHub - MeanderingProgrammer/render-markdown.nvim: Plugin to improve viewing Markdown files in…

:RenderMarkdown toggle で enable/disable の切り替えができます。

m️ermaid に対応してるのあったら誰か教えてください。

nvcheatsheet-nvim

NvChad で知った plugins です。
AstroCommunity にもあったので入れています。

astrocommunity/lua/astrocommunity/keybinding/nvcheatsheet-nvim at main · AstroNvim/astrocommunity

先程 clone した astrocommunity からコピーしてきます。

Plain text
cp \
  ${HOME}/astrocommunity/lua/astrocommunity/keybinding/nvcheatsheet-nvim/init.lua \
  ${HOME}/.config/nvim/lua/plugins/nvcheatsheet-nvim.lua

これで有効にできます。
astrocommunity のは key mapping が F1 key になっててちょっと使いにくいので自分は変えました。

NvChad から AstroNvim に戻ってきた感想

NvChad は軽いって言われてるけど、そこまで気にならないかな
確かに AstroNvim で画面描画を切り替える toggle したりするとほんの一瞬カクついたりはするけど、日常的に困るほどではない。

NvChad で感動したのは Nvcheatsheet!
これは触りたてでわからないことだらけでめちゃくちゃ便利だった。

GitHub - smartinellimarco/nvcheatsheet.nvim: NvChad cheatsheet as a standalone neovim plugin

とはいうものの、これだけ多機能なのにこのまとまりの良さは AstroNvim の素敵なところかもしれないですね。

ターミナル環境について他の記事も書いているので、よろしければこちらもご覧ください!
『ターミナルがダサいとモテない』シリーズ一覧

転載:ターミナルがダサいとモテない。neovim + AstroNvim v4.0紹介編(Medium)