" Strip trailing whitespace function! StripWhitespace() let l = line(".") let c = col(".") %s/\s\+$//e call cursor(l, c) endfunction command! StripWhitespace :call StripWhitespace() augroup strip_white_space " Strip whitespace on buffer write autocmd! autocmd BufWritePre * :call StripWhitespace() augroup END " Show highlight group under cursor map \hi :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . \ '> trans<' . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" \ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">" " Stringify " Make a code block in to a C string literal function! Stringify() " Escape existing escape characters execute 's/\\/\\\\/ge' " Escape quotes execute 's/"/\\"/ge' " Prepend quote execute 's/^/"/g' " Append carriage return, quote execute 's/$/\\n"/g' noh endfunction map s :call Stringify() " Make a C string literal in to a code block function! Destringify() " Remove final quote and carriage return execute 's/\\n"\s*$//ge' " Remove first quote execute 's:^\(\s*\)":\1:ge' " Remove quote escapes execute 's/\\"/"/ge' " Remove escapes of escapes characters execute 's/\\\\/\\/ge' noh endfunction map S :call Destringify() " Invoke terminal command without prompt and then redraw. command! -nargs=+ Silent execute 'silent ' | redraw! " Set the tab width for the current filetype function! TabWidth(width) execute "set tabstop=".a:width execute "set shiftwidth=".a:width execute "set softtabstop=".a:width echo "Tab width is now ".a:width endfunction command! -nargs=1 TabWidth :call TabWidth() " Toggle task list bullet function! TaskToggle() " 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 command! TaskToggle :call TaskToggle() nnoremap x :TaskToggle