Code Monkey home page Code Monkey logo

betterterm.nvim's Introduction

Better Term

๐Ÿ”ฅ The improved vscode terminal for Neovim written in pure lua ๐Ÿ”ฅ

recording_uAWNXgbd.mp4

Introduction

I like the concept of vscode terminal, if you are like me, this complement will be the best of your options. Normally I like to stay inside the editor, if I can make coffee in the editor, believe me I would do it. So having an integrated terminal is the most sensible option, however I tried for a long time to use the integrated terminal of neovim and I didn't get used to write so much to do what I wanted, so I tried and tried plugins, which were not for me, I just wanted something simple and usable, without so many complications. Then as other times I started to program and from that Saturday afternoon came out this plugin. I hope you enjoy it and make all your PR's.

By the way, it's called betterTerm, because it's the best for me. But for you it could very well suck.

recording_8to3c6ce.mp4

Requirements

  • Neovim (>= 0.10)

Install

use { 'CRAG666/betterTerm.nvim' }
{
  "CRAG666/betterTerm.nvim",
  opts = {
    position = "bot",
    size = 15,
  },
}

Quick start

Add the following line to your init.lua(If not use Lazy)

require('betterTerm').setup()

Features

  • Toggle term
  • Multi term
  • Close the terminal as always, no rare mapping were added, just use :q! to close
  • Send command
  • Select the terminal you need, with Neovim's native selector
  • If you want you could have HotReload easily
  • Bring the terminal focus to your current tab, no matter if the terminal is open in tab 100 and you need it in tab 1.

Functions

  • :lua require("config.betterTerm").open(num) - Show or hide a specific terminal(num: terminal id).
  • :lua require("config.betterTerm").send(cmd, num, press) - Send a command to a specific terminal(cmd: command, num: terminal id, press: Press clean and/or interrupt).
  • :lua require("config.betterTerm").select() -Select any terminal.Whether you want to show or hide(use: vim.ui.select as backend).

Recommended keymaps

No keymaps is assigned by default.It is better that you do it yourself, I will show my preferred keymaps:

local betterTerm = require('betterTerm')
-- toggle firts term
vim.keymap.set({"n", "t"}, "<C-;>", betterTerm.open, { desc = "Open terminal"})
-- Select term focus
vim.keymap.set({"n"}, "<leader>tt", betterTerm.select, { desc = "Select terminal"})
-- Create new term
local current = 2
vim.keymap.set(
    {"n"}, "<leader>tn",
    function()
        betterTerm.open(current)
        current = current + 1
    end,
    { desc = "New terminal"}
)

Options

  • prefix: It is used to create the names and a autocmd(default: Term_).
  • startInserted: Should the terminal be in insert mode when opened(default: true)
  • position: Integrated terminal position(for option :h opening-window, default: bot)
  • size: Size of the terminal window (default: 18)

Setup

-- this is a config example
require('betterTerm').setup {
  prefix = "CRAG_",
  startInserted = false,
  position = "bot",
  size = 25
}

Default values

require('betterTerm').setup {
  prefix = "Term_",
  startInserted = true,
  position = "bot",
  size = 18
}

Integration with code_runner.nvim, see for more info.

Contributing

Your help is needed to make this plugin the best of its kind, be free to contribute, criticize (don't be soft) or contribute ideas. All PR's are welcome.

โš ๏ธ Important!

If you have any ideas to improve this project, do not hesitate to make a request, if problems arise, try to solve them and publish them. Don't be so picky I did this in one afternoon

betterterm.nvim's People

Contributors

aarondill avatar crag666 avatar sam-hobson 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

Watchers

 avatar

betterterm.nvim's Issues

Integrating with code_runner.nvim gives error after first run

  • Description
    If the user runs a code with code_runner.nvim, it works first time but fails thereafter.
  • Steps to repro
  1. Setup hotkeys as described in https://github.com/CRAG666/betterTerm.nvim#integration-with-code_runnernvim
  2. Make a simple python script such as below:
print("hello")
  1. Run above code using the hotkey set up in step 1
  2. A terminal will open and "hello" is printed
  3. Type exit in terminal to kill the terminal
  4. Repeat step 3
  5. See error message:
E5108: Error executing lua: .../Local/nvim-data/lazy/betterTerm.nvim/lua/betterTerm.lua:204: E900: Invalid channel id
stack traceback:
        [C]: in function 'nvim_chan_send'
        .../Local/nvim-data/lazy/betterTerm.nvim/lua/betterTerm.lua:204: in function 'send'
        ...rs/choij/AppData/Local/nvim/after/plugin/code_runner.lua:17: in function <...rs/choij/AppData/Local/nvim/afte                                                                                                                                                      r/plugin/code_runner.lua:16>
  • Expected
    "hello" is printed
  • Environment
    Windows 11 22H2
    NVIM 0.8.3
    Windows Terminal

Integration with flatten.nvim

Would it be possible to have this plugin work with flatten.nvim? With flatten, I can use :term to open a terminal buffer, open a file with nvim {file}, and it will open in the first neovim instance rather than a nested one. Having this functionality with betterTerm would be awesome. Any help would be greatly appreciated! (I'm nowhere near good enough with neovim to figure this out alone)

This same functionality as flatten can be achieved with this plugin: https://github.com/samjwill/nvim-unception

feat: pass directory to open terminal in

this would allow the user to detect the project root and open a terminal automatically there.

require('betterTerm').open(1, { cwd = "<ROOT DIR>" })

this could be implemented by calling lcd DIR before term, after creating the window with <pos> new.

Use tabs to switch between terminals instead of select window

I think it would be very useful to have a tab system for the terminal as its quite more comfortable than using the select view every time you want to change terminal. I think most people use 1-3 terminals, and i think having a select system becomes preferable to a tab based system at 3-4 and up. Maybe something similar to rider or vscode
image
image

I am not sure how to handle the keybindings. At first i thought you could have a autocommand that changes the keybindings if youre focused on the terminal. For instance I use "J" and "K" to switch buffers normally, but if i focus the terminal, there could switch between buffers instead. The problem is that most of these keys are regular keys in the terminal so you cant quite do that, but you could do it with like and . Using autocommands means you dont have to dedicate keys just to switch terminal bufers

Terminal stays in background after :q

  • Description
    If the user opens a new terminal and :q to close the terminal, the terminal isn't removed completely

  • Steps to repro

  1. Press the hotkey mapped to require('betterTerm').select
  2. See "Empty betterTerm's" message
  3. Open a terminal by pressing a hotkey mapped to require('betterTerm').open
  4. Close the terminal by :q
  5. Press the hotkey mapped to require('betterTerm').select
  6. See the closed terminal is still available
  • Expected
    Closed terminal is completely removed from memory

  • Environment
    Windows 11 22H2
    NVIM v0.8.3
    Windows Terminal

Opening betterTerm in current window

I've been wondering if there's a way to not only have the default config open terminals in a new window located at the bottom of the screen, but also to have a custom keymap that opens a betterTerm instance in the currently focused window instead of at the bottom of the screen.

Toggling the terminal creates empty buffers

The terminal seems to create a new buffer every time you toggle it. I've tried with this minimal config (just betterterm and bufferline to showcase the buffers):

vim.cmd [[set runtimepath=$VIMRUNTIME]]
vim.cmd [[set packpath=/tmp/nvim/site]]
local package_root = '/tmp/nvim/site/pack'
local install_path = package_root .. '/packer/start/packer.nvim'
local function load_plugins()
  require('packer').startup {
    {
      'wbthomason/packer.nvim',
      {
        "CRAG666/betterTerm.nvim",
    	"akinsho/bufferline.nvim",
      },
    },
    config = {
      package_root = package_root,
      compile_path = install_path .. '/plugin/packer_compiled.lua',
      display = { non_interactive = true },
    },
  }
end
_G.load_config = function()
  require('betterTerm').setup()
	require("bufferline").setup{}
  --require('nvim-bufferline').setup()
end
if vim.fn.isdirectory(install_path) == 0 then
  print("Installing Telescope and dependencies.")
  vim.fn.system { 'git', 'clone', '--depth=1', 'https://github.com/wbthomason/packer.nvim', install_path }
end
load_plugins()
require('packer').sync()
vim.cmd [[autocmd User PackerComplete ++once echo "Ready!" | lua load_config()]]



-- betterTerminal
local betterTerm = require('betterTerm')
vim.keymap.set({"n", "t"}, "<C-t>", betterTerm.open, { desc = "Open terminal"})
vim.keymap.set({"n", "t"}, "<leader>tt", betterTerm.select, { desc = "Select terminal"})
local current = 2
vim.keymap.set(
    {"n", "t"}, "<leader>tn",
    function()
        betterTerm.open(current)
        current = current + 1

    end,
    { desc = "New terminal"}
)

The result is this:
image

really good plugin btw :)

Integration of code_runner

I want to set the window size to be bigger, but when I use code_runner plugin and the window popped out is still the default value of 18, which is so small.

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.