始終可以欣賞到拆分窗戶
注意:有關參考,此屏幕截圖的尺寸設置為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進行測試。