From 4040dc7508270f2b856903d4ac9fce6ef7240410 Mon Sep 17 00:00:00 2001 From: "Kenneth Benzie (Benie)" Date: Mon, 20 Nov 2017 22:35:27 +0000 Subject: [PATCH] Move rarely used functions to autoload --- autoload/do.vim | 34 ++++++++++++++++++++++ plugin/commands.vim | 12 ++++++++ plugin/functions.vim | 69 -------------------------------------------- plugin/mappings.vim | 6 ++++ 4 files changed, 52 insertions(+), 69 deletions(-) diff --git a/autoload/do.vim b/autoload/do.vim index 944a67e..ce55419 100644 --- a/autoload/do.vim +++ b/autoload/do.vim @@ -10,6 +10,7 @@ function! do#isort() 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('.') @@ -18,3 +19,36 @@ function! do#rstrip_lines() 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 diff --git a/plugin/commands.vim b/plugin/commands.vim index fa618e8..2a3c980 100644 --- a/plugin/commands.vim +++ b/plugin/commands.vim @@ -1,3 +1,15 @@ +" Sort Python Imports command! ISort call do#isort() + +" Strip white space from right of all lines. " TODO: Make RStripLines work on a range command! RStripLines call do#rstrip_lines() + +" Set tab width +command! -nargs=1 TabWidth call do#set_tab_width() + +" Toggle Checkbox +command! ToggleCheckbox call do#toggle_checkbox() + +" Show highlight groups under the cursor +command! CursorHighlightGroups :call do#cursor_highlight_groups() diff --git a/plugin/functions.vim b/plugin/functions.vim index 5959e53..0034ee4 100644 --- a/plugin/functions.vim +++ b/plugin/functions.vim @@ -39,74 +39,5 @@ function! s:Synstack() endfunction command Synstack :call s:Synstack() -" Stringify -" Make a code block in to a C string literal -function! s: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 s:Stringify() -" Make a C string literal in to a code block -function! s: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 s:Destringify() - " Invoke terminal command without prompt and then redraw. command! -nargs=+ Silent execute 'silent ' | redraw! - -" Set the tab width for the current filetype -function! s:TabWidth(width) - execute 'setlocal tabstop='.a:width - execute 'setlocal shiftwidth='.a:width - execute 'setlocal softtabstop='.a:width - echo 'Tab width is now '.a:width -endfunction -command! -nargs=1 TabWidth :call s:TabWidth() - -" Toggle GitHub style bullet checkbox -function! s:CheckboxToggle() - " 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! CheckboxToggle :call s:CheckboxToggle() -nnoremap :CheckboxToggle - -" Show highlight groups under the cursor -function! s:CursorHighlightGroups() - 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 -command! CursorHighlightGroups :call s:CursorHighlightGroups() -nnoremap hi :CursorHighlightGroups diff --git a/plugin/mappings.vim b/plugin/mappings.vim index 1af5317..1a7e1ae 100644 --- a/plugin/mappings.vim +++ b/plugin/mappings.vim @@ -85,3 +85,9 @@ noremap K " Split line at the cursor nnoremap [j i nnoremap ]j a + +" Toggle Checkbox +nnoremap :ToggleCheckbox + +" Show highlight groups under the cursor +nnoremap hi :CursorHighlightGroups