Skip to content

musjj/nvterm

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

34 Commits
 
 
 
 
 
 
 
 

Repository files navigation

NvChad terminal Plugin

Install

  • Simply install the plugin with packer as you would for any other:
use {
  "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,
  },
})
require("nvterm").setup({
  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 },
})

is equivalent to:

require("nvterm").setup({
  terminals = {
    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 },
    },
  },
  toggle {
    horizontal = "<A-s>",
  },
})

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"

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 () require("nvterm.terminal").send(ft_cmds[vim.bo.filetype]) end },
  { toggle_modes, '<A-h>', function () require("nvterm.terminal").toggle('horizontal') end },
  { toggle_modes, '<A-v>', function () require("nvterm.terminal").toggle('vertical') end },
  { toggle_modes, '<A-i>', function () require("nvterm.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

About

NvChad Official Terminal Plugin

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Lua 100.0%