vim/autoload/do.vim
Kenneth Benzie (Benie) 4c2d9b8089 Add do#cursor_escape_sequences()
Control the cursor shape based on the current mode.
2018-08-26 10:50:08 +01:00

75 lines
2.1 KiB
VimL

" Setup changing cursor dependant on mode
function! do#cursor_escape_sequences()
if has('unix')
if $ITERM_SESSION_ID !=# ''
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_SR = "\<Esc>]50;CursorShape=2\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
else
let &t_SI = "\<Esc>[6 q"
let &t_SR = "\<Esc>[4 q"
let &t_EI = "\<Esc>[2 q"
endif
if $TMUX !=# ''
let &t_SI = "\<Esc>Ptmux;\<Esc>".&t_SI."\<Esc>\\"
let &t_SR = "\<Esc>Ptmux;\<Esc>".&t_SR."\<Esc>\\"
let &t_EI = "\<Esc>Ptmux;\<Esc>".&t_EI."\<Esc>\\"
endif
endif
endfunction
" 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
" 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