LoginSignup
197
60

More than 1 year has passed since last update.

Vimで年賀状を作る

Last updated at Posted at 2020-12-07

こんにちは、IKです。
もうすぐ12月も終わってしまいますね。
時が経つのは早いものです。
そして、12月が終わってしまうということは1月が来るということです。
年賀状の進捗はどうですか?僕はダメです。
そんな年賀状の進捗がダメダメな人に向けて、エンジニアらしい、かっこいい年賀状をすぐに作れる方法を紹介します。

用意するもの

  • Vim
  • やる気
  • 年賀状
  • プリンタ

Vimに書くものを決める

Vimで年賀状を書くということは、それなりに書けるものは限られてきます。まず画像が表示できないです。悲しい...

そもそも、画像をVimで表示させたらただの年賀状になってしまいます。エンジニアらしさはどこにもない...
そこで今回はアスキーアートを駆使して、エンジニアらしい年賀状を作っていきましょう。

年賀状に必須なもの(主観)

  • happy new year という文字列
  • 2021 という文字列
  • を表すなにか

以下のサイトを使っていい感じのアスキーアートを作りましょう!

https://patorjk.com/software/taag

今回は graffitiフォントを使用しています。

注意書き

上記のAAジェネレータのサイトには、ライセンス表記がありません。そこで、作者に確認をとったので、その内容を書かせていただきたいと思います。

Short answer: Go for it!

