开发者

TextMate Comment Banner in Vim

I am making the switch from TextMate to Vim for all of my text editing. However, one of the features 开发者_StackOverflow社区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!

TextMate Comment Banner in Vim


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.


I currently use Snipmate.vim https://github.com/msanders/snipmate.vim

Although I am not completely sure there is a snippet that will match your exact need, it would be trivial to add one that would do so!

It has very easy scripting to add whatever you need.

You would have to assign the snippet a certain key combination, so that when you are at that combination in insert mode and you hit Tab, the plugin inserts all the things you need plus it lets you change the text that you have previously set.

So for the example you give, I would give it a combination that says "banner". When I type that word and hit Tab, I would be placed in the "Comment Banner" so that I can type and replace the title.

This site has a very good video on how everything works: http://www.catonmat.net/blog/vim-plugins-snipmate-vim/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