├── LICENSE ├── README.md ├── doc ├── .gitignore └── fern-hijack.txt └── plugin └── fern_hijack.vim /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2020 Alisue, hashnote.net 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🌿 fern-hijack.vim 2 | 3 | [![fern plugin](https://img.shields.io/badge/🌿%20fern-plugin-yellowgreen)](https://github.com/lambdalisue/fern.vim) 4 | [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE) 5 | [![Doc](https://img.shields.io/badge/doc-%3Ah%20fern--hijack-orange.svg)](doc/fern-hijack.txt) 6 | 7 | A plugin for [fern.vim](https://github.com/lambdalisue/fern.vim) to make the fern.vim as a default file explorer instead of Netrw. 8 | 9 | ## Usage 10 | 11 | Just install the plugin then the default file explorer become fern.vim. 12 | Uses can confirm that by: 13 | 14 | ``` 15 | :e . 16 | ``` 17 | 18 | Or from terminal: 19 | 20 | ``` 21 | vim . 22 | ``` 23 | 24 | ## License 25 | 26 | The code in fern-hijack.vim follows MIT license texted in [LICENSE](./LICENSE). 27 | Contributors need to agree that any modifications sent in this repository follow the license. 28 | -------------------------------------------------------------------------------- /doc/.gitignore: -------------------------------------------------------------------------------- 1 | tags 2 | -------------------------------------------------------------------------------- /doc/fern-hijack.txt: -------------------------------------------------------------------------------- 1 | *fern-hijack.txt* Use fern.vim as a default explorer instead of Netrw 2 | 3 | Author: Alisue 4 | License: MIT license 5 | 6 | ============================================================================= 7 | CONTENTS *fern-hijack-contents* 8 | 9 | INTRODUCTION |fern-hijack-introduction| 10 | 11 | ============================================================================= 12 | INTRODUCTION *fern-hijack-introduction* 13 | 14 | *fern-hijack.vim* (fern-hijack) is a plugin to use fern.vim as a default 15 | explorer instead of Netrw. 16 | 17 | Installing this plugin automatically overwrite the default explorer. To 18 | disable the feature, write the following code somewhere in your |vimrc|: 19 | > 20 | let g:loaded_fern_hijack = 1 21 | < 22 | Or just uninstall the plugin. 23 | 24 | 25 | ============================================================================= 26 | vim:tw=78:fo=tcq2mM:ts=8:ft=help:norl 27 | -------------------------------------------------------------------------------- /plugin/fern_hijack.vim: -------------------------------------------------------------------------------- 1 | if exists('g:loaded_fern_hijack') || ( !has('nvim') && v:version < 801 ) 2 | finish 3 | endif 4 | let g:loaded_fern_hijack = 1 5 | 6 | function! s:hijack_directory() abort 7 | let path = s:expand('%:p') 8 | if !isdirectory(path) 9 | return 10 | endif 11 | let bufnr = bufnr() 12 | execute printf('keepjumps keepalt Fern %s', fnameescape(path)) 13 | execute printf('silent! bwipeout %d', bufnr) 14 | endfunction 15 | 16 | function! s:suppress_netrw() abort 17 | if exists('#FileExplorer') 18 | autocmd! FileExplorer * 19 | endif 20 | endfunction 21 | 22 | " Called every BufEnter, but checks if fern#util#expand exists, thus preventing unnecessary load of fern.vim. 23 | function! s:expand(expr) abort 24 | if exists('fern#util#expand') 25 | return fern#util#expand(a:expr) 26 | endif 27 | return expand(a:expr) 28 | endfunction 29 | 30 | augroup fern-hijack 31 | autocmd! 32 | autocmd VimEnter * call s:suppress_netrw() 33 | autocmd BufEnter * ++nested call s:hijack_directory() 34 | augroup END 35 | --------------------------------------------------------------------------------