Longer answer: Around half of the FIGlet fonts are licensed under the MIT license (free, you can get the list of them here: http://www.figlet.org/fontdb.cgi), a couple are created by me (free), and many of the others are from a program called JavE, the author of which told me that he believes any font output is public domain. There are a handful of fonts that don't fall into any of these categories (ex: fonts I converted from letter sets, fonts sent directly to me). If you click the "Font Info" button in the bottom right corner of my app you'll be able to get more info about the font you're interested in.

I think the only area that is a little sketchy is commercially using the fonts - like if you were going to be selling this Christmas Card. If your project is for commercial purposes and you're super paranoid about this, I would recommend just using a font that is listed in the figlet database (linked above), as those are MIT licensed. The frustrating thing is that when people created the fonts, they didn't attach a license to them. I think everyone just assumed they were for fun and were free to use (no font in the app was ever for sale - they were all freely distributed). Years later people want to use the output and are concerned about licensing, but the people who created the fonts are long gone (many of the fonts are 25+ years old). I've never heard of anyone having a problem. If this is just a Christmas card for friends/family, I think it's exactly the kind of purpose for why these fonts were created.

best,

Pat

happy new year という文字列

新年を祝うには必須ですね。


  ___ ___                                                                                ._._._.
 /   |   \_____  ______ ______ ___.__.   ____   ______  _  __  ___.__. ____ _____ _______| | | |
/    ~    \__  \ \____ \\____ <   |  |  /    \_/ __ \ \/ \/ / <   |  |/ __ \\__  \\_  __ \ | | |
\    Y    // __ \|  |_> >  |_> >___  | |   |  \  ___/\     /   \___  \  ___/ / __ \|  | \/\|\|\|
 \___|_  /(____  /   __/|   __// ____| |___|  /\___  >\/\_/    / ____|\___  >____  /__|   ______
       \/      \/|__|   |__|   \/           \/     \/          \/         \/     \/       \/\/\/

2021 という文字列

来年の西暦を示す文字列も入れてあげましょう。


_______________   ________  ____ 
\_____  \   _  \  \_____  \/_   |
 /  ____/  /_\  \  /  ____/ |   |
/       \  \_/   \/       \ |   |
\_______ \_____  /\_______ \|___|
        \/     \/         \/     

を表すなにか

2021年は丑年ですよね。
というわけで丑がいります。

丑を召喚しましょう

\|/          (__)
     `\------(oo)
       ||    (__)
       ||w--||     \|/
   \|/

参照したサイト

https://www.asciiart.eu/animals/cows

上記の3つの要素が揃えば、最低限年賀状としての体を示すことができます。

合体させた様子



         ___ ___                                                                                  ._._._.
        /   |   \_____  ______ ______ ___.__.   ____   ______  _  __  ___.__. ____ _____ _______  | | | |
       /    ~    \__  \ \____ \\____ <   |  |  /    \_/ __ \ \/ \/ / <   |  |/ __ \\__  \\_  __ \ | | | |
       \    Y    // __ \|  |_> >  |_> >___  | |   |  \  ___/\     /   \___  \  ___/ / __ \|  | \/  \|\|\|
        \___|_  /(____  /   __/|   __// ____| |___|  /\___  >\/\_/    / ____|\___  >____  /__|     ______
              \/      \/|__|   |__|   \/           \/     \/          \/         \/     \/         \/\/\/


                                       _______________   ________  ____
                                       \_____  \   _  \  \_____  \/_   |
                                        /  ____/  /_\  \  /  ____/ |   |
                                       /       \  \_/   \/       \ |   |
                                       \_______ \_____  /\_______ \|___|
                                               \/     \/         \/


\|/          (__)
     `\------(oo)
       ||    (__)
       ||w--||     \|/
   \|/

このテキストをファイルに保存して、Vimに表示すれば下図のような見た目になります。

スクリーンショット 2020-12-04 0.17.07.png

しかし、これだけでは殺風景です。
そこで、ステータスラインなどをカスタマイズして、Vimに彩りをつけていきましょう

statuslineでVimを彩る

今回使うのはvim-airlineというpluginを使います。

vim-airline

https://github.com/vim-airline/vim-airline

しかし、わざわざ年賀状を作るためだけにプラグインをインストールしたり、vimrcを弄るのは少しめんどくさいので、ここで一工夫を入れます

自動化する

  1. ホームディレクトリにディレクトリを作ります(今回はHappyNewYear2021とします)
    mkdir ~/HappyNewYear2021

  2. 上で作ったディレクトリに移動します
    cd HappyNewYear2021

  3. 先程作った、年賀状のアスキーアートを保存しましょう(ここでは HappyNewYear2021.txtとします)

  4. サブモジュールで、プラグインをインストールします。(ここではpluginディレクトリにsubmoduleでvim-airlineをインストールします)
    mkdir plugin && cd plugin && git submodule add https://github.com/vim-airline/vim-airline

  5. Vim scriptを用意します。(ここではautoscript.vimとします)

  • 用意する Vim script
autoscript.vim
scriptencoding utf-8
set runtimepath+=~/HappyNewYear2021/plugins/vim-airline

set nonumber
set noshowmode

edit HappyNewYear2021.txt
  • 実行コマンド
vim -N -u autoscript.vim
やってることの解説(余談)

-uは、vimrcの代わりにautoscript.vimを使うというオプションです。これにより、vimrcが見つからなかったとVimが認識され、Vimがvi互換モードで起動することに注意しましょう

-N というのはVimをVi非互換モードで開くオプションです。これをつけないとvim-airlineが起動しません。

そしてautoscript.vimでは、runtimepathにvim-airlineを追加するように書いてあります。
これで、vimrcが読み込まれなくなったので、dein.vimやvim-plugなどの設定をvimrcに書いていた場合は、それは完全に無視され、既存のpluginはロードされなくなり、HappyNewYear2021/pluginsディレクトリに追加されたvim-airlineのみがロードされるようになります。
それにより、既存のvimrcやplugin構成を全く変更せずに、年賀状を準備する構成が出来上がったわけです。

しかし、minpacなどのpackadd機能を使ってpluginをロードしている場合は、この方法では無視できないので注意が必要です。

上記の手段で準備は整ったので、statuslineをカスタマイズしていきます。

ステータスラインをカスタマイズする

vim-airlineはstatusline pluginの一つです。

スクリーンショット 2020-12-07 2.24.14.png

上記は、tabline拡張を有効にしたvim-airlineですが、これらのstatuslineをいくつかカスタマイズしていきましょう。

カスタマイズする場所

airline_section_b

スクリーンショット 2020-12-07 23.40.44.png

airline_section_c

スクリーンショット 2020-12-07 23.41.23.png

airline_section_x

スクリーンショット 2020-12-07 23.42.12.png

上記の三箇所をカスタマイズしていきましょう。これはvim-airlineの設定からカスタマイズする事ができます。

以下の設定を、先程のautoscript.vimに追記しましょう。

" airline setting

let g:airline_section_b = '2021 AD'
let g:airline_section_c = 'I hope you will have a great year!'
let g:airline_section_x = '㊗'
let g:airline_extensions = ['tabline']

  • 最終的なautoscript.vim
autoscript.vim
scriptencoding utf-8
set runtimepath+=~/workspace/HappyNewYear2021/plugins/vim-airline

set nonumber
set noshowmode

" airline setting

let g:airline_section_b = '2021 AD'
let g:airline_section_c = 'I hope you will have a great year!'
let g:airline_section_x = '㊗'
let g:airline_extensions = ['tabline']

edit HappyNewYear2021.txt

最終的な構成

スクリーンショット 2020-12-07 0.49.23.png

あとはこれをスクリーンショットなりなんなりして、年賀状に書き込めば完成です。

印刷した図

vim.jpg

かっこいいですね。
こんなにVimVimしい年賀状ができました。
これで、今年の年賀状の準備は万端ですね。

↓のリンクに今までの事柄をまとめておいたので、よかったら参考にしてください。

https://github.com/kazukazuinaina/HappyNewYear2021

参考文献

https://orgachem.hatenablog.com/entry/2013/12/19/130701

197
60
2

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
197
60