-
Notifications
You must be signed in to change notification settings - Fork 715
Status line
%opt{modelinefmt}
is used to set what info are displayed in the right part of the status line.
By default it has the following value: %val{bufname} %val{cursor_line}:%val{cursor_char_column} {{context_info}} {{mode_info}} - %val{client}@[%val{session}]
The {{context_info}}
placeholder displays hard-coded info:
String generate_context_info(const Context& context)
{
String s = "";
if (context.buffer().is_modified())
s += "[+]";
if (context.client().input_handler().is_recording())
s += format("[recording ({})]", context.client().input_handler().recording_reg());
if (context.buffer().flags() & Buffer::Flags::New)
s += "[new file]";
if (context.hooks_disabled())
s += "[no-hooks]";
if (context.buffer().flags() & Buffer::Flags::Fifo)
s += "[fifo]";
return s;
}
The {{mode_info}}
placeholder also displays hard-coded info, depending of the current mode:
DisplayLine mode_line() const override
{
AtomList atoms = { { to_string(context().selections().size()) + " sel", get_face("StatusLineInfo") } };
if (m_params.count != 0)
{
atoms.emplace_back(" param=", get_face("StatusLineInfo"));
atoms.emplace_back(to_string(m_params.count), get_face("StatusLineValue"));
}
if (m_params.reg)
{
atoms.emplace_back(" reg=", get_face("StatusLineInfo"));
atoms.emplace_back(StringView(m_params.reg).str(), get_face("StatusLineValue"));
}
return atoms;
}
Here's some simple things you might want to include in your status line.
The modeline is regularly updated, so:
set global modelinefmt '%sh{date}'
will display the current date with elapsing seconds.
Many Unicode characters are quite similar, and it can be difficult to tell at a glance whether the character you're looking at is (say) U+0027 APOSTROPHE or U+2019 RIGHT SINGLE QUOTE. If you display the codepoint of the character under the cursor in the status bar, even if you don't recognise the specific code-point, at least you've got a specific value you can look up.
set global modelinefmt 'U+%sh{printf "%04x" "$kak_cursor_char_value"}'
set global modelinefmt '%sh{bs=${kak_buflist//[^:]};echo $((${#bs}+1))} buffers'
Explanation:
# $kak_buflist is a string having each buffer name separated by a colon
%sh{
bs=${kak_buflist//[^:]}; # erase non colon chars
echo $((${#bs}+1)) # count the number of colons, and add 1
}
To show the relative position of the cursor in percent using wc
:
decl str modeline_pos_percent
hook global WinCreate .* %{
hook window NormalIdle .* %{ %sh{
if [ -f "${kak_buffile}" ]; then
echo "set window modeline_pos_percent '$(($kak_cursor_line * 100 / $(wc -l < $kak_buffile)))'"
else
echo "
eval -save-regs 'm' %{
exec -draft '%<a-s>:reg m %reg{#}<ret>'
set window modeline_pos_percent %sh{echo \$((\$kak_cursor_line * 100 / \$kak_reg_m))}
}
"
fi
} }
}
Here's another example by lenormf on how to add more info to the modeline, like the current git branch (status bar)
## customize the status bar
hook global BufOpen .*/?[^*].+ %{
%sh{
function add_hook_on_idle {
echo "hook global NormalIdle .* %{ $@ }"
}
tools=(
## cursor coordinates in the buffer
"%val{cursor_line}:%val{cursor_char_column}"
## filetype of the buffer detected by kak
"%opt{filetype}"
## name of the buffer
"%val{bufname}"
)
fmt_line=""
## current git branch
if which git 1>/dev/null; then
echo "decl str modeline-git-branch"
tools[${#tools[@]}]="%opt{modeline-git-branch}"
add_hook_on_idle "%sh{
branch=\$(cd \$(readlink -e \$(dirname \${kak_bufname})) && git rev-parse --abbrev-ref HEAD 2>/dev/null)
test -n \"\${branch}\" && echo \"set global modeline-git-branch '\${branch}'\"
}"
fi
for t in "${tools[@]}"; do
test -z "${t}" && continue
test -n "${fmt_line}" && fmt_line="${t} ${fmt_line}" || fmt_line="${t}"
done
echo set global modelinefmt "'${fmt_line}'"
}
}
- Normal mode commands
- Avoid the escape key
- Implementing user mode (Leader key)
- Kakoune explain
- Kakoune TV