GithubHelp home page GithubHelp logo

lf.nvim's Introduction

Lf.nvim

This is a neovim plugin for the lf file manager. It is very similar to lf.vim, except for that this is written in Lua.

NOTE: This plugin uses toggleterm.nvim.

Installation

-- Sample configuration is supplied
use({
    "lmburns/lf.nvim",
    config = function()
        -- This feature will not work if the plugin is lazy-loaded
        vim.g.lf_netrw = 1

        require("lf").setup({
            escape_quit = false,
            border = "rounded",
        })

        vim.keymap.set("n", "<M-o>", "<Cmd>Lf<CR>")

        vim.api.nvim_create_autocmd({
            event = "User",
            pattern = "LfTermEnter",
            callback = function(a)
                vim.api.nvim_buf_set_keymap(a.buf, "t", "q", "q", {nowait = true})
            end,
        })
    end,
    requires = {"toggleterm.nvim"}
})

Setup/Configuration

local fn = vim.fn

-- Defaults
require("lf").setup({
  default_action = "drop", -- default action when `Lf` opens a file
  default_actions = { -- default action keybindings
    ["<C-t>"] = "tabedit",
    ["<C-x>"] = "split",
    ["<C-v>"] = "vsplit",
    ["<C-o>"] = "tab drop",
  },

  winblend = 10, -- psuedotransparency level
  dir = "", -- directory where `lf` starts ('gwd' is git-working-directory, ""/nil is CWD)
  direction = "float", -- window type: float horizontal vertical
  border = "rounded", -- border kind: single double shadow curved
  height = fn.float2nr(fn.round(0.75 * o.lines)), -- height of the *floating* window
  width = fn.float2nr(fn.round(0.75 * o.columns)), -- width of the *floating* window
  escape_quit = true, -- map escape to the quit command (so it doesn't go into a meta normal mode)
  focus_on_open = true, -- focus the current file when opening Lf (experimental)
  mappings = true, -- whether terminal buffer mapping is enabled
  tmux = false, -- tmux statusline can be disabled on opening of Lf
  default_file_manager = false, -- make lf default file manager
  disable_netrw_warning = true, -- don't display a message when opening a directory with `default_file_manager` as true
  highlights = { -- highlights passed to toggleterm
    Normal = {link = "Normal"},
    NormalFloat = {link = 'Normal'},
    FloatBorder = {guifg = "<VALUE>", guibg = "<VALUE>"},
  },

  -- Layout configurations
  layout_mapping = "<M-u>", -- resize window with this key
  views = { -- window dimensions to rotate through
    {width = 0.800, height = 0.800},
    {width = 0.600, height = 0.600},
    {width = 0.950, height = 0.950},
    {width = 0.500, height = 0.500, col = 0, row = 0},
    {width = 0.500, height = 0.500, col = 0, row = 0.5},
    {width = 0.500, height = 0.500, col = 0.5, row = 0},
    {width = 0.500, height = 0.500, col = 0.5, row = 0.5},
})

-- Equivalent
vim.keymap.set("n", "<M-o>", "<Cmd>lua require('lf').start()<CR>", {noremap = true})
vim.keymap.set("n", "<M-o>", "<Cmd>Lf<CR>", {noremap = true})

Another option is to use vim.keymap.set, which requires nvim 0.7.0 or higher. This doesn't require local variables and would allow customization of the program.

vim.keymap.set(
  "n",
  "<mapping>",
  function()
    require("lf").start(
      -- nil, -- this is the path to open Lf (nil means CWD)
              -- this argument is optional see `.start` below
      {
        -- Pass options (if any) that you would like
        dir = "", -- directory where `lf` starts ('gwd' is git-working-directory)
        direction = "float", -- window type: float horizontal vertical
        border = "double", -- border kind: single double shadow curved
        height = 0.80, -- height of the *floating* window
        width = 0.85, -- width of the *floating* window
        mappings = true, -- whether terminal buffer mapping is enabled
    })
  end,
  {noremap = true}
)

There is a command that does basically the exact same thing :Lf. This command takes one optional argument, which is a directory for lf to start in.

require("lf").start()

This function is able to take two arguments. The first is the path (string), and the second is configuration options (table). If there is only one argument and it is a table, this will be treated as configuration options and lf will open in the current directory. The following are all valid:

require('lf').start({border = "rounded"}) -- opens in CWD with rounded borders
require('lf').start(nil, {border = "rounded"}) -- opens in CWD with rounded borders

require('lf').start("~/.config") -- opens in `~/.config` with either `.setup()` or default options
require('lf').start("~/.config", nil) -- opens in `~/.config` with either `.setup()` or default options

require('lf').start(nil, nil) -- opens in CWD with either `.setup()` or default options
require('lf').start() -- opens in CWD with either `.setup()` or default options

require('lf').start("~/.config", {border = "rounded"}) -- opens in `~/.config` with rounded borders

Highlight Groups

The highlight groups that I know for sure work are the ones mentioned above (Normal, NormalFloat, FloatBorder). These are passed to toggleterm, and there is a plan in the future to make these Lf's own groups. For now, a one-shot way to change the color of the border of the terminal is the following:

:lua require("lf").start({highlights = {FloatBorder = {guifg = "#819C3B"}}})

Default Actions

These are various ways to open the wanted file(s). The process works by creating a Neovim mapping to send lf a command to manually open the file. The available commands are anything that can open a file in Vim. See tabpage.txt and windows.txt

Resizing Window

The configuration option layout_mapping is the key-mapping that will cycle through the window views. Once the last view is reached, the cycle is restarted.

Neovim 0.7.0

If you do not have the nightly version of nvim, then the mappings field can be set to false. Otherwise, a notification will be displayed saying that you are not allowed to use them.

require("lf").start({mappings = false})

Replacing Netrw

The only configurable environment variable is g:lf_netrw, which can be set to 1 or true to replace netrw. Also, note that this option will not work if lf is lazy-loaded.

Key mappings

The mappings that are listed in the setup call above are the default bindings.

  • <C-t> = tabedit
  • <C-x> = split
  • <C-v> = vsplit
  • <C-o> = tab drop (<r-o> is also suggested)
  • <M-u> = resize the floating window

Notes

The autocmd LfTermEnter is fired when the terminal buffer first opens

TODO

  • Set custom filetype
  • :LfToggle command
  • Save previous size when terminal is closed, so it is restored on open
  • Set Lualine to Lf title
  • Fix weird wrapping error that occurs every so often when moving down a list of files

lf.nvim's People

Contributors

0xrichardh avatar gilitos92 avatar lmburns avatar thalting avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

lf.nvim's Issues

Question: action without closing lf

Is there a way to perform an action while keeping the lf window open?

My use case is that I want to add the selected file to the arglist with Ctrl + a without having the lf window closed after.

Making lf floating window impossible to unfocuss

Hi, I have the following issue:
When my mouse hovers out of the lf terminal window, the mode changes to "normal mode terminal", thus I have to manually return to the "insert mode terminal".
Also, I mapped to exit lf and also mapped this keybinding to open lf inside neovim, for the sake of toggling lf; when my mouse hovers out of the lf window and I press to toggle off lf, I get an unpleasant error, since I'm not inside lf anymore.
Do you have an idea of how to make it impossible to unfocuss the lf's window? Or a tip to manage a way to toggle lf more consistently?
Thanks for this essential plugin.

module 'kimbox.palette' not found

What is kimbox.palette and how can i install it? Getting the following error after installing lf.nvim.

Failed to run `config` for lf.nvim

...haraf/AppData/Local/nvim/lua/user/plugins/lf-manager.lua:13: module 'kimbox.palette' not found:
	no field package.preload['kimbox.palette']
cache_loader: module kimbox.palette not found
cache_loader_lib: module kimbox.palette not found
	no file '.\kimbox\palette.lua'
	no file 'C:\Program Files\Neovim\bin\lua\kimbox\palette.lua'
	no file 'C:\Program Files\Neovim\bin\lua\kimbox\palette\init.lua'
	no file '.\kimbox\palette.dll'
	no file 'C:\Program Files\Neovim\bin\kimbox\palette.dll'
	no file 'C:\Program Files\Neovim\bin\loadall.dll'
	no file '.\kimbox.dll'
	no file 'C:\Program Files\Neovim\bin\kimbox.dll'
	no file 'C:\Program Files\Neovim\bin\loadall.dll'

# stacktrace:
  - lf-manager.lua:13 _in_ **config**

install/config using Lazy:

return {
        "lmburns/lf.nvim",
        event = "VeryLazy",
        dependencies = {"plenary.nvim", "toggleterm.nvim"},
        config = function()
          -- This feature will not work if the plugin is lazy-loaded
          vim.g.lf_netrw = 1

          require("lf").setup(
              {
                  escape_quit = false,
                  border = "rounded",
                  highlights = {FloatBorder = {guifg = require("kimbox.palette").colors.magenta}}
              }
          )

          vim.keymap.set("n", "<C-o>", ":Lf<CR>")
        end,
    }

conflict with kj mapping

Hi! Nice plugin! The only issue I have is that I use "kj" to enter normal mode, and it seems that because of this, there is a delay when I scroll upwards. similarly, typing kj causes a normal mode cursor to appear on the screen, and I have to enter insert mode again for the plugin to work.

Could there be an easy fix to this? I'm trying to work out a hack in the meantime

thank you

Select current file on open

Hey!
I had issues selecting current open files and made a fork with a dirty fix. Keep-Simple@eef4ca9

The idea was to pass the current file path to the lf directly at the start, instead of the directory

Open in current directory

Does this package have the ability to open in current directory ? When I run :cd / inside of neovim in command mode and then start Lf it does not actually open in the root directory, same for any other directory. Lf opens in the directory where current opened file lives.

Error: attempt to index upvalue 'fs' (a nil value)

The plugin seems to work fine, but I get the following error when I run :Lf:

Error executing vim.schedule lua callback: ...hare/nvim/site/pack/packer/start/lf.nvim/lua/lf/main.lua:265: attempt to index upvalue 'fs' (a nil value) stack traceback: ...hare/nvim/site/pack/packer/start/lf.nvim/lua/lf/main.lua:265: in function '' vim/_editor.lua: in function '' vim/_editor.lua: in function <vim/_editor.lua:0>

Feat: Add the ability to specify custom lf command

Hi,

Thanks for this super handy plugin!

It would be really useful to have a variable to specify a custom lf command so I can add whatever flag I want and do wonders with it. For example, I could add the -config flag to specify a minimal lfrc for lf.nvim, instead of using my original bloated config which includes so many things that I don't need for this plugin, or I can set it to use my lfrun script that integrates image previews and stuff like that.

default_file_manager: expected boolean, got nil

Hi and thanks for the plugin :)

One of the last 3 commits broke those functions:

M.lf.change_workspace = function()
    vim.g.is_floatterm = true
    local lf = require("lf")
    lf.start("~/workspaces", { default_action = "cd" })
end
M.lf.open_file = function()
    vim.g.is_floatterm = true
    local lf = require("lf", { default_action = "drop" })
    local res = lf.start()
end

The first command fails with:

E5108: Error executing lua .../dimfred/.local/share/nvim/lazy/vimpeccable/lua/vimp.lua:269: Error when executing map '<leader>po':
...dimfred/.local/share/nvim/lazy/lf.nvim/lua/lf/config.lua:65: default_file_manager: expected boolean, got nil
stack traceback:
        [C]: in function 'error'
        vim/shared.lua: in function 'validate'
        ...dimfred/.local/share/nvim/lazy/lf.nvim/lua/lf/config.lua:65: in function 'validate'
        ...dimfred/.local/share/nvim/lazy/lf.nvim/lua/lf/config.lua:101: in function 'override'
        ...e/dimfred/.local/share/nvim/lazy/lf.nvim/lua/lf/main.lua:70: in function 'new'
        /home/dimfred/.local/share/nvim/lazy/lf.nvim/lua/lf.lua:127: in function 'start'
        /home/dimfred/.config/nvim/lua/user/commands.lua:238: in function </home/dimfred/.config/nvim/lua/user/commands.lua:235>
        [C]: in function 'xpcall'
        .../dimfred/.local/share/nvim/lazy/vimpeccable/lua/vimp.lua:265: in function '_executeMap'
        [string ":lua"]:1: in main chunk

stack traceback:
        [C]: in function 'error'
        .../dimfred/.local/share/nvim/lazy/vimpeccable/lua/vimp.lua:269: in function '_executeMap'
        [string ":lua"]:1: in main chunk

The second command failes with:

E5108: Error executing lua .../dimfred/.local/share/nvim/lazy/vimpeccable/lua/vimp.lua:269: Error when executing map '<leader>pt':
...e/dimfred/.local/share/nvim/lazy/lf.nvim/lua/lf/main.lua:98: attempt to index field 'env' (a nil value)
stack traceback:
        ...e/dimfred/.local/share/nvim/lazy/lf.nvim/lua/lf/main.lua:98: in function '__create_term'
        ...e/dimfred/.local/share/nvim/lazy/lf.nvim/lua/lf/main.lua:83: in function 'new'
        /home/dimfred/.local/share/nvim/lazy/lf.nvim/lua/lf.lua:127: in function 'start'
        /home/dimfred/.config/nvim/lua/user/commands.lua:243: in function </home/dimfred/.config/nvim/lua/user/commands.lua:240>
        [C]: in function 'xpcall'
        .../dimfred/.local/share/nvim/lazy/vimpeccable/lua/vimp.lua:265: in function '_executeMap'
        [string ":lua"]:1: in main chunk

stack traceback:
        [C]: in function 'error'
        .../dimfred/.local/share/nvim/lazy/vimpeccable/lua/vimp.lua:269: in function '_executeMap'
        [string ":lua"]:1: in main chunk

Sry I am currently too lazy to debug, if something is broke, could you just tell me if I am using the commands correctly?
I reverted for now to: c30426d2fb70ac3ada0dbc07f204dffb3293e86b

Extra files are loaded if current filename contains whitespace

How to reproduce:

  1. touch 'file with space in its name.txt' other.txt

  2. nvim 'file with space in its name.txt'

  3. Start Lf in nvim, select other.txt and open it

  4. run :ls and there will be extra loaded files named file, with, space, in, its, name.txt

simplescreenrecorder-2024-01-05_18.58.51.mp4

Cannot open lf after renaming the currently open file

If you try renaming the currently open file then start lf, this error message shows up and you'll never be able to open lf afterwards unless you restart Neovim, even if you switch to the newly created file or to other buffers:

Error executing Lua callback: /home/mahdi/.local/share/nvim/lazy/lf.nvim/lua/lf/main.lua:299: wrong number of arguments to 'insert'           
stack traceback:
        [C]: in function 'insert'
        /home/mahdi/.local/share/nvim/lazy/lf.nvim/lua/lf/main.lua:299: in function '__set_argv'
        /home/mahdi/.local/share/nvim/lazy/lf.nvim/lua/lf/main.lua:75: in function 'new'
        /home/mahdi/.local/share/nvim/lazy/lf.nvim/lua/lf.lua:127: in function 'start'
        /home/mahdi/.local/share/nvim/lazy/lf.nvim/lua/lf.lua:37: in function </home/mahdi/.local/share/nvim/lazy/lf.nvim/lua/lf.lua:36>

Lfcd

Does this pluggin actually have the ability to change directory like lf.vim plugin does with its Lfcd command ?

Unexpected reset of arglist when opening file from LF

Issue Description:

Upon opening a file from LF, the arglist unexpectedly resets to only contain the opened file's name, disregarding any previous entries.

Steps to Reproduce:

  1. Create two test files, one.md and two.md, using the command:
touch one.md two.md
  1. Open one.md with Neovim:
nvim one.md
  1. Within Neovim, run the command :arg which outputs [one.md].

  2. Open LF using the :Lf command.

  3. With LF open, highlight two.md and press enter to open it.

  4. Now run :arg command again. This outputs [/home/mroavi/lf-bug/two.md], meaning the arglist has been reset to contain only two.md.

Problem:

This behavior of resetting the arglist to contain only the newly opened file from LF becomes problematic for users who rely on the arglist for various purposes. Ideally, the arglist should retain its previous entries and add any new file opened from LF, rather than completely resetting.

Background highlights broken

Commit 70c9b1d Causes LF to force a background color, even when using a transparent terminal. The fixes in #5 don't seem to work.

Relevant config (functional when using 3834294):

packer.nvim entry

{ "lmburns/lf.nvim",
    opt = true,
--    commit = "383429497292dd8a84271e74a81c6db6993ca7ab",
    config = function()
        require('plugins.config.lf')
        require('config.keymaps').map("lf")
    end
},

plugins.config.lf

local status_ok, lf = pcall(require, 'lf')
if not status_ok then
    return
end

lf.setup({
    mappings = false,
    winblend = 0,
    border = "rounded",
})

Error: executing Lua callback: /lf.nvim/lua/lf.lua:46: attempt to index field 'Lf' (a nil value)

Every now and then I get this error running :Lf command. Seems like some race condition at Neovim start:

Error executing Lua callback: ...cal/share/nvim/site/pack/packer/start/lf.nvim/lua/lf.lua:46: attempt to index field 'Lf' (a nil value)
stack traceback:
        ...cal/share/nvim/site/pack/packer/start/lf.nvim/lua/lf.lua:46: in function 'start'
        ...wall/.local/share/nvim/lazy/lf.nvim/plugin/lf.lua:16: in function <...wall/.local/share/nvim/lazy/lf.nvim/plugin/lf.lua:14>

Neovim version: 0.9.0
Package Manager: Lazy

'width' key must be a positive Integer

After recent changes width and height doesn't work with float values.

Getting this error from toggleterm:

.../toggleterm/ui.lua:362: 'width' key must be a positive Integer

Default config used from Readme:

-- Defaults
require("lf").setup({
  default_cmd = "lf", -- default `lf` command
  default_action = "edit", -- default action when `Lf` opens a file
  default_actions = { -- default action keybindings
    ["<C-t>"] = "tabedit",
    ["<C-x>"] = "split",
    ["<C-v>"] = "vsplit",
    ["<C-o>"] = "tab drop",
  },

  winblend = 10, -- psuedotransparency level
  dir = "", -- directory where `lf` starts ('gwd' is git-working-directory, ""/nil is CWD)
  direction = "float", -- window type: float horizontal vertical
  border = "double", -- border kind: single double shadow curved
  height = 0.80, -- height of the *floating* window ===========> Culprit
  width = 0.85, -- width of the *floating* window ===========> Culprit
  escape_quit = true, -- map escape to the quit command (so it doesn't go into a meta normal mode)
  focus_on_open = false, -- focus the current file when opening Lf (experimental)
  mappings = true, -- whether terminal buffer mapping is enabled
  tmux = false, -- tmux statusline can be disabled on opening of Lf
})

floating window does not respect default background color settings

My neovim has a transparent background and this work on all windows (including terminals) except for the LF floating term window. Here is an image

image

I've tried to set the highlights but it doesn't seem to change anything. The :ToggleTerm command opens a terminal split with a transparent background though so it doesn't seem that the problem is in toggleterm.nvim

Template configuration fails with lazy.nvim

I tried porting your configuration to the lazy.nvim package manager. This is what I got:

return {
  "lmburns/lf.nvim",
  dependencies = {
    {
      "akinsho/toggleterm.nvim",
      version = "*",
      config = true, -- Runs require("toggleterm").setup()
    },
  },
  config = function()
    vim.g.lf_netrw = 1
    require("lf").setup()
    vim.api.nvim_create_autocmd({
      event = "User",
      pattern = "LfTermEnter",
      callback = function(a)
        vim.api.nvim_buf_set_keymap(a.buf, "t", "q", "q", { nowait = true })
      end,
    })
  end,
}

The one bit that seems to be having issues is the autocmd. Without it, nvim launches fine (but lf doesn't seem to work). With it, nvim gives me the following error at launch:

Failed to run `config` for lf.nvim

/home/master/.config/nvim/lua/ben/plugins/lf.lua:13: Expected 2 arguments

# stacktrace:
  - lua/ben/plugins/lf.lua:13 _in_ **config**
  - lua/ben/lazy.lua:13
  - init.lua:2
Press ENTER or type command to continue

Error: attempt to index global 'g' (a nil value)

Hello, nice plugin.

When I start nvim with this installed using defaults I get

Error detected while processing /Users/adam/.local/share/nvim/site/pack/packer/start/lf.nvim/plugin/lf.lua:
E5113: Error while calling lua chunk: .../share/nvim/site/pack/packer/start/lf.nvim/plugin/lf.lua:18: attempt to index global 'g' (a nil value)
stack traceback:
.../share/nvim/site/pack/packer/start/lf.nvim/plugin/lf.lua:18: in main chunk

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.