Fold your vim config - Marble Zone
source link: https://sevensidedmarble.com/folds-for-better-vim-configs/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Fold your vim config
You may or may not know that I am pretty into Emacs and Org mode. Org mode, if you haven't seen it, it's an outliner built into Emacs:
Org mode is great for writing structured content like scripts.
Some people even use Org mode as a literate programmingConceived by the famous Donald Knuth, which is interesting. tool for their Emacs config. I've always thought this was pretty cool, and thought literate programming in general was pretty cool, but never found a great way to apply it to my vim config until now.
The inspiration
Before continuing I'd like to lead with where I found this idea online:
I'm not sure which of these I saw first, but the basic concept is using manually placed fold markers in your vim config to break it down into sections. Kind of like this:
Before...
Please forgive my messy config.
After!
This is what it looks like with one of the folded sections opened.
Some people even take this a step farther and apply some crazy fold styling to make it look even more like Org mode, which you can see in one of the links above.
Here's what you need
fold-marker
is a folding method few people I'd imagine spend much time thinking about. The markers themselves look like this:
"" Autocomplete {{{
Plug 'Shougo/neco-vim'
Plug 'neoclide/coc-neco'
Plug 'neoclide/coc-sources'
Plug 'neoclide/coc.nvim', {'branch': 'release'}
"" }}}
"" The almighty tpope {{{
Plug 'tpope/vim-sensible'
Plug 'tpope/vim-endwise'
Plug 'tpope/vim-repeat'
Plug 'tpope/vim-eunuch'
Plug 'tpope/vim-rhubarb'
Plug 'tpope/vim-rsi'
Plug 'tpope/vim-unimpaired'
" }}}
"" Spellcheck {{{
autocmd BufRead,BufNewFile *.md setlocal spell spelllang=en_us
autocmd FileType gitcommit setlocal spell spelllang=en_us
"" }}}
Which when folded look something like this:
+-- 7 lines: " Autocomplete
+-- 18 lines: " The almighty tpope
+-- 5 lines: " Spellcheck
I've found this is an amazing way of breaking up your vim config into sections without relying on splitting it into different files (which I was doing before, and wasn't ever completely satisfied with).
But wait, there's more
There's only one problem though, you probably don't want to set foldmethod
to fold-marker
for everything. I personally think syntax
or indent
is the most useful general-purpose foldmethod
, so that is what I set mine to in my vim config. So how you change foldmethod
only for .vim
files?
Well, there is of course a few ways to do it, but the best is to use ftplugin
.
In your vim config directories after/ftplugin
directory (I use neovim, so for me this is at ~/.config/nvim/after/ftplugin/vim/vim.vim
) add the following file to the following directory:
"" ~/.config/nvim/after/ftplugin/vim/vim.vim
set foldmethod=marker
Breaking this down
- The
after
directory is whereftplugin
files can run after vim default configurations have loaded. - The
ftplugin
directory then contains a bunch of subdirectories for each file type. - Then the
vim
directory contains files that will run only when editing.vim
files, after other config files have fully loaded. - Then the file itself is just setting foldmethod to marker. Settings put here are filetype specific, so they won't bleed into other filetypes.
Well, that's about it. I hope you find this somewhat as cool as I do!
Recommend
-
51
README.MD Marble is a high performance in-memory hive sql engine based on Apache Calcite. It can help yo...
-
58
Android Studio 3.5: Project Marble goes into stable 2019-08...
-
5
Testing RxJava with executable marble diagrams25 Mar 2013 Reactive Extensions (Rx) from the .Net world are observable sequences. In particular they are push based sequences, in contrast to the pull based seq api in Clojure. Fur...
-
7
Hello Folks đź‘‹! Today it's time to speak about testing and how to test the code when we use RxJS. Before moving our focus to the testing, I need to explain two different types of Observables: cold and hot. Hot and Col...
-
3
February 17, 2022
-
4
Testing RxJava with executable marble diagrams25 Mar 2013 Reactive Extensions (Rx) from the .Net world are observable sequences. In particular they are push based sequences, in contrast to the pull based seq api in Clojure. Fur...
-
5
Unreleased Atari game Marble Madness II leaks online after more than three decades An unreleased "holy grail" among gaming historians and enthusiasts By
-
8
After 30 Years, The World Can Now Play The Lost 'Marble Madness II' Technology
-
2
AdvertisementGadgetsNow You Can Build Mesmerizing Gravitrax Marble Mazes That Run Forever With New Powered Elements
-
2
Support is great. Feedback is even better."We're pretty much willing to do anything to make sure you have the best link-in-bio experience possible with Marble. Even though it's a paid product, you can build a full profile prior to pa...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK