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

  • @ascourter
    @ascourter8 ай бұрын

    What code folding plugins or methods do you use?

  • @LinuxForLife

    @LinuxForLife

    2 ай бұрын

    I am using AstroNvim which provide all of this out of the box. No configuration needed.

  • @ascourter

    @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

  • @bassamsaleh8034
    @bassamsaleh80348 ай бұрын

    One of the best videos I've seen. I always had hard time with folds in neovim. Thanks a lot

  • @ascourter

    @ascourter

    8 ай бұрын

    Thank you!

  • @JoshMedeski
    @JoshMedeski8 ай бұрын

    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

    @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!

  • @iusearchbtw4969
    @iusearchbtw49697 ай бұрын

    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

  • @thadrunsfaster
    @thadrunsfaster2 ай бұрын

    Enjoying your content! Subscribed!

  • @ascourter

    @ascourter

    2 ай бұрын

    Thank you!

  • @rkbgkgmjfm5155
    @rkbgkgmjfm51558 ай бұрын

    Code folding is one of those things I never use, but cool to see you cover topics like these

  • @ascourter

    @ascourter

    8 ай бұрын

    Thanks! Let me know if there are other topics you are interested in!

  • @feresp
    @feresp7 ай бұрын

    GREAT video man! Thanks!

  • @legion_prex3650
    @legion_prex36506 ай бұрын

    nice stuff! keep on teaching!

  • @drewberchtolzthofen886
    @drewberchtolzthofen8862 ай бұрын

    Pretty handy, thanks!!

  • @temelgunaydin7585
    @temelgunaydin75853 ай бұрын

    Indent method is good for now. Thanks for all information that you shared.👍

  • @cantucodes
    @cantucodes8 ай бұрын

    Great Video! I had no idea there were so many options! Agree that nvim-ufo is 🔥

  • @ascourter

    @ascourter

    8 ай бұрын

    Thanks! Yeah there's a ton built-in

  • @cody_codes_youtube
    @cody_codes_youtube8 ай бұрын

    Yeah buddy! Always love your content!

  • @ascourter

    @ascourter

    8 ай бұрын

    Thanks Cody! Right back at you!

  • @bihanbanerjee
    @bihanbanerjeeАй бұрын

    Thanks a lot man. ❤❤❤

  • @sumanth3036
    @sumanth30368 ай бұрын

    Awesome. Comprehensive

  • @ascourter

    @ascourter

    8 ай бұрын

    Thank you!!

  • @kraigochieng6395
    @kraigochieng63956 ай бұрын

    be blessed.

  • @alopradocai
    @alopradocai6 ай бұрын

    Nice video. I gave up on using folding because every time I would use a formatter, folds would always get disorganized.

  • @ascourter

    @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

    @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

    @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

    @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.

  • @arnoeagleeyes
    @arnoeagleeyes8 ай бұрын

    Hey great video ! Do you happen to know if you can switch it off for certain buffers ? Like Dapui for example ?

  • @ascourter

    @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

    @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

  • @setobiralo
    @setobiralo7 ай бұрын

    The video was really helpful. Thank you. Is there any way to save the fold state even after closing the buffer?

  • @ascourter

    @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

    @setobiralo

    7 ай бұрын

    Thank you for your answer. I managed to do it just like you mentioned.

  • @mokied
    @mokied2 ай бұрын

    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

    @ascourter

    2 ай бұрын

    Checkout this link to add a couple autocommands to save the folds. github.com/kevinhwang91/nvim-ufo/issues/115#issuecomment-1436059023

  • @fegyi001
    @fegyi0018 ай бұрын

    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

    @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

    @fegyi001

    8 ай бұрын

    @@ascourterwow, thanks a lot!

  • @GrzegorzMilka
    @GrzegorzMilka8 ай бұрын

    Does folding and unfolding by one level work with nvim-ufo? I don't any mentions of remapping zr/zm.

  • @ascourter

    @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

  • @naranyala_dev
    @naranyala_dev8 ай бұрын

    A small trick, but it can still improve workflow

  • @Faisal_89
    @Faisal_895 ай бұрын

    Andew , How can we select or copy whole function and can we jump function to function?! Love your content brother

  • @ascourter

    @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

    @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

    @Faisal_89

    5 ай бұрын

    @@ascourter thanks brother ,va{Vd works well. and exactly vaf / daf to select or delete whole function

  • @mokied

    @mokied

    2 ай бұрын

    You need to set up Text Objects You can use nvim-treesitter-textobjects for that

  • @aumhren3480
    @aumhren3480Ай бұрын

    with foldmethod=indent, how to fold all code (ie all class ...) indents at once ? thx for sharing, have fun

  • @ascourter

    @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.

  • @rkdeshdeepak4131
    @rkdeshdeepak41317 ай бұрын

    How to enable folds for particular filetype e.g. norg, markdown?

  • @ascourter

    @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

  • @Ace10thPlanetJJ
    @Ace10thPlanetJJ29 күн бұрын

    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

    @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

  • @arnoldwolfstein
    @arnoldwolfstein2 күн бұрын

    ufo is great but i really hate these lvl numbers on the left. and cant remove them without additional plugin and nvim>=0.10

  • @innerthreatcircus5651
    @innerthreatcircus56512 ай бұрын

    Any trick to have color picker to edit css? Thankssss

  • @ascourter

    @ascourter

    2 ай бұрын

    Do you mean having a color picker for RGB values in CSS?

  • @innerthreatcircus5651

    @innerthreatcircus5651

    2 ай бұрын

    @@ascourter yeah, but I found exactly that, a color picker. And already installed it. Thanks a lot

  • @ascourter

    @ascourter

    2 ай бұрын

    @@innerthreatcircus5651 Nice! What plugin did you end up installing?

  • @innerthreatcircus5651

    @innerthreatcircus5651

    2 ай бұрын

    @@ascourter color-highlighter and color-picker

  • @kubectlgetpo
    @kubectlgetpo2 ай бұрын

    So we went from simple code folding in vscode to a 15 min video and it still doesn't work well

  • @ascourter

    @ascourter

    2 ай бұрын

    Code folding in Vim is pretty complex for sure. Nvim-ufo gives you a lot of great stuff.

  • @kubectlgetpo

    @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.

Келесі