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

Indentation and Tabulation

ygrek edited this pageOct 5, 2024 ·32 revisions

Tabs versus Spaces (Silicon Valley)

Basic Settings

Kakoune has two relevant settings you might want to check:tabstop sets the width of each tab character (inserted with the<tab> key), andindentwidth sets the number of spaces inserted or removed by the> and< commands.

If you're the kind of person who hates tabs for indentation and only wants to use spaces, you'll probably want to map<tab> to something else, and control the amount of indenting by settingindentwidth.

If you're the kind of person who hates spaces for indentation and only wants to use tabs, you'll probably want to setindentwidth to 0 (which means "indent with a tab, not spaces") and control the amount of indenting by settingtabstop.

Paste some text from the clipboard without triggering indentation

Use\ before entering insert mode to prevent hooks from being executed in this insert session (\i for example, then use your terminal pasting capability likeShiftInsert or mouse middle click).

Indentation andTab handling — Through a mapping

# except for MakefilehookglobalWinSetOptionfiletype=(?!makefile).* %{mapglobal insert<tab>'<a-;><a-gt>'mapglobal insert <s-tab>'<a-;><a-lt>'}

Indentation andTab handling — Through hooks

hookglobalInsertChar \t %{try %{execute-keys -draft"h<a-h><a-k>\A\h+\z<ret><a-;>;%opt{indentwidth}@"}}
hookglobalInsertDelete'' %{try %{execute-keys -draft'h<a-h><a-k>\A\h+\z<ret>i<space><esc><lt>'}}

UseTab for both indenting and completion

When the completion menu is visible in insert mode,Tab andShiftTab will cycle through the available options. When the completion menu is not shown, or when the character before the cursor is whitespace,Tab andShiftTab are just handled normally, so the previous tab-expansion example still works.

hookglobalInsertCompletionShow .* %{try %{# this command temporarily removes cursors preceded by whitespace;# if there are no cursors left, it raises an error, does not# continue to execute the mapping commands, and the error is eaten# by the `try` command so no warning appears.execute-keys -draft'h<a-K>\h<ret>'mapwindow insert<tab> <c-n>mapwindow insert <s-tab> <c-p>hook -once -alwayswindowInsertCompletionHide .* %{unmapwindow insert<tab> <c-n>unmapwindow insert <s-tab> <c-p>        }    }}

Smarttab, expandtab and noexpandtab

You can usesmarttab.kak plugin. It provides these commands to toggle different policy when usingTab and> keys:

  • noexpandtab - usetab for everything.
    Tab will insert\t character, and> will use\t character when indenting. Aligning cursors with& uses\t character.
  • expandtab - usespace for everything.
    Tab will insert%opt{indentwidth} amount of spaces, and> will indent with spaces.
  • smarttab - indent withtab, align withspace.
    Tab will insert\t character if your cursor is inside indentation area, e.g. before any non-whitespace character, and insert spaces if cursor is after any non-whitespace character. Aligning cursors with& usesspace.

If you are looking for a more faithful implementation of vim'sexpandtab andsofttabstop options, try this gist:vimtab.kak. Just copy and paste it into yourkakrc file and set the options as you wish. It also respects the usage of\ to disable hooks for insert mode, thus allowing you to insert a<tab> even whenexpandtab is enabled.

See also

Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp