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

VIm設定

1
Last updated at Posted at 2021-09-12

vimの設定方法

vimrcの作成

vim ~/.vimrc

"----------------------------------------
" 基本設定
"----------------------------------------
" 文字コードをUTF-8に設定
set fenc=utf-8
" バックアップファイルを作らない
set nobackup
" スワップファイルを作らない
set noswapfile
" 編集中のファイルが変更されたら自動で読み直す
set autoread
" バッファが編集中でもその他のファイルを開けるように
set hidden

"----------------------------------------
" 見た目系
"----------------------------------------
" 行番号を表示
set number
" 貼り付けずれない
set paste!
" 現在の行を強調表示
set cursorline
" 現在の列を強調表示
set cursorcolumn
" 矩形選択で文字がなくても右へ進める(後勝ち設定)
set virtualedit=block
" インデントはスマートインデント
set smartindent
" ビープ音を可視化
set visualbell
" コマンドラインの補完
set wildmode=list:longest
" 折り返し時に表示行単位での移動できるようにする
nnoremap j gj
nnoremap k gk
" シンタックスハイライト
syntax on
" メッセージ表示欄を2行確保
set cmdheight=2
" ウィンドウの幅を設定
:set columns=230
" ウィンドウの高さを設定
:set lines=55

"----------------------------------------
" Tab系
"----------------------------------------
" 不可視文字を可視化
set list
" タブと行末スペースの表示
set listchars=tab:^\ ,trail:~
" Tab文字を半角スペースにする
set expandtab
" Tab幅
set tabstop=2
" 自動インデント幅
set shiftwidth=2
" Tabキー押下時のスペース数
set softtabstop=2

"----------------------------------------
" 検索系
"----------------------------------------
" 小文字検索 → 大文字小文字を無視
set ignorecase
" 大文字を含む検索 → 区別
set smartcase
" 入力しながら検索
set incsearch
" 検索が末尾まで行ったら先頭に戻る
set wrapscan
" 検索語をハイライト
set hlsearch
" ESC連打でハイライト解除
nnoremap <Esc><Esc> :nohlsearch<CR><Esc>
" 上書き時のバックアップを作らない
set nowritebackup
" バックスペースで削除できる範囲を拡張
set backspace=indent,eol,start
" 全角文字を幅2で扱う
set ambiwidth=double
" wildmenuを有効化
set wildmenu

"----------------------------------------
" 表示設定
"----------------------------------------
" エラーメッセージのビープを無効化
set noerrorbells
" Windowsでパス区切りをスラッシュに
set shellslash
" 対応する括弧を表示
set showmatch matchtime=1
" C言語系のインデント調整
set cinoptions+=:0
" ステータス行を常に表示
set laststatus=2
" 入力中のコマンドを右下に表示
set showcmd
" 行を省略せずに表示
set display=lastline
" コマンド履歴を10000件保存
set history=10000
" コメントの色を水色に
hi Comment ctermfg=3
" GUIのツールバーを非表示
set guioptions-=T
" yでコピーした時にクリップボードに入る
set guioptions+=a
" メニューバーを非表示
set guioptions-=m
" 右スクロールバーを非表示
set guioptions+=R
" フォールド無効
set nofoldenable
" タイトルを表示
set title
" ヤンクをOSクリップボードと共有
set clipboard=unnamed,autoselect
" 数値を常に10進数として扱う
set nrformats=
" 行をまたいで移動
set whichwrap=b,s,h,l,<,>,[,],~
" マウス操作を有効化
set mouse=a

"----------------------------------------
" 自動処理
"----------------------------------------

" .vimrc を保存したら自動で再読み込み
augroup source-vimrc
  autocmd!
  " .vimrc 保存後に即反映
  autocmd BufWritePost *vimrc source $MYVIMRC | set foldmethod=marker
  " gvimrc 保存後に即反映(GUI時のみ)
  autocmd BufWritePost *gvimrc if has('gui_running') source $MYGVIMRC
augroup END

" 自動コメントを無効化
augroup auto_comment_off
  autocmd!
  " 改行時にコメントが自動挿入されるのを防ぐ
  autocmd BufEnter * setlocal formatoptions-=r
  " o / O で改行したときのコメント挿入を防ぐ
  autocmd BufEnter * setlocal formatoptions-=o
augroup END

"----------------------------------------
" HTML/XML閉じタグ自動補完
"----------------------------------------
augroup MyXML
  autocmd!
  autocmd Filetype xml  inoremap <buffer> </ </<C-x><C-o>
  autocmd Filetype html inoremap <buffer> </ </<C-x><C-o>
augroup END

"----------------------------------------
" 編集箇所のカーソル位置を記憶
"----------------------------------------
if has("autocmd")
  augroup redhat
    " テキストファイルは幅78で折り返し
    autocmd BufRead *.txt set tw=78
    " 前回のカーソル位置にジャンプ
    autocmd BufReadPost *
      \ if line("'\"") > 0 && line("'\"") <= line("$") |
      \   exe "normal! g'\"" |
      \ endif
  augroup END
endif
1
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
1
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?