这并不是在文件名上点击“p”,而是只需将光标放在其上即可获得相同的结果。
最佳答案
您可以将一些 Action 重新映射到根据光标下的当前单词填充预览窗口的功能。
这是处理文本文件和目录的基本示例:
set nocompatible
set autochdir
" Previewed files are present in the current directory
let g:netrw_keepdir = 0
function! PreviewFile(...)
let l:wordUnderCursor = a:1
if !empty(glob(l:wordUnderCursor))
let l:type = system('file -ib ' . shellescape(l:wordUnderCursor))
if l:type =~# '^text/plain'
silent! execute 'pedit' l:wordUnderCursor
elseif l:type =~# '^inode/directory'
let l:name = tempname()
set noautochdir
silent! execute 'pedit! ' . l:name
wincmd P
normal! ggdG
silent! execute 'r !ls ' . l:wordUnderCursor
normal! ggdd
wincmd w
endif
endif
endfunction
autocmd FileType netrw
\ nnoremap j j:call PreviewFile(expand("<cWORD>"))<CR> |
\ nnoremap k k:call PreviewFile(expand("<cWORD>"))<CR>
关于vim - 有没有办法在 netrw 列表中将光标放在文件上时自动预览文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45379462/