vimrc.d/misc.vim

Enforce vim script implementation to reduce ambiguities and improve robustness:

scriptversion 4

Show highlight group of the current location:

command! ShowHighlightGroups
\   echo map(
\       display#get_highlight_group(),
\       {k, v -> map(v, {k, v -> k .. ':' .. v})->values()->join(', ')}
\   )->join(' | ')

User email address, as used by various plugins:

silent const s:user_data = systemlist(
\   'git -C ~ config user.name; git -C ~ config user.email')
if v:shell_error == 0
    let g:user_email = printf('%s <%s>', s:user_data[0], s:user_data[1])
endif

Display base vim version:

command! Version echo 'vim-' .. misc#version()

Make it easy to diff options between sessions, which can be nice for debugging, by printing the entirety of options:

command! InsertOptions call misc#insert_options()

Note

This is different to :mkexrc in that it displays all options, not just the ones you have changed. This is far nicer behaviour when you’ve upgraded vim and want to see what has changed. It is also different to using :set with :redir as the output is easier to read in diff’s output.

Add on-hover word definitions, which can be useful for prose editing:

if has('gui_running') && executable('wn')
    command WordNetBalloon
    \   setlocal balloonexpr=display#command_balloon('wn\ %s\ -over')
endif

Note

This is only enabled for gvim as I have the mouse configured in a way which would be problematic for use with 'balloonevalterm'.

Search for paths with easy access to completion at the prompt:

command PathSearch call misc#path_search()

Insert a modeline on the last line:

command! -bang Modeline call misc#modeline_stub(<bang>0)

Tip

When executed with ! write a fuller and more verbose modeline.

Pretty print an option’s value to make it easier to read:

command! -complete=option -nargs=1 PrintOption
\   call misc#print_option(<q-args>)

Convenience command to build a given target with full completion:

command! -nargs=* -complete=customlist,completion#build_complete Make
\   :call misc#call_build(<q-args>)<CR>

This places perforation-style lines around the given range:

command! -range Snip <line1>,<line2>call misc#scissors()

See also