Vim's Built In Completion Awesome, And You Can Make It Better!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments

I'll be looking out for the second video on mucomplete. I've been looking for a way to get away from coc.vim and this looks like it has potential!

👍︎︎ 14 👤︎︎ u/fuzzymidget 📅︎︎ Feb 14 2021 🗫︎ replies

Can somebody reason with me on something?

I rely heavily on autocompletion. I consider myself a bad coder and my memory is that of a gold fish. I also can't write two sentences without a typo.

So my workflow is almost always write a few letters of whatever I want to write and then tab it to complete it. Even if I know exactly what I want to write, I'd still write something like functio and then tab to complete so that I have an immediate test of spellchecking.

Having said that, even just thinking about having to press control x control whatever every time I do that makes my fingers hurt.

So, what gives? Why would anyone condition themselves to these emacs like shortcuts?

👍︎︎ 10 👤︎︎ u/nraw 📅︎︎ Feb 14 2021 🗫︎ replies

Great stuff! I have help-page reading to do! I never thought that I needed omnicomplete before, but I regularly use <C-x><C-n> and <C-x><C-l>. Using <C-x><C-o> for snippets is just SO clean. Got some learning to be before I can think of how to improve my workflow, but this will definitely fit into it. Thanks for sharing!

👍︎︎ 9 👤︎︎ u/Schnarfman 📅︎︎ Feb 14 2021 🗫︎ replies

Made a video focused on using and extending vim's builtin completion. Home all of you like it!

👍︎︎ 21 👤︎︎ u/a-concerned-mother 📅︎︎ Feb 13 2021 🗫︎ replies

Very nice! I've been using 'youcompleteme', though I'll give mucomplete a whirl now.

👍︎︎ 3 👤︎︎ u/8thdev 📅︎︎ Feb 14 2021 🗫︎ replies

see-oh-see (coc) not cock lol

cool vid thanks

👍︎︎ 4 👤︎︎ u/wetsip 📅︎︎ Feb 14 2021 🗫︎ replies

I first read , "Vim's sth sth competition"
and I asked to myself, "what?" Does even vim has competition?

I had to read again :D

