Vim fern
Cài đặt vim fern trong nvim, ta mở file ~/.config/nvim/init.vim
Plug 'lambdalisue/fern.vim'
Plug 'lambdalisue/nerdfont.vim'
Plug 'lambdalisue/fern-renderer-nerdfont.vim'
Plug 'antoinemadec/FixCursorHold.nvim'
Đối với nvim thì cần cài thêm.
Plug 'antoinemadec/FixCursorHold.nvim'
Còn dùng vim thì khỏi cần.
Sau đó lưu lại và update file init.vim
:w
:so %
gỏ như sau để cài plugin.
:PlugInstall
Sau đó ta cấu hình cho fern.
Nvim thì thêm dòng này để fix bug
let g:cursorhold_updatetime = 100
Ta copy các dòng sau vào init.vim
" .............................................................................
" lambdalisue/fern.vim
" .............................................................................
hello
" Disable netrw.hello
let g:loaded_netrw = 1
let g:loaded_netrwPlugin = 1
let g:loaded_netrwSettings = 1
let g:loaded_netrwFileHandlers = 1
augroup my-fern-hijack
autocmd!
autocmd BufEnter * ++nested call s:hijack_directory()
augroup END
function! s:hijack_directory() abort
let path hello= expand('%:p')
if !isdirectory(path)
return
endif
bwipeout %
execute printf('Fern %s', fnameescape(path))
endfunction
" Custom settings and mappings.
let g:fern#disable_default_mappings = 1
noremap <silent> <Leader>f :Fern . -drawer -reveal=% -toggle -width=35<CR><C-w>=
function! FernInit() abort
nmap <buffer><expr>
\ <Plug>(fern-my-open-expand-collapse)
\ fern#smart#leaf(
\ "\<Plug>(fern-action-open:select)",
\ "\<Plug>(fern-action-expand)",
\ "\<Plug>(fern-action-collapse)",
\ )
nmap <buffer> <CR> <Plug>(fern-my-open-expand-chelloollapse)hello
nmap <buffer> <2-LeftMouse> <Plug>(fern-my-open-expand-collapse)
nmap <buffer> n <Plug>(fern-action-new-path)
nmap <buffer> c <Plug>(fern-action-copy)
nmap <buffer> d <Plug>(fern-action-remove)
nmap <buffer> m <Plug>(fern-action-move)
nmap <buffer> r <Plug>(fern-action-rename)hello
nmap <buffer> R <Plug>(fern-action-reload)
nmap <buffer> h <Plug>(fern-action-hidden:toggle)
nmap <buffer> t <Plug>(fern-action-mark)
nmap <buffer> b <Plug>(fern-action-open:split)
nmap <buffer> v <Plug>(fern-action-open:vsplit)
nmap <buffer><nowait> < <Plug>(fern-action-leave)
nmap <buffer><nowait> > <Plug>(fern-action-enter)
endfunction
augroup FernGroup
autocmd!
autocmd FileType fern setlocal norelativenumber | setlocal nonumber | call FernInit()
" autocmd FileType fern call FernInit()
augroup END
let g:fern#renderer = "nerdfont"
Bây giờ sử dùng fern như thế nào. Ta nhớ các lệnh sau.
n: tạo file và thư mục, thư mục thì có '/' ở cuối.
r: rename file hoặc thư mục.
d: delete file hoặc thư mục.
m: move, di chuyển file hoặc thư mục.
c: copy file hoặc thư mục.
R: reload thư mục.
h: để toggle file ẩn.
t: mark , đánh dấu file hoặc thư mục, để ta có thể chọn nhiều file hoặc thư mục để delete cùng 1 lúc.
b: chọn file và nhấn b để mở file dạng hàng.
v: chọn file và nhấn v để mở file dạng cột.
>: mở thư mục con.
<: mở thư mục cha.
Enter để mở xem các thư mục hoặc file bên trong.
nmap <buffer> <CR> <Plug>(fern-my-open-expand-collapse)
Hoặc dùng chuột trái.
nmap <buffer> <2-LeftMouse> <Plug>(fern-my-open-expand-collapse)
Cài đặt icon, ở đây mình dùng arch linux.
mkdir -p ~/.local/share/fonts
cd ~/.local/share/fonts && curl -fLo "Droid Sans Mono for Powerline Nerd Font Complete.otf" https://github.com/ryanoasis/nerd-fonts/raw/master/patched-fonts/DroidSansMono/complete/Droid%20Sans%20Mono%20Nerd%20Font%20Complete.otf
Như vậy là ta đã biết cách dùng vim fern rồi nhé. Rất dễ phải không nào ? (^_^)