我發現Vim的快捷鍵nmap <enter> o<esc>
或nmap <enter> O<esc>
,它用enter鍵插入一個空行,非常有用。然而,他們對插件造成嚴重破壞;例如,ag.vim
,它使用要跳轉到的文件名填充quickfix列表。在這個窗口中按回車(應該跳轉到文件)給我錯誤E21: Cannot make changes; modifiable is off
。如何檢查Vim緩衝區是否可修改?
爲了避免在quickfix緩衝區應用映射,我可以這樣做:
" insert blank lines with <enter>
function! NewlineWithEnter()
if &buftype ==# 'quickfix'
execute "normal! \<CR>"
else
execute "normal! O\<esc>"
endif
endfunction
nnoremap <CR> :call NewlineWithEnter()<CR>
這工作,但我真正想要的是避免映射任何不可更改緩衝,不只是在quickfix窗口。例如,映射在位置列表中也沒有意義(也可能會破壞使用它的其他插件)。如何檢查我是否處於可修改的緩衝區中?
感謝@肯特 - 我接受了其他答案,因爲它正好回答了我的問題,但我在.vimrc中使用了你的映射:) – Sasgorilla