Code Folding in Neovim
Ғылым және технология
In this video I go over the different code folding methods in Neovim and how to configure my favorite plugin, nvim-ufo to make code folds even better.
KickstartNvim: github.com/nvim-lua/kickstart...
NVIM_APPNAME: neovim.io/doc/user/starting.h...
Code Folding Function: • Coding a foldcolumn To...
nvim-ufo: github.com/kevinhwang91/nvim-ufo
Companion Article: / code-folding-in-neovim
Join this channel to get access to perks:
www.youtube.com/@ascourter/join
Twitter: / exosyphon
Website: andrewcourter.com
Twitch: / exosyphon
Gear:
Mic: amzn.to/40GUGFg
Mic Interface: amzn.to/3YGxaGE
Mic preamp: amzn.to/3XtBXtY
Webcam: amzn.to/3OEOZRU
Boom Arm: amzn.to/3qLr0GE
Vissles (VS II switches): vissles.com/?ref=69zn8aei20 - Coupon Code for $5 off: ANDREWCOURTER
IQUNIX F97 (TTC ACE switches): iqunix.store/collections/f97-...
🎵 Music
Music: Evan King
/ @contextsensitive
contextsensitive.bandcamp.com/
⏰ Timestamps
0:00 Intro
0:30 Example
0:59 The Fold Methods
1:29 Manual
3:32 Indent
4:06 Marker
5:09 Syntax
5:39 Expr
6:38 Diff
7:14 Troubleshooting and saving folds
7:58 Custom keymaps
8:36 nvim-ufo
10:57 Outro
#neovim #coding #programming
Пікірлер: 64
What code folding plugins or methods do you use?
@LinuxForLife
2 ай бұрын
I am using AstroNvim which provide all of this out of the box. No configuration needed.
@ascourter
2 ай бұрын
@@LinuxForLife AstroNvim uses nvim-ufo so now you know how it is configured! :D github.com/AstroNvim/AstroNvim/blob/main/lua/astronvim/plugins/nvim-ufo.lua
One of the best videos I've seen. I always had hard time with folds in neovim. Thanks a lot
@ascourter
8 ай бұрын
Thank you!
Nice overview of how folds work. I learned some new things! And I’ve set some custom icons with UFO as virtual text to not clutter up the gutter.
@ascourter
8 ай бұрын
Thanks Josh! Oh nice. I think you mentioned this to me before, I'll check out your config again to give that a try!
I didn't know i need folding before in neovim, now i need one cuz i need to read long php code from my senior and i came accross this video Anyway thank's for the amazing and simple explanation video without going through much of configuration
Enjoying your content! Subscribed!
@ascourter
2 ай бұрын
Thank you!
Code folding is one of those things I never use, but cool to see you cover topics like these
@ascourter
8 ай бұрын
Thanks! Let me know if there are other topics you are interested in!
GREAT video man! Thanks!
nice stuff! keep on teaching!
Pretty handy, thanks!!
Indent method is good for now. Thanks for all information that you shared.👍
Great Video! I had no idea there were so many options! Agree that nvim-ufo is 🔥
@ascourter
8 ай бұрын
Thanks! Yeah there's a ton built-in
Yeah buddy! Always love your content!
@ascourter
8 ай бұрын
Thanks Cody! Right back at you!
Thanks a lot man. ❤❤❤
Awesome. Comprehensive
@ascourter
8 ай бұрын
Thank you!!
be blessed.
Nice video. I gave up on using folding because every time I would use a formatter, folds would always get disorganized.
@ascourter
6 ай бұрын
Thanks! Yeah I've heard that from a couple folks. I've seen suggestions about workarounds but sometimes I think how the formatter is implemented just messes folds up.
@alopradocai
6 ай бұрын
@@ascourter Who knows, maybe there is a good way of both working together. Right now I prefer using just the formatter and no folds.
@GonzaloStoll
Ай бұрын
@alopradocai which formatter do you use? Supposedly conform doesn’t mess with your folds. Been using it for months and it works jim-dandy
@alopradocai
Ай бұрын
@@GonzaloStoll I use mostly intelephense for php and typescript-language-server for js, also have php-cs-fixer. I need to review/study a lot about nvim, because my config is a little too messy, folds might take a while for me to revisit, but thanks for the tip appreciate it.
Hey great video ! Do you happen to know if you can switch it off for certain buffers ? Like Dapui for example ?
@ascourter
8 ай бұрын
Thanks! You should be able to turn it off using UfoDisable (github.com/kevinhwang91/nvim-ufo#commands). You could then create a keymap to do it manually or run that in a ftype file for language types you didn't want it on.
@arnoeagleeyes
8 ай бұрын
@@ascourter Thank you for your answer. For anyone interested. This is what i did in my dap.lua: dap.listeners.after.event_initialized["dapui_config"] = function() require("ufo").detach() dapui.open() end
The video was really helpful. Thank you. Is there any way to save the fold state even after closing the buffer?
@ascourter
7 ай бұрын
Thanks! Good question. I believe you could save the folds to a file and reload them like I mentioned. You could set that up via auto command too
@setobiralo
7 ай бұрын
Thank you for your answer. I managed to do it just like you mentioned.
Hey thanks, for the video. I had a hard time setting up ufo & understanding how it should be used. I still have an issue with fold not remaining persistent after quitting nvim. What did I miss?
@ascourter
2 ай бұрын
Checkout this link to add a couple autocommands to save the folds. github.com/kevinhwang91/nvim-ufo/issues/115#issuecomment-1436059023
very helpful video, thanks a lot! Just one question - rather irrelevant to this video, sorry for that -, but I really like how your terminal looks with showing the git branch icon and the nodejs version as well. How can one do that?
@ascourter
8 ай бұрын
Thanks! Haha good question. I use starship as my prompt. Here's how I configure it: github.com/exosyphon/dotfiles/blob/main/starship.toml
@fegyi001
8 ай бұрын
@@ascourterwow, thanks a lot!
Does folding and unfolding by one level work with nvim-ufo? I don't any mentions of remapping zr/zm.
@ascourter
8 ай бұрын
Yes, folding one level should work out of the box with nvim-ufo. You need to remap zR and zM because it will override foldlevel if you don't. github.com/kevinhwang91/nvim-ufo#usage
A small trick, but it can still improve workflow
Andew , How can we select or copy whole function and can we jump function to function?! Love your content brother
@ascourter
5 ай бұрын
Thank you! What language are you programming in? It kind of depends on the language for selecting but vap or va{ might do the trick. Check out this other video about jumping around buffers if you haven't already: kzread.info/dash/bejne/eX6i0ZKlj9Gnqco.html I also will do another type of video like this before long.
@Faisal_89
5 ай бұрын
@@ascourter thanks, checked the video , learned many things.currently I am working with js/ts. we can do it with symbols. but if there any short key way select whole function please tell me. like i want to copy whole function or delete it.
@Faisal_89
5 ай бұрын
@@ascourter thanks brother ,va{Vd works well. and exactly vaf / daf to select or delete whole function
@mokied
2 ай бұрын
You need to set up Text Objects You can use nvim-treesitter-textobjects for that
with foldmethod=indent, how to fold all code (ie all class ...) indents at once ? thx for sharing, have fun
@ascourter
Ай бұрын
Thanks for watching! I believe you can use zM to close all folds. Give that a try and let me know if that does not work for you.
How to enable folds for particular filetype e.g. norg, markdown?
@ascourter
7 ай бұрын
Check out this link to the docs. You get a filetype in the provider_selector where you can map the provider and provide an empty string for filetypes you don't want to have folds on. github.com/kevinhwang91/nvim-ufo#customize-configuration
Ive installed ufo and its dependency in kickstart, and lazy tells me it installed correctly, but whenever i type "require('ufo')" anywhere and restart the editor i get an error that the ufo module cant be found, i cant find any info on how to resolve this anywhere
@ascourter
26 күн бұрын
You might open an issue on the nvim ufo github page. See if they might be able to get you sorted. You can double check the plugin is getting installed under ~/.local/share/nvim/lazy
ufo is great but i really hate these lvl numbers on the left. and cant remove them without additional plugin and nvim>=0.10
Any trick to have color picker to edit css? Thankssss
@ascourter
2 ай бұрын
Do you mean having a color picker for RGB values in CSS?
@innerthreatcircus5651
2 ай бұрын
@@ascourter yeah, but I found exactly that, a color picker. And already installed it. Thanks a lot
@ascourter
2 ай бұрын
@@innerthreatcircus5651 Nice! What plugin did you end up installing?
@innerthreatcircus5651
2 ай бұрын
@@ascourter color-highlighter and color-picker
So we went from simple code folding in vscode to a 15 min video and it still doesn't work well
@ascourter
2 ай бұрын
Code folding in Vim is pretty complex for sure. Nvim-ufo gives you a lot of great stuff.
@kubectlgetpo
2 ай бұрын
@ascourter yeah I am loving neovim so far but also missing some of these modern features. It's a fair compromise so far TBH. I am ok letting go off folding in lieu of faster jumping across the screen.