diff --git a/init.vim b/init.vim index 2b63045..72225a1 100644 --- a/init.vim +++ b/init.vim @@ -16,8 +16,9 @@ Plug 'junegunn/fzf', { 'do': { -> fzf#install() } } " Fast fuzzy file searching Plug 'junegunn/fzf.vim' Plug 'tpope/vim-fugitive' " Adds git support to vim Plug 'tpope/vim-surround' " Adds motions for dealing with parentheses -Plug 'tpope/vim-commentary' " Easily comment/uncomment lines with `gc` +" Plug 'tpope/vim-commentary' " Easily comment/uncomment lines with `gc` (updated to work with style/script) Plug 'tpope/vim-unimpaired' " A series of bindings for complementary actions [ and ] for adding lines before and after +Plug 'tpope/vim-vinegar' " Improvements to the file browser Plug 'jiangmiao/auto-pairs' " Creates closing parentheses when writing the opening, use to wrap the next word/group, to disable Plug 'mattn/emmet-vim' " Emmet support ,em to toggle it Plug 'dylanaraps/wal.vim' " Set the theme to match the system colours @@ -281,6 +282,24 @@ let g:chadtree_settings = { \ } \ } +" function s:set_commentary_format() +" echo "running command" +" if &filetype =~ 'vue\|html\|svelte' +" if searchpair('<\(script\|style\)', '', '', 'Wn') +" let b:commentary_format="// %s" +" else +" let b:commentary_format=&commentstring +" endif +" endif +" endfunction + +" xnoremap gc :call set_commentary_format()Commentary +" nnoremap gc :call set_commentary_format()Commentary +" onoremap gc :call set_commentary_format()Commentary +" nnoremap gcc :call set_commentary_format()Commentary +" nnoremap cgc :call set_commentary_format()Commentary +" nnoremap cgu :call set_commentary_format()CommentaryCommentary + " }}} " Moving around --- {{{ @@ -325,6 +344,18 @@ augroup autofolding autocmd FileType zsh setlocal foldmethod=marker augroup END +"Set commentary formats +function s:setcommentary() + if &commentstring =~ '/\*\s*%s\s*\*/' + let b:commentary_format="// %s" + endif +endfunction + +augroup autocomment + autocmd! + autocmd FileType * call setcommentary() +augroup END + "Automatically save files augroup autosaving autocmd! @@ -341,8 +372,7 @@ augroup END augroup suckless autocmd BufWritePost ~/.local/src/dwmblocks/config.h !cd ~/.local/src/dwmblocks/; doas make install && { killall -q dwmblocks;setsid -f dwmblocks } autocmd BufWritePost ~/.local/src/dwm/config.h !cd ~/.local/src/dwm/; doas make clean install - autocmd BufWritePost ~/.local/src/st/config.h !cd ~/.local/st/dwm/; doas make clean install - + autocmd BufWritePost ~/.local/src/st/config.h !cd ~/.local/src/st/; doas make clean install " }}} " Notes and tips diff --git a/plugin/commentary.vim b/plugin/commentary.vim new file mode 100644 index 0000000..b108e62 --- /dev/null +++ b/plugin/commentary.vim @@ -0,0 +1,131 @@ +" commentary.vim - Comment stuff out +" Maintainer: Tim Pope +" Version: 1.3 +" GetLatestVimScripts: 3695 1 :AutoInstall: commentary.vim + +if exists("g:loaded_commentary") || v:version < 700 + finish +endif +let g:loaded_commentary = 1 + +function! s:surroundings() abort + if &filetype =~ 'vue\|html\|svelte' + if searchpair('<\(script\|style\)', '', '', 'Wn') + let b:commentary_format="// %s" + else + let b:commentary_format=&commentstring + endif + endif + return split(get(b:, 'commentary_format', substitute(substitute(substitute( + \ &commentstring, '^$', '%s', ''), '\S\zs%s',' %s', '') ,'%s\ze\S', '%s ', '')), '%s', 1) +endfunction + +function! s:strip_white_space(l,r,line) abort + let [l, r] = [a:l, a:r] + if l[-1:] ==# ' ' && stridx(a:line,l) == -1 && stridx(a:line,l[0:-2]) == 0 + let l = l[:-2] + endif + if r[0] ==# ' ' && a:line[-strlen(r):] != r && a:line[1-strlen(r):] == r[1:] + let r = r[1:] + endif + return [l, r] +endfunction + +function! s:go(...) abort + if !a:0 + let &operatorfunc = matchstr(expand(''), '[^. ]*$') + return 'g@' + elseif a:0 > 1 + let [lnum1, lnum2] = [a:1, a:2] + else + let [lnum1, lnum2] = [line("'["), line("']")] + endif + + let [l, r] = s:surroundings() + let uncomment = 2 + let force_uncomment = a:0 > 2 && a:3 + for lnum in range(lnum1,lnum2) + let line = matchstr(getline(lnum),'\S.*\s\@ 2 && l.r !~# '\\' + let line = substitute(line, + \'\M' . substitute(l, '\ze\S\s*$', '\\zs\\d\\*\\ze', '') . '\|' . substitute(r, '\S\zs', '\\zs\\d\\*\\ze', ''), + \'\=substitute(submatch(0)+1-uncomment,"^0$\\|^-\\d*$","","")','g') + endif + if force_uncomment + if line =~ '^\s*' . l + let line = substitute(line,'\S.*\s\@,,0) +xnoremap Commentary go() +nnoremap Commentary go() +nnoremap CommentaryLine go() . '_' +onoremap Commentary :call textobject(get(v:, 'operator', '') ==# 'c') +nnoremap ChangeCommentary c:call textobject(1) +nmap CommentaryUndo :echoerr "Change your CommentaryUndo map to CommentaryCommentary" + +if !hasmapto('Commentary') || maparg('gc','n') ==# '' + xmap gc Commentary + nmap gc Commentary + omap gc Commentary + nmap gcc CommentaryLine + if maparg('c','n') ==# '' && !exists('v:operator') + nmap cgc ChangeCommentary + endif + nmap gcu CommentaryCommentary +endif + +" vim:set et sw=2: