feiyoug / commander.nvim Goto Github PK
View Code? Open in Web Editor NEWCreate and manage keybindings and commands in a more organized manner, and search them quickly through Telescope
License: MIT License
Create and manage keybindings and commands in a more organized manner, and search them quickly through Telescope
License: MIT License
Hi! I noticed that when I source my init.vim after changing something in the config the changed command will get appended to the list instead of replaced.
So for example, I have these set up
command_center.add({
{
description = "Show changed files",
cmd = "<CMD>Telescope changed_files<CR>",
},
{
description = "Edit init.vim",
cmd = "<CMD>:e $CONFIG/nvim/init.vim<CR>",
},
{
description = "Source init.vim",
cmd = "<CMD>:source $CONFIG/nvim/init.vim<CR>",
},
{
description = "Delete all buffers",
cmd = "<CMD>:%bd|e#<CR>",
},
})
if I change something, for example
command_center.add({
{
description = "I CHANGED THIS COMMAND",
cmd = "<CMD>Telescope changed_files<CR>",
},
{
description = "Edit init.vim",
cmd = "<CMD>:e $CONFIG/nvim/init.vim<CR>",
},
{
description = "Source init.vim",
cmd = "<CMD>:source $CONFIG/nvim/init.vim<CR>",
},
{
description = "Delete all buffers",
cmd = "<CMD>:%bd|e#<CR>",
},
})
command_center.nvim
breaking changes will be announced here
The following error is generated at Neovim startup after updating the plugin:
packer.nvim: Error running config for command-center.nvim: ...er\start\command-center.nvim/lua/command_center/init.lua:37: attempt to index local 'opts' (a number value)
Packer Config:
{
"gfeiyou/command-center.nvim",
config = function()
require("user.cc").config()
end,
requires = "nvim-telescope/telescope.nvim",
},
I am new to vim with lua so this may make no sense... Lets do simple example: saving buffer.
In normal
mode it is: :w<CR>
In insert
mode it is: <Esc>:w<CR>a
And I would for example map those both to <c-s>
Now (I think) there is no way of adding this to the command center.
There is an option to add different keybinding per mode you are in, so for example you can run a command just by s
in normal
but <c-s>
in insert
but in both cases the command is the same, there is no way of passing different command for each mode.
I think it would be great addition to be able to invoke different commands dependent the mode you are currently in. What do you think?
The workaround I am currently thinking is to write lua function that will decide inside which cmd to run and pass the function to the command center, but I think CC should natively support this ;)
It would be nice if we could also provide an autocmd
event in addition to keys
to trigger a command. For example you might have a formatting command that you want to bind on a key, be able to use from Commander and trigger on save.
Hi there!
Thank you for this awesome plugin. Working great for me!
Just wanted to make you aware of a minor typo in the configuration parameter: seperator
should be called separator
.
Hiya!
After looking at which-key, legendary and command_center, it is very clear to me, that your config format is the most elegant one.
If users can one day easily feed their which-key plugin from their command_center config, the most user friendly configuration of keymaps and command reminders has been achieved.
Seems like a good plan to me :)
we should write keymaps, or using : in vim, if taking a step back, we still have Telescope Commands to search commands, I don't think add another menu is meaningful.
Hello!
It seems that telescope is giving more importance to the matches on the command definition than in the command description, which could lead to some confusing situations like in the screenshot below:
I usually put my attention to the descriptions, so you can imagine my surprise when my exact match appeared 6th in the list, and all the items above it were not even closer.
Is this already configurable? Can it be made default?
Regards
Hi,
thank you for this great plugin.
What do you think about adding keybindings for non-commands (just key sequences).
For example i have this keybinding in my config:
utils.map('n', '<leader>a', '"ayiw')
Would be nice to also add this into the command center.
/edit: This would also enable multiple commands. For example
utils.map('n', '<F5>', ':CMake build<CR>:copen<CR>')
Hello, first: thanks for great plugin.
I have experienced following error:
Error executing Lua callback: ...vim/plugged/commander.nvim/lua/commander/model/Layer.lua:211: bad argument #1 to 'pairs' (table expected, got nil)
stack traceback:
[C]: in function 'pairs'
...vim/plugged/commander.nvim/lua/commander/model/Layer.lua:211: in function 'validate_cache'
...vim/plugged/commander.nvim/lua/commander/model/Layer.lua:92: in function 'get_commands'
...d/commander.nvim/lua/telescope/_extensions/commander.lua:20: in function <...d/commander.nvim/lua/telescope/_extensions/commander.lua:18>
...re/nvim/plugged/telescope.nvim/lua/telescope/command.lua:199: in function 'run_command'
...re/nvim/plugged/telescope.nvim/lua/telescope/command.lua:259: in function 'load_command'
...l/share/nvim/plugged/telescope.nvim/plugin/telescope.lua:108: in function <...l/share/nvim/plugged/telescope.nvim/plugin/telescope.lua:107>
When my config for commander was like this:
local command_center = require("commander")
command_center.add({{
desc = "get github url to current line",
cmd = '<CMD>lua require"gitlinker".get_buf_range_url()<CR>',
}})
(I have used this plugin named as command_center and didn't update variable name)
In order to make it work I have had to add any setup() call, this suffices:
command_center.setup({})
It only breaks when opening the commander telescope window but does not break using keys
associated with commands.
I am using these versions (latest at this moment)
silent! let g:plugs['telescope.nvim'].commit = '6213322ab56eb27356fdc09a5078e41e3ea7f3bc'
silent! let g:plugs['commander.nvim'].commit = 'cef3cf34dc478b2cc27e72fb592690cba718a091'
Is there a way to set the telescope width when using commander? I have the following in my telescope setup()
but it doesn't seem to be picked up by commander and instead it's set to minimum required
defaults = {
layout_config = {
horizontal = { height = 0.65, width=0.9 }
},
}
the order of command list display does not match insertion order
command_center.add({
{
description = 'history',
cmd = '<cmd>FzfLua command_history<cr>',
}, {
description = 'tab new',
cmd = '<cmd>tabnew<cr>',
}, {
description = 'tab close',
cmd = '<cmd>tabclose<cr>',
},
}, {
mode = command_center.mode.ADD_ONLY,
category = "command",
})
Each new nvim session I get a new order of my commands in the command center for ex
open nvim, open command center (:Telescope command_center)
close nvim, open nvim again, open command center
The order of the commands should be fixed and prefereably to the order in which the command_center.add() functions are called
I have two requests for command.nvim
:
CommanderItems
. When I reload the lua script that configures commander.nvim
, all the CommanderItems
appear twice. In this case, if we could eliminate the current Items, that repetition would not occur.Another minor thing: in the configuration section there's a missing command_center
tag.
Right now we have:
local telescope = require("telescope")
local command_center = require("command_center")
telescope.setup {
extensions = {
-- Below are default settings that can be overriden ...
-- Change what to show on telescope prompt and in which order
-- Currently support the following three components
-- Components may repeat
components = {
command_center.component.DESCRIPTION,
command_center.component.KEYBINDINGS,
command_center.component.COMMAND,
},
-- Change the seperator used to seperate each component
seperator = " ",
-- When set to false,
-- The description compoenent will be empty if it is not specified
auto_replace_desc_with_cmd = true,
}
}
telescope.load_extension("command_center")
But it should be:
local telescope = require("telescope")
local command_center = require("command_center")
telescope.setup {
extensions = {
command_center = {
-- Below are default settings that can be overriden ...
-- Change what to show on telescope prompt and in which order
-- Currently support the following three components
-- Components may repeat
components = {
command_center.component.DESCRIPTION,
command_center.component.KEYBINDINGS,
command_center.component.COMMAND,
},
-- Change the seperator used to seperate each component
seperator = " ",
-- When set to false,
-- The description compoenent will be empty if it is not specified
auto_replace_desc_with_cmd = true,
}
}
}
telescope.load_extension("command_center")
Mode | Norm | Ins | Cmd | Vis | Sel | Opr | Term | Lang |
Command |------|-----|-----|-----|-----|-----|------|------|
[nore]map | yes | - | - | yes | yes | yes | - | - |
n[nore]map | yes | - | - | - | - | - | - | - |
[nore]map! | - | yes | yes | - | - | - | - | - |
i[nore]map | - | yes | - | - | - | - | - | - |
c[nore]map | - | - | yes | - | - | - | - | - |
v[nore]map | - | - | - | yes | yes | - | - | - |
x[nore]map | - | - | - | yes | - | - | - | - |
s[nore]map | - | - | - | - | yes | - | - | - |
o[nore]map | - | - | - | - | - | yes | - | - |
t[nore]map | - | - | - | - | - | - | yes | - |
l[nore]map | - | yes | yes | - | - | - | - | yes |
Hi there, thanks for this amazing plugin. I would like to understand how to use themes. The config in the readme states one can use the command_center theme or any telescope or custom theme, but I don't understand where themes
in theme = themes..command_center
comes from. I also tried using a Telescope default theme, but because I lazy-load telescope, it becomes an chicken-or-egg problem where telescope is not yet loaded before I can require("telescope.themes")
(at least that's my understanding of the error I'm getting, I'm still relatively new to lua/telescope).
Can you please help shed some like on what I might possibly be doing wrong here? Thanks!
Hello,
I was wondering if it would be possible to call command_center with a filter set from the commands? Like Telescope command_center mode="normal"
to only show keybindings from normal mode.
Sometimes I want to see my keybindings, but I am only interested in the ones in normal mode, or insert mode, etc.
Hi, my config is partially broken after update to 31468fd.
Message I'm getting:
Invalid declaration of keys:
mode: expected one of { "n", "i", "c", "x", "v" }, got t
{ "t", "<C-\\>", {
noremap = true
} }
Part of config in question:
command_center.add({{
desc = "Toggle terminal",
cmd = "<CMD>ToggleTerm<CR>",
keys = {{"n", "<C-\\>", noremap}, {"t", "<C-\\>", noremap}}
}})
I have already tried to add t
to the list in following line, and it seams to solve te issue. Is there any reason why it should't be there?
https://github.com/FeiyouG/command_center.nvim/blob/81a2200d90bcb2477d2db7375fe7aa9b8a9007d5/lua/command_center/constants.lua#L33
Anyway thanks for the work on this plugin. Apart for occasional issues, I really do enjoy using it.
This looks really nice, but I have a suggestion:
With the (almost there) release of nvim 0.7, :h vim.keymap.set()
was introduced. Maybe this could take similar syntax, but with an additional description
field? This would make it both easier for the user (they do not need to change much about their configs, if they were to start using this plugin), and for the developer (they can just forward everything to vim.keymap.set())
Command palette in VSCode allows to quickly reuse the last action by putting last used actions above others. It would be nice to have an option in Commander to achieve similar behavior. For example by adding a "LAST_USED"
key to sort_by
option. If a command hasn't been ever used, sorting falls back to other values. If possible, it would also be convenient to track usage stats per working directory (so it is separated between projects).
<ENTER>
Alternatively, open Command Center without and bindings added and hit <ENTER>
.
E5108: Error executing lua ...mand_center/lua/telescope/_extensions/command_center.lua:151: attempt to index local 'selection' (a nil value)
stack traceback:
...mand_center/lua/telescope/_extensions/command_center.lua:151: in function 'run_replace_or_original'
...ite/pack/paqs/opt/telescope/lua/telescope/actions/mt.lua:65: in function 'key_func'
.../site/pack/paqs/opt/telescope/lua/telescope/mappings.lua:242: in function 'execute_keymap'
[string ":lua"]:1: in main chunk
Telescope + CC config:
telescope.setup {
extensions = {
command_center = {
-- Change what to show on telescope prompt and in which order
-- Currently support the following three components
-- Components may repeat
components = {
command_center.component.DESCRIPTION,
command_center.component.KEYBINDINGS,
-- command_center.component.COMMAND,
},
-- Change the separator used to separate each component
separator = " ",
-- When set to false,
-- The description compoenent will be empty if it is not specified
auto_replace_desc_with_cmd = false,
}
}
}
-- Plug Command Center into Telescope
telescope.load_extension('command_center')
I got this error while using 0.2 with example config on README.md
(the minimal one)
Error detected while processing /home/chau/.config/nvim/init.lua:
E5113: Error while calling lua chunk: /home/chau/.config/nvim/lua/command_palette.lua:1: module 'commander.nvim' not found:
no field package.preload['commander.nvim']
cache_loader: module commander.nvim not found
cache_loader_lib: module commander.nvim not found
no file './commander/nvim.lua'
no file '/usr/share/luajit-2.1/commander/nvim.lua'
no file '/usr/local/share/lua/5.1/commander/nvim.lua'
no file '/usr/local/share/lua/5.1/commander/nvim/init.lua'
no file '/usr/share/lua/5.1/commander/nvim.lua'
no file '/usr/share/lua/5.1/commander/nvim/init.lua'
no file './commander/nvim.so'
no file '/usr/local/lib/lua/5.1/commander/nvim.so'
no file '/usr/lib/lua/5.1/commander/nvim.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
no file './commander.so'
no file '/usr/local/lib/lua/5.1/commander.so'
no file '/usr/lib/lua/5.1/commander.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
stack traceback:
[C]: in function 'require'
/home/chau/.config/nvim/lua/command_palette.lua:1: in main chunk
[C]: in function 'require'
/home/chau/.config/nvim/init.lua:6: in main chunk
From the paths listed, I can see it looking for commander/nvim/init.lua
, so I changed it to just require('commander')
and it works.
One benefit I've found with switching to lazy.nvim is that it encourages grouping your config, keybindings, etc together with the plugin. I would love to be able to register commands in the same place.
I've found a way to do this that works, but figured I'd suggest this in case there's a shareable way to do it:
{
"gfeiyou/command-center.nvim",
lazy = true,
config = function()
local command_center = require("command_center")
local plugins = require("lazy").plugins()
for _, plugin in ipairs(plugins) do
if plugin.command_center then
-- only add for enabled plugins
-- copied from require('lazy.core.plugin').Spec:fix_disabled
local enabled = not (
plugin.enabled == false or (type(plugin.enabled) == "function" and not plugin.enabled())
)
if enabled then
command_center.add(plugin.command_center)
end
end
end
},
neovim config:
{
"FeiyouG/commander.nvim",
commit = "9febde3150e29915b72c2ee8da500d396c8dba03",
dependencies = {
"nvim-telescope/telescope.nvim",
},
keys = {
{
"<leader>fm",
"<cmd>Telescope commander<cr>",
desc = "telescope commander",
mode = "n",
},
},
config = function()
require("commander").setup({
-- Specify what components are shown in the prompt;
-- Order matters, and components may repeat
components = {
"DESC",
"KEYS",
"CMD",
"CAT",
},
-- Specify by what components the commands is sorted
-- Order does not matter
sort_by = {
"DESC",
"KEYS",
"CMD",
"CAT",
},
-- Change the separator used to separate each component
separator = " ",
-- When set to true,
-- The desc component will be populated with cmd if desc is empty or missing.
auto_replace_desc_with_cmd = true,
-- Default title of the prompt
prompt_title = "Commander",
-- enable integration
integration = {
telescope = {
enable = true,
},
lazy = {
enable = true,
-- set_plugin_name_as_cat = true,
},
},
})
end,
}
desc:
Telescope commander does not trigger the original command, but instead triggers the most recent command.
eg:
1 Telescope commander --> show telescope table --> choose command "Find Files"
2 Telescope commander --> Find Files
The bug originated from commit 2b048d5.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.