my core question how create custom mapping allows count , motion. count override motion. clarify want following work:
[count][cmd] - useful on [count] lines, , not wait [motion].
[cmd][motion] - useful in range of [motion] of lines.
my exact scenario trying add comments lines, use information other mappings in vimrc. here have far.
"comment motion of lines nmap <silent> ,c :set opfunc=comment<cr>g@ "comment count lines nmap <silent> ,cc :s/^/\/\//<cr>:noh<cr> function! comment(...) silent exe "'[,']s/^/\\/\\//" silent exe "noh" endfunction ,c[motion] comments line motion. [count],cc comments line count.
i ,c[motion] , [count],c work.
is possible?
edit: clarified quesiton. changed "range" "count"
function s:executecountormotion() setlocal operatorfunc=comment if v:count 0 return 'g@' else return 'g@g@' endif endfunction nnoremap <expr> ,c <sid>executecountormotion() by way, don't need execute:
- instead of
silent exe "{range}s/.../.../"should write{range}s/.../.../e. - you can use
s#^#//#eavoid escaping. silent nohlworkssilent execute "nohl", causes vim not parsing of additional line.
Comments
Post a Comment