Coder Social home page Coder Social logo

anhle199 / nvchad-nvterm Goto Github PK

View Code? Open in Web Editor NEW

This project forked from zbirenbaum/nvterm

0.0 0.0 0.0 39 KB

NvChad's Official Terminal Plugin ( Unmaintained but still usable and stable), wait for v3.0

License: GNU General Public License v3.0

Lua 100.00%

nvchad-nvterm's Introduction

NvChad terminal Plugin

Install

  • Simply install the plugin with lazy.nvim as you would for any other:
{
  "NvChad/nvterm",
  config = function ()
    require("nvterm").setup()
  end,
}

Configuration

  • Pass a table of configuration options to the plugin's .setup() function above.
  • Default configuration table
require("nvterm").setup({
  terminals = {
    shell = vim.o.shell,
    list = {},
    type_opts = {
      float = {
        relative = 'editor',
        row = 0.3,
        col = 0.25,
        width = 0.5,
        height = 0.4,
        border = "single",
      },
      horizontal = { location = "rightbelow", split_ratio = .3, },
      vertical = { location = "rightbelow", split_ratio = .5 },
    }
  },
  behavior = {
    autoclose_on_quit = {
      enabled = false,
      confirm = true,
    },
    close_on_exit = true,
    auto_insert = true,
  },
})

Functions

Use the below functions to map them for keybindings

Toggle

require("nvterm.terminal").toggle "float"
require("nvterm.terminal").toggle "horizontal"
require("nvterm.terminal").toggle "vertical"

Spawn new terminals

require("nvterm.terminal").new "horizontal"
require("nvterm.terminal").new "vertical"

Send commands to the terminal

    require("nvterm.terminal").send(" your command ", "horizontal|vertical|float") -- the 2nd argument i.e direction is optional
  • This function will first open a horizontal terminal and then run the node test.js command
  • Whenever you re-run this function, it'll just run that command in that horizontal terminal.
function()
      require("nvterm.terminal").send("node test.js", "horizontal")
end,

Additional Functionality

NvTerm provides an api for you to send commands to the terminal. You can create different ones for different filetypes like so:

require("nvterm").setup()

local terminal = require("nvterm.terminal")

local ft_cmds = {
  python = "python3 " .. vim.fn.expand('%'),
  ...
  <your commands here>
}
local toggle_modes = {'n', 't'}
local mappings = {
  { 'n', '<C-l>', function () terminal.send(ft_cmds[vim.bo.filetype]) end },
  { toggle_modes, '<A-h>', function () terminal.toggle('horizontal') end },
  { toggle_modes, '<A-v>', function () terminal.toggle('vertical') end },
  { toggle_modes, '<A-i>', function () terminal.toggle('float') end },
}
local opts = { noremap = true, silent = true }
for _, mapping in ipairs(mappings) do
  vim.keymap.set(mapping[1], mapping[2], mapping[3], opts)
end

terminal.send also takes a 'type' parameter, so you can choose what type of terminal to send the command to. By default, it runs the command in the last opened terminal, or a vertical one if none exist. terminal.send(ft_cmds[vim.bo.filetype], "float") will run the command in a floating terminal

nvchad-nvterm's People

Contributors

zbirenbaum avatar siduck avatar amirhhashemi avatar philolo1 avatar musjj avatar shaun-mathew avatar sitiom avatar

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.