Giter Site home page Giter Site logo

kakoune-buffers's Introduction

kakoune-buffers

kakoune plugin to ease navigation between opened buffers.

Install

Add buffers.kak to your autoload dir: ~/.config/kak/autoload/.

Or via plug.kak:

plug 'delapouite/kakoune-buffers' %{
  map global normal ^ q
  map global normal <a-^> Q
  map global normal q b
  map global normal Q B
  map global normal <a-q> <a-b>
  map global normal <a-Q> <a-B>
  map global normal b ': enter-buffers-mode<ret>' -docstring 'buffers'
  map global normal B ': enter-user-mode -lock buffers<ret>' -docstring 'buffers (lock)'
}

Usage

Run the info-buffers command. It will display an info box with a numbered list of opened buffers.

  • The current buffer is prefixed by a >.
  • The alt buffer is prefixed by a # (use ga to reach it).
  • Modified buffers are prefixed by a +.

If this list gets too big, decrease the max_list_buffers option (42 entries by default).

To jump to a specific buffer index use the buffer-by-index n command. Use buffer-first and buffer-last to move to the ends of the list. With buffer-first-modified, jump to the first modified buffer.

To delete all buffers except the current one, use buffer-only or the more destructive buffer-only-force version. You can also delete all buffers except the ones in the same dir as the current buffer with buffer-only-directory.

User mode

All these commands are grouped in a dedicated buffers user-mode.

While opened in lock mode, it means that you can press p or n many times to cycle through your buffers. Press <esc> to leave this mode.

# Suggested hook

hook global WinDisplay .* info-buffers

# Suggested mappings

map global user b ':enter-buffers-mode<ret>'              -docstring 'buffers…'
map global user B ':enter-user-mode -lock buffers<ret>'   -docstring 'buffers (lock)…'

# Suggested aliases

alias global bd delete-buffer
alias global bf buffer-first
alias global bl buffer-last
alias global bo buffer-only
alias global bo! buffer-only-force

More controversial mappings

Ask yourself: how often do you use macros? If you're like me, not so much thanks to all the cool interactive ways to accomplish a task with Kakoune. But they waste a nice spot on the q key! Time to free it for something else.

What about moving the b actions, (moving word backward) here instead? It makes sense on a qwerty keyboard. The q is on the left of w which goes the opposite direction. The q, w and e actions are now finally together just under your left hand like the 3 musketeers.

Therefore your b key is free and you can now use it for buffer actions:

# ciao macros
map global normal ^ q
map global normal <a-^> Q

map global normal q b
map global normal Q B
map global normal <a-q> <a-b>
map global normal <a-Q> <a-B>

map global normal b ':enter-buffers-mode<ret>'              -docstring 'buffers…'
map global normal B ':enter-user-mode -lock buffers<ret>'   -docstring 'buffers (lock)…'

Screenshots

info displayed by the info-buffers command:

info-buffers

info displayed by the buffers user-mode:

mode-buffers

See also

Licence

MIT

Thanks a lot to danr and occivink for the original implementation: https://github.com/occivink/config/blob/master/.config/kak/buflist.kak

kakoune-buffers's People

Contributors

caksoylar avatar crote avatar delapouite avatar nikhilmitrax avatar occivink avatar vbauerster avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

kakoune-buffers's Issues

Add a max limit option

On long list of buffers, the infobox can get quite intrusive. Also indexes > 9 are not targetable with the keyboard.

pick-buffers empty

Hi!

When I do enter-user-mode pick-buffers, I get an empty list.

The top of my buffers user mode info also has no 'by index' hint.

this is my kakrc:

# Plugins

# source custom plugins
source "~/git/pandoc.kak/rc/pandoc.kak"

# source plug.kak script
source "%val{config}/plugins/plug.kak/rc/plug.kak"

