mikesmithgh / kitty-scrollback.nvim

😽 Open your Kitty scrollback buffer with Neovim. Ameowzing!
Apache License 2.0
460 stars 11 forks source link

The plugin does not respect `keymaps_enabled` option #152

Closed sahinakkaya closed 9 months ago

sahinakkaya commented 9 months ago

First of all, thank you very much for this plugin! I will be honest, I didn't get excited when I see the demos at the README page because why would I want to use a plugin to insert git add at the beginning of file names? There are tons of other tools better at doing this job. I know it is not just git stuff, you can do much more. But I could already edit my commands to some extent using <C-a>, <C-e>, <C-k>, <C-u> etc. So I didn't think there is much need for using a plugin. Why I am telling you this? Maybe you can introduce your plugin differently so that potential users won't see it as bloat. I don't know maybe it is just me. I just wanted to mention it.

Anyway, I was also not a big fan of the default pager (less) while viewing scrollback in kitty so I wanted to give this plugin a try. MAN! It is the best plugin ever created! The best thing about it is that I can't even tell if I am inside neovim or terminal while using it. Suddenly I realized that this is all I want to do in a terminal. Using it is so satisfactory that I unnecessarily open my scrollback buffer and go into insert mode to run my commands :D Really good job!

The least favorite part of my experience with this plugin is default keymappings. I want to use my own mappings so I tried to disable them with keymaps_enabled=false in setup function but they are still there. I don't think this is how it supposed to work.

20240106_23h55m52s_grim

As you can see, I've disabled the keymaps in setup function but they are still showing up on my whichkey window.

sahinakkaya commented 9 months ago

Looking at screenshot above, I realized the name of my config is same with the name of the plugin. Would that confuse neovim? I don't think it does because it should give me error telling it can't find setup but I am not sure.

Edit: Nope, it is impossible for nvim to confuse because I have a typo in the filename :D Here is my lazy spec with the same typo:

  {
    'mikesmithgh/kitty-scrollback.nvim',
    enabled = true,
    lazy = true,
    cmd = { 'KittyScrollbackGenerateKittens', 'KittyScrollbackCheckHealth' },
    event = { 'User KittyScrollbackLaunch' },
    -- version = '*', -- latest stable version, may have breaking changes if major version changed
    -- version = '^3.0.0', -- pin major version, include fixes and features that do not have breaking changes
    config = function()
      require("configs.util.kitty-scrolback")
    end,
  }
mikesmithgh commented 9 months ago

Hey @sahinakkaya thanks for the feedback! I agree the demo isn't really a real use case, I was just playing around. It would probably be better to put something more practical. Also, thanks for the kind words, it was a bit of a rollercoaster ride reading that πŸ˜‚.

So, the configuration of the plugin isn't that obvious at first and has some gotchas. I have a issue https://github.com/mikesmithgh/kitty-scrollback.nvim/issues/69 where I plan to improve this.

A configuration needs a name on the lhs and a function on the rhs. Something like this,

require('kitty-scrollback').setup({
  myconfig = function()
    return { keymaps_enabled = false }
  end,
})

Then in your kitty.conf, you need to specify the name from the lhs as the --config-name to your map or action_alias depending on which ones you want it applied to. After you do that, it still won't pick up though because by default kitty-scrollback.nvim runs nvim with the arguments --clean --noplugin -n which prevents nvim from loading any plugins. So, it won't load your lazy config. To get around this you can specify the argument --no-nvim-args and no arguments will be passed to nvim. (there is also --nvim args and anything after that will be passed to nvim if you want to pass some arguments of your own).

That would look like the following in your kitty.conf

action_alias kitty_scrollback_nvim kitten /Users/mike/gitrepos/kitty-scrollback.nvim/python/kitty_scrollback_nvim.py --config-name myconfig --no-nvim-args

There is also a special reserved configuration name global that with apply to all configurations allowing you to skip the step of passing the --config-name.

With global it would look like this

