GithubHelp home page GithubHelp logo

folke / twilight.nvim Goto Github PK

View Code? Open in Web Editor NEW
1.1K 6.0 18.0 48 KB

๐ŸŒ… Twilight is a Lua plugin for Neovim 0.5 that dims inactive portions of the code you're editing using TreeSitter.

License: Apache License 2.0

Lua 97.37% Vim Script 2.63%
neovim neovim-plugin treesitter tree-sitter

twilight.nvim's Introduction

๐ŸŒ… Twilight

Twilight is a Lua plugin for Neovim 0.5 that dims inactive portions of the code you're editing.

The plugin was heavily inspired by Limelight, but uses TreeSitter for better dimming.

Pairs well with zen-mode.

image

โšก๏ธ Requirements

  • Neovim >= 0.5.0

๐Ÿ“ฆ Installation

Install the plugin with your preferred package manager:

-- Lua
{
  "folke/twilight.nvim",
  opts = {
    -- your configuration comes here
    -- or leave it empty to use the default settings
    -- refer to the configuration section below
  }
}

โš™๏ธ Configuration

Twilight comes with the following defaults:

{
  dimming = {
    alpha = 0.25, -- amount of dimming
    -- we try to get the foreground from the highlight groups or fallback color
    color = { "Normal", "#ffffff" },
    term_bg = "#000000", -- if guibg=NONE, this will be used to calculate text color
    inactive = false, -- when true, other windows will be fully dimmed (unless they contain the same buffer)
  },
  context = 10, -- amount of lines we will try to show around the current line
  treesitter = true, -- use treesitter when available for the filetype
  -- treesitter is used to automatically expand the visible text,
  -- but you can further control the types of nodes that should always be fully expanded
  expand = { -- for treesitter, we we always try to expand to the top-most ancestor with these types
    "function",
    "method",
    "table",
    "if_statement",
  },
  exclude = {}, -- exclude these filetypes
}

๐Ÿš€ Usage

You can manually trigger Twilight using the commands:

  • Twilight: toggle twilight
  • TwilightEnable: enable twilight
  • TwilightDisable: disable twilight

๐Ÿง˜ Zen Mode Integration

If you have zen-mode installed, then Twilight is activated automatically. Refer to the Zen Mode documentation to disable.

twilight.nvim's People

Contributors

benstockil avatar danielhvs avatar folke avatar github-actions[bot] avatar max397574 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  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

twilight.nvim's Issues

Not dimming anything

Hi,
it seems that twilight is not dimming the text that I'm not editing. I have the impression that the plugin is not doing anything (see screenshot).

INFO:
neovim: v0.5.1
plugins:

Plug 'folke/zen-mode.nvim'
Plug 'folke/twilight.nvim'
Plug 'neovim/nvim-lspconfig'
Plug 'nvim-treesitter/nvim-treesitter', {'do': ':TSUpdate'}

The command :PlugInstall has been runned succesfully and neovim was restarted.
Zen-mode and twilight are configure as follow:
image

I'm trying to edit a bash script while being in zen-mode:

image

what am I doing wrong?

Auto dimming; not dimming other split/buffers

Is there a way to have twilight auto activate?

Is there away to make it so twilight does not dim inactive buffers / splits at all?

I have the value set to false but it leaves the area I last was highlighted.

bug: weird highlighting behaviour

Did you check docs and existing issues?

  • I have read all the twilight.nvim docs
  • I have searched the existing issues of twilight.nvim
  • I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

v0.9.0-dev-e30cc8b

Operating system/version

MacOS 13.2.1

Describe the bug

Whenever I enable Twilight, this is how my editor looks:

Screenshot 2023-04-12 at 10 13 42

As you can see, it dims many of the tokens outside of the focus area, but a lot stay as-is.

Here's a list of plugins I'm currently using:

  impatient-nvim
  gruvbox-flat-nvim
  which-key-nvim
  lualine-nvim
  nvim-web-devicons
  fidget-nvim
  telescope-nvim
  telescope-zf-native-nvim
  telescope-all-recent
  sqlite-lua
  neoscroll-nvim
  dressing-nvim
  nvim-notify
  gitsigns-nvim
  cmd-palette
  telescope-hop
  zen-mode-nvim
  twilight-nvim

It doesn't appear to be a problem with the colorscheme, as switching from gruvbox-flat to gruvbox-material shows the extract same thing happening (but with different colours, obviously):

Screenshot 2023-04-12 at 11 05 37

Steps To Reproduce

n/a

Expected Behavior

n/a

Repro

n/a

Better Dimming with Markdown Files?

I am loving using Twilight, but I have noticed that in markdown files Twilight does not proper see the see the beginning or end of each block. For example here you can see it highlight two blocks instead of just one. Is there anything I can do to get it to only highlight one block?

laggy when using with zenmode

Using twilight outside zenmode works great, while in zenmode it's almost unable to use (I don't know whether it is it my potato computer's problem, really hope somebody can help because I really like this plugin (also zenmode))

Error on running twilight

I really enjoy using zen-mode with this plugin when writing markdown files. But after a recent update, I got the following error:

