Mercurial > vim
annotate runtime/macros/less.vim @ 26634:c75f70257cf5 v8.2.3846
patch 8.2.3846: no error when using control character for 'lcs' or 'fcs'
Commit: https://github.com/vim/vim/commit/60618c8f1a7ea55452837a446525272142286471
Author: zeertzjq <zeertzjq@outlook.com>
Date: Sat Dec 18 15:32:46 2021 +0000
patch 8.2.3846: no error when using control character for 'lcs' or 'fcs'
Problem: No error when using control character for 'lcs' or 'fcs'.
Solution: Use char2cells() to check the width. (closes https://github.com/vim/vim/issues/9369)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 18 Dec 2021 16:45:03 +0100 |
parents | fab58304f77d |
children | 4027cefc2aab |
rev | line source |
---|---|
7 | 1 " Vim script to work like "less" |
2 " Maintainer: Bram Moolenaar <Bram@vim.org> | |
23305 | 3 " Last Change: 2020 Dec 17 |
7 | 4 |
5 " Avoid loading this file twice, allow the user to define his own script. | |
6 if exists("loaded_less") | |
7 finish | |
8 endif | |
9 let loaded_less = 1 | |
10 | |
11 " If not reading from stdin, skip files that can't be read. | |
12 " Exit if there is no file at all. | |
13 if argc() > 0 | |
14 let s:i = 0 | |
15 while 1 | |
16 if filereadable(argv(s:i)) | |
17 if s:i != 0 | |
18 sleep 3 | |
19 endif | |
20 break | |
21 endif | |
22 if isdirectory(argv(s:i)) | |
23 echomsg "Skipping directory " . argv(s:i) | |
24 elseif getftime(argv(s:i)) < 0 | |
25 echomsg "Skipping non-existing file " . argv(s:i) | |
26 else | |
27 echomsg "Skipping unreadable file " . argv(s:i) | |
28 endif | |
29 echo "\n" | |
30 let s:i = s:i + 1 | |
31 if s:i == argc() | |
32 quit | |
33 endif | |
34 next | |
35 endwhile | |
36 endif | |
37 | |
23305 | 38 " we don't want 'compatible' here |
39 if &cp | |
40 set nocp | |
41 endif | |
42 | |
43 " enable syntax highlighting if not done already | |
44 if !get(g:, 'syntax_on', 0) | |
45 syntax enable | |
46 endif | |
47 | |
7 | 48 set so=0 |
49 set hlsearch | |
50 set incsearch | |
51 nohlsearch | |
52 " Don't remember file names and positions | |
53 set viminfo= | |
54 set nows | |
55 " Inhibit screen updates while searching | |
56 let s:lz = &lz | |
57 set lz | |
58 | |
7245
8896150aba23
commit https://github.com/vim/vim/commit/e392eb41f8dfc01bd13634e534ac6b4d505326f4
Christian Brabandt <cb@256bit.org>
parents:
5908
diff
changeset
|
59 " Allow the user to define a function, which can set options specifically for |
8896150aba23
commit https://github.com/vim/vim/commit/e392eb41f8dfc01bd13634e534ac6b4d505326f4
Christian Brabandt <cb@256bit.org>
parents:
5908
diff
changeset
|
60 " this script. |
8896150aba23
commit https://github.com/vim/vim/commit/e392eb41f8dfc01bd13634e534ac6b4d505326f4
Christian Brabandt <cb@256bit.org>
parents:
5908
diff
changeset
|
61 if exists('*LessInitFunc') |
8896150aba23
commit https://github.com/vim/vim/commit/e392eb41f8dfc01bd13634e534ac6b4d505326f4
Christian Brabandt <cb@256bit.org>
parents:
5908
diff
changeset
|
62 call LessInitFunc() |
8896150aba23
commit https://github.com/vim/vim/commit/e392eb41f8dfc01bd13634e534ac6b4d505326f4
Christian Brabandt <cb@256bit.org>
parents:
5908
diff
changeset
|
63 endif |
8896150aba23
commit https://github.com/vim/vim/commit/e392eb41f8dfc01bd13634e534ac6b4d505326f4
Christian Brabandt <cb@256bit.org>
parents:
5908
diff
changeset
|
64 |
7 | 65 " Used after each command: put cursor at end and display position |
66 if &wrap | |
67 noremap <SID>L L0:redraw<CR>:file<CR> | |
68 au VimEnter * normal! L0 | |
69 else | |
70 noremap <SID>L Lg0:redraw<CR>:file<CR> | |
71 au VimEnter * normal! Lg0 | |
72 endif | |
73 | |
74 " When reading from stdin don't consider the file modified. | |
75 au VimEnter * set nomod | |
76 | |
20552 | 77 " Can't modify the text or write the file. |
78 set nomodifiable readonly | |
7 | 79 |
80 " Give help | |
81 noremap h :call <SID>Help()<CR> | |
82 map H h | |
83 fun! s:Help() | |
84 echo "<Space> One page forward b One page backward" | |
85 echo "d Half a page forward u Half a page backward" | |
86 echo "<Enter> One line forward k One line backward" | |
87 echo "G End of file g Start of file" | |
88 echo "N% percentage in file" | |
89 echo "\n" | |
90 echo "/pattern Search for pattern ?pattern Search backward for pattern" | |
91 echo "n next pattern match N Previous pattern match" | |
11347 | 92 if &foldmethod != "manual" |
93 echo "\n" | |
94 echo "zR open all folds zm increase fold level" | |
95 endif | |
7 | 96 echo "\n" |
97 echo ":n<Enter> Next file :p<Enter> Previous file" | |
98 echo "\n" | |
99 echo "q Quit v Edit file" | |
100 let i = input("Hit Enter to continue") | |
101 endfun | |
102 | |
103 " Scroll one page forward | |
104 noremap <script> <Space> :call <SID>NextPage()<CR><SID>L | |
105 map <C-V> <Space> | |
106 map f <Space> | |
107 map <C-F> <Space> | |
5908 | 108 map <PageDown> <Space> |
109 map <kPageDown> <Space> | |
110 map <S-Down> <Space> | |
11347 | 111 " If 'foldmethod' was changed keep the "z" commands, e.g. "zR" to open all |
112 " folds. | |
113 if &foldmethod == "manual" | |
114 map z <Space> | |
115 endif | |
7 | 116 map <Esc><Space> <Space> |
117 fun! s:NextPage() | |
118 if line(".") == line("$") | |
119 if argidx() + 1 >= argc() | |
3513 | 120 " Don't quit at the end of the last file |
121 return | |
7 | 122 endif |
123 next | |
124 1 | |
125 else | |
126 exe "normal! \<C-F>" | |
127 endif | |
128 endfun | |
129 | |
130 " Re-read file and page forward "tail -f" | |
131 map F :e<CR>G<SID>L:sleep 1<CR>F | |
132 | |
133 " Scroll half a page forward | |
134 noremap <script> d <C-D><SID>L | |
135 map <C-D> d | |
136 | |
137 " Scroll one line forward | |
138 noremap <script> <CR> <C-E><SID>L | |
139 map <C-N> <CR> | |
140 map e <CR> | |
141 map <C-E> <CR> | |
142 map j <CR> | |
143 map <C-J> <CR> | |
5908 | 144 map <Down> <CR> |
7 | 145 |
146 " Scroll one page backward | |
147 noremap <script> b <C-B><SID>L | |
148 map <C-B> b | |
5908 | 149 map <PageUp> b |
150 map <kPageUp> b | |
151 map <S-Up> b | |
7 | 152 map w b |
153 map <Esc>v b | |
154 | |
155 " Scroll half a page backward | |
156 noremap <script> u <C-U><SID>L | |
157 noremap <script> <C-U> <C-U><SID>L | |
158 | |
159 " Scroll one line backward | |
160 noremap <script> k <C-Y><SID>L | |
161 map y k | |
162 map <C-Y> k | |
163 map <C-P> k | |
164 map <C-K> k | |
5908 | 165 map <Up> k |
7 | 166 |
167 " Redraw | |
168 noremap <script> r <C-L><SID>L | |
169 noremap <script> <C-R> <C-L><SID>L | |
170 noremap <script> R <C-L><SID>L | |
171 | |
172 " Start of file | |
173 noremap <script> g gg<SID>L | |
174 map < g | |
175 map <Esc>< g | |
5908 | 176 map <Home> g |
177 map <kHome> g | |
7 | 178 |
179 " End of file | |
180 noremap <script> G G<SID>L | |
181 map > G | |
182 map <Esc>> G | |
5908 | 183 map <End> G |
184 map <kEnd> G | |
7 | 185 |
186 " Go to percentage | |
187 noremap <script> % %<SID>L | |
188 map p % | |
189 | |
190 " Search | |
191 noremap <script> / H$:call <SID>Forward()<CR>/ | |
192 if &wrap | |
193 noremap <script> ? H0:call <SID>Backward()<CR>? | |
194 else | |
195 noremap <script> ? Hg0:call <SID>Backward()<CR>? | |
196 endif | |
197 | |
198 fun! s:Forward() | |
199 " Searching forward | |
200 noremap <script> n H$nzt<SID>L | |
201 if &wrap | |
202 noremap <script> N H0Nzt<SID>L | |
203 else | |
204 noremap <script> N Hg0Nzt<SID>L | |
205 endif | |
1125 | 206 cnoremap <silent> <script> <CR> <CR>:cunmap <lt>CR><CR>zt<SID>L |
7 | 207 endfun |
208 | |
209 fun! s:Backward() | |
210 " Searching backward | |
211 if &wrap | |
212 noremap <script> n H0nzt<SID>L | |
213 else | |
214 noremap <script> n Hg0nzt<SID>L | |
215 endif | |
216 noremap <script> N H$Nzt<SID>L | |
1125 | 217 cnoremap <silent> <script> <CR> <CR>:cunmap <lt>CR><CR>zt<SID>L |
7 | 218 endfun |
219 | |
220 call s:Forward() | |
5908 | 221 cunmap <CR> |
7 | 222 |
223 " Quitting | |
224 noremap q :q<CR> | |
225 | |
226 " Switch to editing (switch off less mode) | |
227 map v :silent call <SID>End()<CR> | |
228 fun! s:End() | |
229 set ma | |
874 | 230 if exists('s:lz') |
7 | 231 let &lz = s:lz |
232 endif | |
233 unmap h | |
234 unmap H | |
235 unmap <Space> | |
236 unmap <C-V> | |
237 unmap f | |
238 unmap <C-F> | |
239 unmap z | |
240 unmap <Esc><Space> | |
241 unmap F | |
242 unmap d | |
243 unmap <C-D> | |
244 unmap <CR> | |
245 unmap <C-N> | |
246 unmap e | |
247 unmap <C-E> | |
248 unmap j | |
249 unmap <C-J> | |
250 unmap b | |
251 unmap <C-B> | |
252 unmap w | |
253 unmap <Esc>v | |
254 unmap u | |
255 unmap <C-U> | |
256 unmap k | |
257 unmap y | |
258 unmap <C-Y> | |
259 unmap <C-P> | |
260 unmap <C-K> | |
261 unmap r | |
262 unmap <C-R> | |
263 unmap R | |
264 unmap g | |
265 unmap < | |
266 unmap <Esc>< | |
267 unmap G | |
268 unmap > | |
269 unmap <Esc>> | |
270 unmap % | |
271 unmap p | |
272 unmap n | |
273 unmap N | |
274 unmap q | |
275 unmap v | |
276 unmap / | |
277 unmap ? | |
5908 | 278 unmap <Up> |
279 unmap <Down> | |
280 unmap <PageDown> | |
281 unmap <kPageDown> | |
282 unmap <PageUp> | |
283 unmap <kPageUp> | |
284 unmap <S-Down> | |
285 unmap <S-Up> | |
286 unmap <Home> | |
287 unmap <kHome> | |
288 unmap <End> | |
289 unmap <kEnd> | |
7 | 290 endfun |
291 | |
292 " vim: sw=2 |