Code Formatting made easy

  Рет қаралды 16,788

TJ DeVries

TJ DeVries

Күн бұрын

Пікірлер: 58
@mohammadkhosravi3285
@mohammadkhosravi3285 11 күн бұрын
I look forward to this series every day. Thank you TJ
@cag1
@cag1 11 күн бұрын
same
@avramukk
@avramukk 11 күн бұрын
me too)
@yuxiang4218
@yuxiang4218 11 күн бұрын
+1
@echobucket
@echobucket 11 күн бұрын
The biggest problem people will usually run into that you didn't cover is when languages don't have LSP based formatting, but instead have command line based formatting tools. So you probably should also cover how to set those up (which has been in vim forever). I kind of wish there was a built in abstraction for formatting in neovim over both mechanisms.
@cubiccode3867
@cubiccode3867 10 күн бұрын
He kinda of hints it in the end of the video when he says that lua is a programming language
@pmmeurcatpics
@pmmeurcatpics 3 күн бұрын
Isn't that exactly what null-ls does?
@heian17
@heian17 17 сағат бұрын
Just set `formatprg` to name of a program
@demolazer
@demolazer 11 күн бұрын
I switched from VS Code to Neovim a few months back, installed Kickstarter and was blown away by the LSP and environment. Thank you TJ and code, you made coding amazing. My colleague trying to encourage VS code cos of some tooling in there, I lasted an hour. Like coding with one hand. Even with the vim plugin.
@Luclecool123
@Luclecool123 11 күн бұрын
Love this series! thank you so much for your work
@asd121asd
@asd121asd 10 күн бұрын
Went over all advent of nvim videos up to date and liked those. Keep 'em coming!
@examinethose
@examinethose 11 күн бұрын
another day another line of code saying "Hey!"
@yogxoth1959
@yogxoth1959 10 күн бұрын
I don’t understand where you put the editorconfig file so the LSP in Neovim respects it for every project?
@DavRambo
@DavRambo 8 күн бұрын
Have you tried putting one in your home directory?
@hackerware_sh
@hackerware_sh 11 күн бұрын
Great series so far! ❤ I’m wondering what’s generally your reasoning wether to use the vim (api) “native way” to do things vs to use a plugin that has slightly more functionality (in this particular case conform). I realize this is a beginners series, but generally speaking… Thanks!
@jorgeimo
@jorgeimo 11 күн бұрын
This is awesome! The config I have to format on save is a fucking mess, now I know how to make it better 😎 Thanks TJ!
@dadinhoschannel4003
@dadinhoschannel4003 11 күн бұрын
This man is on fire!
@taetaebahohiningamo
@taetaebahohiningamo 11 күн бұрын
Next vid: Linting made easy
@teej_dv
@teej_dv 11 күн бұрын
very speedy reply, nice work :)
@gustavoviana5508
@gustavoviana5508 11 күн бұрын
Please more of these thank you
@Bvngee
@Bvngee 9 күн бұрын
I would love if you considered covering non-lsp-based formatters at some point :P (and the plugins that integrate with them, i.e. conform.nvim) great series!!
@WeshalbDennNicht
@WeshalbDennNicht 11 күн бұрын
What is the benefit of using .editorconfig vs. implementing a ftplugin for lua, specifying the wanted shiftwidth? Because the ftplugin would be nvim-only and the .editorconfig also works für lua-ls? Keep up the great videos! 🙂
@hoxefko
@hoxefko 11 күн бұрын
.editorconfig is compatible with more editors and you can put it in a git repository to keep consistency of format among every project member ;-)
@m.ihnatenko
@m.ihnatenko 11 күн бұрын
2:46 Out of curiosity. Wouldn't it be simpler to pass vim.lsp.buf.format instead of wrapping it into a function and then calling format inside of it? Or am I missing something?
@hoxefko
@hoxefko 11 күн бұрын
so are conform.nvim and that kind of plugins useless these days? or they are something to extend the formatting feature? I'm lost in this part of Neovim
@LinuxCook
@LinuxCook 11 күн бұрын
Plugins like conform.nvim enable integration with third-party formatters. The formatting method demonstrated by TJ in this video relies on the LSP's textDocument/formatting endpoint, which may be limited or unavailable for some language servers. To use standalone formatters such as stylua for Lua, prettier for JavaScript, ruff for Python, or clang-format for C, you need to integrate these tools separately. A plugin like conform.nvim can simplify hooking into these external formatters.
@hoxefko
@hoxefko 11 күн бұрын
​@@LinuxCook thanks so much for your explanation :-)
@avramukk
@avramukk 11 күн бұрын
Awesome. Thank you.
@ivanaytzhanov8846
@ivanaytzhanov8846 7 күн бұрын
I have very similar setup with formatting on save and *sometimes* it just doesn't work. I save a file and formatting just does not fire
@miyalys
@miyalys 4 күн бұрын
There needs to be an LSP available for the current file type, that supports code formatting. If it inconsistently works for the same format that is strange.
@ivanaytzhanov8846
@ivanaytzhanov8846 4 күн бұрын
@miyalys I have a key binding that calls exactly the same `format` function and it works
@leonardodavinci2856
@leonardodavinci2856 11 күн бұрын
is there any plugin to auto import stuff in neovim like in cursor ai . it automatically suggests and with single tap boom everything that was not imported is imported it
@miyalys
@miyalys 4 күн бұрын
Some LSPs support automatic importing via code actions.
@CNich90
@CNich90 10 күн бұрын
You also applied the formatting to your hair…fresh cut!
@andriesvanwyk3226
@andriesvanwyk3226 11 күн бұрын
Thanks TJ! Question: Any idea why using something like Prettier formatting in VSCode and Neovim would give different results? A colleague of mine is on Mac + VSCode and I'm on linux + Neovim. We can't get prettier to format the exact same way. We are working in Angular. From what I can tell, the Typescript files are relatively the same, except for an extra line at the end of the file in VSCode. The html file formatting is quite significantly different. And yes, all other formatting options and plugins have been disabled. We merely have a .editorconfig file. If you know of anything, would really appreciate it, thanks!
@maleldil1
@maleldil1 10 күн бұрын
Have you tried running Prettier on the CLI? Is the result the same of either VS Code or Neovim?
@guitarhero69
@guitarhero69 11 күн бұрын
at 4:32 what did teej do? how did he get the diagnostic fix by typing "gra"
@WeshalbDennNicht
@WeshalbDennNicht 11 күн бұрын
"gra" (in normal mode) is the default mapping for LSP code actions (see previous video of the series on LSP), which he uses here the show the available code actions and select the appropriate one do disable the diagnostic warning.
@teej_dv
@teej_dv 11 күн бұрын
Exactly right.
@nazarzibilyuk1511
@nazarzibilyuk1511 6 күн бұрын
I just wander, Error like: 'attempt to index field 'completion' (a nil value) is a result of me using nvim 0.10 and not 0.11?
@СергейЛюбимов-у3ф
@СергейЛюбимов-у3ф 11 күн бұрын
Thank you for the video, teej. Could you, please, explain, how to set up own rules for code formatting? I.e. what if I need to use only single quotes instead of double quotes and my default code.format produces double quotes?
@moussaadem7933
@moussaadem7933 11 күн бұрын
some language servers look for a configuration file (such as tsconfig.json in the case of the typescript language server) and some send a "workspace/configuration" request to neovim, which you can specify when you setup the lsp, example lspconfig.tsserver.setup { settings = { javascript = { format = { semicolons = "insert" -- etc... } } } }
@biffandhapp418
@biffandhapp418 11 күн бұрын
I'm not sure but I think you should have gotten bufnr from the args in the BufWritePre callback, not the LspAttach callback. When I use your code the formatted code seems to go in the wrong buffer if more than one buffer is open. Either that or I am doing something really wrong and can't see it.
@tekladongmekanikal5672
@tekladongmekanikal5672 9 күн бұрын
I think the error code on the vim.lsp.Client function supports_method is missing self cause your using (.) not (:).
@THIRSTYGNOME
@THIRSTYGNOME 11 күн бұрын
I like my LSP formatting to be under a hotkey so i don't accidentally format co-workers files.
@ArdentInfoSec
@ArdentInfoSec 11 күн бұрын
Absolutely loving this series. Been using vim since Yoda was a boy and learning something new each day so far. I have been following along with the series day-by-day, right down to building from scratch and isolating this config from my usual working setup. All was going well until today, when I simply do not have the same `:help lsp` result as Teej. at 3:20 - `/format` & nnnnn'd to 8/57 line 119 and the boilerplate code used in the example just isn't the same for me. I'm on v0.10.2 freshly built. The code example for me doesn't have the 'textDocument/formatting' example below 'rename' & 'implementation'. It's not a massive issue to get to the result I need, but it makes following along a bit challenging when it's done so fast and you don't get the same results... (I can see this very easily because 'textDocument/formatting' only appears once in my version of `:help lsp`) I wonder if the demo is on a different tag of NeoVim...
@ArdentInfoSec
@ArdentInfoSec 8 күн бұрын
I see this was related to changes in the v0.11.0-dev version of nevovim.
@mnk4allcaps
@mnk4allcaps 11 күн бұрын
he got a hair cut
@teej_dv
@teej_dv 11 күн бұрын
True. Thanks for noticing 😁
@muizzyranking
@muizzyranking 11 күн бұрын
I've always pronounced teej as tee jay.
@teej_dv
@teej_dv 11 күн бұрын
Actually, my initials are TJ. So lots of ppl call me that. Teej is a Nickname of a nickname
@abdulalimmahir
@abdulalimmahir 11 күн бұрын
Please get out of Fireships influence, let's make 15-20 minutes video. Me loving this series
@Ryuujin1024
@Ryuujin1024 11 күн бұрын
It's great to see this but my goodness what a lot of work for something so basic. Ctrl + alt + L for IntelliJ Ctrl + shift + l for vs Code.
@zeyadalaa8015
@zeyadalaa8015 10 күн бұрын
You can map your vim.lsp.buf.format() function to your desired shortcut as shown in the video so it’ll do what those do. In Intellij for example, the concept is the same except that the default settings there are already specified for Java according to “some conventions” which you can either modify yourself or use a configuration file (check out a plugin called checkstyle) Here in neovim, you’re building up exactly the same thing with your own configs how you like them instead of using something that someone else has done for you (ex. Intellij devs) which is the whole point of using something like neovim as an editor ;)
@miyalys
@miyalys 4 күн бұрын
You get more fleshed out default functionality and binds - including code formatting - if you use something like LunarVim, SpaceVim or NVChad. Ie. preconfigured neovim distros.
@grim.reaper
@grim.reaper 11 күн бұрын
yay .editorconfig mentioned!! 🤓
Floating toggle-able terminal in Neovim in 50 lines of Lua
11:09
telescope.nvim introduction
10:15
TJ DeVries
Рет қаралды 15 М.
Что-что Мурсдей говорит? 💭 #симбочка #симба #мурсдей
00:19
Правильный подход к детям
00:18
Beatrise
Рет қаралды 11 МЛН
Арыстанның айқасы, Тәуіржанның шайқасы!
25:51
QosLike / ҚосЛайк / Косылайық
Рет қаралды 700 М.
(Neo)Vim Made Me a Better Software Developer
40:27
vim-jp
Рет қаралды 42 М.
Quickfix can do so much!
6:58
TJ DeVries
Рет қаралды 18 М.
Wrapping your favorite CLI in neovim
26:15
senkwich
Рет қаралды 8 М.
I Created The Best AI Tool Ever
9:12
ThePrimeTime
Рет қаралды 109 М.
DONT use Neovim!! (in these scenarios)
8:56
typecraft
Рет қаралды 46 М.
Neovim has it's own terminal?!
10:25
TJ DeVries
Рет қаралды 20 М.
Vim Motions & Tricks I Wish I Learned Sooner
9:25
Henry Misc
Рет қаралды 49 М.
Automatically Execute *Anything* in Nvim
11:03
TJ DeVries
Рет қаралды 76 М.
Why Can't We Make Simple Software? - Peter van Hardenberg
41:34
Handmade Cities
Рет қаралды 159 М.
LSP in Neovim (with like 3 lines of code)
10:40
TJ DeVries
Рет қаралды 16 М.
Что-что Мурсдей говорит? 💭 #симбочка #симба #мурсдей
00:19