vim/autoload/do.vim
Kenneth Benzie (Benie) 92a23103e3 Fix vim-tmux-focus-events errors in command-line
When changing focus away and back to vim while in the middle of editing
the command-line, vim-tmux-focus-events emits errors from the function
called by the `:cnoremap` mappings. This patch replaces these mappings
with a call to `do#sink()` which does nothing. Simply removing the
mappings will result in `<F24><F25>` being inserted on the command-line
since tmux will send this text when `tmux set-option -g focus-events
on`, this is why `do#sink()` is needed.
2021-01-27 19:23:13 +00:00

103 lines
3.0 KiB
VimL

" Save, call isort on, then reload a python file.
function! do#isort()
if &filetype !=# 'python'
echohl ErrorMsg
echomsg 'isort only supports python files'
echohl None
endif
write!
call system('isort '.expand('%:p'))
edit!
endfunction
" Strip white space from right of all lines.
" TODO: Make do#rstrip_lines work on a range
function! do#rstrip_lines()
let l:line = line('.')
let l:column = col('.')
execute '%s/\s\+$//e'
nohlsearch
call cursor(l:line, l:column)
endfunction
" TODO: Strip white space from left of all lines, retains relative indentation.
" Set the tab width for the current filetype
function! do#set_tab_width(width)
execute 'setlocal tabstop='.a:width
execute 'setlocal shiftwidth='.a:width
execute 'setlocal softtabstop='.a:width
echo 'Tab width is now '.a:width
endfunction
" Toggle GitHub style bullet checkbox
function! do#toggle_checkbox()
" Get current line
let l:line = getline('.')
" Get the ' ' or 'x' character from within the task bullet
let l:pattern = '[-\*+] \[\zs[ x]\ze]'
let l:char = matchstr(l:line, l:pattern)
" Toggle the ' ' or 'x' character
if l:char ==? 'x'
let l:char = ' '
else
let l:char = 'x'
endif
" Replace the current line with a new one
call setline(line('.'), substitute(l:line, l:pattern, l:char, ''))
endfunction
" Show highlight groups under the cursor
function! do#cursor_highlight_groups()
let l:hi = synIDattr(synID(line('.'),col('.'),1),'name')
let l:trans = synIDattr(synID(line('.'),col('.'),0),'name')
let l:lo = synIDattr(synIDtrans(synID(line('.'),col('.'),1)),'name')
echo 'hi<'.l:hi.'> trans<'.l:trans.'> lo<'.l:lo.'>'
endfunction
" Rename C/C++ include guard
function! do#rename_include_guard(old)
" Prompt for new guard name
let l:new = input('Rename include guard: ', a:old)
" Get the current position
let l:pos = getpos('.')
" Replace the old guard name with the new one
exec '%s/\(#ifndef\|#define\|#endif\s\+\/\/\)\s\+\zs'.a:old.'/'.l:new.'/g'
" Stop highlighting search results
nohlsearch
" Jump back to the start position
call setpos('.', l:pos)
endfunction
" Setup and start a debugging command
function! do#debug(...)
packadd termdebug
let l:command = 'TermdebugCommand'
for l:arg in a:000
let l:command = l:command.' '.l:arg
endfor
exec l:command
endfunction
function! do#last_change()
if &filetype ==# 'help'
" vint: next-line -ProhibitCommandRelyOnUser -ProhibitCommandWithUnintendedSideEffect
1s/Last change: \zs.*$/\=strftime('%Y %b %d')/e
norm!``
endif
endfunction
" Augment vim-signify update events
function! do#signify() abort
" Disable update on cursor hold
autocmd! signify CursorHold,CursorHoldI
" Enable updates on leaving insert mode
autocmd signify InsertLeave,TextChanged <buffer> call sy#start()
" Enable update on text change e.g. undo/redo
autocmd signify TextChanged <buffer> call sy#start()
endfunction
" A sink for mappings to do nothing
function! do#sink() abort
endfunction