10 Advanced Vim Features (You Probably Didn't Know)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
my name is sebastian and in this video i want to show you 10 vim features that you probably didn't know yet you might know that i'm a big fan of vim and i use this editor pretty much every day but not just because well i'm not necessarily a fan of the editor but of this vim mode that is just really effective to edit text with but also there are some interesting features of the vim editor and a few of which i want to show you in this video and the first one that i want to show you is autocomplete so if you edit well any text or any thing in vim here you can actually just autocomplete your text in a way that you say well hello world control p or control n will just then autocomplete something there you can even browse through this so for example if you say hello and hi and hey and then if you press h then it will just give you a possibility to auto complete your words here it especially makes sense with some keyboards or the word of a method name or a variable name while you editing some coding but obviously for that you get into the area where using an ide makes more sense but it's sometimes it's helpful if you edit some text and if you have longer words such as asynchronous or something like that that then you know once you type once you can just auto complete faster so that's the first one it uses um control uh p and n for well the previous and the next match so you can browse through them i typically press ctrl p while i'm in insert mode and that works in this regard now the second one the second feature is using buffers so these are file buffers with which we can open multiple files uh well at once or in one session how this works is well you can have some commands for opening up multiple buffers but in the simplest way you just go and say well i would like to edit multiple files that of course don't need to exist here that you just provide as arguments when you start a bim and now you have this one available which then just gives you a possibility to browse through these files so you can then use a command buffer next or buffer previous in which you can change them so you say hello world file one and um hello world file two and then you can browse through them quite quickly so what you can do um you can have these commands buffer next buffer previous you can also use i think it's e new for opening up a new file and therefore in a in a new buffer i will also link you my dot files in the description down below because i usually don't type these as you've seen i use some shortcuts for them so for example i use my leader key and l and h for switching through these buffers and leader key t to well have a new and that is part of your so-called buffer list so you have just these files open and you can browse through them quite quickly which is just nice because then you can quickly compare the files that you have and also obviously copy and paste within them so buffers is just a very nice way to handle multiple files and to keep keep them open and also to you know open this up so just if you use you might want to get familiar with this thing of buffers if you want to close a buffer it is with b and d or exclamation mark to override if you have some changes so you can do in this way and then close that again so that's another just helpful feature as the next feature that you maybe hopefully even know about is recordings so recordings are really helpful when we edit some more advanced text and i've been showing this on my youtube channel before you might want to have a look at a previous session where i specifically use this feature what it does is that i say well if i have some change here for example for the second word i want to make this uppercase or let's say i want to have both words uppercase something like this so i have hello world goodbye world hey world and so on and so forth and this a few times so to edit this this can become quite cumbersome but with this recording feature this works quite well by pressing q and then some key for a register a for example then you see that now it's recording there and you can do a few things and you can do basically anything you like so let's say we make this uppercase we jump to the end exclamation mark and then we go to the front again and one down so you already have to think of well how do i want to do and end the recording in order to be repeatable afterwards why because now if i press q again the recording is finished and i can just very quickly execute that again by pressing at and then well the key for the recording so at a in this case so in that way i can say well really quickly do this but even that is too slow because it's a lot of work to do this so instead i can say well apply this but not only once but in this case for example 13 times so i say 1 3 at a and that was just much faster to apply them all at once so here again once i have like these are 13 lines down below so i can have this for 14 times to do all at once 1 4 at a and that will just apply all of them immediately so how this works is just pressing q for start to recording and then some key for example a or b or c for some register and then in order to end it you press q again so you do anything here in between and then with at a you can apply it once or some number before to apply it multiple times this is why i ended it one line below so that it always like jumps down for example but this is very flexible to do all sorts of editing and in general a very helpful feature for the next feature i want to show you this norm or normal command that you can execute with this colon so if you do some stuff and then you press this colon then you can write something here and you can execute some commands for example norm that's typically what i type which is short for normal for normal mode which will just execute something in a normal mode for example normal mode i can do something so i now can type any key that i typically would type in my bim and then i can do something for example i for insert and then say hello and just execute this so then it will just write hello now you might think okay that's somewhat silly what does that bring me well quite easy you can actually do this for um also applying things in multiple uh times so assuming i have a lot of lines here and i always want to have a single character or some single form of editing for all of these lines what works really nicely is if i say i want to select all of them in the visual line mode and then i can press this colon and type norm or normal and then for example a for jump at the end of the line and append it there exclamation mark which then says hello world exclamation mark for all of these lines so for example this works really well if i um want to add some well invocation here for example norm and then go to the beginning uppercase i say for example call brackets and then some quotes some double quotes and do the same thing again at the end something like this where you can very quickly then add some invocation this is what i'm doing quite often if i have many statements i will copy them over into whim and then i edit this just in a very simple way using this normal command so it in general just executes anything that you uh tell it to here so for example if i would um remove the end again i could go and say well norm jump to the end with dollar and then what i can do i can say well delete maybe the last character the semicolon so just make an x for delete that so go to the last position and then delete this and i can remove that again for example so this is what works quite nicely i'm using this norm or normal command and then with anything that you would otherwise just have in your normal mode in them and that would just be executed and works quite nicely with the visual selection to be executed for each line as a next thing i want to show you this way of executing some commands some external commands which are actually the same commands that you would run on your command line so for example i can say exclamation mark and then uh for instance a cat and then some file so if i would um create i don't know some file tem do we have file hello world for example this then i could say well just actually emit this here and then it would just show this i can show you again will show the hello world now in this case it doesn't really make sense but it depends what the command does so if the command works with input and output then you can actually edit something here in your files so for example for hello world you have something like goodbye world and again hey world and hi world and now i would like to sort all of these lines so what you can do you select them and then press colon exclamation mark sort which is a unix functionality that then will just sort all of them here or you say you do this exclamation mark sort and then unique i think it is so for just making them unique and sorted here in that case so you can then use and combine some unix commands that you would use on the command line and obviously you can also then call any arbitrary command so for example while you're coding or editing text you can just execute some command and you don't have to switch the windows here so that works especially well when you use the result in order to work with your text and your text selection so that's quite helpful and the syntax is just the colon again and then some exclamation mark and the command that you would like to execute and then obviously you can combine this with some shell scripting or other mechanisms that work with your input and output in order to modify something so that's quite helpful as well especially the default sorting functionalities and so on by of unix then what is also kind of cool is that you can open some files and urls with gf and gx that you can do here so for example if i write just the path of this of a file of a different file so this one is now not a file yet that's just you know i opened up a new buffer but then i can open and follow this by pressing gf sorry gf and then now it will open this up in a new buffer so now i have this file open which is quite helpful even if you have some text-based documentation on your local file system you can pretty much have a pointer to another file in an absolute or in a relative path and then you just open this up by providing it like that so gf will just then jump to this file basically the same works if you have some url here so gx will just open this up in a browser and then you know you can quickly jump to some specific site which is also kind of cool so just these work quite nicely by providing these links and then following them so it's gf for files and gx for urls for files it works in both absolute and relative path manner another thing that you probably didn't know you can actually encrypt files in vim by using this colon uppercase x command which is quite interesting so now let's say i open up my file again let me quickly close this this was file text hello world and now i go and say colon uppercase x enter and then it tells me to enter some encryption key for example one two three and repeat that and now this is actually stored in an encrypted way so if i press save now it would be written with this blowfish encryption utility and now if i would like to read it you see okay now it's encrypted here but of course with wim it works but obviously you need to provide this encryption key and then while you can edit and write it again if you would like to remove it you use this again i'm calling uppercase x to change the password and if it's um if the key is empty then it won't be encrypted so then it's just the plain text again so that's kind of cool you use uppercase x colon x to encrypt some files what is connected to that is another functionality that you can use in a very interesting way which is so-called auto source well not really a command but a functionality that you can use in your vim rc file so that it can set up in a way and again i will link my dot files which point to this so i have some well i have this for some testing purposes for some syntax file but the one i wanted to show you is that you can have with encryption so now let me just quickly search this here that is yeah a similar auto source command for just encrypted files so you can combine this with a file extension and for me for example if i use a gpg extension then it will also be written in my case by the gpg functionality which in my case uses actually my key that i can provide so it's a little bit different to what i just showed so for example if i say file.txt.gpg then i say hello world i can save it and now it looks a little bit differently but it was actually encrypted using my key and then you will see that this file is actually there in an encrypted way where then well you cannot read it immediately but if you open it up with bim in the same way it would read your key it would optionally ask you for your passphrase of the key and then decrypt it again so that's just another different way and this also works with the combination of some some other functionalities for example the syntax highlighting um if it's a file.json.gpg and and things like that so i will link uh for the dot files where how you can include this yourself but auto sourcing is just another interesting feature or way in which you can really customize and the experience that you get with wim when loading and saving files and another thing that i want to show you that you probably know wim has a spell checking a mechanism built in so if you set this for me i also have some of functionality some shortcut for it so set spell and then you can set some spell language for example english here then we'll just we'll have some spell checking here that will just highlight some words so then if you go and for example press it's a z and then equals sign it will actually will just provide some provide some suggestions if you have a spelling mistake what this would be now with this latin lorem ipsum it doesn't really make sense but if i just have some some other spelling mistake if i just press this then it will just suggest something and then i can then i can press of course i want goodbye so i say it should be one and then i change this here and this also um has another of um functionality for grammar checking at least very very basic one so here for example it says well that should be the beginning of a sentence so please make this uppercase and things like that so it does have this as well but just a very basic spell checking is helpful when you're writing some text and just for the functionality of including this here of just seeing well the obvious mistakes that you did and for the other purpose what you can also do if you have some let's see microservice something like that well it knows about these words but if you had some functionality like well i don't know what you would like to include for example json but for me i already added them so let's say p yes that is not known if it has some unknown word that you would like to add to your dictionary you press c and g and then it will be added to this particular language and then you know jsonp for example will be a known word for that regard so this is just a very basic functionality how spell checking works in vim which is quite helpful if you're writing text another helpful more like fun fact but i've used it once or twice is that them can do very basic arithmetics so for example you can increment and decrement some integer values so for example if i say 1 2 3 2 3 4 if i press ctrl a it will jump to the next integer and just increment it and control x will decrement it so if i go here then it will jump to the next one and so on and so forth which sometimes can be helpful if you combine it with some other automation command for example i say well do this i would like to have some list with some some numbered list i say use this recording feature that we had before copy the current line paste it to uh the next line and then increment it ctrl a by once and now ends the recording and now play the recording at a again and play it 10 times 10 at a and then you have something like a numbered list so sometimes that can be um an interesting feature by just using these arithmetic arithmetics in a different way what you can also do so that's quite interesting now just as a bonus i've been showing this before on my channels you can actually include and combine these features with some other mechanism to execute them with a keyboard for example i can say well write something that should be a command and then in my case i have a special binding if i press the leader key and enter it will just execute this in my shell now for echo that's kind of boring but for example what i can say will do some more arithmetics so what a shell for example can do now press this leader enter and then it will well that was boring then we'll execute this and just calculate the results so this is sometimes helpful if for example i say i have some list here and then in this case that doesn't really make sense but assuming that it would like to have just these numbers and let's say i want to remove them and now i would like to add them all together so what i do now i combine multiple things that you just learned i say well have some plus command remove the last one take them all in the visual mode press j to join the lines and then jump the beginning and say please write something that could be interpreted as a shell command press leader key and enter and now i have them all added together so now this was just a short demo of adding some features here together with this arithmetics and some other features that are maybe not that known in vim and that you can use sometimes because they're helpful and just kind of cool to show off your vim skills so i hope this was interesting if you're interested in more of these sort of tips especially on how to become more productive as a developer you might want to check out my video course on developer productivity linked down below and if you enjoyed this video i would really appreciate if you liked the video and if you subscribe to my channel and as always thanks a lot for watching bye
Info
Channel: Sebastian Daschner
Views: 51,144
Rating: undefined out of 5
Keywords: VIM, 10 tips, Productivity
Id: gccGjwTZA7k
Channel Id: undefined
Length: 21min 47sec (1307 seconds)
Published: Mon Jun 27 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.