始终可以欣赏到拆分窗户
注意:有关参考,此屏幕截图的尺寸设置为40行和120列。
在此处查看每个焦点功能的视觉演示。
这是一些常见安装方法的代码片段(仅使用一种):
| Github仓库 | 分支 | 代码段 |
|---|---|---|
| 'focus.nvim'库 | 主要的 | { 'nvim-focus/focus.nvim', version = false }, |
| 稳定的 | { 'nvim-focus/focus.nvim', version = '*' }, |
| Github仓库 | 分支 | 代码段 |
|---|---|---|
| 'focus.nvim'库 | 主要的 | use 'nvim-focus/focus.nvim' |
| 稳定的 | use { 'nvim-focus/focus.nvim', branch = 'stable' } |
| Github仓库 | 分支 | 代码段 |
|---|---|---|
| 'focus.nvim'库 | 主要的 | Plug 'nvim-focus/focus.nvim' |
| 稳定的 | Plug("nvim-focus/focus.nvim", {["tag"]="stable"}) -- stable should be the latest stable version, as of 16th july 2024, it's v1.0.0 |
对于所有电池的基本设置,包括:
require ( " focus " ). setup ()配置可以传递给设置功能。这是默认设置的示例:
require ( " focus " ). setup ({
enable = true , -- Enable module
commands = true , -- Create Focus commands
autoresize = {
enable = true , -- Enable or disable auto-resizing of splits
width = 0 , -- Force width for the focused window
height = 0 , -- Force height for the focused window
minwidth = 0 , -- Force minimum width for the unfocused window
minheight = 0 , -- Force minimum height for the unfocused window
height_quickfix = 10 , -- Set the height of quickfix panel
},
split = {
bufnew = false , -- Create blank buffer for new split windows
tmux = false , -- Create tmux splits instead of neovim splits
},
ui = {
number = false , -- Display line numbers in the focussed window only
relativenumber = false , -- Display relative line numbers in the focussed window only
hybridnumber = false , -- Display hybrid line numbers in the focussed window only
absolutenumber_unfocussed = false , -- Preserve absolute numbers in the unfocussed windows
cursorline = true , -- Display a cursorline in the focussed window only
cursorcolumn = false , -- Display cursorcolumn in the focussed window only
colorcolumn = {
enable = false , -- Display colorcolumn in the foccused window only
list = ' +1 ' , -- Set the comma-saperated list for the colorcolumn
},
signcolumn = true , -- Display signcolumn in the focussed window only
winhighlight = false , -- Auto highlighting for focussed/unfocussed windows
}
})注意调整大小时要管理窗口视图,请参见
:h splitkeep。
对于Neovim> = 0.10的用户,建议使用splitkeep=cursor。
对于Neovim <= 0.8的用户,建议使用稳定插件。对于lazyvim的用户,他们将opt.winminwidth = 5在默认选项中进行,可能会导致与会话管理插件的冲突。
启用/禁用重点
-- Completely disable this plugin
-- Default: true
require ( " focus " ). setup ({ enable = false })启用/禁用焦点命令
-- This not export :Focus* commands
-- Default: true
require ( " focus " ). setup ({ commands = false })启用/禁用焦点窗口自动化
-- The focussed window will no longer automatically resize. Other focus features are still available
-- Default: true
require ( " focus " ). setup ({ autoresize = { enable = false } })设置焦点宽度
-- Force width for the focused window
-- Default: Calculated based on golden ratio
require ( " focus " ). setup ({ autoresize = { width = 120 } })设置焦点最小宽度
-- Force minimum width for the unfocused window
-- Default: Calculated based on golden ratio
require ( " focus " ). setup ({ autoresize = { minwidth = 80 } })设置焦点高度
-- Force height for the focused window
-- Default: Calculated based on golden ratio
require ( " focus " ). setup ({ autoresize = { height = 40 } })设置重点最小高度
-- Force minimum height for the unfocused window
-- Default: 0
require ( " focus " ). setup ({ autoresize = { minheight = 10 } })设置焦点QuickFix高度
-- Sets the height of quickfix panel, in case you pass the height to
-- `:copen <height>`
-- Default: 10
require ( " focus " ). setup ({ autoresize = { height_quickfix = 10 })创建新的拆分窗口时,请/不要将其作为空缓冲区初始化
-- True: When a :Focus.. command creates a new split window, initialise it as a new blank buffer
-- False: When a :Focus.. command creates a new split, retain a copy of the current window in the new window
-- Default: false
require ( " focus " ). setup ({ split = { bufnew = true } })设置焦点自动号码
-- Displays line numbers in the focussed window only
-- Not displayed in unfocussed windows
-- Default: true
require ( " focus " ). setup ({ ui = { number = false } })设置焦点自动相对数字
-- Displays relative line numbers in the focussed window only
-- Not displayed in unfocussed windows
-- See :help relativenumber
-- Default: false
require ( " focus " ). setup ({ ui = { relativenumber = true } })设置焦点自动混合数字
-- Displays hybrid line numbers in the focussed window only
-- Not displayed in unfocussed windows
-- Combination of :help relativenumber, but also displays the line number of the
-- current line only
-- Default: false
require ( " focus " ). setup ({ ui = { hybridnumber = true } })设置保存绝对数字
-- Preserve absolute numbers in the unfocussed windows
-- Works in combination with relativenumber or hybridnumber
-- Default: false
require ( " focus " ). setup ({ ui = { absolutenumber_unfocussed = true } })创建新的拆分窗口时,请使用TMUX拆分代替Neovim
-- True: Create tmux splits instead of neovim splits
-- False: Create neovim split windows
-- Default: false
require ( " focus " ). setup ({ split = { tmux = true } })设置焦点自动光标线
-- Displays a cursorline in the focussed window only
-- Not displayed in unfocussed windows
-- Default: true
require ( " focus " ). setup ({ ui = { cursorline = false } })设置焦点自动光标列
-- Displays a cursor column in the focussed window only
-- See :help cursorcolumn for more options
-- Default: false
require ( " focus " ). setup ({ ui = { cursorcolumn = true } })设置焦点自动颜色列
-- Displays a color column in the focussed window only
-- See :help colorcolumn for more options
-- Default: enable = false, list = '+1'
require ( " focus " ). setup ({
ui = {
colorcolumn = {
enable = true ,
list = ' +1,+2 '
}
}
})设置焦点自动符号列
-- Displays a sign column in the focussed window only
-- Gets the vim variable setcolumn when focus.setup() is run
-- See :help signcolumn for more options e.g :set signcolum=yes
-- Default: true, signcolumn=auto
require ( " focus " ). setup ({ ui = { signcolumn = false } })设置聚焦窗口突出显示
-- Enable auto highlighting for focussed/unfocussed windows
-- Default: false
require ( " focus " ). setup ({ ui = { winhighlight = true } })
-- By default, the highlight groups are setup as such:
-- hi default link FocusedWindow VertSplit
-- hi default link UnfocusedWindow Normal
-- To change them, you can link them to a different highlight group, see
-- `:help hi-default` for more info.
vim . highlight . link ( ' FocusedWindow ' , ' CursorLine ' , true )
vim . highlight . link ( ' UnfocusedWindow ' , ' VisualNOS ' , true )可以通过仅为一个窗口设置变量( vim.w.focus_disable = true ),仅一个缓冲区( vim.b.focus_disable = true )或全局( vim.g.focus_disable = true )来禁用焦点。
如果要禁用某些缓冲区或文件类型的焦点,则可以通过在配置中设置AutoCommands( :help autocmd )来执行此操作。
这是一个示例:
local ignore_filetypes = { ' neo-tree ' }
local ignore_buftypes = { ' nofile ' , ' prompt ' , ' popup ' }
local augroup =
vim . api . nvim_create_augroup ( ' FocusDisable ' , { clear = true })
vim . api . nvim_create_autocmd ( ' WinEnter ' , {
group = augroup ,
callback = function ( _ )
if vim . tbl_contains ( ignore_buftypes , vim . bo . buftype )
then
vim . w . focus_disable = true
else
vim . w . focus_disable = false
end
end ,
desc = ' Disable focus autoresize for BufType ' ,
})
vim . api . nvim_create_autocmd ( ' FileType ' , {
group = augroup ,
callback = function ( _ )
if vim . tbl_contains ( ignore_filetypes , vim . bo . filetype ) then
vim . b . focus_disable = true
else
vim . b . focus_disable = false
end
end ,
desc = ' Disable focus autoresize for FileType ' ,
})有关下面命令的更多信息,向下滚动以查看每个命令,详细描述它们
| 命令 | 描述 |
|---|---|
:FocusDisable | 每次会话禁用插件。拆分将归一化为默认值,然后均匀间隔。 |
:FocusEnable | 每个会话启用插件。如果未设置,拆分将调整回您的配置或默认设置。 |
:FocusToggle | 再次开关(全球范围内)打开焦点。 |
:FocusSplitNicely | 根据黄金比率规则拆分窗口。 |
:FocusSplitCycle | 如果没有拆分,请创建一个并移动到它,否则循环集中拆分。 :FocusSplitCycle reverse |
:FocusDisableWindow | 禁用当前窗口(WINNR)的调整大小。 |
:FocusEnableWindow | 启用调整当前窗口(WINNR)的大小。 |
:FocusToggleWindow | 在每个窗口的基础上再次关注和关闭。 |
:FocusDisableBuffer | 禁用当前缓冲区(BUFNR)的调整大小。 |
:FocusEnableBuffer | 启用调整当前缓冲区(BUFNR)的大小。 |
:FocusToggleBuffer | 每次缓冲区再次关注和关闭。 |
:FocusSplitLeft | 移动到现有或创建当前窗口 +打开文件或自定义命令的左侧的新拆分。 |
:FocusSplitDown | 移动到现有或创建新的拆分到当前窗口 +打开文件或自定义命令的底部。 |
:FocusSplitUp | 移至现有或创建新的拆分到当前窗口 +打开文件或自定义命令的顶部。 |
:FocusSplitRight | 移动到现有或创建新的拆分到当前窗口 +打开文件或自定义命令的右侧。 |
:FocusEqualise | 暂时等于分裂,因此它们都是相似的宽度/高度。 |
:FocusMaximise | 暂时最大化集中窗口。 |
:FocusMaxOrEqual | 在使拆分均衡或最大化的集中窗口之间切换。 |
FOCUS可以使您可以根据黄金比例将窗户拆分为瓷砖窗户的尺寸很好。
+----------------+------------+
| | S1 |
| | |
| +------------+
| | |
| MAIN PANE | S2 |
| | |
| | |
| | |
+----------------+------------+
为了获得此视图,您将按键组合2次。
<Cl>很好地拆分 keymap ( ' n ' , ' <c-l> ' , function ()
require ( ' focus ' ). split_nicely ()
end , { desc = ' split nicely ' })此外,您可以打开文件或运行:FocusSplitNicely自定义命令:
在FocusSplitNicely命令创建的拆分中打开一个文件
:FocusSplitNicely README.md
通过使用CMD arg运行自定义命令,在FocusSplitNicely命令创建的拆分中打开终端窗口
:FocusSplitNicely cmd term
不用担心多个命令和快捷方式,而只需考虑要迈出的方向。
调用焦点拆分命令,即:pocussplitright将做两件事之一,它将尝试沿指定方向移动到窗口。否则,如果相对于当前窗口的指定方向不存在窗口,则它将在指定的方向上创建一个新的空白缓冲区窗口,然后移动到该窗口。
local focusmap = function ( direction )
vim . keymap . set ( ' n ' , ' <Leader> ' .. direction , function ()
require ( ' focus ' ). split_command ( direction )
end , { desc = string.format ( ' Create or move to split (%s) ' , direction ) })
end
-- Use `<Leader>h` to split the screen to the left, same as command FocusSplitLeft etc
focusmap ( ' h ' )
focusmap ( ' j ' )
focusmap ( ' k ' )
focusmap ( ' l ' )此外,您可以打开文件或运行:FocusSplit<direction>命令:
在创建或移动到的拆分中打开一个文件
:FocusSplitRight README.md
通过使用CMD arg在创建或移动到的拆分中运行自定义命令,打开终端窗口
:FocusSplitDown cmd term
我的显示幅度很小,我发现分裂调整得太大
例如,如果您的屏幕分辨率为1024x768- > IE在较小的侧,则可能会注意到默认情况下的焦点可能会使窗口最大化。
也就是说,由于屏幕房地产有限,窗户将“粉碎”您的其他一些分裂。这不是重点的问题,而是最少的屏幕房地产问题。在这种情况下,您可以简单地减少焦点的宽度/高度。
QuickFix窗口始终在右拆分中打开。这是由焦点引起的吗?
否。这是Core VIM的记录设计决定,这可能是可以在上游调整的。
同时,您可以打开一个QuickFix窗口,占据窗口的完整宽度的窗口:botright copen
我试图以:FocusToggle懒负载重点,但是我需要再次切换它以进行自动工作
请注意,如果您使用命令懒负载:FocusToggle ,它将加载焦点,但最初将其切换。参见#34。
这是因为当您加载焦点时,默认情况下将焦点打开,因此,如果您加载焦点并运行命令:FocusToggle ,则将其再次切换。
在提交PR安装stylua之前,请在focus.nvim的根文件夹中运行。
stylua .这将根据.stylua.toml中设置的准则格式化代码。
如果您初始化GIT子模型,则可以使用make test进行测试。