網頁

2014年10月21日

[linux] 解決使用vim方向鍵變亂碼(出現ABCD)問題

使用vim編輯文件方向鍵變成亂碼,只要關閉vi兼容模式即可解決,關閉兼容模式可以分為兩個方式。


方式一:
若主機上全部使用者都要套用這個設定,就將設定置寫在/etc/vim/vimrc.tiny檔案內。
vi /etc/vim/vimrc.tiny

檔案vimrc.tiny預設的內容:

" Vim configuration file, in effect when invoked as "vi". The aim of this
" configuration file is to provide a Vim environment as compatible with the
" original vi as possible. Note that ~/.vimrc configuration files as other
" configuration files in the runtimepath are still sourced.
" When Vim is invoked differently ("vim", "view", "evim", ...) this file is
" _not_ sourced; /etc/vim/vimrc and/or /etc/vim/gvimrc are.

" Debian system-wide default configuration Vim
set runtimepath=~/.vim,/var/lib/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/vim73,/usr/share/vim/vimfiles/after,/var/lib/vim/addons/after,~/.vim/after

set compatible

" vim: set ft=vim:

將「set compatible」變更為「set nocompatible」即完成設定。


方式二:
若只有目前這個登入的帳號要套用這個設定,就在家目錄建立「.vimrc」設定檔。
vi ~/.vimrc
直接寫入「set nocompatible」後儲存,帳號重新登入後就用套用設定,方向鍵就可以正常控制游標。

另外,常遇到的還有Backspace無作用及大小寫搜尋問題。

將backspace設定為2表示可以刪除全部字元,預設只能刪除本次輸入的字元。
set backspace=2

開啟不分大小寫搜尋功能。
set ignorecase