自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

通過一個(gè)插件來了解Neovim的Winbar屬性

開發(fā) 前端
neovim的插件目前幾乎都是用lua進(jìn)行編寫的,lua使用起來不僅效率高,而且配置起來也非常的方便,此外,neovim也在不斷地完善自己的api,用戶開發(fā)起來變得非常輕松。

window bar

window bar 是顯示在每個(gè)窗口的上面的,默認(rèn)它是不顯示的,你需要配置才可以。你可以把它看成和底部的狀態(tài)欄類似的東西,只不過它顯示在窗口頂部。

圖片

通過:h winbar命令可以查看它的幫助文檔。我們可以通過配置選項(xiàng)來配置winbar的顯示內(nèi)容。

配置的命令是vim.opt.winbar=配置內(nèi)容。

代碼上下文

winbar 可以顯示任何內(nèi)容,但是我們更多的時(shí)候是希望它顯示一些有意義的內(nèi)容,比如文件名和一些代碼的函數(shù)名,屬性信息等,此外,我們還可以顯示文件的狀態(tài),比如文件是否被修改了。

圖片

函數(shù)api介紹

  • get_winbar 函數(shù)用來顯示當(dāng)前代碼的上下文信息
  • get_location 函數(shù)用來獲取當(dāng)前代碼的上下文。
  • get_modified 用來顯示文件名,檢查文件是否修改,如果修改顯示圖標(biāo)。
  • WinBarSeparator, WinBarContext, and WinBarFilename 是用來顯示自定義的高亮。

在代碼中我們使用nvim-navic插件來幫助我們獲取代碼的上下文更詳細(xì)的信息。

高亮配置

為了更好地顯示窗口樣式,我們可以通過修改winbar提供的高亮組樣式來修改winbar的樣式。

圖片

  • WinBar 用來配置當(dāng)前窗口的樣式
  • WinBarNC 用來配置非當(dāng)前窗口樣式。

主要代碼

local M = {}

local colors = require "config.colors"
local navic = require "nvim-navic"
local utils = require "utils"
local icons = require "config.icons"

vim.api.nvim_set_hl(0, "WinBarSeparator", { fg = colors.grey })
vim.api.nvim_set_hl(0, "WinBarFilename", { fg = colors.green, bg = colors.grey })
vim.api.nvim_set_hl(0, "WinBarContext", { fg = colors.green, bg = colors.grey })

M.winbar_filetype_exclude = {
"help",
"startify",
"dashboard",
"packer",
"neogitstatus",
"NvimTree",
"Trouble",
"alpha",
"lir",
"Outline",
"spectre_panel",
"toggleterm",
}

local excludes = function()
if vim.tbl_contains(M.winbar_filetype_exclude, vim.bo.filetype) then
vim.opt_local.winbar = nil
return true
end
return false
end

local function get_modified()
if utils.get_buf_option "mod" then
local mod = icons.git.Mod
return "%#WinBarFilename#" .. mod .. " " .. "%t" .. "%*"
end
return "%#WinBarFilename#" .. "%t" .. "%*"
end

local function get_location()
local location = navic.get_location()
if not utils.is_empty(location) then
return "%#WinBarContext#" .. " " .. icons.ui.ChevronRight .. " " .. location .. "%*"
end
return ""
end

function M.get_winbar()
if excludes() then
return ""
end
if navic.is_available() then
return "%#WinBarSeparator#"
.. "%="
.. ""
.. "%*"
.. get_modified()
.. get_location()
.. "%#WinBarSeparator#"
.. ""
.. "%*"
else
return "%#WinBarSeparator#" .. "%=" .. "" .. "%*" .. get_modified() .. "%#WinBarSeparator#" .. "" .. "%*"
end
end

return M

總結(jié)

neovim的插件目前幾乎都是用lua進(jìn)行編寫的,lua使用起來不僅效率高,而且配置起來也非常的方便,此外,neovim也在不斷地完善自己的api,用戶開發(fā)起來變得非常輕松。

責(zé)任編輯:武曉燕 來源: 程序那些事兒
相關(guān)推薦

2022-10-21 13:14:41

lua插件neovim

2020-09-01 13:10:42

JavaScript開發(fā) 技巧

2016-03-08 09:52:22

xcode插件開發(fā)

2020-06-23 10:03:33

版本控制項(xiàng)目

2024-07-19 10:31:15

2020-09-02 07:22:17

JavaScript插件框架

2011-10-19 09:30:23

jQuery

2023-12-19 16:39:18

CSS開發(fā)前端

2020-11-25 08:13:33

CPU主板GPU

2009-07-29 09:58:38

民工通過CCNACCNA

2020-12-01 17:46:24

FossilGit

2021-08-16 08:53:07

Go 插件系統(tǒng)

2012-05-10 16:46:09

Visual Stud

2014-04-03 10:46:12

Dockermaven

2012-11-19 11:07:42

IBMdw

2023-12-12 08:08:17

插件PRPulsar

2020-10-12 10:58:15

IDEA插件監(jiān)聽

2011-01-19 13:19:39

Thunderbird插件

2021-01-14 08:55:20

C語言編程

2021-01-03 16:30:34

Rust編程語言
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)