wbthomason / packer.nvim

A use-package inspired plugin manager for Neovim. Uses native packages, supports Luarocks dependencies, written in Lua, allows for expressive config
MIT License
7.75k stars 261 forks source link

Keys lazy loading mappings not working #1078

Closed grezp closed 1 year ago

grezp commented 1 year ago

As the title suggest, lazy loading keys does not work as expected. If the map is defined inside a config table, then it works as expected. However, if the map is defined before or after packer startup, then the key mapping does not work.

Features: +acl +iconv +tui See ":help feature-compile"

system vimrc file: "$VIM/sysinit.vim" fall-back for $VIM: " /home/runner/work/neovim/neovim/build/nvim.AppDir/usr/share/nvim"

Run :checkhealth for more info

- `git --version`: `git version 2.31.1.621.g97eea85a0a`
- Operating system/version: `CentOS 7.2`
- Terminal name/version: `tmux 3.3`

### Steps to reproduce

<details>
<summary> minimal.lua with map defined before packer startup </summary>

vim.g.mapleader = ' '

vim.keymap.set( 'n', 'f', function() require('telescope.builtin').fd { hidden = false, -- don't show hidden files no_ignore = false, -- don't show ignore files sorting_strategy = 'ascending', find_command = { 'fd', '--type', 'f', '--strip-cwd-prefix' }, } end, {noremap = true} )

local install_path = vim.fn.stdpath'data'..'/site/pack/packer/opt/packer.nvim' if vim.fn.isdirectory(install_path) == 0 then os.execute('git clone https://github.com/wbthomason/packer.nvim '..install_path) vim.cmd'packadd packer.nvim' end

require'packer'.startup(function() use'wbthomason/packer.nvim' use{ 'nvim-telescope/telescope.nvim', requires = { 'nvim-lua/popup.nvim', 'nvim-lua/plenary.nvim', }, keys = { 'f', }, } end)

</details>

<details>
<summary> minimal.lua with map defined after packer startup </summary>

vim.g.mapleader = ' '

local install_path = vim.fn.stdpath'data'..'/site/pack/packer/opt/packer.nvim' if vim.fn.isdirectory(install_path) == 0 then os.execute('git clone https://github.com/wbthomason/packer.nvim '..install_path) vim.cmd'packadd packer.nvim' end

require'packer'.startup(function() use'wbthomason/packer.nvim' use{ 'nvim-telescope/telescope.nvim', requires = { 'nvim-lua/popup.nvim', 'nvim-lua/plenary.nvim', }, keys = { 'f', }, } end)

vim.keymap.set( 'n', 'f', function() require('telescope.builtin').fd { hidden = false, -- don't show hidden files no_ignore = false, -- don't show ignore files sorting_strategy = 'ascending', find_command = { 'fd', '--type', 'f', '--strip-cwd-prefix' }, } end, {noremap = true} )

</details>

Using `minimal.lua` with map defined before/after packer startup
1. `nvim -i NONE -nu minimal.lua`
2. `:PackerInstall & :PackerCompile`
3. `:qa`
4. Open nvim, then type: `<Space>f` 

Nothing happens. However `:Telescope` works...

<details>
<summary> minimal.lua with map defined in cofing </summary>

vim.g.mapleader = ' '

local install_path = vim.fn.stdpath'data'..'/site/pack/packer/opt/packer.nvim' if vim.fn.isdirectory(install_path) == 0 then os.execute('git clone https://github.com/wbthomason/packer.nvim '..install_path) vim.cmd'packadd packer.nvim' end

require'packer'.startup(function() use'wbthomason/packer.nvim' use{ 'nvim-telescope/telescope.nvim', requires = { 'nvim-lua/popup.nvim', 'nvim-lua/plenary.nvim', }, keys = { 'f', }, config = function() vim.keymap.set( 'n', 'f', function() require('telescope.builtin').fd { hidden = false, -- don't show hidden files no_ignore = false, -- don't show ignore files sorting_strategy = 'ascending', find_command = { 'fd', '--type', 'f', '--strip-cwd-prefix' }, } end, {noremap = true} ) end, } end)


</details>

Using `minimal.lua` with map defined in packer cofing and following the previous steps works fine.
musjj commented 1 year ago

It doesn't work because packer needs to remap the keys in order for lazy loading to work. Is there a reason why you can't load your keymap inside config = ...? If you don't want your keymap to be overwritten, then you can remove the keys inside the packer recipe and do one of the following instead: