3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

コーディングしていたらスライムに遭遇した件

Posted at

概要

Vimのポップアップ機能を使って、
jを押した時にランダムでスライム(っぽいもの)を表示するようにしてみました

Apr-03-2020 23-22-15.gif

コード

.vimrc
function! RandomEncount()
    let l:line = line('.')
    let l:now = localtime()
    let l:random = l:now % l:line
    if l:random >= 5
        call popup_notification("スライムがあらわれた", #{
                \ line: 13,
                \ col: 75,
                \ })
        let l:slime = readfile(expand("~/slime.txt"))
        call popup_dialog(l:slime, #{
                \ maxheight: 40,
                \ minwidth: 40,
                \ moved: "WORD",
                \ })
    endif
endfunction

j を押した時にポップアップ機能の実行とカーソル移動を行う設定

.vimrc
nnoremap <silent> j j:call RandomEncount()<CR>

使用したpopup関数

popup_notification

3秒間 第一引数をVimに表示させる。
第二引数のオプションで表示行と表示列を設定。

popup_dialog

Vimの中央に枠付きのポップアップウィンドウを表示させる。

第一引数がポップアップの内容。
第二引数のオプションでポップアップのサイズとカーソルを動かした時にポップアップウィンドウを閉じるように設定。

参考

popup - Vim日本語ドキュメント

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?