LoginSignup
7
8

More than 5 years have passed since last update.

[Vim] modeline 設定サンプル

Last updated at Posted at 2016-07-14

modelineの設定を追加しておくと、他の環境に持って行った場合に規約を合わせた変更が楽になるので設定しておく。

modelineの仕様

ファイルの上下端からmodelinesオプションで設定された行数だけ、 modelineを探しに行きます。
デフォルトは上端/下端から5行以内のようです。

設定可能なオプション

option short option 詳細
textwidth tw 設定された幅で行を改行
tabstop ts タブを画面で表示する際の幅
expandtab / noexpandtab et インデント/タブ入力時にタブではなく半角スペースとして挿入
shiftwidth sw (expandtab設定時)インデント時に使用されるスペースの数
softtabstop sts (expandtab設定時)タブを入力時にその数値分だけ半角スペースを挿入
wrap / nowrap 画面端の行の折り返し設定
fileformat ff ファイルの改行の種類 (dos, mac, unix)
filetype ft ファイルタイプ (sh, python等)
fileencoding fenc ファイルエンコーディング(utf-8 か shift_jis あたり)

設定サンプル

python

python2
#! /usr/bin/env python
# -*- coding: utf-8 -*-
# vim:fenc=utf-8 ff=unix ft=python ts=4 sw=4 sts=4 si et :
python3
#! /usr/bin/env python3
# -*- coding: utf-8 -*-
# vim:fenc=utf-8 ff=unix ft=python ts=4 sw=4 sts=4 si et :

shell

bash
# vim: set ft=sh ff=unix fileencoding=utf-8 expandtab ts=4 sw=4 :

参考

モードラインを使って、ファイルごとにvimエディタのオプションを指定する。 — 名無しのvim使い

7
8
1

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