Let's say I'm a terrible person and I'm thinking about remapping <CR>
to do what :
normally does (start command-line mode).
Vim's built-in netrw
plugin also remaps <CR>
to open the selected directory or file. Specifically, it appears to map it to
:call netrw#LocalBrowseCheck(<SID>NetrwBrowseChgDir(1, <SID>NetrwGetWord()))`)<CR>
The use of <SID>
makes it impractical for me to simply reproduce this map in my .vimrc
, which I would like to do, because I would like to
autocmd FileType netrw nnoremap <buffer> <CR> :
in order to access command-line mode consistently. What might be an effective way to move netrw
's default <CR>
functionality to another keystroke so I can still open files with it?
My experiments thus far have led to my trying to use maparg
to do something like
function! s:ConfigureNetrw()
execute "nnoremap <buffer> o " . maparg("<CR>", "n")
nnoremap <buffer> <CR> :
endfunction
augroup configure_netrw
autocmd!
autocmd FileType netrw call s:ConfigureNetrw()
augroup end
However this seems to result in both <CR>
and o
doing the same thing when I check the output of nmap
(they both get mapped to :
). I could understand how this might happen if I used nmap
, since the maparg
result has a <CR>
in it. But it confuses me how it doesn't seem to matter if I use nmap
or nnoremap
; the same thing happens.
EDIT: After a lot of frustrated poking around I have narrowed my apparent problem to this:
let g:prior = maparg("<CR>", "n")
nmap <buffer> <CR> -
I put this in ~/.vim/after/ftplugin/netrw.vim
. I would expect that getting into a Netrw buffer and doing :echo g:prior
would print the LocalBrowseCheck
text that netrw maps <CR>
to. Instead it prints -
.
This happens if I put the same two lines in a function called from an autocmd
, as I was originally doing. It happens if use nnoremap
instead of nmap
. It does not happen if I change the filename or autocmd so it associates with a different filetype (say, text); in that it prints what <CR>
is originally bound to (:
). I am now completely confused.