require('kitty-scrollback').setup({
  global = function()
    return { keymaps_enabled = false }
  end,
})
action_alias kitty_scrollback_nvim kitten /Users/mike/gitrepos/kitty-scrollback.nvim/python/kitty_scrollback_nvim.py --no-nvim-args

Hopefully that made sense. The either positive/negative of --no-nvim-args is now all of you plugins will load, which may or may not be desired.

My current solution to that is the following: kitty.conf

action_alias kitty_scrollback_nvim kitten /Users/mike/gitrepos/kitty-scrollback.nvim/python/kitty_scrollback_nvim.py --nvim-args -u /Users/mike/.config/nvim/lua/kitty-scrollback-nvim-kitten-config.lua

kitty-scrollback-nvim-kitten-config.lua

vim.g.mapleader = ' '
vim.opt.runtimepath:append(vim.fn.stdpath('data') .. '/lazy/kitty-scrollback.nvim')

require('kitty-scrollback').setup({
  -- your config here
})

You should also checkout the Advanced Configuration Wiki if you haven't yet. Specifically ksb_example_keymaps_custom and ksb_example_keymaps_disabled examples.

Let me know if this gets things working for you or if you have any other questions/comments. πŸ‘

mikesmithgh commented 9 months ago

@sahinakkaya also random question lol, what font are you using in your screenshot? looks nice

sahinakkaya commented 9 months ago

it was a bit of a rollercoaster ride reading that

lol

Then in your kitty.conf, you need to specify the name from the lhs as the --config-name to your map or action_alias depending on which ones you want it applied to

I am already using --no-nvim-args to load my config. This is also why the whichkey is available in above screenshot. I don't understand, why do I have adjust kitty part of my configuration in order to disable neovim keybindings? The keybindings I want to change are:

<Plug> Mapping Default Mapping Mode API Description
<Plug>(KsbVisualYankLine) <Leader>Y v Maps to "+Y
<Plug>(KsbVisualYank) <Leader>y v Maps to "+y
<Plug>(KsbNormalYankEnd) <Leader>Y n Maps to "+y$
<Plug>(KsbNormalYank) <Leader>y n Maps to "+y
<Plug>(KsbNormalYankLine) <Leader>yy n Maps to "+yy

Specifically ksb_example_keymaps_custom and ksb_example_keymaps_disabled examples.

Ok, I've looked at the examples. Looks like they are doing what I am trying to do. I will try all this and let you know if I manage to pull it off. It still doesn't make any sense why would I need to change kitty part of my config. Maybe after trying what you suggested, it will be clearer.

what font are you using in your screenshot?

It is FantasqueSansM Nerd Font Mono.

sahinakkaya commented 9 months ago

Maybe I can write my end goal here to clarify things for you. Basically I want to remove <Leader> from default mappings and use them without having to press <Leader> first. All the other mappings are fine but once I've done keymaps_enabled = false, I have to reassign them again I think.

sahinakkaya commented 9 months ago

I tried it with this config by combining two examples you mentioned to see if it works but it looks like new mappings are not registered. The default mappings are correctly removed:

require('kitty-scrollback').setup({
  global = function()
    vim.keymap.set({ 'v' }, 'sY', '<Plug>(KsbVisualYankLine)', {})
    vim.keymap.set({ 'v' }, 'sy', '<Plug>(KsbVisualYank)', {})
    vim.keymap.set({ 'n' }, 'sY', '<Plug>(KsbNormalYankEnd)', {})
    vim.keymap.set({ 'n' }, 'sy', '<Plug>(KsbNormalYank)', {})
    vim.keymap.set({ 'n' }, 'syy', '<Plug>(KsbYankLine)', {})

    vim.keymap.set({ 'n' }, 'q', '<Plug>(KsbCloseOrQuitAll)', {})
    vim.keymap.set({ 'n', 't', 'i' }, 'ZZ', '<Plug>(KsbQuitAll)', {})

    vim.keymap.set({ 'n' }, '<tab>', '<Plug>(KsbToggleFooter)', {})
    vim.keymap.set({ 'n', 'i' }, '<cr>', '<Plug>(KsbExecuteCmd)', {})
    vim.keymap.set({ 'n', 'i' }, '<c-v>', '<Plug>(KsbPasteCmd)', {})
    return {
      keymaps_enabled = false
    }
  end,
})
sahinakkaya commented 9 months ago

