いつもあなたのスプリットウィンドウを見栄えを良くしてください
注:参照のために、このスクリーンキャストには、40行と120列に設定された寸法があります。
こちらの各フォーカス機能の視覚的なデモをご覧ください。
いくつかの一般的なインストール方法のコードスニペットは次のとおりです(1つだけを使用してください):
| 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のユーザーの場合、Stabilize Pluginを使用することをお勧めします。 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 } })フォーカスクイックフィックスの高さを設定します
-- 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 } })新しいスプリットウィンドウを作成するときは、neovimの代わりにtmux分割を使用します
-- 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 )1つのウィンドウ( vim.w.focus_disable = true )、1つのバッファ( 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 | 分割がない場合は、1つを作成してそれに移動します。 :FocusSplitCycle reverse |
:FocusDisableWindow | 現在のウィンドウ(Winnr)のサイズ変更を無効にします。 |
:FocusEnableWindow | 現在のウィンドウ(winnr)のサイズ変更を有効にします。 |
:FocusToggleWindow | トグルごとのウィンドウごとに再びフォーカスをオフにします。 |
:FocusDisableBuffer | 現在のバッファー(bufnr)のサイズ変更を無効にします。 |
:FocusEnableBuffer | 現在のバッファー(bufnr)のサイズ変更を有効にします。 |
:FocusToggleBuffer | バッファごとに再びフォーカスを切り替えます。 |
:FocusSplitLeft | 既存に移動するか、現在のウィンドウの左側に新しい分割を作成し、ファイルまたはカスタムコマンドを開きます。 |
:FocusSplitDown | 既存に移動するか、現在のウィンドウの下部に新しい分割を作成し、ファイルを開くか、カスタムコマンドを開きます。 |
:FocusSplitUp | 既存に移動するか、現在のウィンドウの上部に新しい分割を作成し、ファイルまたはカスタムコマンドを開きます。 |
:FocusSplitRight | 既存に移動するか、現在のウィンドウの右側に新しい分割を作成し、ファイルを開くか、カスタムコマンドを開きます。 |
:FocusEqualise | スプリットを一時的に等しくして、それらがすべて似たような幅/高さです。 |
:FocusMaximise | 焦点を合わせたウィンドウを一時的に最大化します。 |
:FocusMaxOrEqual | スプリットをイコライズするか、フォーカスされたウィンドウを最大化するかの間の切り替えます。 |
フォーカスを使用すると、Windowsをタイル張りのウィンドウに分割して、ゴールデン比に応じてサイズがあります。
+----------------+------------+
| | 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
複数のコマンドやショートカットを心配する代わりに、どの方向に進みたいかを分割するだけです。
フォーカススプリットコマンドの呼び出しIE:FocussplitRightは2つのことのいずれかを実行します。指定された方向のウィンドウに移動しようとします。それ以外の場合、現在のウィンドウに対して指定された方向にウィンドウが存在しない場合、代わりに指定された方向に新しい空白バッファーウィンドウが作成され、そのウィンドウに移動します。
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
私は怠zyなロードフォーカスを使用しようとしました:FocusToggle 、しかし、私はそれをもう一度切り替える必要があります自動居住動作を得る必要があります
コマンド:FocusToggleを使用してLazy Loadを使用している場合は、フォーカスをロードしますが、最初は切り替えます。 #34を参照してください。
これは、フォーカスがフォーカスをロードするときにデフォルトで切り替えるため、コマンド:FocusToggleを実行すると、再び切り替えます。
PRインストールStyluaを提出する前に、 focus.nvimのルートフォルダーで実行してください。
stylua .これにより、 .stylua.tomlに設定されたガイドラインに従ってコードがフォーマットされます。
Gitサブモジュールを初期化する場合、 make testを使用してテストを実行できます。