aboutsummaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
Diffstat (limited to 'runtime')
-rw-r--r--runtime/autoload/man.vim65
-rw-r--r--runtime/doc/map.txt21
-rw-r--r--runtime/ftplugin/man.vim7
-rw-r--r--runtime/plugin/man.vim4
4 files changed, 62 insertions, 35 deletions
diff --git a/runtime/autoload/man.vim b/runtime/autoload/man.vim
index 6c2d4eae8e..7eb7ac1ab1 100644
--- a/runtime/autoload/man.vim
+++ b/runtime/autoload/man.vim
@@ -1,12 +1,9 @@
" Maintainer: Anmol Sethi <anmol@aubble.com>
-" Ensure Vim is not recursively invoked (man-db does this)
-" by forcing man to use cat as the pager.
-" More info here http://comments.gmane.org/gmane.editors.vim.devel/29085
if &shell =~# 'fish$'
- let s:man_cmd = 'man -P cat ^/dev/null'
+ let s:man_cmd = 'man ^/dev/null'
else
- let s:man_cmd = 'man -P cat 2>/dev/null'
+ let s:man_cmd = 'man 2>/dev/null'
endif
let s:man_find_arg = "-w"
@@ -26,7 +23,7 @@ endtry
" by the user. count defaults to 0 which is a valid section and
" count1 defaults to 1 which is also a valid section. Only when they
" are equal was the count explicitly set.
-function! man#open_page(count, count1, ...) abort
+function! man#open_page(count, count1, mods, ...) abort
if a:0 > 2
call s:error('too many arguments')
return
@@ -49,48 +46,52 @@ function! man#open_page(count, count1, ...) abort
" user explicitly set a count
let sect = string(a:count)
endif
- let [sect, name] = s:verify_exists(sect, name)
+ let [sect, name, path] = s:verify_exists(sect, name)
catch
call s:error(v:exception)
return
endtry
call s:push_tag()
let bufname = 'man://'.name.(empty(sect)?'':'('.sect.')')
- let found_man = s:find_man()
- if getbufvar(bufname, 'manwidth') ==# s:manwidth()
- if found_man
- silent execute 'buf' bufnr(bufname)
- else
- execute 'split' bufname
+ if a:mods !~# 'tab' && s:find_man()
+ if s:manwidth() ==# getbufvar(bufname, 'manwidth')
+ silent execute 'buf' bufname
+ call man#set_window_local_options()
+ keepjumps 1
+ return
endif
+ noautocmd execute 'edit' bufname
+ elseif s:manwidth() ==# getbufvar(bufname, 'manwidth')
+ execute a:mods 'split' bufname
+ call man#set_window_local_options()
keepjumps 1
return
- endif
- if found_man
- noautocmd execute 'edit' bufname
else
- noautocmd execute 'split' bufname
+ noautocmd execute a:mods 'split' bufname
endif
- call s:read_page(sect, name)
+ call s:read_page(path)
endfunction
function! man#read_page(ref) abort
try
let [sect, name] = s:extract_sect_and_name_ref(a:ref)
- let [sect, name] = s:verify_exists(sect, name)
+ " The third element is the path.
+ call s:read_page(s:verify_exists(sect, name)[2])
catch
call s:error(v:exception)
return
endtry
- call s:read_page(sect, name)
endfunction
-function! s:read_page(sect, name) abort
+function! s:read_page(path) abort
setlocal modifiable
setlocal noreadonly
keepjumps %delete _
let b:manwidth = s:manwidth()
- silent execute 'read!env MANWIDTH='.b:manwidth s:man_cmd s:man_args(a:sect, a:name)
+ " Ensure Vim is not recursively invoked (man-db does this)
+ " by forcing man to use cat as the pager.
+ " More info here http://comments.gmane.org/gmane.editors.vim.devel/29085
+ silent execute 'read !env MANPAGER=cat MANWIDTH='.b:manwidth s:man_cmd a:path
" remove all the backspaced text
silent execute 'keeppatterns keepjumps %substitute,.\b,,e'.(&gdefault?'':'g')
while getline(1) =~# '^\s*$'
@@ -134,7 +135,7 @@ function! s:verify_exists(sect, name) abort
if a:name =~# '\/'
" We do not need to extract the section/name from the path if the name is
" just a path.
- return ['', a:name]
+ return ['', a:name, path]
endif
" We need to extract the section from the path because sometimes
" the actual section of the manpage is more specific than the section
@@ -142,7 +143,8 @@ function! s:verify_exists(sect, name) abort
" Also on linux, it seems that the name is case insensitive. So if one does
" ':Man PRIntf', we still want the name of the buffer to be 'printf' or
" whatever the correct capitilization is.
- return s:extract_sect_and_name_path(path[:len(path)-2])
+ let path = path[:len(path)-2]
+ return s:extract_sect_and_name_path(path) + [path]
endfunction
let s:tag_stack = []
@@ -203,6 +205,15 @@ function! s:manwidth() abort
return $MANWIDTH
endfunction
+function! man#set_window_local_options() abort
+ setlocal nonumber
+ setlocal norelativenumber
+ setlocal foldcolumn=0
+ setlocal colorcolumn=0
+ setlocal nolist
+ setlocal nofoldenable
+endfunction
+
function! s:man_args(sect, name) abort
if empty(a:sect)
return shellescape(a:name)
@@ -271,11 +282,11 @@ function! man#complete(arg_lead, cmd_line, cursor_pos) abort
return uniq(sort(map(globpath(s:mandirs,'man?/'.name.'*.'.sect.'*', 0, 1), 's:format_candidate(v:val, sect)'), 'i'))
endfunction
-function! s:format_candidate(c, sect) abort
- if a:c =~# '\.\%(pdf\|in\)$' " invalid extensions
+function! s:format_candidate(path, sect) abort
+ if a:path =~# '\.\%(pdf\|in\)$' " invalid extensions
return
endif
- let [sect, name] = s:extract_sect_and_name_path(a:c)
+ let [sect, name] = s:extract_sect_and_name_path(a:path)
if sect ==# a:sect
return name
elseif sect =~# a:sect.'[^.]\+$'
diff --git a/runtime/doc/map.txt b/runtime/doc/map.txt
index c1eef398e2..4561020d22 100644
--- a/runtime/doc/map.txt
+++ b/runtime/doc/map.txt
@@ -1406,6 +1406,27 @@ The valid escape sequences are
<bang> (See the '-bang' attribute) Expands to a ! if the
command was executed with a ! modifier, otherwise
expands to nothing.
+ *<mods>*
+ <mods> The command modifiers, if specified. Otherwise, expands to
+ nothing. Supported modifiers are |aboveleft|, |belowright|,
+ |botright|, |browse|, |confirm|, |hide|, |keepalt|,
+ |keepjumps|, |keepmarks|, |keeppatterns|, |lockmarks|,
+ |noswapfile|, |silent|, |tab|, |topleft|, |verbose|, and
+ |vertical|.
+ Examples: >
+ command! -nargs=+ -complete=file MyEdit
+ \ for f in expand(<q-args>, 0, 1) |
+ \ exe '<mods> split ' . f |
+ \ endfor
+
+ function! SpecialEdit(files, mods)
+ for f in expand(a:files, 0, 1)
+ exe a:mods . ' split ' . f
+ endfor
+ endfunction
+ command! -nargs=+ -complete=file Sedit
+ \ call SpecialEdit(<q-args>, <q-mods>)
+<
*<reg>* *<register>*
<reg> (See the '-register' attribute) The optional register,
if specified. Otherwise, expands to nothing. <register>
diff --git a/runtime/ftplugin/man.vim b/runtime/ftplugin/man.vim
index 6a9ad27956..fddfee3c31 100644
--- a/runtime/ftplugin/man.vim
+++ b/runtime/ftplugin/man.vim
@@ -33,12 +33,7 @@ setlocal tabstop=8
setlocal softtabstop=8
setlocal shiftwidth=8
-setlocal nonumber
-setlocal norelativenumber
-setlocal foldcolumn=0
-setlocal colorcolumn=0
-setlocal nolist
-setlocal nofoldenable
+call man#set_window_local_options()
if !exists('g:no_plugin_maps') && !exists('g:no_man_maps')
nmap <silent> <buffer> <C-]> <Plug>(Man)
diff --git a/runtime/plugin/man.vim b/runtime/plugin/man.vim
index d49276047f..f3fe7151ca 100644
--- a/runtime/plugin/man.vim
+++ b/runtime/plugin/man.vim
@@ -5,9 +5,9 @@ if exists('g:loaded_man')
endif
let g:loaded_man = 1
-command! -range=0 -complete=customlist,man#complete -nargs=+ Man call man#open_page(v:count, v:count1, <f-args>)
+command! -range=0 -complete=customlist,man#complete -nargs=+ Man call man#open_page(v:count, v:count1, <q-mods>, <f-args>)
-nnoremap <silent> <Plug>(Man) :<C-U>call man#open_page(v:count, v:count1, &filetype ==# 'man' ? expand('<cWORD>') : expand('<cword>'))<CR>
+nnoremap <silent> <Plug>(Man) :<C-U>call man#open_page(v:count, v:count1, '', &filetype ==# 'man' ? expand('<cWORD>') : expand('<cword>'))<CR>
augroup man
autocmd!