Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
Dmitry Matveyev edited this pageAug 13, 2024 ·25 revisions

Formatting

format.kak is a built-in script that allows formatting multiple selections or the entire buffer.

The editor does not have language-specific parsers to format a buffer’s contents, but instead relies on third-party tools specified via theformatcmd option.

The benefit is that it can apply more clever rules than simple ones like "when<ret> is pressed after a{ it should indent the new opened line". So the user can focus on just raw typing, execute the:format command and let the magic happens. This command can also be run automatically on buffer-save via hooks.

For example, a popular formatting tool in the web community isprettier.

Here are other points to consider, in relation with other built-in commands:

  • if possible, the formatting rules should be in sync with the ones used byEditorConfig

  • someLSP servers provide a format command but it’s often not very configurable

AsciiDoc

C

hookglobalBufSetOptionfiletype=c %{set-optionbuffer formatcmd'astyle'}
hookglobalBufSetOptionfiletype=c %{set-optionbuffer formatcmd'indent'}

C++

hookglobalBufSetOptionfiletype=cpp %{set-optionbuffer formatcmd'astyle'}

Clojure

CoffeeScript

CSS

hookglobalBufSetOptionfiletype=css %{set-optionbuffer formatcmd"prettier --stdin-filepath=%val{buffile}"}
hookglobalBufSetOptionfiletype=css %{set-optionbuffer formatcmd"npx stylelint --fix --stdin-filename='%val{buffile}'"}

D

hookglobalBufSetOptionfiletype=d %{set-optionbuffer formatcmd'dfmt'}

Elixir

hookglobalBufSetOptionfiletype=elixir %{set-optionbuffer formatcmd'mix format -'}

Elm

hookglobalBufSetOptionfiletype=elm %{set-optionbuffer formatcmd'elm-format --stdin'}

Go

hookglobalBufSetOptionfiletype=go %{set-optionbuffer formatcmd'gofmt'}

HAML

HTML

hookglobalWinSetOptionfiletype=html %{set-optionbuffer formatcmd"run(){ tidy -q --indent yes --indent-spaces %opt{tabstop}  2>/dev/null || true; } && run"}

Handlebars

Haskell

INI

Java

JavaScript

hookglobalBufSetOptionfiletype=javascript %{set-optionbuffer formatcmd"prettier --stdin-filepath=%val{buffile}"}

JSON

hookglobalBufSetOptionfiletype=json %{set-optionbuffer formatcmd"prettier --stdin-filepath=%val{buffile}"}
hookglobalBufSetOptionfiletype=json %{set-optionbuffer formatcmd"jq --indent %opt{tabstop} ."}
hookglobalBufSetOptionfiletype=json %{set-optionbuffer formatcmd'python3 -m json.tool'}

Julia

Latex

Lua

LISP

Makefile

Markdown

hookglobalBufSetOptionfiletype=markdown %{set-optionbuffer formatcmd'markdownfmt'}
hookglobalBufSetOptionfiletype=markdown %{set-optionbuffer formatcmd'pandoc -f commonmark -t commonmark'}

MoonScript

Nim

PHP

hookglobalBufSetOptionfiletype=php %{set-optionbuffer formatcmd"phpcbf -q --stdin-path=%val{buffile} - || true"}

Python

hookglobalBufSetOptionfiletype=python %{set-optionbuffer formatcmd'autopep8'}
hookglobalBufSetOptionfiletype=python %{set-optionbuffer formatcmd'black -'}

Pony

Pug

Ragel

Ruby

hookglobalBufSetOptionfiletype=ruby %{set-optionbuffer formatcmd"rubocop -x -o /dev/null -s %val{buffile} | sed -n '2,$p'"}

Rubocop can also be executed withbundler:

hookglobalBufSetOptionfiletype=ruby %{set-optionbuffer formatcmd"bundle exec rubocop -x -o /dev/null -s %val{buffile} | sed -n '2,$p'"}

Rust

hookglobalBufSetOptionfiletype=rust %{set-optionbuffer formatcmd'rustfmt'}

SASS & SCSS

Scala

Shell

hookglobalWinSetOptionfiletype=sh %{set-optionbuffer formatcmd"shfmt"}

Swift

Installswift-format and make sure the executable is in your$PATH. Make sure you check out the correct branch ofswift-format — the main branch is synced to the main branch in swift, which is likely not what you need.

hookglobalWinSetOptionfiletype=swift %{set-optionbuffer formatcmd'swift-format'}

TUP

Zig

hookglobalBufSetOptionfiletype=zig %{set-optionbuffer formatcmd'zig fmt --stdin'}
Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp