LoginSignup
8
7

More than 5 years have passed since last update.

いまさら聞けないVim Tips(インデント編)

Posted at

ソースコードのインデント

単一行

インデントしたい行で ==

バッファ全体に適用

ggVG=

gg: バッファの1行目に移動
V: 行選択モードに入る
G: バッファの最終行に移動
=: オートインデント

インデント幅の調整

4カラムインデント

sample
set ts=4 sts=4 sw=4 

2カラムインデント

sample
set ts=2 sts=2 sw=2

ts: tabstop
sts: softtabstop
sw: shiftwidth

インデントをタブではなくスペースにする

sample
set et

et: expandtab、タブをスペースに展開する

ファイルタイプ毎にインデント幅を設定する

拡張子毎にファイルタイプを判別できるようにする

以下を.vimrcや.vimrc.localに書く

.vimrc
" あまりメジャーではない拡張子の場合、プレーンなvimではファイルタイプを判別してくれない
" *.coffeeをcoffeescriptと判別させる
autocmd BufRead,BufNewFile,BufReadPre *.coffee set filetype=coffee

インデント幅の指定

.vimrc
" ファイルタイプに対して、インデント幅を指定
autocmd FileType coffee setlocal ts=2 sts=2 sw=2 et
8
7
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
8
7