added example config to readme

This commit is contained in:
Rudis Muiznieks 2021-09-19 22:03:02 -05:00
parent bffbb5a5d7
commit c9b88aaeb4

View file

@ -24,3 +24,32 @@ Bind this to a key (I recommend `-`) and execute it to open the file browser in
```lua
require('telescope').extensions.vinegar.file_browser()
```
## Example Config
The following config maps `-` to the file browser, disables `netrw`, and automatically opens the file browser when you launch nvim with a directory as the file argument.
```lua
-- add keybinding
vim.api.nvim_set_keymap('n', '-',
'<cmd>lua require("telescope").extensions.vinegar.file_browser()<cr>',
{noremap = true})
-- disable netrw
vim.g['loaded_netrw'] = 1
-- create function to open file browser when opening a directory
_G.browse_if_dir = function()
if require('plenary.path'):new(vim.fn.expand('%:p')):is_dir() then
local buf = vim.api.nvim_get_current_buf()
vim.api.nvim_buf_set_option(buf, 'buftype', 'nofile')
vim.api.nvim_buf_set_option(buf, 'buflisted', false)
vim.api.nvim_buf_set_option(buf, 'swapfile', false)
vim.api.nvim_buf_set_option(buf, 'bufhidden', 'hide')
require('telescope').extensions.vinegar.file_browser()
end
end
-- autocommand to run the above function when launching
vim.api.nvim_command('au VimEnter * call v:lua.browse_if_dir()')
```