👍︎︎ 3 👤︎︎ u/FakuVe 📅︎︎ Feb 14 2021 🗫︎ replies
Captions
what's up you guys so today i wanted to talk to you a bit about how i use vim i've had a few people ask me questions about how i do completion the main reason that people have been asking is because i said i don't use caulk in fact i don't use anything that really relies on an external resource so for example like using python i don't use you complete me i don't use caulk i don't use any of the other tools that exist like do pleat instead i actually use mu complete mucomplete basically acts as a simple wrapper around vim's built-in completion yeah that's right vim has built in completion in case you guys didn't know it can actually complete in a bunch of different ways it can complete based on the words in the actual file that you're looking at included files and it can even use intellisense which is a way of basically doing smart completion using something called omnicomplete which actually a lot of languages have built into vim and on top of that you can even use the syntax to make the completion better so there's a lot of cool ways that you can do completion in vim but as a lot of people are used to an ides you don't have as you type completion where when you're typing it will just automatically try and suggest words that you may want to be trying to type but if you guys do want as you type completion you will actually need to use new complete or some other tool like it this is why i use mu complete is because it basically allows you to do chains which is basically a way to do one completion method so using something like omni complete as its first one and then if that fails just try and complete based on the words in the file and if that fails maybe look in the included files any of that sort of stuff can be done and so as an advantage to this you can make it adapt based on the language maybe if you're writing in the comments you don't need all the other kinds of completion maybe just do spelling completion all that sort of stuff so it's really awesome and really powerful for that sort of thing now one of the greatest things about using vim's built-in completion is the fact that you can do really neat things like integrating with different snippet plugins without having to do very much extra work because most of the time they already have a way to do completion you just have to make it work with whatever completion method you're using in mu complete it can basically just call the function right away as long as you can find out what it is you can just call it right there bam integration very simple on top of that you can actually integrate different things like faking key bindings whenever you're using something native versus doing something like that within something like you complete me would require you to look a lot more into the documentation and count on someone not changing too much versus with mute complete the changes are pretty minimal and most of the times things just work out of the box now in this video i'll actually be showing you guys how you can make your own completion methods so say for example if you wanted to complete the month of the year it'll be pretty simple to integrate into something like mu complete anyways guys if you guys are interested in more videos on vim if you guys want to learn how to customize it improve your workflow and try and stay a bit more native then be sure to like comment subscribe the big three let me know that you guys are enjoying this content on top of that if you guys are interested in letting me know about what completion you're using let me know in the comments i'd love to hear what you guys are using i want to know what's the most popular way to do completion right now maybe you guys do the same sort of thing as me maybe you guys have a more minimal faster way to do it let me know i'd love to hear from you anyways guys let's get into it let's show you guys how you guys can use native completion within vim how you guys can make your own completion within bim and how you guys can get started with mew complete without any more delays let's get into it all right so just to start off let's open up a terminal and we're going to run vim we're just going to do none and no rc so dash u none dash u no rc this just gives us vim without any of the extra features and then we just do set no compatible and there we go so now we have vim with everything set up like normally would without vi compatibility um if you don't know what i'm talking about don't worry this just allows us to actually access a lot of vim's features so now what we're going to do is we're going to fill this with text and then we're going to start off with the normal completion that you'll see all right so now that we've started off pretty normal we've got this text right here and we can do our basic completion just by doing ctrl n now this will basically start from the top right top left and go all the way to the bottom right pretty simple and it will just basically give us completion so if i did c o u control n it will replace with could if i just did c and hit ctrl n it will give me everything that starts with a c now if i did c control p it will complete everything in the opposite direction and in fact i can do ctrl n and control p to go back and forth now that's actually just the normal completion it has a bunch of different options that you guys can set then i will hopefully get a chance to show off later on in the video but on top of that you can actually use ctrl x control p to get the same sort of thing but limited to just the buffer like you'd expect control x control n same sort of thing and basically all the extra special completion that you get with vim follows that same sort of pattern control x control something will give you completion for that kind so for example control x control l will complete the line so that's pretty fancy and then control x control s we'll complete with spelling but since we've done a spelling setup we have to do that so we're going to do set spill now that we have the spell set up we could do stuff like this so say we did th i we do ctrl x ctrl s and it will correct it to v and give us a bunch of different corrections for maybe what we could have meant which can be pretty helpful if you guys like me are terrible spellers now another completion that you guys may want to use is say you've got to complete a path so say for example we did home and we can do control x control f and it will just complete as we go and then once there's no other option it will start offering us completions so say we want to go to doc documents all that sort of stuff so we can do simple path completion just like that now as much as i'd like to show you all the different kinds of completions that you guys can do i'll just go ahead and show you where you can find some more completions and how you can use them so you're going to go help and then you're going to do ins dash completion and there you go there's a huge list of them right here so we have control control x control l we have control x control n allows your stuff and there's a bunch of different kinds of completions you can do completion by tag a dictionary so a collection of different words you can do a thesaurus all that sort of stuff you can do current and included files and with ctrl x control i and i'll try and show some of these off as we go but obviously i can't show everything um some important ones to look at that might be helpful is if you guys are writing some dim script um right here ctrl x control v actually does completion for the vim commands so like when i'm down here and i do h tab it will give me completions which can be pretty useful so for example if i'm down here and i do let control x control v it will give me all the different options that it would in the command line so that's pretty helpful kind of hard to see since the spell is enabled but if i just use set no spell then it will go away and then i can just do equals control x control v let's just try that again and then it will give me all the different things that it thinks that it might want to complete with so that can be really helpful if you guys are writing vim script and makes it substantially easier to work with so the main star of the completions that i wanted to actually show off today is omni complete so omni complete is like i mentioned before similar to intelligent completion or intellisense in different ides and it gives you basically completion based on the language and what it suggests that you need so if i just quit this window and i tried to use it so control x control o it's going to say there's no omni complete funcs or omnifunk set and that's just basically saying that there's nothing set to use for completion in this file type since we don't have any special things set up if i just leave this and so here we have a javascript file so we're going to do set on the funk equals and then we're gonna do java hashtag all right so as you guys could probably tell i had to read that off of a separate file because that's pretty long so for something like this you'd probably want to automate setting this up for you and setting your omni complete in your vmrc um which is pretty simple in your vmrc you just do set omni func equals dot dot dot like i was entering before um i'll put that in the description so you guys can access it later so now when i do ctrl x control n it will give me like document i can do control x control n again or i can shut x control o to get the on the completion and it's pretty powerful pretty effective and it gives you some pretty general stuff so yeah so we could do doc control x control n or control x control o actual x control o and it will give us a bunch of other completion pretty powerful if you guys are working with javascript but some things like i said before like c are not quite as nice to work with and if you guys want to learn a bit more about how omnifunk works you can just do a help on the funk and this will give you information about it and then see that it usually wants you to set it with file type plugins which is something you guys can look into i feel like it's not worth covering in this video but there's a lot of different stuff like that that you guys can go ahead and implement yourselves now finding these omnifunks can be a bit frustrating because they can't really be the easiest to find but the best way to find them if somebody knows a better way please let me know in the comments but the best way that i have found them is either seeing someone else is using them and slash and then hit tab and it will complete you and then you want to go to omni complete and then you can go through here and there's a bunch of different language specific ones so say oh a did a complete most the ones that you're looking for will have complete in the name these will all be so there's a bunch of different completion plugins that you guys can use like haskell complete it goes on and on so just to get started with actually making our own completions we're going to just start off with a simple file so i'm just going to do e is just a alias i have for vim and then we're going to open mycomp.vim and so this is just an empty file and it's going to have its file type set to vim just because it ends with the dot vm so now just to start off we're gonna make a function don't worry if you guys have never actually worked with vim script before this should be uh pretty self-explanatory and i'll try to explain every step as we go so we're gonna do funk and then so it's gonna be function bang and that's basically the bangs just there so that way if there's already a function with the same name as what we're doing then it will be overwritten so for example it's not going to give us an error saying oh this function already exists and we're just going to call this my funk and the reason that is capitalized is just because bim's built-in functions actually uh have all lowercase so this is just to avoid us overlapping with them so now what we're going to do is we're going to get started so just to start off really easy we're just going to do echo hello and we're going to want to put that in quotes all right so now we've got our plugin and so now what we're going to do is we're going to do source we're going to source this file right and then what we can do now is we're going to do call my funk bam prints hello pretty easy so now we're going to kind of mix this up a bit more and we're going to get started making something else so let's make a variable so the first thing we're gonna do is we're gonna do let words equals hello and then we're gonna do words and just like before we're gonna save we're going to source it and then we are going to call it and so it's going to print hello we could do world just to clarify that this is running a second time hello world so now we can keep expanding upon this so another really simple way to expand on this is we're going to basically want to make like a list is probably what we'll want to do so to make a list we're just going to do square brackets and we're going to put some stuff in it so we're going to just give it uh let's just give it gavin oh i forgot to mention best practice to use single quotes instead of double quotes just because single quotes and vim can be a comment so it just kind of makes things a bit easier so now we're going to do gavin um wall and all right and we're going to want to put commas to separate out the list and then we're going to do words we're going to do words one all right now you guys could think about this for a second think about what it's going to be but we're just going to save it we're going to source it again and we are going to call it and it's going to print one so as you'd expect with most languages gavin is at zero wall is at one and hello is at two so pretty simple now i'm gonna try and kind of get a bit further on in this and we're going to actually do something else so now we're gonna call a function built into vim we're gonna do call and we're gonna do so we can use that control x control v to get completion and we're going to do complete now we want to learn more about it so if we go to the help for complete you'll see that it says start call and matches now it has a lot of different stuff that we can do but what we're going to do is we're just going to go ahead and do the start call as call dot and dot is just basically wherever the cursor is so it's basically just going to start where the cursor is and then we have to give it something to complete with so here we're just going to complete with words um and that should all add up all right now just to add to this we're going to do return and we're just going to return nothing all right so that's not super important it's just going to tell it basically to do this completion and then that is the end of our function so now we're just going to save that we're going to source it and then we're going to go down here we're going to do control r equals and then we're going to do my my funk and it's gonna give us our words to complete now we can expand this maybe make the words a bit longer and you can actually add some extra stuff so if i just open this up all the way you'll see that you can do stuff like adding completion options check for completion you can do completion info uh as well which will give it basically more information like stuff like is it a keyword and extra information to put in your completion um and so that's pretty cool so now that we've got this let's actually map it to something so we're just gonna do uh control x um instead of doing control x control m we're just gonna do control x m and we're gonna map that to control r equals my func funk right so now we're just going to save that we're going to source it like we had before the reason i used imap is just because it allows us to remap the same key binding but if you are actually like comfortable with this and this is what you wanted you do i no remap just to avoid anything from overlapping with it anyways so going back to this we're just going to save it we're going to source it and then what we're going to do is we're just going to do control x m and then it will give us this and we can hit enter and it will give us all our completion options in fact i could actually just add cr to basically say do enter for me let's save it source it and then control x m bam there we go now we've made our own completion pretty simple and pretty easy now you can actually write your own omni completes as well i don't think i'll cover that in this video i feel like we've done enough uh vim scripting for any normal person but this sort of a thing can obviously be expanded basically the world's your oyster make what you like a lot of different things you can do with it now on top of that there's actually ways to expand a bunch of different tools and this is kind of the reason that i use mu complete so just to give you guys a quick little look at how i use mute complete let's just save that and we're going to go ahead and take a look at my vimrc so really quickly we're just in my vmrc and you guys can actually take a link look at it it's linked in the description and right here i have just where all my settings from you complete are they're pretty simple and i have pretty general stuff in here so first off let's just look at the normal settings so so complete opt basically just tells it what to do when doing completion um so this stuff down here basically tells it don't complete with include or tag because i want me to complete to take care of that no select as in don't select it right away auto on all that sort of stuff this is the big one you kind of just want that's that way when you start up vim it will enable it right away now there's a couple of different things so for word list this basically just gives you a bunch of words that it will offer as completion just as another fallback there's some completion chains so you can set the default completion chain um and then it will give you just the default and mini right here is actually my snippets uh list will be the word list uh omni is omni complete obviously path is file completion control n is control n like normal and you spill is basically just a special form of spelling completion and then you can have extra stuff like spelling and strings spelling on comments we'll use just spelling same sort of thing you'd expect from a lot of other options and you can give it its own regex for how to select what syntax areas you're in to say that you're in a string or a comment now we get into the actual specifics for each language so for html i have like omni complete and mute mini snippets uh set up ahead of time um there's a bunch of different stuff all for specific languages um you can duplicate them so all the settings that i have from markdown i want to use for due to which is like org mode that i use male and git commits and then on top of that you can have special stuff like say triggering special completion for example like when you hit dot it will use omnicomplete like you'd see here you can go pretty crazy with how in-depth you want your completion to work i highly recommend taking a look at it but you don't need all this completion you can simplify it a lot more than i have i just am picky and i like to customize so this is kind of how i ended up in this sort of a situation now if you guys remember before i showed you guys that you can make your own functions and map them to a key now what you get with mu complete is you can actually do your own sort of thing very similar to that you'll see it right here is you could do view complete user mappings and so here i have one set up which is mini which we'll basically call uh mini snip complete the big thing is that this is actually basically mapping the same sort of thing that we did before but instead of actually having to map it to a key we're mapping it to a keyword and so now if we go back to my different languages you'll see that mini snip is at the start because i wanted to complete my snippets before it completes all the other stuff for example if i did if it will complete me with a snippet and then i can expand my snippet but if it didn't find anything in there and i did a g colon mu it will offer more completions outside of that so if we looked we could actually see oh we have all this different stuff set up for vim but cmd right here is actually using vim's built-in completion so pretty powerful and i'm sure you guys can see the advantage to doing something like this gives you as you type completion but it doesn't go too crazy anyways i think i'll probably make a similar video in the future maybe just giving a quick showcase of mute complete but for now i think we'll just start off with just this and i feel like you guys can work from there if you guys need to learn more about mute complete you can do go to the help and it will give you all the information you can need i find this really awesome especially because um i can integrate with other things so for example as much as i like omni funks and completion with that it does have its limitations so the way that i actually overcome those limitations is if i go back to my vmrc i actually go ahead and use a separate plug-in which is vim lsc and there's other ones vim lsp is another option which allows you to use vim's omni complete but using an lsp or a language server if you don't know what that is it's basically a way to get even more complex completion which is really awesome and it allows you to get a bit more uh special and customize a bit more and get a lot better completion as well as linting all that sort of stuff built into your editor anyways guys i hope you guys feel like you've learned a decent amount in these videos and i hope you guys feel like you can start using this completion right away obviously i didn't go too in depth on some of the different things i mentioned this was more just to give you guys a quick introduction and get you guys started with it let me know if you guys want me to go more into depth on any of these different topics let me know if you guys are interested in a bit more vim script related stuff anything like that hit me up in the comments let me know anyways guys i hope you enjoyed this video hope to see you next time have a great day see you later
Info
Channel: Gavin Freeborn
Views: 5,966
Rating: 4.9829059 out of 5
Keywords: coc, coc.nvim, youcompleteme, neovim, vim, nvim, lua, vimscript, viml
Id: NUr-VvaOEHQ
Channel Id: undefined
Length: 20min 54sec (1254 seconds)
Published: Sat Feb 13 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.