9
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

neat-json を使って Vim で JSON を整形する

Posted at

neat-json

neat-json は、Vim のカレントバッファにある JSON を綺麗に表示するためのプラグインです。(PR)

内部で Python の JSON モジュールを利用しているので、if_pyth が必須です。

インストール

NeoBundle を使っている場合は、.vimrc に以下を追加してください。

NeoBundle '5t111111/neat-json.vim'

もしくは、普通にダウンロードして展開してプラグインのパスが通っているところに置けばOKです。
https://github.com/5t111111/neat-json.vim

使い方

例えば、バッファのJSONが以下のようなぐちゃぐちゃ状態だったとします。

json1.png

以下のコマンドを実行すると、バッファの内容を書き換え、綺麗にインデントして表示します。

NeatJson

json2.png

通常はUTF8でエンコードして表示しますが、
以下のコマンドを実行した場合には、生のUTF8で表示します。

NeatRawJson

json3.png

いずれの場合も、JSONとして適切なデータでない場合にはエラーとなります。

if_pyth

先述の通り、Python インターフェースが必須なので、--enable-pythoninterp でビルドされている必要があります。
http://vim-users.jp/2010/03/hack132/

Thx2

生のUTF8データから日本語への変換については、以下の投稿を参考にさせていただきました。

Vim (with python) で json を整形

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?