Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TextMate Comment Banner in Vim

Tags:

vim

textmate

I am making the switch from TextMate to Vim for all of my text editing. However, one of the features that I used a lot in TextMate was the comment banner command (ctr-shift-b). It would create a banner and allow you to enter text inside the banner, and the banner would adjust to the length of the text. Is there any plugins, or any similiar feature in Vim? If not, is there a way I can program vim to make a comment banner? Any suggestions would be great. Thanks!

enter image description here

like image 646
ab217 Avatar asked Dec 21 '22 17:12

ab217


1 Answers

I've got these lines in my .vimrc:

autocmd FileType vim map <leader>ccb I"<Del>  <Esc>A  "<Del><Esc>yyp0lv$hhr"yykPjj
autocmd FileType javascript,php,c map <leader>ccb I//  <Esc>A  //<Esc>yyp0llv$hhhr-yykPjj
autocmd FileType python,ruby,sh,zsh map <leader>ccb I#  <Esc>A  #<Esc>yyp0lv$hhr-yykPjj
autocmd FileType css map <leader>ccb I/*  <Esc>A  */<Esc>yyp0llv$r-$hc$*/<Esc>yykPjj

In .vimrc it turns this:

vimrc banner

into this:

""""""""""""""""""
"  vimrc banner  "
""""""""""""""""""

In a JS file it turns this:

javascript banner

into this:

//---------------------//
//  javascript banner  //
//---------------------//

Etc.

" Creating underline/overline headings for markup languages
" Inspired by http://sphinx.pocoo.org/rest.html#sections
nnoremap <leader>== yyP^v$r=jyyp^v$r=
nnoremap <leader>** yyP^v$r*jyyp^v$r*
nnoremap <leader>= yyp^v$r=
nnoremap <leader>- yyp^v$r-
nnoremap <leader>^ yyp^v$r^
nnoremap <leader>" yyp^v$r"

I wish I'd keep a link to where I found it, though.

like image 149
romainl Avatar answered Jan 22 '23 09:01

romainl