Mercurial > vim
annotate runtime/ftplugin/man.vim @ 10048:43efa4f5a8ea
commit https://github.com/vim/vim/commit/89bcfda6834aba724d12554a34b9ed49f5789fd5
Author: Bram Moolenaar <Bram@vim.org>
Date: Tue Aug 30 23:26:57 2016 +0200
Updated runtime files. Remove version checks for Vim older than 6.0.
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Tue, 30 Aug 2016 23:30:09 +0200 |
parents | cd9c4bbe1d03 |
children | 74effdaa369e |
rev | line source |
---|---|
7 | 1 " Vim filetype plugin file |
2 " Language: man | |
2034 | 3 " Maintainer: SungHyun Nam <goweol@gmail.com> |
9326
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
4 " Last Change: 2016 Jun 20 |
7 | 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 | |
2662 | 18 " Ensure Vim is not recursively invoked (man-db does this) |
19 " when doing ctrl-[ on a man page reference. | |
3082 | 20 if exists("$MANPAGER") |
21 let $MANPAGER = "" | |
22 endif | |
2662 | 23 |
7 | 24 " allow dot and dash in manual page name. |
25 setlocal iskeyword+=\.,- | |
26 | |
27 " Add mappings, unless the user didn't want this. | |
28 if !exists("no_plugin_maps") && !exists("no_man_maps") | |
29 if !hasmapto('<Plug>ManBS') | |
30 nmap <buffer> <LocalLeader>h <Plug>ManBS | |
31 endif | |
816 | 32 nnoremap <buffer> <Plug>ManBS :%s/.\b//g<CR>:setl nomod<CR>'' |
7 | 33 |
34 nnoremap <buffer> <c-]> :call <SID>PreGetPage(v:count)<CR> | |
35 nnoremap <buffer> <c-t> :call <SID>PopPage()<CR> | |
7272
17333ebd2bbd
commit https://github.com/vim/vim/commit/d042dc825c9b97dacd84d4728f88300da4d5b6b9
Christian Brabandt <cb@256bit.org>
parents:
6476
diff
changeset
|
36 nnoremap <buffer> <silent> q :q<CR> |
17333ebd2bbd
commit https://github.com/vim/vim/commit/d042dc825c9b97dacd84d4728f88300da4d5b6b9
Christian Brabandt <cb@256bit.org>
parents:
6476
diff
changeset
|
37 endif |
17333ebd2bbd
commit https://github.com/vim/vim/commit/d042dc825c9b97dacd84d4728f88300da4d5b6b9
Christian Brabandt <cb@256bit.org>
parents:
6476
diff
changeset
|
38 |
17333ebd2bbd
commit https://github.com/vim/vim/commit/d042dc825c9b97dacd84d4728f88300da4d5b6b9
Christian Brabandt <cb@256bit.org>
parents:
6476
diff
changeset
|
39 if exists('g:ft_man_folding_enable') && (g:ft_man_folding_enable == 1) |
17333ebd2bbd
commit https://github.com/vim/vim/commit/d042dc825c9b97dacd84d4728f88300da4d5b6b9
Christian Brabandt <cb@256bit.org>
parents:
6476
diff
changeset
|
40 setlocal foldmethod=indent foldnestmax=1 foldenable |
7 | 41 endif |
42 | |
3410
94601b379f38
Updated runtime files. Add Dutch translations.
Bram Moolenaar <bram@vim.org>
parents:
3082
diff
changeset
|
43 let b:undo_ftplugin = "setlocal iskeyword<" |
94601b379f38
Updated runtime files. Add Dutch translations.
Bram Moolenaar <bram@vim.org>
parents:
3082
diff
changeset
|
44 |
7 | 45 endif |
46 | |
47 if exists(":Man") != 2 | |
48 com -nargs=+ Man call s:GetPage(<f-args>) | |
49 nmap <Leader>K :call <SID>PreGetPage(0)<CR> | |
50 endif | |
51 | |
52 " Define functions only once. | |
53 if !exists("s:man_tag_depth") | |
54 | |
55 let s:man_tag_depth = 0 | |
56 | |
1623 | 57 let s:man_sect_arg = "" |
58 let s:man_find_arg = "-w" | |
59 try | |
60 if !has("win32") && $OSTYPE !~ 'cygwin\|linux' && system('uname -s') =~ "SunOS" && system('uname -r') =~ "^5" | |
61 let s:man_sect_arg = "-s" | |
62 let s:man_find_arg = "-l" | |
63 endif | |
64 catch /E145:/ | |
65 " Ignore the error in restricted mode | |
66 endtry | |
7 | 67 |
68 func <SID>PreGetPage(cnt) | |
69 if a:cnt == 0 | |
70 let old_isk = &iskeyword | |
6369 | 71 if &ft == 'man' |
72 setl iskeyword+=(,) | |
73 endif | |
7 | 74 let str = expand("<cword>") |
75 let &l:iskeyword = old_isk | |
76 let page = substitute(str, '(*\(\k\+\).*', '\1', '') | |
77 let sect = substitute(str, '\(\k\+\)(\([^()]*\)).*', '\2', '') | |
78 if match(sect, '^[0-9 ]\+$') == -1 | |
79 let sect = "" | |
80 endif | |
81 if sect == page | |
82 let sect = "" | |
83 endif | |
84 else | |
85 let sect = a:cnt | |
86 let page = expand("<cword>") | |
87 endif | |
88 call s:GetPage(sect, page) | |
89 endfunc | |
90 | |
91 func <SID>GetCmdArg(sect, page) | |
92 if a:sect == '' | |
93 return a:page | |
94 endif | |
95 return s:man_sect_arg.' '.a:sect.' '.a:page | |
96 endfunc | |
97 | |
98 func <SID>FindPage(sect, page) | |
99 let where = system("/usr/bin/man ".s:man_find_arg.' '.s:GetCmdArg(a:sect, a:page)) | |
100 if where !~ "^/" | |
101 if matchstr(where, " [^ ]*$") !~ "^ /" | |
102 return 0 | |
103 endif | |
104 endif | |
105 return 1 | |
106 endfunc | |
107 | |
108 func <SID>GetPage(...) | |
109 if a:0 >= 2 | |
110 let sect = a:1 | |
111 let page = a:2 | |
112 elseif a:0 >= 1 | |
113 let sect = "" | |
114 let page = a:1 | |
115 else | |
116 return | |
117 endif | |
118 | |
119 " To support: nmap K :Man <cword> | |
120 if page == '<cword>' | |
121 let page = expand('<cword>') | |
122 endif | |
123 | |
124 if sect != "" && s:FindPage(sect, page) == 0 | |
125 let sect = "" | |
126 endif | |
127 if s:FindPage(sect, page) == 0 | |
128 echo "\nCannot find a '".page."'." | |
129 return | |
130 endif | |
131 exec "let s:man_tag_buf_".s:man_tag_depth." = ".bufnr("%") | |
132 exec "let s:man_tag_lin_".s:man_tag_depth." = ".line(".") | |
133 exec "let s:man_tag_col_".s:man_tag_depth." = ".col(".") | |
134 let s:man_tag_depth = s:man_tag_depth + 1 | |
135 | |
136 " Use an existing "man" window if it exists, otherwise open a new one. | |
137 if &filetype != "man" | |
138 let thiswin = winnr() | |
139 exe "norm! \<C-W>b" | |
1125 | 140 if winnr() > 1 |
7 | 141 exe "norm! " . thiswin . "\<C-W>w" |
142 while 1 | |
143 if &filetype == "man" | |
144 break | |
145 endif | |
146 exe "norm! \<C-W>w" | |
147 if thiswin == winnr() | |
148 break | |
149 endif | |
150 endwhile | |
151 endif | |
1125 | 152 if &filetype != "man" |
9326
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
153 if exists("g:ft_man_open_mode") |
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
154 if g:ft_man_open_mode == "vert" |
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
155 vnew |
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
156 elseif g:ft_man_open_mode == "tab" |
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
157 tabnew |
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
158 else |
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
159 new |
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
160 endif |
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
161 else |
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
162 new |
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
163 endif |
1125 | 164 setl nonu fdc=0 |
165 endif | |
7 | 166 endif |
167 silent exec "edit $HOME/".page.".".sect."~" | |
168 " Avoid warning for editing the dummy file twice | |
816 | 169 setl buftype=nofile noswapfile |
7 | 170 |
5220 | 171 setl ma nonu nornu nofen |
7 | 172 silent exec "norm 1GdG" |
9326
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
173 let unsetwidth = 0 |
7992
78106b0f2c56
commit https://github.com/vim/vim/commit/cbebd4879cc78e670d79b2c57dc33d7b911c962a
Christian Brabandt <cb@256bit.org>
parents:
7272
diff
changeset
|
174 if empty($MANWIDTH) |
78106b0f2c56
commit https://github.com/vim/vim/commit/cbebd4879cc78e670d79b2c57dc33d7b911c962a
Christian Brabandt <cb@256bit.org>
parents:
7272
diff
changeset
|
175 let $MANWIDTH = winwidth(0) |
9326
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
176 let unsetwidth = 1 |
7992
78106b0f2c56
commit https://github.com/vim/vim/commit/cbebd4879cc78e670d79b2c57dc33d7b911c962a
Christian Brabandt <cb@256bit.org>
parents:
7272
diff
changeset
|
177 endif |
7 | 178 silent exec "r!/usr/bin/man ".s:GetCmdArg(sect, page)." | col -b" |
9326
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
179 if unsetwidth |
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
180 let $MANWIDTH = '' |
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
181 endif |
7 | 182 " Remove blank lines from top and bottom. |
183 while getline(1) =~ '^\s*$' | |
6476 | 184 silent keepj norm ggdd |
7 | 185 endwhile |
186 while getline('$') =~ '^\s*$' | |
6476 | 187 silent keepj norm Gdd |
7 | 188 endwhile |
189 1 | |
190 setl ft=man nomod | |
191 setl bufhidden=hide | |
192 setl nobuflisted | |
9326
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
193 setl noma |
7 | 194 endfunc |
195 | |
196 func <SID>PopPage() | |
197 if s:man_tag_depth > 0 | |
198 let s:man_tag_depth = s:man_tag_depth - 1 | |
199 exec "let s:man_tag_buf=s:man_tag_buf_".s:man_tag_depth | |
200 exec "let s:man_tag_lin=s:man_tag_lin_".s:man_tag_depth | |
201 exec "let s:man_tag_col=s:man_tag_col_".s:man_tag_depth | |
202 exec s:man_tag_buf."b" | |
203 exec s:man_tag_lin | |
204 exec "norm ".s:man_tag_col."|" | |
205 exec "unlet s:man_tag_buf_".s:man_tag_depth | |
206 exec "unlet s:man_tag_lin_".s:man_tag_depth | |
207 exec "unlet s:man_tag_col_".s:man_tag_depth | |
208 unlet s:man_tag_buf s:man_tag_lin s:man_tag_col | |
209 endif | |
210 endfunc | |
211 | |
212 endif | |
213 | |
9326
cd9c4bbe1d03
commit https://github.com/vim/vim/commit/ddf8d1c746ee081d15c9d7e0515f6ac43adbf363
Christian Brabandt <cb@256bit.org>
parents:
7992
diff
changeset
|
214 " vim: set sw=2 ts=8 noet: |