Code Folding in Neovim

Sdílet
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

Komentáře • 68

  • @ascourter
    @ascourter  Před 9 měsíci +2

    What code folding plugins or methods do you use?

    • @LinuxForLife
      @LinuxForLife Před 3 měsíci +1

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

    • @ascourter
      @ascourter  Před 3 měsíci +1

      @@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
    @bassamsaleh8034 Před 9 měsíci +5

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

  • @JoshMedeski
    @JoshMedeski Před 9 měsíci +1

    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  Před 9 měsíci +1

      Thanks Josh! Oh nice. I think you mentioned this to me before, I'll check out your config again to give that a try!

  • @feresp
    @feresp Před 9 měsíci

    GREAT video man! Thanks!

  • @iusearchbtw4969
    @iusearchbtw4969 Před 8 měsíci +1

    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
    @thadrunsfaster Před 3 měsíci +1

    Enjoying your content! Subscribed!

  • @linkarzu
    @linkarzu Před 24 dny

    Great video by the way, I knew nothing about folds, and this helped me clear a lot of doubts. Thank you!

    • @ascourter
      @ascourter  Před 24 dny

      Thanks! I learned a ton about folds in getting this video together as well. Glad it helped!

  • @rkbgkgmjfm5155
    @rkbgkgmjfm5155 Před 9 měsíci

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

    • @ascourter
      @ascourter  Před 9 měsíci

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

  • @legion_prex3650
    @legion_prex3650 Před 8 měsíci

    nice stuff! keep on teaching!

  • @temelgunaydin7585
    @temelgunaydin7585 Před 4 měsíci

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

  • @bihanbanerjee
    @bihanbanerjee Před 2 měsíci

    Thanks a lot man. ❤❤❤

  • @drewberchtolzthofen886
    @drewberchtolzthofen886 Před 3 měsíci

    Pretty handy, thanks!!

  • @kraigochieng6395
    @kraigochieng6395 Před 7 měsíci

    be blessed.

  • @sumanth3036
    @sumanth3036 Před 9 měsíci +1

    Awesome. Comprehensive

  • @cody_codes_youtube
    @cody_codes_youtube Před 9 měsíci +4

    Yeah buddy! Always love your content!

    • @ascourter
      @ascourter  Před 9 měsíci

      Thanks Cody! Right back at you!

  • @naveenbisht4627
    @naveenbisht4627 Před 17 dny

    Cool

  • @alopradocai
    @alopradocai Před 8 měsíci +1

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

    • @ascourter
      @ascourter  Před 8 měsíci

      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 Před 8 měsíci

      @@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 Před 2 měsíci

      @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 Před 2 měsíci

      ​@@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
    @arnoeagleeyes Před 9 měsíci

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

    • @ascourter
      @ascourter  Před 9 měsíci

      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 Před 9 měsíci

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

  • @cantucodes
    @cantucodes Před 9 měsíci

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

    • @ascourter
      @ascourter  Před 9 měsíci

      Thanks! Yeah there's a ton built-in

  • @v8yqTstw2S5U39LV
    @v8yqTstw2S5U39LV Před 8 měsíci

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

    • @ascourter
      @ascourter  Před 8 měsíci +1

      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

    • @v8yqTstw2S5U39LV
      @v8yqTstw2S5U39LV Před 8 měsíci

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

  • @mokied
    @mokied Před 4 měsíci

    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  Před 4 měsíci

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

  • @fegyi001
    @fegyi001 Před 9 měsíci

    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  Před 9 měsíci

      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 Před 9 měsíci

      @@ascourterwow, thanks a lot!

  • @GrzegorzMilka
    @GrzegorzMilka Před 9 měsíci +1

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

    • @ascourter
      @ascourter  Před 9 měsíci +2

      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

  • @Faisal_89
    @Faisal_89 Před 6 měsíci

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

    • @ascourter
      @ascourter  Před 6 měsíci +1

      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.

    • @Faisal_89
      @Faisal_89 Před 6 měsíci

      @@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 Před 6 měsíci

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

    • @mokied
      @mokied Před 4 měsíci

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

  • @naranyala_dev
    @naranyala_dev Před 9 měsíci

    A small trick, but it can still improve workflow

  • @aumhren3480
    @aumhren3480 Před 2 měsíci

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

    • @ascourter
      @ascourter  Před 2 měsíci

      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
    @rkdeshdeepak4131 Před 9 měsíci

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

    • @ascourter
      @ascourter  Před 8 měsíci

      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
    @Ace10thPlanetJJ Před 2 měsíci

    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  Před 2 měsíci

      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

  • @innerthreatcircus5651
    @innerthreatcircus5651 Před 4 měsíci

    Any trick to have color picker to edit css? Thankssss

    • @ascourter
      @ascourter  Před 4 měsíci +1

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

    • @innerthreatcircus5651
      @innerthreatcircus5651 Před 4 měsíci

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

    • @ascourter
      @ascourter  Před 4 měsíci

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

    • @innerthreatcircus5651
      @innerthreatcircus5651 Před 4 měsíci

      @@ascourter color-highlighter and color-picker

  • @kubectlgetpo
    @kubectlgetpo Před 3 měsíci +1

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

    • @ascourter
      @ascourter  Před 3 měsíci +1

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

    • @kubectlgetpo
      @kubectlgetpo Před 3 měsíci

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

  • @arnoldwolfstein
    @arnoldwolfstein Před měsícem

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

    • @ascourter
      @ascourter  Před měsícem

      what is the additional plugin you are adding to remove them?