Blog記事をVim+Markdownで書きたいと思った
私は普段何かを書くとき(プログラムなり文章なり)大抵Vimを使用している。 そんなこともあって、Blog記事もできれば書き慣れてるVimで書きたいと思った。 Hatenaブログの設定を見ると記事をMarkdown記法で書けるそうな。
ここからが、本題。
書こうと決めたは良いが、書くためには環境設定が必要だ。 Vimは、普段使っているがMarkdownを書く設定は入れてない。 今回は、VimでMarkdownを書くための設定方法をまとめようと思う。
使用環境
DISTRIB_ID=Debian #DISTRIB_RELEASE=8.0 DISTRIB_CODENAME=jessie DISTRIB_DESCRIPTION="Kona Linux 3.0"
ちなみに、私が使っているマシンは15年も前に買った、NECのノートPC。 ぶっちゃけ、ウェブブラウジングもしんどいレベルのスペックの低さである。 しかしながら、長く使っているからかタイピングはこのマシンが一番しっくりくる。
dein.vim
githubにある(https://github.com/Shougo/dein.vim )説明文によると
ということらしい
設定
早速、説明を見ながら設定していく
1. 必要要件としてはVimの8.0以上が必要なようだ
vim --version
で、確認したところ8.1が入っていた。要件は問題なし。
2. インストール用のディレクトリを用意する
mkdir ~/.cache/dein
3. インストール用のスクリプトを作る
cd ~/.cache/dein curl https://raw.githubusercontent.com/Shougo/dein.vim/master/bin/installer.sh > installer.sh
ちなみに、インストール用のスクリプトを作るには、gitとcurlがインストールされている必要がある
私の端末にはインストールされていなかったのでインストールを行った
sudo apt-get install git sudo apt-get install curl
4. スクリプトを実行する
sh installer.sh ~/.cache/dein
スクリプトを実行すると、最後に以下のような設定が表示される。それを、.vimrcに設定する必要がある
""dein Scripts----------------------------- if &compatible set nocompatible " Be iMproved endif " Required: set runtimepath+=/home/K38/.cache/dein/./repos/github.com/Shougo/dein.vim " Required: if dein#load_state('/home/K38/.cache/dein/.') call dein#begin('/home/K38/.cache/dein/.') " Let dein manage dein " Required: call dein#add('/home/K38/.cache/dein/./repos/github.com/Shougo/dein.vim') " Add or remove your plugins here: call dein#add('Shougo/neosnippet.vim') call dein#add('Shougo/neosnippet-snippets') " You can specify revision/branch/tag. call dein#add('Shougo/deol.nvim', { 'rev': '01203d4c9' }) " Required: call dein#end() call dein#save_state() endif " Required: filetype plugin indent on syntax enable " If you want to install not installed plugins on startup. " if dein#check_install() " call dein#install() " endif ""End dein Scripts-------------------------
5. deinで管理するプラグインを追加する
先ほど、.vimrcに追加した記述の中の
" Add or remove your plugins here: call dein#add('Shougo/neosnippet.vim') call dein#add('Shougo/neosnippet-snippets')
の下に、以下の3つを追加する
call dein#add('plasticboy/vim-markdown') call dein#add('kannokanno/previm') call dein#add('tyru/open-browser.vim')
- plasticboy/vim-markdown
- kannokanno/previm
- プレビューを行うためのプラグイン
- tyru/open-browser.vim
- プレビューをブラウザ表示するプラグイン
これら、3つを入れることでMarkdown記法がVimでも容易にできるようになる。とのこと。
加えて、拡張子の設定を.vimrcにを入れる
autocmd BufNewFile,BufRead *.{md,mdwn,mkd,mkdn,mark*} set filetype=markdown
最後に、プラグインがインストールされているかチェックを行うために下3行のコメントを外す
" If you want to install not installed plugins on startup. if dein#check_install() call dein#install() endif
最終的に、今回.vimrcの中身は以下のようになった。
autocmd BufNewFile,BufRead *.{md,mdwn,mkd,mkdn,mark*} set filetype=markdown ""dein Scripts----------------------------- if &compatible set nocompatible " Be iMproved endif " Required: set runtimepath+=/home/K38/.cache/dein/./repos/github.com/Shougo/dein.vim " Required: if dein#load_state('/home/K38/.cache/dein/.') call dein#begin('/home/K38/.cache/dein/.') " Let dein manage dein " Required: call dein#add('/home/K38/.cache/dein/./repos/github.com/Shougo/dein.vim') " Add or remove your plugins here: call dein#add('Shougo/neosnippet.vim') call dein#add('Shougo/neosnippet-snippets') call dein#add('plasticboy/vim-markdown') call dein#add('kannokanno/previm') call dein#add('tyru/open-browser.vim') " You can specify revision/branch/tag. call dein#add('Shougo/deol.nvim', { 'rev': '01203d4c9' }) " Required: call dein#end() call dein#save_state() endif " Required: filetype plugin indent on syntax enable " If you want to install not installed plugins on startup. if dein#check_install() call dein#install() endif ""End dein Scripts-------------------------
6. プラグインのインストール
最後に、設定に加えたプラグインをインストールして終了
vimを起動して以下のコマンドを打つ
:call dein#install()
2018/10/08(月) 追記
Vimで書いたMarkdownの記事をプレビューするためのコマンドは以下
:PrevimOpen
設定終了!
長々と書いてきたが、これで設定終了。Vim+Markdownの環境ができた。
今回のこの記事も早速設定した環境で書いているが中々快適に使えている。
この記事のように今後も勉強したこと(調べたこと)をまとめていければ良いなと思う。