1
- " keyword based jump dictionary maps {{{1
1
+ " K {{{1
2
+ " keyword based jump dictionary maps {{{2
3
+
2
4
" Mapping short keywords to their longer version so they can be found
3
5
" in man page with 'K'
4
6
" '\[' at the end of the keyword ensures the match jumps to the correct
@@ -105,7 +107,8 @@ let s:highlight_group_manpage_section = {
105
107
\ ' tmuxMiscCmds' : ' MISCELLANEOUS'
106
108
\ }
107
109
108
- " keyword based jump {{{1
110
+ " keyword based jump {{{2
111
+
109
112
function ! s: get_search_keyword (keyword )
110
113
if has_key (s: keyword_mappings , a: keyword )
111
114
return s: keyword_mappings [a: keyword ]
@@ -147,7 +150,8 @@ function! s:keyword_based_jump(highlight_group, keyword)
147
150
end
148
151
endfunction
149
152
150
- " highlight group based jump {{{1
153
+ " highlight group based jump {{{2
154
+
151
155
let s: highlight_group_to_match_mapping = {
152
156
\ ' tmuxKeyTable' : [' KEY BINDINGS' , ' ^\s\+\zslist-keys' , ' ' ],
153
157
\ ' tmuxLayoutOptionValue' : [' WINDOWS AND PANES' , ' ^\s\+\zs{}' , ' ^\s\+\zsThe following layouts are supported' ],
@@ -189,7 +193,8 @@ function! s:highlight_group_based_jump(highlight_group, keyword)
189
193
echohl ErrorMsg | echo " Sorry, couldn't find the exact description" | echohl None
190
194
end
191
195
endfunction
192
- " just open manpage {{{1
196
+ " just open manpage {{{2
197
+
193
198
function ! s: just_open_manpage (highlight_group)
194
199
let hg = a: highlight_group
195
200
let char_under_cursor = getline (' .' )[col (' .' )-1 ]
@@ -207,7 +212,8 @@ function! s:just_open_manpage(highlight_group)
207
212
endif
208
213
endfunction
209
214
210
- " 'public' function {{{1
215
+ " 'public' function {{{2
216
+
211
217
function ! tmux#man (... )
212
218
if ! exists (" :Man" )
213
219
runtime ! ftplugin/man.vim
@@ -223,3 +229,87 @@ function! tmux#man(...)
223
229
return s: keyword_based_jump (highlight_group, keyword )
224
230
endif
225
231
endfunction
232
+
233
+ " g! {{{1
234
+ " g! is inspired and in good part copied from https://github.com/tpope/vim-scriptease
235
+
236
+ function ! s: opfunc (type ) abort
237
+ let sel_save = &selection
238
+ let cb_save = &clipboard
239
+ let reg_save = @@
240
+ try
241
+ set selection = inclusive clipboard -= unnamed clipboard -= unnamedplus
242
+ if a: type = ~ ' ^\d\+$'
243
+ silent exe ' normal! ^v' .a: type .' $hy'
244
+ elseif a: type = ~# ' ^.$'
245
+ silent exe " normal! `<" . a: type . " `>y"
246
+ elseif a: type == # ' line'
247
+ silent exe " normal! '[V']y"
248
+ elseif a: type == # ' block'
249
+ silent exe " normal! `[\<C-V> `]y"
250
+ else
251
+ silent exe " normal! `[v`]y"
252
+ endif
253
+ redraw
254
+ return @@
255
+ finally
256
+ let @@ = reg_save
257
+ let &selection = sel_save
258
+ let &clipboard = cb_save
259
+ endtry
260
+ endfunction
261
+
262
+ function ! tmux#filterop (type ) abort
263
+ let reg_save = @@
264
+ try
265
+ let expr = s: opfunc (a: type )
266
+ let lines = split (expr , " \n " )
267
+ let all_output = " "
268
+ let index = 0
269
+ while index < len (lines )
270
+ let line = lines [index ]
271
+
272
+ " if line is a part of multi-line string (those have '\' at the end)
273
+ " and not last line, perform " concatenation
274
+ while line = ~# ' \\\s*$' && index !=# len (lines )-1
275
+ let index += 1
276
+ " remove '\' from line end
277
+ let line = substitute (line , ' \\\s*$' , ' ' , ' ' )
278
+ " append next line
279
+ let line .= lines [index ]
280
+ endwhile
281
+
282
+ " skip empty line and comments
283
+ if line = ~# ' ^\s*#' ||
284
+ \ line = ~# ' ^\s*$'
285
+ continue
286
+ endif
287
+
288
+ let command = " tmux " .line
289
+ if all_output = ~# ' \S'
290
+ let all_output .= " \n " .command
291
+ else " empty var, do not include newline first
292
+ let all_output = command
293
+ endif
294
+
295
+ let output = system (command )
296
+ if v: shell_error
297
+ throw output
298
+ elseif output = ~# ' \S'
299
+ let all_output .= " \n > " .output[0 :-2 ]
300
+ endif
301
+
302
+ let index += 1
303
+ endwhile
304
+
305
+ if all_output = ~# ' \S'
306
+ redraw
307
+ echo all_output
308
+ endif
309
+ catch /^.*/
310
+ redraw
311
+ echo all_output | echohl ErrorMSG | echo v: exception | echohl NONE
312
+ finally
313
+ let @@ = reg_save
314
+ endtry
315
+ endfunction
0 commit comments