GithubHelp home page GithubHelp logo

volskaya / windovigation.nvim Goto Github PK

View Code? Open in Web Editor NEW
42.0 42.0 1.0 47 KB

Nvim plugin that scopes buffers to window split, like VScode and Evil Emacs, instead of a global buffer list.

License: Apache License 2.0

Lua 100.00%

windovigation.nvim's People

Contributors

volskaya 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

Watchers

 avatar

Forkers

myypo

windovigation.nvim's Issues

Unexpected behavior for terminal/ssh buffers

When I focus a terminal buffer, or a buffer opened via ssh (e.g. nvim scp://user@hostname), for a second time after it's already been read (whether from the same window, different window, different tab, etc.) I receive the warning from the associated line in utils.lua:

if event.file:sub(1, 1) ~= "/" then
vim.notify("Event file needs an absolute path. " .. event.file, vim.log.levels.WARN)
end

Here's an example output of vim.fn.expand('%') for these situations:
term://~/.config/nvim//185059:/usr/bin/zsh
scp://user@hostname/.bashrc

Some relevant information is at :h terminal-start and :h default-autocmds and :h netrw. (edit: my suggestion is that these type of files, and probably ftp files, should maybe count as absolute paths here)

Another terminal/ssh buffer issue comes up due to, I believe, the layout.handle_layout_change() function and the utils.maybe_close_buffer_for_file() function. Suppose you have a split window with a terminal/ssh buffer open (the only window that has that buffer), and you close that window. Then open a split window again, then open that same buffer, and finally close that window again. (imagine toggling a show/hide of that terminal buffer in a split window like the bottom-panel in VS Code).

On that second window-close command, this condition evaluates to true and deletes the terminal/ssh buffer:

if not history.is_file_scoped(file) then
didSucceed = pcall(vim.api.nvim_buf_delete, buf, { force = true })
end

This evaluation isn't unique to terminal/ssh buffers. But if you were to reopen the terminal buffer expecting to see your previous work in that terminal, it would be gone, unlike a regular buffer, where so long as you saved your work before deletion, your work is still preserved. And since working over ssh isn't always zippy, re-opening a file over ssh is noticeably slower than browsing to it via the bufist.

(worth noting that even when a normal buffer is removed from the buffer list in this instance, this may be an issue for people who use e.g. Telescope buffers to navigate or aren't expecting a BufDelete event for whatever reason)

Would adding a separate handler for the TermOpen event or something similar help with these two issues (the warning and the terminal buffer deletion)? I'm hacking my way around it by adding a condition to ignore the file deletion if its buftype == terminal in my fork, but I assume that will introduce unintended behavior at some point. Not sure what to do for files opened over ssh.

Hope this wasn't too verbose. I'm assuming this same issue applies to files over ftp. For what it's worth, my personal workflow doesn't actually use windovigation's commands in windows/tabs with terminal buffers. This is a great plugin! Thanks for sharing it.

Tested with this lazy.nvim config:

Click to expand
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not vim.loop.fs_stat(lazypath) then
  vim.fn.system({
    "git",
    "clone",
    "--filter=blob:none",
    "https://github.com/folke/lazy.nvim.git",
    "--branch=stable", -- latest stable release
    lazypath,
  })
end
vim.opt.rtp:prepend(lazypath)

require("lazy").setup({
  "nvim-lua/plenary.nvim",
  {
    "nvim-telescope/telescope.nvim",
    lazy = false,
    config = true,
    keys = {
      {
        "<M-b>",
        function()
          require("telescope.builtin").buffers()
        end,
        desc = "Telescope: buffers",
      },
      {
        "<M-f>",
        function()
          require("telescope.builtin").find_files()
        end,
        desc = "Telescope: Find Files (cwd)",
      },
    },
  },
  {
    "volskaya/windovigation.nvim",
    lazy = false,
    config = true,
    keys = {
      {
        "<BS>",
        function()
          require("windovigation.actions").move_to_previous_file()
        end,
        desc = "WinNav - Prev",
      },
      {
        "<Del>",
        function()
          require("windovigation.actions").move_to_next_file()
        end,
        desc = "WinNav - Next",
      },
    },
  },
}, {})

vim.keymap.set("n", "<C-q>", "<cmd>qa<CR>", { noremap = true, silent = true })
vim.keymap.set("n", "<M-down>", "<c-w>j", { desc = "Move to window below" })
vim.keymap.set("n", "<M-up>", "<c-w>k", { desc = "Move to window above" })
vim.keymap.set("n", "<M-left>", "<c-w>h", { desc = "Move to window left" })
vim.keymap.set("n", "<M-right>", "<c-w>l", { desc = "Move to window right" })

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.