# Recently edited files

**URL:** <https://discuss.kakoune.com/t/recently-edited-files/587>\
**Category:** Recipes & Guides\
**Created:** [May 21, 2019, 7:17am UTC](https://discuss.kakoune.com/t/recently-edited-files/587 "2019-05-21T07:17:04Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![andreyorst](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/andreyorst/32/29_2.png) [@andreyorst](https://discuss.kakoune.com/u/andreyorst)\
**Post date:** [May 21, 2019, 7:17am UTC](https://discuss.kakoune.com/t/recently-edited-files/587/1 "2019-05-21T07:17:04Z")

</div>

Here’s an Idea how one can implement recent files in Kakoune:

```
hook global BufOpenFile .* recentf-add-file
hook global BufWritePost .* recentf-add-file

declare-option str recentf_file "%val{config}/.recentf"
declare-option int max_recentf_files 45

define-command -hidden recentf-add-file %{ nop %sh{
    if ! grep -q "${kak_buffile}" "${kak_opt_recentf_file}"; then
        printf "%s\n%s\n" "${kak_buffile}" "$(cat ${kak_opt_recentf_file})" > ${kak_opt_recentf_file}
        printf "%s\n" "$(head -${kak_opt_max_recentf_files} ${kak_opt_recentf_file})" > ${kak_opt_recentf_file}
    fi
}}

define-command recentf -params 1 -shell-script-candidates %{ cat ${kak_opt_recentf_file} } %{ edit -existing %arg{1} }

```

The only thing I don’t really like about this implementation is that `-shell-script-candidates` sorts candidates and most recent files are no longer at the top of the list. I could use `-shell-script-completion` as it doesn’t do sorting, but it doesn’t allow fuzzy matching.

---

<div class="post-metadata">

**Author:** ![daboross](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/daboross/32/76_2.png) [@daboross](https://discuss.kakoune.com/u/daboross)\
**Post date:** [July 6, 2019, 8:18pm UTC](https://discuss.kakoune.com/t/recently-edited-files/587/2 "2019-07-06T20:18:04Z")

</div>

Since kakoune doesn’t seem to support fuzzy matching with non-alphabetic-sorting, what about using an external tool?

I found a snippet for using [rofi](https://github.com/davatorium/rofi) on open buffers at [https://github.com/mawww/kakoune/wiki/Fuzzy-finder#rofi:](https://github.com/mawww/kakoune/wiki/Fuzzy-finder#rofi:)

```nohighlight
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"]; then
        printf "%s\n" "buffer ${BUFFER}"
    fi
} }

```

After doing some testing, rofi does seem to display things in the order they’re passed in, rather than alphabetic order, and it can _kind of_ support fuzzy matching.

---

<div class="post-metadata">

**Author:** ![andreyorst](https://discuss.kakoune.com/user_avatar/discuss.kakoune.com/andreyorst/32/29_2.png) [@andreyorst](https://discuss.kakoune.com/u/andreyorst)\
**Post date:** [July 7, 2019, 5:39am UTC](https://discuss.kakoune.com/t/recently-edited-files/587/3 "2019-07-07T05:39:03Z")

</div>

I’m using fzf for that
