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
Bob edited this pageJun 9, 2023 ·27 revisions

Find

You can define the following command to act as a simple fuzzy file picker from the command line:

def find -params1 -shell-script-candidates %{ find . -type f } %{edit %arg{1} }

Then:find on the command line will find fuzzy matches to the first argument as you type.

From Kakoune 2022.10.31, the switches for providing command completion are discouraged in favor of thecomplete-command command.The recommended way is now:

define-command find -docstring"find files" -params1 %{edit %arg{1} }complete-command find shell-script-candidates %{ find . -type f }

Recursive file search under%opt{path} option

This command replicates Vim behavior whenpath option contains** item.find will search for file recursively, and if several files found it will prompt you a list of files to choose. This is smart function, so it tries to find match as fast as possible before going full recursive.

define-command -docstring \"find <filename>: search for file recusively under path option: %opt{path}" \find -params1 %{evaluate-commands%sh{    file=$1eval"set --$kak_buflist"while [$#-gt 0 ];do# Check if buffer with thisif ["$file"="$1" ];then# file already exists. Basicallyprintf"%s\n""buffer$1"# emulating what edit command doesexitfishiftdoneif [-e"$file" ];then# Test if file exists underprintf"%s\n""edit -existing %{$file}"# servers' working directoryexit# this is last resort untilfi# we start recursive searchimg# if everthing  above fails - search for file under patheval"set --$kak_opt_path"while [$#-gt 0 ];docase$1in# Since we want to check fewer places            ./) path=${kak_buffile%/*} ;;# I've swapped ./ and %/ because            %/) path=$PWD ;;# %/ usually has smaller scope. So*)  path=$1 ;;# this trick is a speedi-up hack.esacif [-z"${file##*/*}" ];then# test if filename contains pathif [-e"$path/$file" ];thenprintf"%s\n""edit -existing %{$path/$file}"exitfielse# build list of candidates or automatically select if only one foundforcandidatein$(find -L$path -mount -type f -name"$file");doif [-n"$candidate" ];then                    candidates="$candidates %{$candidate} %{evaluate-commands %{edit -existing %{$candidate}}}"fidoneif [-n"$candidates" ];thenprintf"%s\n""menu -auto-single$candidates"exitfifishiftdoneprintf"%s\n""echo -markup %{{Error}unable to find file '$file'}"}}

This command can also be mapped togf keeping old behavior withgAlt+f:

map -docstring"file non-recursive"global goto'<a-f>''<esc>gf'map -docstring"file"global goto'f''<esc>: find %val{selection}<ret>'

Git

def git-edit -params1 -shell-script-candidates %{ git ls-files } %{edit %arg{1} }

Again, the recommended way is now:

define-command git-edit -params1 %{edit %arg{1} }complete-command git-edit shell-script-candidates %{ git ls-files }

FZF

fzf is a basic fuzzy finder tool used to interactively filter large lists of data in a shell.

In the following snippets, a tmux pane is opened with fzf ready to filter a list of files and a list of current buffers.

Other kakoune lists could be filtered this way, takingfzf.vim as inspiration.

define-command -docstring'Invoke fzf to open a file' -params0 fzf-edit %{evaluate-commands%sh{if [-z"${kak_client_env_TMUX}" ];thenprintf'fail "client was not started under tmux"\n'else            file="$(find. -type f|TMUX="${kak_client_env_TMUX}" fzf-tmux -d 15)"if [-n"$file" ];thenprintf'edit "%s"\n'"$file"fifi    }}# the original version no longer works since kak_buflist is no longer ":" separated.# this one works even you have single quote or newline in file names.define-command -docstring'Invoke fzf to select a buffer' fzf-buffer %{evaluate-commands%sh{        BUFFER=$(            (eval"set --$kak_buflist"while [$#-gt 0 ];doprintf"%s\0""$1"shiftdone            )|            fzf-tmux -d 15 --read0)        BUFFER=${BUFFER/\'/\'\'}if [-n"$BUFFER" ];thenprintf"buffer '%s'""${BUFFER}"fi    }}

fzf.kak

There's also afzf.kak plugin, that includes such features:

  • Supports both x11 and tmux
  • Opening files withfind,fd,rg,ag
  • Previewing file contents with syntax highlighting, backed bybat,coderay,highlight,rogue
  • Switching buffers
  • Automatic detection of your VCS to list project files. Supports:
    • Git
    • GNU Bazaar
    • Subversion
    • Mercurial
  • Searching tags withuniversal-ctags
    • Filtering tags bykinds for all ctags supported languages
  • Searching current buffer contents
  • Changing server's working directory

Skim

Useterminal,fd withskim to open a interactively fuzzy file finder in a new terminal window.

define-command find -docstring"Find a file to open" -params .. %{    terminal sk -c"fd -tf %arg{@}" --bind %exp{enter:execute(echoeval -verbatim -client %val{client}edit'"{}"' | kak -p %val{session})+abort}}

Rofi

Select an open buffer usingRofi

define-command rofi-buffers \-docstring'Select an open buffer using Rofi' %{evaluate-commands%sh{    BUFFER=$(printf"%s\n""${kak_buflist}"| tr"""\n"| rofi -dmenu| tr -d\')if [-n"$BUFFER" ];thenprintf"%s\n""buffer${BUFFER}"fi} }

Using Ag + Rofi to select files in your project directory.

define-command rofi-files \-docstring'Select files in project using Ag and Rofi' %{nop%sh{    FILE=$(ag -g""| rofi -dmenu)if [-n"$FILE" ];thenprintf'eval -client %%{%s} edit %%{%s}\n'"${kak_client}""${FILE}"| kak -p"${kak_session}"fi} }

Fast file finder:fasd integration

Addfunction k () kak `fasd -f $1` to your .zshrc to open frecent files withk filename

Clone this wiki locally

[8]ページ先頭

©2009-2025 Movatter.jp