Back to Oil Nvim

API

doc/api.md

2.15.012.2 KB
Original Source

API

<!-- TOC --> <!-- /TOC --> <!-- API -->

get_entry_on_line(bufnr, lnum)

get_entry_on_line(bufnr, lnum): nil|oil.Entry
Get the entry on a specific line (1-indexed)

ParamTypeDesc
bufnrinteger
lnuminteger

get_cursor_entry()

get_cursor_entry(): nil|oil.Entry
Get the entry currently under the cursor

discard_all_changes()

discard_all_changes()
Discard all changes made to oil buffers

set_columns(cols)

set_columns(cols)
Change the display columns for oil

ParamTypeDesc
colsoil.ColumnSpec[]

set_sort(sort)

set_sort(sort)
Change the sort order for oil

ParamTypeDesc
sortoil.SortSpec[]List of columns plus direction. See :help oil-columns to see which ones are sortable.

Examples:

lua
require("oil").set_sort({ { "type", "asc" }, { "size", "desc" } })

set_is_hidden_file(is_hidden_file)

set_is_hidden_file(is_hidden_file)
Change how oil determines if the file is hidden

ParamTypeDesc
is_hidden_filefun(filename: string, bufnr: integer): booleanReturn true if the file/dir should be hidden

toggle_hidden()

toggle_hidden()
Toggle hidden files and directories

get_current_dir(bufnr)

get_current_dir(bufnr): nil|string
Get the current directory

ParamTypeDesc
bufnrnil|integer

open_float(dir, opts, cb)

open_float(dir, opts, cb)
Open oil browser in a floating window

ParamTypeDesc
dirnil|stringWhen nil, open the parent of the current buffer, or the cwd if current buffer is not a file
optsnil|oil.OpenOpts
>previewnil|oil.OpenPreviewOptsWhen present, open the preview window after opening oil
>>verticalnil|booleanOpen the buffer in a vertical split
>>horizontalnil|booleanOpen the buffer in a horizontal split
>>splitnil|"aboveleft"|"belowright"|"topleft"|"botright"Split modifier
cbnil|fun()Called after the oil buffer is ready

toggle_float(dir, opts, cb)

toggle_float(dir, opts, cb)
Open oil browser in a floating window, or close it if open

ParamTypeDesc
dirnil|stringWhen nil, open the parent of the current buffer, or the cwd if current buffer is not a file
optsnil|oil.OpenOpts
>previewnil|oil.OpenPreviewOptsWhen present, open the preview window after opening oil
>>verticalnil|booleanOpen the buffer in a vertical split
>>horizontalnil|booleanOpen the buffer in a horizontal split
>>splitnil|"aboveleft"|"belowright"|"topleft"|"botright"Split modifier
cbnil|fun()Called after the oil buffer is ready

open(dir, opts, cb)

open(dir, opts, cb)
Open oil browser for a directory

ParamTypeDesc
dirnil|stringWhen nil, open the parent of the current buffer, or the cwd if current buffer is not a file
optsnil|oil.OpenOpts
>previewnil|oil.OpenPreviewOptsWhen present, open the preview window after opening oil
>>verticalnil|booleanOpen the buffer in a vertical split
>>horizontalnil|booleanOpen the buffer in a horizontal split
>>splitnil|"aboveleft"|"belowright"|"topleft"|"botright"Split modifier
cbnil|fun()Called after the oil buffer is ready

close(opts)

close(opts)
Restore the buffer that was present when oil was opened

ParamTypeDesc
optsnil|oil.CloseOpts
>exit_if_last_bufnil|booleanExit vim if this oil buffer is the last open buffer

open_preview(opts, callback)

open_preview(opts, callback)
Preview the entry under the cursor in a split

ParamTypeDesc
optsnil|oil.OpenPreviewOpts
>verticalnil|booleanOpen the buffer in a vertical split
>horizontalnil|booleanOpen the buffer in a horizontal split
>splitnil|"aboveleft"|"belowright"|"topleft"|"botright"Split modifier
callbacknil|fun(err: nil|string)Called once the preview window has been opened

select(opts, callback)

select(opts, callback)
Select the entry under the cursor

ParamTypeDesc
optsnil|oil.SelectOpts
>verticalnil|booleanOpen the buffer in a vertical split
>horizontalnil|booleanOpen the buffer in a horizontal split
>splitnil|"aboveleft"|"belowright"|"topleft"|"botright"Split modifier
>tabnil|booleanOpen the buffer in a new tab
>closenil|booleanClose the original oil buffer once selection is made
>handle_buffer_callbacknil|fun(buf_id: integer)If defined, all other buffer related options here would be ignored. This callback allows you to take over the process of opening the buffer yourself.
callbacknil|fun(err: nil|string)Called once all entries have been opened

save(opts, cb)

save(opts, cb)
Save all changes

ParamTypeDesc
optsnil|table
>confirmnil|booleanShow confirmation when true, never when false, respect skip_confirm_for_simple_edits if nil
cbnil|fun(err: nil|string)Called when mutations complete.

Note:

<pre> If you provide your own callback function, there will be no notification for errors. </pre>

setup(opts)

setup(opts)
Initialize oil

ParamTypeDesc
optsoil.setupOpts|nil
<!-- /API -->