Awesome
# ### /### /
/ /### / ############/
/ / ### / #########
/ ## ### # / #
/ ### ### ## / ##
## ## ## ### /### /## / ### /## ### /### ### /### /###
## ## ## ###/ #### / / ### ## ## / ### ###/ #### / ##/ ###/ /## /
## ## ## ## ###/ / ### ## ## / ### ## ###/ ## ###/ ###/
## ## ## ## ## ## ### ## ## ## ### ## ## ## ##
## ## ## ## ## ######## ## ## ######## ## ## ## ##
## ## ## ## ## ####### ## ## ####### ## ## ## ##
## # / ## ## ## ## # / ## ## ## ## ##
### / ## ## #### / ### / #### / ## ## ## ##
######/ ### ### ######/ ######/ ######/ ### ### ### ###
### ### ### ##### ### ##### ### ### ### ###
One terminal plugin to rule them all (eventually).
Introduction
This is my second take at a neovim plugin using the terminal (first was https://github.com/LoricAndre/fzterm.nvim). <br> I dropped the first one because it quickly became a mess and creating another one was faster than refactoring the first one.<br> This does not mean that I'll drop support for this one though, since it is well better designed (for reference, adding a new command now takes little knowledge of lua and only a little bit of tinkering, but with fzterm it was quite the fight).<br> Main difference you'll see with fzterm is the way it is configured and the fact that you can now open files in a new split/tab.
Requirements
The base framework is using neovim nightly features, so you need to be using the latest nightly release.<br>
Most commands require fzf. files
and rg
require ripgrep, ag
requires the silver searcher andranger
requires, well, ranger. git
uses lazygit and gitui
uses gitui.<br>
Credits to all the devs of those projects :heart:.
Usage
Install the plugin using your favorite package manager (or whatever way you deem best). Then, all you have to do is type :OneTerm <Tab>
and browse through the commands.
Using the term
command also requires you to have hidden
set : set hidden
Implemented commands
- empty : default fzf command, defined by
$FZF_DEFAULT_COMMAND
files
: list files using ripgrepgit_files
: list files usinggit ls-files
files_or_git_files
: list files using either method above based on the presence of a.git
dir in nvim's currentpwd
.buffers
: list vim bufferslines
: show lines of all active buffersblines
: show lines from current bufferag
: find lines in files using the silver searcherrg
: find lines in files using ripgrepcommits
: browse git log (nothing special happens on exit)bcommits
: same ascommits
, but restrict to current file. The preview panel will show the whole diff for each commit, but the current file is at the top of the diff.references
: browse (and jump to) references of the keyword under the cursor using neovim's built-in lspsymbols
: browse (and jump to) lsp symbols in the current filews_symbols
: same assymbols
but for the entire workspacegit
: opens lazygit (needs lazygit installed)gitui
: open gitui and push changes on exit (gitui's push feature isn't working for me, I'd love feedback on this)ranger
: open ranger and edit selected filemake
: list makefile targets and run selectedyanks
: list yank history and paste it at the cursor on<CR>
or<C-p>
, yank to+
register on<C-y>
branches
: list git branches and switch to selectedterm
: open a floating terminal. When calling the command again, the same terminal instance will reopen unless you exit the shell.oldfiles
: list previously opened fileshistory
: list command history and run selected commandsnippets
: list available snippets (uses UltiSnips) and expand selection. Currently, this won't expand the snippet if there are other possibilities (for example,elif
won't be expanded becauseif
exists).sessions
: list sessions inoneterm_sessions_path
and sources the selected one.
Configuration
OneTerm's window is configurable using the following variables. You can set them using either let g:var
from vimscript or vim.g.var
from lua.
oneterm_width
andoneterm_height
set the width and height ratios. These should be set to numbers between 0 (for no window) and 1 (window fills the editor)oneterm_x_pos
andoneterm_y_pos
set the position of the center of the window, these are ratios and should be set to numbers between 0 and 1, (0, 0) meaning top right and (1, 1) bottom leftoneterm_yank
needs to be set to true to be able to use the yank command !oneterm_ignore
is an array of gitignore-type patternsoneterm_fzf_prompt
is the prompt used by fzf in onetermoneterm_options
is a dictionary/table of window options, see:help nvim_open_win
for detailsoneterm_sessions_path
should be the path where you store your session files, for example using fzf-session.vim
Using the framework
Each of the commands calls the same lua function, accessible using lua require('oneterm').main(arg_object)
.<br>
arg_object
should be an object, with the following keys :
cmd
(required) : this can be either a string, representing a shell command"git ls-files"
for example or a lua function, likefunction() return vim.api.nvim_exec("ls", true) end
preview
(optional, defaults to"bat --color=always -n {}"
) : this is a string containing the--preview
argument for fzf (seeman fzf
for more details)matcher
(optional, defaults tofzf
with args) : this can be set to replace fzf with any other matcher, orxargs echo
to just use the result ofcmd
delimiter
(optional, defaults to awk-style) : this can be used to set fzf's field delimiter (seeman fzf
) for detailsoutput_format
(optional, defaults to"{}"
)this is a string, using fzf-style argument-replacementmaps
(optional). This should be a table of tables, following the format from:h nvim_set_keymap
. The mappings will be set on the spawned buffer.
The way this function works is very simple : if cmd
is a function, it is ran and writes its output to "/tmp/onetermcmd" (or windows' temp dir), then opens a terminal reading from this file and piping it to matcher
(after having built it) then writing the output to "/tmp/oneterm". If cmd
is a string, the terminal is opened, running the command inside and piping to the rest of the treatment.
Check init.lua for examples
TODO
- Add new commands :
- default for use with
$FZF_DEFAULT_COMMAND
- lines for lines in all loaded buffers
- blines for lines in current buffer
- branches for git branches (and checkout)
- Yanks
- Makefile targets
- Add anything you might need here
- default for use with
- Add a way to ignore files, e.g. for
files
,rg
andag
- Add configuration for prompt & other visual aspects, including border in latest version.