มีมุมมองที่สวยงามเหนือหน้าต่างแยกของคุณเสมอ
หมายเหตุ : สำหรับการอ้างอิงขนาดคุณสมบัตินี้ตั้งค่าเป็น 40 แถวและ 120 คอลัมน์
ดูการสาธิตภาพของแต่ละคุณลักษณะการโฟกัสที่นี่
นี่คือตัวอย่างโค้ดสำหรับวิธีการติดตั้งทั่วไป (ใช้เพียงหนึ่งเดียว):
| GitHub repo | สาขา | รหัสตัวอย่าง |
|---|---|---|
| ห้องสมุด 'focus.nvim' | หลัก | { 'nvim-focus/focus.nvim', version = false }, |
| มั่นคง | { 'nvim-focus/focus.nvim', version = '*' }, |
| GitHub repo | สาขา | รหัสตัวอย่าง |
|---|---|---|
| ห้องสมุด 'focus.nvim' | หลัก | use 'nvim-focus/focus.nvim' |
| มั่นคง | use { 'nvim-focus/focus.nvim', branch = 'stable' } |
| GitHub repo | สาขา | รหัสตัวอย่าง |
|---|---|---|
| ห้องสมุด '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 split แทน 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 '
}
}
})ตั้งค่าคอลัมน์ Sign Auto Focus
-- 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 | สลับระหว่างการแยกความเท่าเทียมกันหรือหน้าต่างที่โฟกัสสูงสุด |
โฟกัสช่วยให้คุณสามารถแยกหน้าต่างออกเป็นหน้าต่างปูกระเบื้องได้อย่างดีและปรับขนาดตามอัตราส่วนทองคำ
+----------------+------------+
| | S1 |
| | |
| +------------+
| | |
| MAIN PANE | S2 |
| | |
| | |
| | |
+----------------+------------+
ในการรับมุมมองนี้คุณจะต้องกดปุ่มรวม 2 ครั้ง
<Cl> keymap ( ' n ' , ' <c-l> ' , function ()
require ( ' focus ' ). split_nicely ()
end , { desc = ' split nicely ' }) นอกจากนี้คุณสามารถเปิดไฟล์หรือคำสั่งเรียกใช้ที่กำหนดเองด้วยคำสั่ง :FocusSplitNicely
เปิดไฟล์ในการแยกที่สร้างโดยคำสั่ง FocusSplitNicely
:FocusSplitNicely README.md
เปิดหน้าต่างเทอร์มินัลในการแยกที่สร้างขึ้นโดยคำสั่ง FocusSplitNicely โดยใช้ cmd arg เพื่อเรียกใช้คำสั่งที่กำหนดเอง
:FocusSplitNicely cmd term
แทนที่จะกังวลเกี่ยวกับคำสั่งและทางลัดหลายคำ เพียงแค่คิดว่าจะแยกไปตามทิศทางที่คุณต้องการไป
การเรียกคำสั่งแยกโฟกัสเช่น: FocussPlitright จะทำหนึ่งในสองสิ่ง มันจะพยายามที่จะย้ายข้ามไปยังหน้าต่าง ในทิศทางที่กำหนด มิฉะนั้น หากไม่มีหน้าต่างอยู่ในทิศทางที่ระบุ เมื่อเทียบกับหน้าต่างปัจจุบัน มันจะสร้างหน้าต่างบัฟเฟอร์เปล่าใหม่ ในทิศทางที่ระบุแล้วย้ายไปที่หน้าต่างนั้น
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 จะเปิดในการแยกด้านขวาเสมอ สิ่งนี้เกิดจาก focus.lua หรือไม่?
ไม่นี่เป็นการตัดสินใจออกแบบที่บันทึกไว้โดย Core Vim นี่อาจเป็นสิ่งที่สามารถปรับต้นน้ำได้
ในระหว่างนี้คุณสามารถเปิดหน้าต่าง QuickFix ที่มีความกว้างเต็มของหน้าต่างด้วย :botright copen
ฉันพยายามที่จะ Lazy Load Focus ด้วย :FocusToggle แต่ฉันต้องสลับมันอีกครั้งเพื่อให้ได้การปรับขนาดอัตโนมัติ
โปรดทราบว่าถ้าคุณขี้เกียจโหลดด้วยคำสั่ง :FocusToggle มันจะโหลดโฟกัส แต่จะสลับออกในตอนแรก ดู #34.
นี่เป็นเพราะโฟกัสถูกสลับโดยค่าเริ่มต้นเมื่อคุณโหลดโฟกัสดังนั้นหากคุณโหลดแล้วเรียกใช้คำสั่ง :FocusToggle มันจะสลับออกอีกครั้ง
กรุณาก่อนที่จะส่ง PR ติดตั้ง Stylua และเรียกใช้ในโฟลเดอร์รูทของ focus.nvim
stylua . สิ่งนี้จะจัดรูปแบบรหัสตามแนวทางที่ตั้งไว้ใน .stylua.toml
คุณสามารถเรียกใช้การทดสอบโดยใช้ make test หากคุณเริ่มต้น submodules git