Error detected while processing WinScrolled Autocommands for "*":
E5108: Error executing lua /usr/share/nvim/runtime/lua/vim/treesitter/language.lua:25: no parser for 'markdown' language, see :help treesitter-parsers

By the way, I'm running nightly neovim.

[Feature Request] Way to not dim comment above function

my setup for twilight is pretty basic, just highlight the current function

require("twilight").setup {
	expand = {
		"function_definition",
	},
}

I would like to not dim the comment above my functions
image

is this achievable in some way? if not, perhaps a neighbour match, when I matches a node from 'expand', it tries to expand more with a 'expand_neighbour', or a dim blacklist, I wouldn't mind if my comments were not dimmed.

Background is black when using guibg=NONE

This is how it looks without guibg=NONE:
image
and here's how it looks with it:
image

(I use this option to set vim's bg to my terminal's, in case there's a better way of doing this)

Match first node for expand options.

Current Behaviour:
Currently, when you have nodes to expand to in your twilight config, twilight will expand to whatever the outer most one is. That is, say I have my expand to expand to conditionals, loops, methods, and classes, then I have some code that looks like this.

class Foo:
    def bar():
        if condition:
            var = expression
            for i in collection:
                # do things

Say I have my cursor on line 4, it will highlight every single line of code because it matches to the outermost node, that being the class.

Desired Behaviour:
I'd like it to match to innermost scope/node and no further. That is, if we have the above example, I'd want it to highlight only the conditional. If I had my cursor on line 6 I'd want it to highlight only the for loop.

Ideally, it would do this from within the block but not on the block declaration itself. This means that if I had my cursor on line 3, it's on the conditional line but it considers it considers the closest inner node as the one just above, that being the method. It also prevents annoying cases where you have a one-liner if statement or things like that.

Random nvim (nightly) crashes when started in a empty buffer

Hi when using with neovim 0.6 release

NVIM v0.6.0-dev+402-g655e489e9
Build type: RelWithDebInfo
LuaJIT 2.1.0-beta3

along with

if !exists("g:twilight_autocommands")
     let g:twilight_autocommands=1
     augroup twilight_mode
         autocmd InsertEnter * :TwilightEnable
         autocmd InsertLeave * :TwilightDisable
     augroup END
endif

When creating a new file or empty buffer and trying to enter insert mode, I get a SIGEV in the neovim process, disabling the autocommand snippet resolved my issue. Until few days ago (3 or 4 days),
I did not have this kind of problem.

Is this the right place to open the issue?

Regards,
Lucas

[Feature request] Better document how to customize which text should be visible

I don't understand how Twilight decides which text should be visible, or how to customize it. I use it with Python + Treesitter, and here's an example of how it works:

image

I would like it to always expand to include the nearest parent function definition, or the nearest parent class definition if I'm not currently inside a function definition.

It sounds like, based on this:

expand = { -- for treesitter, we we always try to expand to the top-most ancestor with these types
"function",
"method",
"table",
"if_statement",
},

That it already should try to include the entire function definition, but it doesn't. It also sounds like based on this:

context = 10, -- amount of lines we will try to show around the current line

That it should show at least 10 lines above/below the current line, but it doesn't do that either. In the screenshot, it only shows 1 line above the current line.

I would really love some more in-depth documentation so I can customize which text is visible.

Can't enable plugin

I am new to lua in vim, but done all things like described in README, not working any way.
I also install zen-mode, which works fine. So, just want to get, what I'm done wrong?

[Feature Request]: Second/Additional non-dimmed area that follows the mouse

When working with this plugin on, I find it quite uncomfortable if I am looking for a specific piece of code nearby in the not highlighted areas ...
I'd love for the cursor-area to stay highlighted and the rest to stay dimmed as is right now, but additionally I'd love to see the feature of an additional (optional) highlighted area that doesn't follow the cursor but the mouse.
I guess this would probably not be much work for you and I think it would be super-useful -
you see: I find myself pointing to the area (more or less) where I'm looking for something anyway, so if that highlight would follow the mouse cursor, that would be so awesome. (while the area round the cursor stays highlighted as well - any way)

Imagine for example in a split buffer, you got the cursor in one buffer and quickly want to double check something in one of the other buffers ... need to switch off/toggle the plugin for a sec => oh, but not so, no, you just hover with the mouse that other section in that other buffer and there's the other highlight following that mouse-cursor, yeah!

bug: Dim Inlay Hints

Did you check docs and existing issues?

  • I have read all the twilight.nvim docs
  • I have searched the existing issues of twilight.nvim
  • I have searched the existing issues of plugins related to this issue

Neovim version (nvim -v)

0.9.2

Operating system/version

OpenSuse TumbleWeed

Describe the bug

Forgive me if this is beyond the control of Twilight, but I noticed that type hints in rust projects are not dimmed when using Rust-tools. (They are rendered using virtual text)
twilight

Steps To Reproduce

  1. Open a project in Rust with rust-tools attached
  2. Use Twilight

Expected Behavior

Inlay hints on non-highlighted lines will be dimmed as well

Repro

No response

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.