# call plug.kak with `plug' command
plug "robertmeta/plug.kak" noload config %{
    # configure plug.kak here
}        
plug "ul/kak-lsp" do %{
    cargo build --release --locked
    cargo install --force --path .
} config %{

    # uncomment to enable debugging
    # eval %sh{echo ${kak_opt_lsp_cmd} >> /tmp/kak-lsp.log}
    # set global lsp_cmd "kak-lsp -s %val{session} -vvv --log /tmp/kak-lsp.log"

    # this is not necessary; the `lsp-enable-window` will take care of it
    # eval %sh{${kak_opt_lsp_cmd} --kakoune -s $kak_session}

    set global lsp_diagnostic_line_error_sign '║'
    set global lsp_diagnostic_line_warning_sign '┊'

    define-command ne -docstring 'go to next error/warning from lsp' %{ lsp-find-error --include-warnings }
    define-command pe -docstring 'go to previous error/warning from lsp' %{ lsp-find-error --previous --include-warnings }
    define-command ee -docstring 'go to current error/warning from lsp' %{ lsp-find-error --include-warnings; lsp-find-error --previous --include-warnings }

    define-command lsp-restart -docstring 'restart lsp server' %{ lsp-stop; lsp-start }
    hook global WinSetOption filetype=(c|cpp|cc|rust|javascript|typescript) %{
        set-option window lsp_auto_highlight_references true
        set-option window lsp_hover_anchor false
        lsp-auto-hover-enable
        echo -debug "Enabling LSP for filtetype %opt{filetype}"
        lsp-enable-window
    }

    hook global WinSetOption filetype=(rust) %{
        set window lsp_server_configuration rust.clippy_preference="on"
    }

    hook global WinSetOption filetype=rust %{
        hook window BufWritePre .* %{
            evaluate-commands %sh{
                test -f rustfmt.toml && printf lsp-formatting-sync
            }
        }
    }

    hook global KakEnd .* lsp-exit
}

plug 'delapouite/kakoune-buffers' %{
    # Suggested hook

    hook global WinDisplay .* info-buffers

    # Suggested mappings

    map global user b ':enter-buffers-mode<ret>'              -docstring 'buffers…'
    map global user B ':enter-user-mode -lock buffers<ret>'   -docstring 'buffers (lock)…'

    # Suggested aliases

    alias global bd delete-buffer
    alias global bf buffer-first
    alias global bl buffer-last
    alias global bo buffer-only
    alias global bo! buffer-only-force
}
# plug "enricozb/tabs.kak" %{
#   set-option global modelinefmt_tabs '%val{cursor_line}:%val{cursor_char_column} {{context_info}} {{mode_info}}'
#   map global user b ': enter-user-mode tabs<ret>' -docstring 'tabs'
#   map global user B ': enter-user-mode -lock tabs<ret>' -docstring 'tabs (lock)'
# }
plug "jdugan6240/powerline.kak" defer powerline %{
    # set-option global powerline_format 'git bufname filetype mode_info line_column position'
    # powerline-toggle line_column off
    powerline-separator triangle
    powerline-theme gruvbox
} config %{
    powerline-start
}
plug "caksoylar/kakoune-smooth-scroll" config %{
     hook global WinCreate .* %{ hook -once window WinDisplay .* smooth-scroll-enable }
}
plug "alexherbo2/prelude.kak"
plug "alexherbo2/connect.kak" %{
    require-module connect
    require-module connect-nnn
}
plug 'alexherbo2/palette.kak'
plug 'occivink/kakoune-sudo-write '
plug 'evanrelf/number-toggle.kak' %{
    set-option global number_toggle_params -hlcursor
}
plug 'alexherbo2/surround.kak' %{
    require-module surround
    ## Quoting
    map -docstring 'Surround' global normal q ': enter-user-mode surround<ret>'
    map -docstring 'Surround insert' global normal Q ': surround-enter-insert-mode<ret>'

    ## Move macros to ^
    map -docstring 'Play macro' global normal ^ q
    map -docstring 'Record macro' global normal <a-^> Q
}
plug 'alexherbo2/auto-pairs.kak' %{
    require-module auto-pairs
    hook global WinCreate .* %{ auto-pairs-enable }
}
plug 'laelath/kakoune-show-matching-insert'
plug 'alexherbo2/snippets.kak'

plug "jbomanson/search-doc.kak" config %{
        require-module search-doc
}

plug "andreyorst/smarttab.kak" defer smarttab %{
    # when `backspace' is pressed, 4 spaces are deleted at once
    set-option global softtabstop 4
} config %{
    # these languages will use `expandtab' behavior
    hook global WinSetOption filetype=.* expandtab
    # these languages will use `noexpandtab' behavior
    hook global WinSetOption filetype=(makefile|gas) noexpandtab
    # these languages will use `smarttab' behavior
    hook global WinSetOption filetype=(c|cpp|java) smarttab
}
plug "andreyorst/fzf.kak"

# Key Mappings

## quick safe

map global user w -docstring 'safe file' ':w<ret>'

## edit kakrc
map global user <,> -docstring 'edit kakrc' ':e "%val{config}/kakrc"<ret>'
map global user <a-,> -docstring 'source kakrc' ':source "%val{config}/kakrc"<ret>'

map global user <a-<> -docstring 'source current buffer' ':source "%val{buffile}<ret>'

## jj to escape
hook global InsertChar j %{ try %{
  exec -draft hH <a-k>jj<ret> d
  exec <esc>
}}

## commenting

map global user c -docstring '(un-)comment line' ':comment-line<ret>'
map global user C -docstring '(un-)comment block' ':comment-block<ret>'

## Mac Clipboard
hook global NormalKey y|d|c %{ nop %sh{
      printf %s "$kak_main_reg_dquote" | pbcopy
}}
map global user P -docstring 'Paste above' '!pbpaste<ret>'
map global user p -docstring 'Paste below' '<a-!>pbpaste<ret>'
map global user R -docstring 'Replace' '|pbpaste<ret>'

# general Configuration

##verbose autoinfo
set-option -add global autoinfo normal

## case insensitive search by default
map global normal / "/(?i)"

# Pandoc
set-option global pandoc_options "-d default"
 
# Appearance

colorscheme gruvbox

add-highlighter global/ number-lines -relative -hlcursor
add-highlighter global/ show-whitespaces

add-highlighter global/ line '%val{cursor_line}' default,rgb:3c3735
add-highlighter global/ column 81 default,red
add-highlighter global/ wrap -indent -word -marker ' … '

list-buffers not working

hi.
i copied buffers.kak from (https://github.com/Delapouite/kakoune-buffers) and placed it in /usr/share/kak/rc/extra/

the command appears in the bar but when i select it. it reports an error:

1:1: 'list-buffers' 2:3: 'refresh-buffers-info' 4:3: 'eval' no such env var: modified

Information for package kakoune:

Repository : openSUSE-Leap-42.3-Oss
Name : kakoune
Version : 0.0+git.20170513-1.10
Arch : x86_64
Vendor : openSUSE
Installed Size : 2.7 MiB
Installed : Yes
Status : up-to-date
Source package : kakoune-0.0+git.20170513-1.10.src

what should i do to get this to work?

add :pick-buffers to user-mode buffers

I've just found out about the very convenient pick-buffers command, which is mapped neither by default nor per suggested servings. I've hacked my kakoune-buffers config with

  map global buffers ':' '<esc>: buffer '           -docstring 'use :buffer ..'
  map global buffers 'f' '<esc>: pick-buffers<ret>' -docstring 'pick-buffers'

... (I think : makes more sense than f, whatever) but there are many other reasonable choices, like ? or ^ or , for handing control over to pick-buffers after using the mapped ,b = enter-user-mode buffers

Interactive editing of buffer list to close open files

Sometimes my buffer list gets a bit out of hand and needs to be trimmed down, but I'm not aware of any good ways of doing that. Something like opening a list of all the files currently open and allowing interactive editing such that after closing this buffer, the buffer list matches the list of files still present. Would something like this be a useful feature for this plugin?

Support $XDG_CONFIG_HOME in buffers-mode `c`

The c (config) option in the buffers user mode has the configuration file hardcoded as ~/.config/kak/kakrc. This is incorrect when $XDG_CONFIG_HOME is not set to ~/.config, thus opening the wrong file. Would it be possible to fix this?

buffer by index menu in buffer mode

Hey, thanks for the nice plugin! It's probably a very novice question, but I'm wondering how I can get the buffer by index menu in buffer mode as depicted in the readme picture:
image

Bad substitution when dash is used for sh

Hello,

First of all, thanks for this nice plugin.
I have use dash as my /bin/sh as dash is POSIX compliant but way faster than bash.
I seems however that this break the pick-buffer command. The list of buffer stay empty and the debug buffer tells me:

shell stedrr: <<<
sh: 16: Bad substitution
>>>

We may want to explicitely use #!/bin/bash or to use a POSIX compliant substitution instead.

I am writing this quickly, I will take more time to investigate when I can.

Charles

two questions about nomenclature and alias

First of all, congratulations on this extension! It is quite useful to me. Big thanks!

In case my list is medium size, I rather go faster if I go by number, after using info-buffers. So, I think in an alias for buffer-by-index n.

Since I'm a noob in kakoune, is it possible to have an alias with an argument?

Just a silly question. Why did you name info-buffers, and not buffers-info? My question is just curiosity, and because when I think of buffers, I usually start typing a letter b…

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.