Ok, it looks like I don't need to both set new keymaps and do keymaps_enabled = false. Setting keymaps alone works just fine. After playing around with a little bit, I figured why you had to prefix the default mappings with <Leader>. Because when I use y alone, then I have to find another mapping to trigger the command editing window with the current yank :D This plugin is so well written that it comes with the most sensible defaults. Hats off!

mikesmithgh commented 9 months ago

Ok, it looks like I don't need to both set new keymaps and do keymaps_enabled = false. Setting keymaps alone works just fine. After playing around with a little bit, I figured why you had to prefix the default mappings with <Leader>. Because when I use y alone, then I have to find another mapping to trigger the command editing window with the current yank :D This plugin is so well written that it comes with the most sensible defaults. Hats off!

ah I see, so there is an option paste_window.yank_register which lets you change the register that opens the paste window. By default this is the unnamed register ''. I played around a bit and was able to reverse it so without the leader key copies to clipboard and quits, with the leader key it opens the paste window.

        global = function()
          vim.keymap.set({ 'v' }, 'Y', '<Plug>(KsbVisualYankLine)', {})
          vim.keymap.set({ 'v' }, 'y', '<Plug>(KsbVisualYank)', {})
          vim.keymap.set({ 'n' }, 'Y', '<Plug>(KsbNormalYankEnd)', {})
          vim.keymap.set({ 'n' }, 'y', '<Plug>(KsbNormalYank)', {})
          vim.keymap.set({ 'n' }, 'yy', '<Plug>(KsbYankLine)', {})

          vim.keymap.set({ 'v' }, '<leader>Y', '"aY', {})
          vim.keymap.set({ 'v' }, '<leader>y', '"ay', {})
          vim.keymap.set({ 'n' }, '<leader>Y', '"aY', {})
          vim.keymap.set({ 'n' }, '<leader>y', '"ay', {})
          vim.keymap.set({ 'n' }, '<leader>yy', '"ayy', {})
          return {
            paste_window = { yank_register = 'a' },
          }

I did notice some odd things when trying to use other registers, so I may have to polish this a bit.

sahinakkaya commented 9 months ago

Even better! Will try when I am home. Thanks!

ciscohack commented 9 months ago

First of all, thank you very much for this plugin! I will be honest, I didn't get excited when I saw the demos on the README page because why would I want to use a plugin to insert git add at the beginning of file names? There are tons of other tools better at doing this job. I know it is not just git stuff, you can do much more. But I could already edit my commands to some extent using <C-a>, <C-e>, <C-k>, <C-u> etc. So I didn't think there was much need for using a plugin. Why I am telling you this? Maybe you can introduce your plugin differently so that potential users won't see it as bloat. I don't know maybe it is just me. I just wanted to mention it.

Anyway, I was also not a big fan of the default pager (less) while viewing scrollback in kitty so I wanted to give this plugin a try. MAN! It is the best plugin ever created! The best thing about it is that I can't even tell if I am inside Neovim or terminal while using it. Suddenly I realized that this is all I want to do in a terminal. Using it is so satisfactory that I unnecessarily open my scrollback buffer and go into insert mode to run my commands :D Really good job!

The least favourite part of my experience with this plugin is default keymappings. I want to use my mappings so I tried to disable them with keymaps_enabled=false in the setup function but they are still there. I don't think this is how it is supposed to work.

20240106_23h55m52s_grim

As you can see, I've disabled the keymaps in the setup function but they are still showing up on my whichkey window.

@sahinakkaya Thanks for this post helps me to solve my issue. one more question what terminal color scheme you are using and font ... this is not Tokyo night. it looks nice to the eyes and clear... I would like to use it >>

Talking about this theme and font

image
sahinakkaya commented 9 months ago

