R-nvim / R.nvim

Neovim plugin to edit R files
GNU General Public License v3.0
128 stars 15 forks source link

Using kitty terminal #115

Closed PMassicotte closed 2 months ago

PMassicotte commented 2 months ago

Quick question.

I am trying to use kitty by doing this in my config:

external_term = "kitty"

The thing is this opening an external terminal (i.e., another terminal outside nvim, instead of a new window within nvim). Is this expected behavior? Can I use kitty within neovim?

PMassicotte commented 2 months ago

Also, then I use external_term = "kitty" I am getting this message:

image

And opens tmux even if kitty is specified.

jalvesaq commented 2 months ago

The goal is to have separate windows, which can be freely positioned, for example, on different monitors (if you have a dual monitor setup), or partially overlapping each other (if you have only one small monitor).

You can't use kitty within nvim because kitty is a graphical application, not a text one.

You can suppress the warning with the following config option:

silent_term = true
PMassicotte commented 2 months ago

Thank you for the explanation!

samtrek commented 2 months ago

I am using kitty and I can share my kitty config if you want. Although I am not using an external term but it is possible. I view data tables in a separate tab witthin kitty although I could also view it in a new window if I so desire

samtrek commented 2 months ago

I mostly run kitty as a server, and use only one instance of kitty, from this instance, I can then launch new tabs, split the tabs and so on. I have something like this in my sway config

set $term kitty -1 --instance-group "kitty_sock" -o allow_remote_control=yes --listen-on unix:/tmp/kitty_sock

And then have something like this for viewing datatables

vim.g["R_csv_app"] = "kitten @ --to unix:/tmp/kitty_sock launch --type tab sc-im" so I believe that the above can be modified as an external_app to something like this vim.g["R_external_app"] = "kitten @ --to unix:/tmp/kitty_sock launch --type window"

their are many options that can be considered, you can use tab, window, split the current window and so on, you can get more info from

https://sw.kovidgoyal.net/kitty/remote-control/#remote-control-via-a-socket

PMassicotte commented 2 months ago

vim.g["R_external_app"] = "kitten @ --to unix:/tmp/kitty_sock launch --type window"

do you mean external_term?

samtrek commented 2 months ago

vim.g["R_external_app"] = "kitten @ --to unix:/tmp/kitty_sock launch --type window"

do you mean external_term?

Yes it should have been vim.g["R_external_term"]

PMassicotte commented 2 months ago

Should I define set $term kitty -1 --instance-group "kitty_sock" -o allow_remote_control=yes --listen-on unix:/tmp/kitty_sock in my zshrc file?

samtrek commented 2 months ago

The $term is mainly defined in sway I don't know the window manager you are using mine is sway it has similar configs to i3, in gnome, KDE and other none tilled window manager I have no clue, and then subsequently the $term is called when a kitty terminal is to be launched.

for example to launch a new terminal window from sway I simply use

bindsym $mod+Shift+Return exec $term

where $term is the initial defined variable in sway, other window manager may have different methods of achieving this.

PMassicotte commented 2 months ago

Cool this is almost working out. The only thing is that the terminal is opening horizontally instead of vertically on the right as before.

samtrek commented 2 months ago

Did you split your kitty terminal, by creating windows within it?, if yes, you may have to change the default r.nvim layout configs by reducing the length at which it changes to horizontal layout.

PMassicotte commented 2 months ago

I have tried

kitten @ --to unix:/tmp/kitty_sock launch --type window --location=after kitten @ --to unix:/tmp/kitty_sock launch --type window --location=vsplit kitten @ --to unix:/tmp/kitty_sock launch --type window --location=hsplit

samtrek commented 2 months ago

seems kitty has a default layout scheme, below is lifted from the kitty page which can be changed with ctrl+shift+l

https://sw.kovidgoyal.net/kitty/overview/

By default, all layouts are enabled and you can switch between layouts using the [ctrl+shift+l](https://                        sw.kovidgoyal.net/  kitty/conf/#shortcut-kitty.Next-layout) key combination. You can also create shortcuts to select particular layouts, and choose which layouts you want to enable, see [Layout management](https://sw.kovidgoyal.net/kitty/conf/#conf-kitty-shortcuts-layout) for examples. The first layout listed in [enabled_layouts](https://sw.kovidgoyal.net/kitty/conf/#opt-kitty.enabled_layouts) becomes the default layout.
samtrek commented 2 months ago

To make it permanent you can specify the default layout in your kitty.conf, because I am not sure if the changes made through ctrl+shift+L is permanent or not.

the layout scheme and how they can be enabled is found in the link below. https://sw.kovidgoyal.net/kitty/layouts/

samtrek commented 2 months ago

It is possible to set the layout you want, however, you have to include the layout you want when you run the initial server/socket set $term kitty -1 --instance-group "kitty_sock" -o allow_remote_control=yes --listen-on unix:/tmp/kitty_sock -o enable_layout=splits"

or include it in your kitty.conf as layout splits

you may have to kill all active kitty terminals before the new layout can be used.

then you can then use the following to state either horizontal split or vertical split

kitten @ --to unix:/tmp/kitty_sock launch --type window --location hsplit kitten @ --to unix:/tmp/kitty_sock launch --type window --location vsplit

jalvesaq commented 2 months ago

"You can change [...] get text from one window and send text to another, etc."

This means that it would be possible to run R in an external terminal (kitty) without Tmux.

samtrek commented 2 months ago

yes I have done this before without any kind of problem

PMassicotte commented 2 months ago

Got it working. I was playing with this because I could not use all the vim motion in the built-in terminal (running radian). For example, when I am in normal mode, I can not use ciw or other derivative. It gives me:

image

Running radian in kitty allows me to do it.

PMassicotte commented 3 weeks ago

Reviving this older discussion.

How would you close the terminal (kitty in my case) on :qa? If I use localleader rq it closes the terminal. It is not working if I quit my editor window.

image

I would like to close the terminal automatically when I :qa. Possible?

jalvesaq commented 3 weeks ago

There is an option for this: :h auto_quit.

PMassicotte commented 3 weeks ago

Excellent! Thank you

PMassicotte commented 3 weeks ago

Just pasting my config here, so it is findable by others (in case someone else needs it):

In my R.nvim config I have this:

external_term = "/usr/bin/kitten @ --to unix:/tmp/kitty_sock launch --type window --location=vsplit",

In my i3 config I have this to start kitty and make it listen on a socket:

bindsym $mod+Return exec kitty -1 --instance-group "kitty_sock" -o allow_remote_control=yes --listen-on unix:/tmp/kitty_sock