man.vim: default K mapping

- Also some small improvements in other parts.
This commit is contained in:
Anmol Sethi 2016-08-05 00:04:48 -04:00
parent 64013a5deb
commit f665bde183
3 changed files with 19 additions and 17 deletions

View File

@ -22,7 +22,7 @@ catch /E145:/
" Ignore the error in restricted mode " Ignore the error in restricted mode
endtry endtry
function! man#open_page_command(...) abort function! man#open_page_command(count, count1, ...) abort
if a:0 > 2 if a:0 > 2
call s:error('too many arguments') call s:error('too many arguments')
return return
@ -40,6 +40,10 @@ function! man#open_page_command(...) abort
endif endif
try try
let [sect, name] = s:extract_sect_and_name_ref(ref) let [sect, name] = s:extract_sect_and_name_ref(ref)
if a:count ==# a:count1
" user explicitly set a count
let sect = string(a:count)
endif
let [sect, name] = s:verify_exists(sect, name) let [sect, name] = s:verify_exists(sect, name)
catch catch
call s:error(v:exception) call s:error(v:exception)
@ -54,7 +58,7 @@ endfunction
" are equal was the count explicitly set. " are equal was the count explicitly set.
function! man#open_page_mapping(count, count1, ref) abort function! man#open_page_mapping(count, count1, ref) abort
if empty(a:ref) if empty(a:ref)
call s:error('what manual page do you want?') call s:error('missing argument')
return return
endif endif
try try
@ -164,25 +168,23 @@ function! s:open_page(sect, name)
endif endif
if getbufvar(bufname, 'manwidth') ==# manwidth if getbufvar(bufname, 'manwidth') ==# manwidth
if found_man if found_man
silent execute 'buf '.bufnr(bufname) silent execute 'buf' bufnr(bufname)
else else
execute 'split '.bufname execute 'split' bufname
setlocal nobuflisted
endif endif
keepjumps 1 keepjumps 1
return return
endif endif
let already_opened = bufexists(bufname)
if found_man if found_man
execute 'edit '.bufname execute 'edit' bufname
else else
execute 'split '.bufname execute 'split' bufname
endif endif
if already_opened setlocal modifiable
setlocal modifiable setlocal noreadonly
setlocal noreadonly keepjumps %delete _
keepjumps %delete _ silent execute 'read!env MANWIDTH='.manwidth s:man_cmd s:man_args(a:sect, a:name)
endif
silent execute 'read!env MANWIDTH='.manwidth.' '.s:man_cmd.' '.s:man_args(a:sect, a:name)
let b:manwidth = manwidth let b:manwidth = manwidth
" remove all the backspaced text " remove all the backspaced text
silent keeppatterns keepjumps %substitute,.\b,,ge silent keeppatterns keepjumps %substitute,.\b,,ge

View File

@ -17,9 +17,9 @@ if has('vim_starting')
else else
keepjumps 1 keepjumps 1
endif endif
" This is not perfect.See `man glDrawArraysInstanced`. Since the title is " This is not perfect. See `man glDrawArraysInstanced`. Since the title is
" all caps it is impossible to tell what the original capitilization was. " all caps it is impossible to tell what the original capitilization was.
execute 'file '.'man://'.tolower(matchstr(getline(1), '^\S\+')) execute 'file man://'.tolower(matchstr(getline(1), '^\S\+'))
endif endif
setlocal buftype=nofile setlocal buftype=nofile

View File

@ -5,6 +5,6 @@ if exists('g:loaded_man')
endif endif
let g:loaded_man = 1 let g:loaded_man = 1
command! -complete=customlist,man#complete -nargs=* Man call man#open_page_command(<f-args>) command! -count=0 -complete=customlist,man#complete -nargs=* Man call man#open_page_command(v:count, v:count1, <f-args>)
nnoremap <silent> <Plug>(Man) :<C-U>call man#open_page_mapping(v:count, v:count1, expand('<cWORD>'))<CR> nnoremap <silent> <Plug>(Man) :<C-U>call man#open_page_mapping(v:count, v:count1, &filetype ==# 'man' ? expand('<cWORD>') : expand('<cword>'))<CR>