NvChad / NvChad

Blazing fast Neovim config providing solid defaults and a beautiful UI, enhancing your neovim experience.
https://nvchad.com/
GNU General Public License v3.0
24.83k stars 2.13k forks source link

Current line and column in status line #1562

Closed viking66 closed 2 years ago

viking66 commented 2 years ago

Is there a way to configure NvChad's status line to include the current line number and column next to the file location percentage? If not, is that a feature that can be added?

siduck commented 2 years ago

https://nvchad.com/config/nvchad_ui override statusline modules

dhruvinsh commented 2 years ago

Here is my solution:

lua/custom/plugins/init.lua ```lua local overrides = require("custom.plugins.overrides") return { ["NvChad/ui"] = { override_options = overrides.statusline }, } ```
lua/custom/plugins/overrides.lua ```lua local M = {} M.statusline = { statusline = { overriden_modules = function () local st_modules = require "nvchad_ui.statusline.modules" return { cursor_position = function() local line, col = unpack(vim.api.nvim_win_get_cursor(0)) -- lets store current logs local cp = st_modules.cursor_position() return cp .. line .. ":" .. (col + 1) end, } end } } return M ```

EDIT: I am not LUA expert so my code might be bit clunky or inaccurate, but hey it works and does what I need :)

siduck commented 2 years ago

@dhruvinsh no need to be a lua expert for this xD, you're the same as me

tanguymagne commented 1 year ago

Hey I am sorry, but I wanted to add this but your code doesn't seem to be working. My custom directory look like this :

├── custom
│  ├── chadrc.lua
│  ├── configs
│  │  ├── lint.lua
│  │  └── lspconfig.lua
│  └── overrides.lua
│  └── plugins.lua

with overrides.lua being the exact file provided and plugins.lua is :

local plugins = {
  {
    "williamboman/mason.nvim",
    opts = {
      ensure_installed = {
        "pyright",
        "black",
        "ruff",
      },
    },
  },
  {
    "neovim/nvim-lspconfig",
    config = function ()
      require "plugins.configs.lspconfig"
      require "custom.configs.lspconfig"
    end,
  },
  {
    "mfussenegger/nvim-lint",
    lazy=false,
    config = function ()
      require "custom.configs.lint"
    end
  },
  {
    "mhartington/formatter.nvim",
    lazy=false,
    config = function ()
      require "custom.configs.format"
    end
  },
  {
    "NvChad/ui",
    override_options = require("custom.overrides").statusline
  }
}
return plugins

Do you have any idea why this doesn't work ?

Also @siduck your link is broken, do you have a new version for it ?

siduck commented 1 year ago

@tanguymagne https://nvchad.com/docs/config/nvchad_ui

tanguymagne commented 1 year ago

Hey thanks for your answer, I manage to make what I wanted with the following code in chadrc.lua:

---@type ChadrcConfig
local M = {}
M.ui = {
    theme = 'catppuccin',
    statusline = {
        -- modules arg here is the default table of modules
        overriden_modules = function(modules)
            table.insert(
                modules,
                11,
                (function()
                    local line, col = unpack(vim.api.nvim_win_get_cursor(0))
                    return "l" .. line .. ":c" .. (col + 1)
                end)()
            )
        end,
    },
}

return M
siduck commented 1 year ago

@tanguymagne :D

      table.insert(modules, " Ln %l, Col %c") -- or
 --   modules[11] = " Ln %l, Col %c" 
Bazulenkov commented 6 days ago

https://nvchad.com/config/nvchad_ui override statusline modules

Link shows 404.

Bazulenkov commented 6 days ago

This is my chadrc.lua

---@type ChadrcConfig
local M = {}

M.base46 = {
  theme = "onenord",
}

M.ui = {
  statusline = {
    -- modules arg here is the default table of modules
    overriden_modules = function(modules)
      table.insert(modules, " Ln %l, Col %c")
    end,
  },
}
return M

But I do not see the cursor position in status line.

I can not find any references for "overriden_modules".

How can I add cursor position in default theme in the newest NvChad?