CentOS7

Vim を設定する

テキストエディタについては非常に使う機会が多いため、より便利な Vim をインストールして設定しておくと便利です。

Vim インストール

[root@dlp ~]# yum -y install vim-enhanced

コマンドエイリアスを適用 (全ユーザーに適用する。ユーザー個別に適用するならばそれぞれのユーザーの「~/.bashrc」等に記述)

[root@dlp ~]# vi /etc/profile
最終行にエイリアス追記
alias vi='vim'
変更を反映
[root@dlp ~]# source /etc/profile

vim の設定 (ユーザー個別に適用する。全ユーザーに適用するならば「/etc/vimrc」に記述。「/etc/vimrc」にはデフォルトである程度設定されている)

[root@dlp ~]# vi ~/.vimrc
vim の独自拡張機能を使う(viとの互換性をとらない)
set nocompatible
文字コードを指定する
set encoding=euc-jp
ファイルエンコードを指定する
set fileencodings=iso-2022-jp,sjis
自動認識させる改行コードを指定する
set fileformats=unix,dos
バックアップをとる
逆は [ set nobackup ]
set backup
バックアップを作るディレクトリを指定する
set backupdir=~/backup
検索履歴を50個残す
set history=50
検索時に大文字小文字を区別しない
set ignorecase
検索語に大文字を混ぜると検索時に大文字を区別する
set smartcase
''検索語にマッチした単語をハイライトする
逆は [ set nohlsearch ]
set hlsearch
インクリメンタルサーチを使う ( 検索語を入れている途中から随時マッチする文字列の検索を開始)
逆は [ set noincsearch ]
set incsearch
行番号を表示する
逆は [ set nonumber ]
set number
改行 ( $ ) やタブ ( ^I ) を可視化する
set list
括弧入力時に対応する括弧を強調する
set showmatch
ファイルの末尾に改行を入れない
set binary noeol
自動インデントを有効にする
逆は [ noautoindent ]
set autoindent
構文ごとに色分け表示する
逆は [ syntax off ]
syntax on
[ syntax on ] の場合のコメント文の色を変更する
highlight Comment ctermfg=LightCyan
ウィンドウ幅で行を折り返す
" 逆は [ set nowrap ]
set wrap

サンプル

set nocompatible
set encoding=euc-jp
set fileencodings=UTF-8,iso-2022-jp,sjis
set fileformats=unix,dos
set nobackup
set history=50
set ignorecase
set smartcase
set hlsearch
set incsearch
set number
set showmatch
set binary noeol
set noautoindent
syntax on
highlight Comment ctermfg=LightCyan
set wrap

トップ   編集 凍結 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2020-04-13 (月) 07:44:30