diff --git a/plugin/functions.vim b/plugin/functions.vim index dfe4eb9..ae87d2e 100644 --- a/plugin/functions.vim +++ b/plugin/functions.vim @@ -1,61 +1,62 @@ " Fold Text set foldtext=FoldText() function! FoldText() - let line = getline(v:foldstart) - return line.' '.string(v:foldend - v:foldstart + 1).' lines ' + let l:line = getline(v:foldstart) + return l:line.' '.string(v:foldend - v:foldstart + 1).' lines ' endfunction " Derived from http://stackoverflow.com/a/1333025 function! CloneHighlightGroupWithAttributes(group, new_group, attributes) " Get group details, resolving group links. - redir => group - exe "silent hi " . a:group + redir => l:group + exe 'silent hi ' . a:group redir END - while group =~ "links to" - let index = stridx(group, "links to") + len("links to") - let linked_group = strpart(group, index + 1) - redir => group - exe "silent hi " . linked_group + while l:group =~? 'links to' + let l:index = stridx(l:group, 'links to') + len('links to') + let l:linked_group = strpart(l:group, l:index + 1) + redir => l:group + exe 'silent hi ' . l:linked_group redir END endwhile " Get highlight parameters and existing remove attributes. - let parameters = matchlist(group, '\\s\+\(.*\)')[1] - let parameters = substitute(parameters, '\(c\?term\|gui\)=\w\+', '', 'g') + let l:parameters = matchlist(l:group, '\\s\+\(.*\)')[1] + let l:parameters = substitute(l:parameters, '\(c\?term\|gui\)=\w\+', '', 'g') " Create the cloned highlight group with new attributes. - exe 'hi '.a:new_group.' '.parameters. + exe 'hi '.a:new_group.' '.l:parameters. \' term='.a:attributes.' cterm='.a:attributes.' gui='.a:attributes endfunction -function! Synstack() - for id in synstack(line('.'), col('.')) - let attributes = synIDattr(id, 'name') - let attr = synIDattr(id, 'fg') - if attr != '' - let attributes = attributes.' fg='.attr +function! s:Synstack() + for l:id in synstack(line('.'), col('.')) + let l:attributes = synIDattr(l:id, 'name') + let l:attr = synIDattr(l:id, 'fg') + if l:attr !=? '' + let l:attributes = l:attributes.' fg='.l:attr endif endfor endfunction -command Synstack :call Synstack() +command Synstack :call s:Synstack() " Strip trailing whitespace -function! StripWhitespace() - let l = line(".") - let c = col(".") - %s/\s\+$//e - call cursor(l, c) +function! s:StripWhitespace() + let l:line = line('.') + let l:column = col('.') + execute '%s/\s\+$//e' + nohlsearch + call cursor(l:line, l:column) endfunction -command! StripWhitespace :call StripWhitespace() +command! StripWhitespace :call s:StripWhitespace() augroup strip_white_space " Strip whitespace on buffer write autocmd! - autocmd BufWritePre * :call StripWhitespace() + autocmd BufWritePre * :call s:StripWhitespace() augroup END " Stringify " Make a code block in to a C string literal -function! Stringify() +function! s:Stringify() " Escape existing escape characters execute 's/\\/\\\\/ge' " Escape quotes @@ -66,9 +67,9 @@ function! Stringify() execute 's/$/\\n"/g' noh endfunction -map s :call Stringify() +map s :call s:Stringify() " Make a C string literal in to a code block -function! Destringify() +function! s:Destringify() " Remove final quote and carriage return execute 's/\\n"\s*$//ge' " Remove first quote @@ -79,22 +80,22 @@ function! Destringify() execute 's/\\\\/\\/ge' noh endfunction -map S :call Destringify() +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! TabWidth(width) - execute "setlocal tabstop=".a:width - execute "setlocal shiftwidth=".a:width - execute "setlocal softtabstop=".a:width - echo "Tab width is now ".a:width +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 TabWidth() +command! -nargs=1 TabWidth :call s:TabWidth() " Toggle GitHub style bullet checkbox -function! CheckboxToggle() +function! s:CheckboxToggle() " Get current line let l:line = getline('.') @@ -103,7 +104,7 @@ function! CheckboxToggle() let l:char = matchstr(l:line, l:pattern) " Toggle the ' ' or 'x' character - if l:char == 'x' + if l:char ==? 'x' let l:char = ' ' else let l:char = 'x' @@ -112,7 +113,7 @@ function! CheckboxToggle() " Replace the current line with a new one call setline(line('.'), substitute(l:line, l:pattern, l:char, '')) endfunction -command! CheckboxToggle :call CheckboxToggle() +command! CheckboxToggle :call s:CheckboxToggle() nnoremap :CheckboxToggle " Show highlight groups under the cursor