1
1

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 3 years have passed since last update.

【Vim】カーソルキーでの移動を禁止する設定(ドラゴン付き)。

Posted at

事前インストール

cowsayとslコマンド必要なので予めインストールが必要
brew install cowsay sl

設定方法

.vimrcに以下を設定する。

設定するとAAのドラゴンが丁寧に教えてくれる。

function TeachKey(message)
    let summon = join([!clear; cowsay -f dragon “, a:message, “を押すのだ”])
    exec summon
endfun
nnoremap <buffer> <Left> <Esc>:call TeachKey(h)<CR>
nnoremap <buffer> <Right> <Esc>:call TeachKey(l)<CR>
nnoremap <buffer> <Up> <Esc>:call TeachKey(k)<CR>
nnoremap <buffer> <Down> <Esc>:call TeachKey(j)<CR>
nnoremap <buffer> <PageUp> <Esc>:call TeachKey(‘Ctrl+B’)<CR>
nnoremap <buffer> <PageDown> <Esc>:call TeachKey(‘Ctrl+F’)<CR>
inoremap <buffer> <Left> <Esc>:call TeachKeyBi)ding(h)<CR>
inoremap <buffer> <Right> <Esc>:call TeachKey(l)<CR>
inoremap <buffer> <Up> <Esc>:call TeachKey(k)<CR>
inoremap <buffer> <Down> <Esc>:call TeachKey(j)<CR>
inoremap <buffer> <PageUp> <Esc>:call TeachKey(‘Ctrl+B’)<CR>
inoremap <buffer> <PageDown> <Esc>:call TeachKey(‘Ctrl+F’)<CR>
vnoremap <buffer> <Left> <Esc>:call TeachKeyBi)ding(h)<CR>
vnoremap <buffer> <Right> <Esc>:call TeachKey(l)<CR>
vnoremap <buffer> <Up> <Esc>:call TeachKey(k)<CR>
vnoremap <buffer> <Down> <Esc>:call TeachKey(j)<CR>
vnoremap <buffer> <PageUp> <Esc>:call TeachKey(‘Ctrl+B’)<CR>
vnoremap <buffer> <PageDown> <Esc>:call TeachKey(‘Ctrl+F’)<CR>

nnoremap <buffer> <Del> <Esc>:<C-u>!sl<CR>
inoremap <buffer> <Del> <Esc>:<C-u>!sl<CR>
vnoremap <buffer> <Del> <Esc>:<C-u>!sl<CR>

set backspace=0

確認方法

設定されるとこんなのが出る。

image.png

参考URL

vi(vim)で完全にカーソルキーを無効化させたい - スタック・オーバーフロー

#development/vim

1
1
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
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?