Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 186 lines (162 sloc) 4.608 kb
e5c6ef7 updated for version 7.0001
vimboss authored
1 " Vim filetype plugin file
2 " Language: man
4895774 Update runtime files.
Bram Moolenaar authored
3 " Maintainer: SungHyun Nam <goweol@gmail.com>
f2c486c Update runtime files.
Bram Moolenaar authored
4 " Last Change: 2010 Nov 29
e5c6ef7 updated for version 7.0001
vimboss authored
5
6 " To make the ":Man" command available before editing a manual page, source
7 " this script from your startup vimrc file.
8
9 " If 'filetype' isn't "man", we must have been called to only define ":Man".
10 if &filetype == "man"
11
12 " Only do this when not done yet for this buffer
13 if exists("b:did_ftplugin")
14 finish
15 endif
16 let b:did_ftplugin = 1
17
f2c486c Update runtime files.
Bram Moolenaar authored
18 " Ensure Vim is not recursively invoked (man-db does this)
19 " when doing ctrl-[ on a man page reference.
20 let $MANPAGER = ""
21
e5c6ef7 updated for version 7.0001
vimboss authored
22 " allow dot and dash in manual page name.
23 setlocal iskeyword+=\.,-
24
25 " Add mappings, unless the user didn't want this.
26 if !exists("no_plugin_maps") && !exists("no_man_maps")
27 if !hasmapto('<Plug>ManBS')
28 nmap <buffer> <LocalLeader>h <Plug>ManBS
29 endif
318148d updated for version 7.0c02
vimboss authored
30 nnoremap <buffer> <Plug>ManBS :%s/.\b//g<CR>:setl nomod<CR>''
e5c6ef7 updated for version 7.0001
vimboss authored
31
32 nnoremap <buffer> <c-]> :call <SID>PreGetPage(v:count)<CR>
33 nnoremap <buffer> <c-t> :call <SID>PopPage()<CR>
34 endif
35
36 endif
37
38 if exists(":Man") != 2
39 com -nargs=+ Man call s:GetPage(<f-args>)
40 nmap <Leader>K :call <SID>PreGetPage(0)<CR>
41 endif
42
43 " Define functions only once.
44 if !exists("s:man_tag_depth")
45
46 let s:man_tag_depth = 0
47
0554c4a updated for version 7.2a
vimboss authored
48 let s:man_sect_arg = ""
49 let s:man_find_arg = "-w"
50 try
51 if !has("win32") && $OSTYPE !~ 'cygwin\|linux' && system('uname -s') =~ "SunOS" && system('uname -r') =~ "^5"
52 let s:man_sect_arg = "-s"
53 let s:man_find_arg = "-l"
54 endif
55 catch /E145:/
56 " Ignore the error in restricted mode
57 endtry
e5c6ef7 updated for version 7.0001
vimboss authored
58
59 func <SID>PreGetPage(cnt)
60 if a:cnt == 0
61 let old_isk = &iskeyword
62 setl iskeyword+=(,)
63 let str = expand("<cword>")
64 let &l:iskeyword = old_isk
65 let page = substitute(str, '(*\(\k\+\).*', '\1', '')
66 let sect = substitute(str, '\(\k\+\)(\([^()]*\)).*', '\2', '')
67 if match(sect, '^[0-9 ]\+$') == -1
68 let sect = ""
69 endif
70 if sect == page
71 let sect = ""
72 endif
73 else
74 let sect = a:cnt
75 let page = expand("<cword>")
76 endif
77 call s:GetPage(sect, page)
78 endfunc
79
80 func <SID>GetCmdArg(sect, page)
81 if a:sect == ''
82 return a:page
83 endif
84 return s:man_sect_arg.' '.a:sect.' '.a:page
85 endfunc
86
87 func <SID>FindPage(sect, page)
88 let where = system("/usr/bin/man ".s:man_find_arg.' '.s:GetCmdArg(a:sect, a:page))
89 if where !~ "^/"
90 if matchstr(where, " [^ ]*$") !~ "^ /"
91 return 0
92 endif
93 endif
94 return 1
95 endfunc
96
97 func <SID>GetPage(...)
98 if a:0 >= 2
99 let sect = a:1
100 let page = a:2
101 elseif a:0 >= 1
102 let sect = ""
103 let page = a:1
104 else
105 return
106 endif
107
108 " To support: nmap K :Man <cword>
109 if page == '<cword>'
110 let page = expand('<cword>')
111 endif
112
113 if sect != "" && s:FindPage(sect, page) == 0
114 let sect = ""
115 endif
116 if s:FindPage(sect, page) == 0
117 echo "\nCannot find a '".page."'."
118 return
119 endif
120 exec "let s:man_tag_buf_".s:man_tag_depth." = ".bufnr("%")
121 exec "let s:man_tag_lin_".s:man_tag_depth." = ".line(".")
122 exec "let s:man_tag_col_".s:man_tag_depth." = ".col(".")
123 let s:man_tag_depth = s:man_tag_depth + 1
124
125 " Use an existing "man" window if it exists, otherwise open a new one.
126 if &filetype != "man"
127 let thiswin = winnr()
128 exe "norm! \<C-W>b"
49b03a5 updated for version 7.1a
vimboss authored
129 if winnr() > 1
e5c6ef7 updated for version 7.0001
vimboss authored
130 exe "norm! " . thiswin . "\<C-W>w"
131 while 1
132 if &filetype == "man"
133 break
134 endif
135 exe "norm! \<C-W>w"
136 if thiswin == winnr()
137 break
138 endif
139 endwhile
140 endif
49b03a5 updated for version 7.1a
vimboss authored
141 if &filetype != "man"
142 new
143 setl nonu fdc=0
144 endif
e5c6ef7 updated for version 7.0001
vimboss authored
145 endif
146 silent exec "edit $HOME/".page.".".sect."~"
147 " Avoid warning for editing the dummy file twice
318148d updated for version 7.0c02
vimboss authored
148 setl buftype=nofile noswapfile
e5c6ef7 updated for version 7.0001
vimboss authored
149
318148d updated for version 7.0c02
vimboss authored
150 setl ma
e5c6ef7 updated for version 7.0001
vimboss authored
151 silent exec "norm 1GdG"
152 let $MANWIDTH = winwidth(0)
153 silent exec "r!/usr/bin/man ".s:GetCmdArg(sect, page)." | col -b"
154 " Remove blank lines from top and bottom.
155 while getline(1) =~ '^\s*$'
156 silent norm ggdd
157 endwhile
158 while getline('$') =~ '^\s*$'
159 silent norm Gdd
160 endwhile
161 1
162 setl ft=man nomod
163 setl bufhidden=hide
164 setl nobuflisted
165 endfunc
166
167 func <SID>PopPage()
168 if s:man_tag_depth > 0
169 let s:man_tag_depth = s:man_tag_depth - 1
170 exec "let s:man_tag_buf=s:man_tag_buf_".s:man_tag_depth
171 exec "let s:man_tag_lin=s:man_tag_lin_".s:man_tag_depth
172 exec "let s:man_tag_col=s:man_tag_col_".s:man_tag_depth
173 exec s:man_tag_buf."b"
174 exec s:man_tag_lin
175 exec "norm ".s:man_tag_col."|"
176 exec "unlet s:man_tag_buf_".s:man_tag_depth
177 exec "unlet s:man_tag_lin_".s:man_tag_depth
178 exec "unlet s:man_tag_col_".s:man_tag_depth
179 unlet s:man_tag_buf s:man_tag_lin s:man_tag_col
180 endif
181 endfunc
182
183 endif
184
185 " vim: set sw=2:
Something went wrong with that request. Please try again.