Code Folding in Neovim
Vložit
- čas přidán 2. 08. 2024
- 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 - Věda a technologie
What code folding plugins or methods do you use?
I am using AstroNvim which provide all of this out of the box. No configuration needed.
@@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
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.
Thanks Josh! Oh nice. I think you mentioned this to me before, I'll check out your config again to give that a try!
GREAT video man! Thanks!
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!
Thank you!
Great video by the way, I knew nothing about folds, and this helped me clear a lot of doubts. Thank you!
Thanks! I learned a ton about folds in getting this video together as well. Glad it helped!
Code folding is one of those things I never use, but cool to see you cover topics like these
Thanks! Let me know if there are other topics you are interested in!
nice stuff! keep on teaching!
Indent method is good for now. Thanks for all information that you shared.👍
Thanks a lot man. ❤❤❤
Pretty handy, thanks!!
be blessed.
Awesome. Comprehensive
Thank you!!
Yeah buddy! Always love your content!
Thanks Cody! Right back at you!
Cool
Nice video. I gave up on using folding because every time I would use a formatter, folds would always get disorganized.
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.
@@ascourter Who knows, maybe there is a good way of both working together. Right now I prefer using just the formatter and no folds.
@alopradocai which formatter do you use? Supposedly conform doesn’t mess with your folds. Been using it for months and it works jim-dandy
@@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 ?
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.
@@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
Great Video! I had no idea there were so many options! Agree that nvim-ufo is 🔥
Thanks! Yeah there's a ton built-in
The video was really helpful. Thank you. Is there any way to save the fold state even after closing the buffer?
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
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?
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?
Thanks! Haha good question. I use starship as my prompt. Here's how I configure it:
github.com/exosyphon/dotfiles/blob/main/starship.toml
@@ascourterwow, thanks a lot!
Does folding and unfolding by one level work with nvim-ufo? I don't any mentions of remapping zr/zm.
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
Andew , How can we select or copy whole function and can we jump function to function?! Love your content brother
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: czcams.com/video/GJno0l_nAyg/video.html
I also will do another type of video like this before long.
@@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.
@@ascourter thanks brother ,va{Vd works well. and exactly vaf / daf to select or delete whole function
You need to set up Text Objects
You can use nvim-treesitter-textobjects
for that
A small trick, but it can still improve workflow
with foldmethod=indent, how to fold all code (ie all class ...) indents at once ? thx for sharing, have fun
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?
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
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
Any trick to have color picker to edit css? Thankssss
Do you mean having a color picker for RGB values in CSS?
@@ascourter yeah, but I found exactly that, a color picker. And already installed it. Thanks a lot
@@innerthreatcircus5651 Nice! What plugin did you end up installing?
@@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
Code folding in Vim is pretty complex for sure. Nvim-ufo gives you a lot of great stuff.
@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.
ufo is great but i really hate these lvl numbers on the left. and cant remove them without additional plugin and nvim>=0.10
what is the additional plugin you are adding to remove them?