Glad you liked it. The font is FantasqueSansM Nerd Font Mono and the theme is kanagawa. I am using kanagawa in both my terminal and neovim.

sahinakkaya commented 9 months ago

@ciscohack

ciscohack commented 9 months ago

@ciscohack

Thanks both screenshot is Kanagawa theme.

steakhutzeee commented 1 month ago

Ok, it looks like I don't need to both set new keymaps and do keymaps_enabled = false. Setting keymaps alone works just fine. After playing around with a little bit, I figured why you had to prefix the default mappings with <Leader>. Because when I use y alone, then I have to find another mapping to trigger the command editing window with the current yank :D This plugin is so well written that it comes with the most sensible defaults. Hats off!

ah I see, so there is an option paste_window.yank_register which lets you change the register that opens the paste window. By default this is the unnamed register ''. I played around a bit and was able to reverse it so without the leader key copies to clipboard and quits, with the leader key it opens the paste window.

        global = function()
          vim.keymap.set({ 'v' }, 'Y', '<Plug>(KsbVisualYankLine)', {})
          vim.keymap.set({ 'v' }, 'y', '<Plug>(KsbVisualYank)', {})
          vim.keymap.set({ 'n' }, 'Y', '<Plug>(KsbNormalYankEnd)', {})
          vim.keymap.set({ 'n' }, 'y', '<Plug>(KsbNormalYank)', {})
          vim.keymap.set({ 'n' }, 'yy', '<Plug>(KsbYankLine)', {})

          vim.keymap.set({ 'v' }, '<leader>Y', '"aY', {})
          vim.keymap.set({ 'v' }, '<leader>y', '"ay', {})
          vim.keymap.set({ 'n' }, '<leader>Y', '"aY', {})
          vim.keymap.set({ 'n' }, '<leader>y', '"ay', {})
          vim.keymap.set({ 'n' }, '<leader>yy', '"ayy', {})
          return {
            paste_window = { yank_register = 'a' },
          }

I did notice some odd things when trying to use other registers, so I may have to polish this a bit.

Hi, following this example I applied the following config:

local M = {
  'mikesmithgh/kitty-scrollback.nvim',
  enabled = true,
  lazy = true,
  cmd = { 'KittyScrollbackGenerateKittens', 'KittyScrollbackCheckHealth' },
  event = { 'User KittyScrollbackLaunch' },
  -- version = '*', -- latest stable version, may have breaking changes if major version changed
  version = '^5.0.0', -- pin major version, include fixes and features that do not have breaking changes

}

function M.config()
  require('kitty-scrollback').setup({
    global = function()
      vim.keymap.set({ 'v' }, 'Y', '<Plug>(KsbVisualYankLine)', {})
      vim.keymap.set({ 'v' }, 'y', '<Plug>(KsbVisualYank)', {})
      vim.keymap.set({ 'n' }, 'Y', '<Plug>(KsbNormalYankEnd)', {})
      vim.keymap.set({ 'n' }, 'y', '<Plug>(KsbNormalYank)', {})
      vim.keymap.set({ 'n' }, 'yy', '<Plug>(KsbNormalYankLine)', {})

      vim.keymap.set({ 'v' }, '<leader>Y', '"+Y', {})
      vim.keymap.set({ 'v' }, '<leader>y', '"+y', {})
      vim.keymap.set({ 'n' }, '<leader>Y', '"+Y', {})
      vim.keymap.set({ 'n' }, '<leader>y', '"a+y', {})
      vim.keymap.set({ 'n' }, '<leader>yy', '"+yy', {})
      -- return {
      --   paste_window = { yank_register = '+' },
      -- }
    end
  })
end

return M

while in my kitty.conf I have:

action_alias kitty_scrollback_nvim kitten $HOME/.local/share/nvim/lazy/kitty-scrollback.nvim/python/kitty_scrollback_nvim.py --no-nvim-args

but this actually does not work. If I open the scroolback and select text after I hit 'y' then the paste window is still shown. Like these mappings are not read. Ideas?