No edit summary |
(Remove html character entities) |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{review}} |
{{review}} |
||
+ | {{TipImported |
||
− | {{Tip |
||
|id=122 |
|id=122 |
||
+ | |previous=121 |
||
− | |title=Skip blank lines when folding text. |
||
+ | |next=123 |
||
− | |created=September 27, 2001 |
+ | |created=September 27, 2001 |
|complexity=intermediate |
|complexity=intermediate |
||
|author=Michael Brailsford |
|author=Michael Brailsford |
||
|version=6.0 |
|version=6.0 |
||
|rating=21/9 |
|rating=21/9 |
||
+ | |category1= |
||
− | |text= |
||
+ | |category2= |
||
⚫ | I love the text folding capabilities of |
||
⚫ | |||
⚫ | I love the text folding capabilities of Vim. I didn't like that it would display the first line of the range as the "title" for the fold. I like to write my comments with the "/*" on a line by itself. So I wrote this little function that will skip over anything that isn't a character, and then display whatever it finds after that character. |
||
⚫ | |||
+ | <pre> |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | endw |
||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
⚫ | |||
+ | </pre> |
||
⚫ | |||
+ | <pre> |
||
⚫ | |||
⚫ | |||
+ | </pre> |
||
⚫ | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
− | endw |
||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
− | |||
− | |||
⚫ | |||
− | |||
− | |||
− | |||
⚫ | |||
− | |||
⚫ | |||
− | |||
− | |||
− | |||
⚫ | |||
⚫ | |||
− | == |
+ | ==Comments== |
− | + | The line that looks like "set fillchars=fold:" has a space at the end. Simply type <C-k><Space><Space> to reproduce it. It's just a space. |
|
− | brailsmt at users.sourceforge.net |
||
− | , September 27, 2001 0:58 |
||
---- |
---- |
||
− | <!-- parsed by vimtips.py in 0.549530 seconds--> |
Latest revision as of 08:29, 28 September 2008
created September 27, 2001 · complexity intermediate · author Michael Brailsford · version 6.0
I love the text folding capabilities of Vim. I didn't like that it would display the first line of the range as the "title" for the fold. I like to write my comments with the "/*" on a line by itself. So I wrote this little function that will skip over anything that isn't a character, and then display whatever it finds after that character.
Just include this in your vimrc:
function GetFirstLineWithChars() let line_num = 0 let charline = matchstr(getline(v:foldstart), '[a-zA-Z][a-zA-Z ]*') while strlen(charline) == 0 let line_num = line_num + 1 let charline = matchstr(getline(v:foldstart + line_num), '[a-zA-Z][a-zA-Z ]*') endw return charline endfunction set foldtext='+'.v:folddashes.substitute(GetFirstLineWithChars(),'\\\/\\\/\\\|\\*\\\|\\*\\\|{{{\\d\\=','','g') set fillchars=fold: hi folded guibg=black guifg=yellow gui=bold
And as an added bonus, for those new to text folding, add this to your vimrc file too:
autocmd BufWinLeave *.* mkview autocmd BufWinEnter *.* silent loadview
That way whatever folds you set won't get lost when you quit. I had that happen after spending 15 minutes folding up a 3000 line file.
Comments[]
The line that looks like "set fillchars=fold:" has a space at the end. Simply type <C-k><Space><Space> to reproduce it. It's just a space.