Vi and Vim Asked by Elliptical view on August 31, 2021
In the tcomment plugin, specifically in:
~/.vim/pack/tml/start/tcomment.vim/autoload/tcomment.vim
and~/.vim/pack/tml/start/tcomment.vim/plugin/tcomment.vim
I’m seeing this at the end of some lines:
"{{{2
or
"{{{3
For example:
let g:tcomment#blank_lines = 2 "{{{2
Are these some sort of special comments? Or what?
Thanks.
It's fold marker. Read more :h fold-marker
Correct answer by Jorengarenar on August 31, 2021
As Jorengarenar said in their answer "{{{2
has to do with foldmarkers. Now, what are foldmarkers anyway? What are they useful for? And how do you use them?
First let's notice that the strings you mention in your question are composed of three parts:
"
the comment character. This is specific to the filetype of your buffer, here it is "
because it's a vimscript file. In a plain text file you could even omit any commenting character as this not a part of the actual marker.{{{
the actual fold marker. :h 'foldmarker'
tells us that {{{
and }}}
are the default values but it could be any strings2
or any number which is optional represent the level of the marker.These markers allow the user to have folds in their buffer, that is a way to define some sections in your buffer. You can then show or hide these sections and navigate between them. For example I use them in my vimrc
to organize my plugins.
Here is what my vimrc
looks like when all folds are closed:
Now if I open the " Plugins {{{
fold I can have a quick glance at the plugins I installed:
And one step deeper I can focus on the configuration of a particular plugin:
Note that I use both opening {{{
and closing }}}
markers, this is a preference of mine but if I used levels I could simply omit the closing markers.
Now if you open the file you linked in vim you might be surprised to see no folding happening. This is because you need to set your foldmethod
option to marker
as :h 'foldmethod'
says.
As the setting is local to a window you have several way to enable it. For example you could do it with an autocommand. You could enable the setting for any new window you open:
augroup folding
autocmd!
autocmd WinNew * set foldmethod=marker
augroup END
Or another common way to do it is by using modeline (:h modeline
). These are these lines you often see at the top or at the bottom of vimscripts looking like this:
" vi: ft=vim:tw=72:fdm=marker
Here the modeline sets filetype
, textwidth
, and foldmethod
for the buffer containing the file. This way next when you open the buffer the folds are enabled.
Some additional useful information when using folds:
:h fold-commands
which shows you how to open them, close them and navigate between them.:h 'foldmethod'
for the different ways to create folds (markers are not the only option):h 'foldtext'
to define how you want your folds to look likeAnswered by statox on August 31, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP