r/vim • u/semicolonandsons • Apr 05 '20
Advanced Vim Workflows - Episode 1 of "A Decade of Vim"
https://www.youtube.com/watch?v=futay9NjOac111
u/Zantoxin Apr 05 '20
Really nice video, looking forward to the next episode.
Vim tip for anyone who may find it useful: If you start recording a macro with say qa, you can "pause" the recording by stopping the recording as normal (q), then when you're ready to "unpause" start recording again with qA. This would append what you record to register a instead of overwriting it.
This could have been used in 2:30 to check what was needed at the bottom of the other file by "pausing" the recording, switching to that window and scrolling down, then switching back and "unpausing".
48
u/semicolonandsons Apr 05 '20
OH MY GOD. That's brilliant. I wish I'd thought of that.
I'm going to add that to the show notes on https://www.semicolonandsons.com/episode/Advanced-Vim-Workflows. Can I credit you somehow (e.g. Twitter handle, link to your website)?
24
u/Zantoxin Apr 05 '20 edited Apr 05 '20
You could credit my github as its the closest thing I have to an active online presence, https://github.com/Zantox. :-)
Flattered that you want to credit me, and I'm glad I could teach you a new trick haha.
12
u/kaitos Apr 05 '20
This makes complete sense with how I know all those keys work, but I never put it together like this. Brilliant.
10
Apr 05 '20
Just to add to the tip, it’s not exclusive to the a register ( the capital A here is not acting as “append”). Any register can be appended to my using the capital version. B appends to register b, F appends to register f, etc.
2
u/timestamp_bot Apr 05 '20
Jump to 02:30 @ Advanced Vim Workflows
Channel Name: Semicolon&Sons, Video Popularity: 94.12%, Video Length: [10:41], Jump 5 secs earlier for context ^@02:25
Downvote me to delete malformed comments. Source ^^Code | ^^Suggestions
8
u/JuicyORiley Apr 05 '20
I hate videos like this as I feel I've finally broken the desire of Vim then videos like this pull me right back in 😫.
Really impressive stuff!
16
u/semicolonandsons Apr 05 '20
There are lots of practical reasons to use Vim but ultimately it's the spiritual ones that keep me loyal.
2
4
4
u/fteem Apr 05 '20
First and foremost – great video, I've been using Vim daily for about 7 years and I definitely learned from this. So, thank you!
Two questions:
Opening the buffers as (what appears like) tabs in the top of the editor, is that a plugin or a configuration? Could you tell me more?
When you do a file-wide search and replace
%s/foo/bar, your Vim does on-the-fly highlighting. I thought this was not possible, but it seems I am wrong? How do you do it?
Thanks in advance, and keep up the great work!
2
u/semicolonandsons Apr 06 '20
There are a few ways to get that affect. I'm using vim-airline and setting `let g:airline#extensions#tabline#enabled = 1 `
For that I'm using a feature of neovim — `set :incsearch`
4
Apr 05 '20
I'm not op, but I can answer:
Is a plugin, I think it's called bufline. A cursory search showed this plugin, not sure which op uses: https://github.com/ap/vim-buftabline
Is a setting with neovim only.
:h inccommand4
Apr 05 '20 edited Apr 05 '20
Incorrect on number 2, available on terminal vim as well. Do :set hls to highlight search
EDIT: As point below, incsearch is also needed to achieve the effect closely in terminal Vim
2
0
Apr 05 '20
[deleted]
1
u/Botskiitto Apr 06 '20
And for terminal vim there is plugin that can be used for that live substitute preview:
markonm/traces.vim
2
3
u/phelipetls Apr 05 '20
2. You might be interested in traces.vim, although I don't know if that is what he is using.
1
3
u/calvers70 Apr 05 '20 edited Apr 05 '20
Some of these are awesome :) Question about the first one -- wouldn't using a regex to delete the bits you didn't want as opposed to hardcoding actions into the macro would have been a bit more robust. This way it wouldn't go wrong if the format varied at all (e.g. if a certain tag didn't exist, there was an extra line break etc).
e.g. (my shit attempt, I'm sure some regex wizard could improve it)
:%s/\v\<head\>_.{-1,}\<\/head\>|\<\/{0,1}html\>|\<\/{0,1}body\>|\@include.*\)//g
Secondly, you probably know this, but when you're essentially diffing files like you were near the start, you can use :set scrollbind in both windows to sync the scroll between the two. Would have allowed viewers to see that @endsection at the bottom of the other file.
EDIT: woohoo it's my cakeday!
2
u/semicolonandsons Apr 06 '20
Great tips! I never heard of
set scrollbindbut I 100% would have reached for it in the video if I had know about it.I'll add your tip to the show notes too, linking to your reddit profile. PM me if you'd prefer me to link to your Twitter/some personal website.
1
u/windsostrange Apr 05 '20
Sadly, there is nothing robust about running regex on HTML/XML. It's one of the evergreen rules in this game and it bears repeating now and then. It's... a dark road. Parse HTML. But no regex wizard can ever improve what you've posted to the point where it functions exactly as you'd expect it to for even a small sample of HTML files. HTML is not regular! Don't attempt regular expressions when the language is not regular!
0
Apr 05 '20
[deleted]
4
u/calvers70 Apr 05 '20 edited Apr 05 '20
dstcould delete the wrong tag though if the correct one wasn't under the cursor?Agree that sed is a better option in general
EDIT: don't really agree that something being difficult to learn/type is a reason not to do it - otherwise none of us would be using Vim in the first place :) If you typed out what he had to do in the macro in one line it would just as much like a random series of letters.
0
Apr 05 '20
[deleted]
1
u/calvers70 Apr 06 '20 edited Apr 06 '20
You get immediate feedback from
:%sit basically lets you "preview" your changes as you type.That's how I wrote it, I just string together all the things I want to remove with
|.Honestly, I don't think it's that bad. You could even write the statements separately I was just going for brevity.
e.g.
Match entire head tag:
\<head\>_.{-1,}<\/head\>Match html tags but leave content:
\<\/{0,1}html\>Match body tags but leave content:
\<\/{0,1}body\>Match @include line:
\@include.*\)I am NOT good at regex but these are pretty basic patterns once you get your head around them.
Hell. Get rid of RegEx completely and just use manual find/replaces and my point would still stand I think. Still much more tolerant of variations in layout/content/
2
u/Probotect0r Apr 05 '20
What plugin is that for highlighting indent lines?
2
u/semicolonandsons Apr 06 '20
I'm using Vim Indent Guides: https://github.com/nathanaelkane/vim-indent-guides
1
2
2
u/crajun gave up on vim Apr 05 '20
Too much stuff installed, look at vimcasts videos for high water mark: clean environment and focus on content not flash. Enjoyed it though!
2
u/semicolonandsons Apr 06 '20
I get where you're coming from and I've even paid hundreds of dollars for in-person Vim training with Drew Neil, the guy who runs Vimcasts. I have nothing to add and no way of improving on the excellent work he's already done, so that's why I decided to convey my bells & whistles setup. (I also want to convince a few specific people I've met over the years who unfairly dismissed Vim since it lacks the conveniences of "modern editors".)
3
u/SutekhThrowingSuckIt Apr 05 '20
I don't see this as a problem since vimcasts already exists and we don't really need someone else with less communication experience reproducing that content. This content has a different stated purpose and showing the full current working environment is aligned with that purpose.
2
u/Botskiitto Apr 06 '20
He specifically focuses how he would do these things in actual real life scenario and this was perfect example.
4
u/ivster666 Apr 05 '20 edited Apr 05 '20
I enjoyed watching it! Would love to see more!
I use macros a lot but I have not needed the argslist trick. That one is really cool. Also the way you on the fly crafted a temporary mapping was really neat.
1
u/mgarort Apr 05 '20
Is that just Vim, or is it Emacs with evil mode?
The powerline looks very similar to the one in Spacemacs. If it is just Vim I would like to know what you did to customize it please!
8
u/semicolonandsons Apr 05 '20
It's
nvim. I have a bajillion customizations and plugins in there. (I appreciate that this isn't everyone's cup of tea, but I personally prefer this approach to having a minimal vimrc)Anyway I'll cover my setup in a future episode. Possibly one about building up my vimrc from scratch.
Is there anything in particular you want to know how to do?
2
u/SutekhThrowingSuckIt Apr 05 '20 edited Apr 05 '20
Thanks for the video, I saw the email and I really like the concept for the series as "fully configured
nvimthat's actually used in a professional environment." To that end, it's actually useful to see your bajillion customizations + plugins. That concept fits with the mission you lay out at the start and is primarily what differentiates this from the more structured basic content on vimcasts.org .I'd suggest at least providing a link to your vimrc/init file in a github repo even before doing such a series. That way people can look for the bits they want to grab themselves and it won't be as pressing to start a whole video series.
2
u/semicolonandsons Apr 06 '20
Great point about leaving a link to my vim dotfiles in show materials and mentioning that at the start of the next video. That way people can investigate themselves.
3
1
u/mgarort Apr 05 '20
I was wondering about the powerline appearance, but someone else explained what were the required plugins below.
Other than that, the explanation about recording was very useful, thanks a lot for the video :)
-5
u/-romainl- The Patient Vimmer Apr 05 '20
Distraction. Now, you have more questions about your setup than about what you actually demonstrate.
3
u/WrathOfRathma Apr 05 '20
It looks like he's using vim-airline/vim-airline with some sort of theme from vim-airline/vim-airline-themes.
https://github.com/vim-airline/vim-airline/wiki/Screenshots
There's also just vim's powerline. https://github.com/powerline/powerline
1
1
u/binaryplease Apr 05 '20
Would you mind sharing your configuration for vim?
1
u/semicolonandsons Apr 06 '20
Sure thing. This one's fairly recent: https://gist.github.com/jackkinsella/aa7374a6832cca8a09eadc3434a33c24
1
u/Nazeeh Apr 05 '20
Love the video! Thanks for the content.
Quick question: How do you get that completion popup menu for command mode?
Thanks
1
u/semicolonandsons Apr 06 '20
As far as I know, it's the default with neovim 0.4.3. If I open without any configuration file `nvim -u NONE` then it works since the default for ` wildoptions` is `pum,tagfile`
2
u/Nazeeh Apr 05 '20
Nevermind. Figured it out. Needed to add this to NeoVim vimrc:
set wildoptions+=pum
1
1
u/IReallyNeedANewName Apr 05 '20
I liked the use of <cword> to get the file name, and getting the file name to use as a class name. Clever stuff
1
1
1
u/Inmute Apr 06 '20
Thank you for such a quality content!! Can't wait for more!!!!
2
u/semicolonandsons Apr 06 '20
Thank you. Your words are very motivating, and I really appreciate it since I feel like a noob doing screencasts :)
1
u/Inmute Apr 06 '20
You deserve it. Only thing I would've liked different. Is for you to use screen key, so we can see the key presses on screen.
2
u/semicolonandsons Apr 07 '20
I hear you. I'm looking into it and what the tradeoffs are (screen real-estate, ease of making video cuts without looking inconsistent). Ideally I could record them with a third video stream and turn them on/off as necessary.
1
Apr 07 '20
How do I save these macros permanently to my vimrc?
2
u/semicolonandsons Apr 07 '20
The short version is: `let @{REGISTER_NUMBER}='content of macro'`
For details:
https://vi.stackexchange.com/questions/12513/save-a-macro-just-created-in-vimrc
1
u/rlopezc Apr 12 '20
How do you configure vim to show the substitute command replacement in the buffer before running it?
1
1
u/Maskdask nmap cg* *Ncgn Apr 05 '20
You're creating new commands by editing old ones in a special buffer and in the video you said that you do this with <c-f>. How do I get that functionality? Is it a plugin or a simple map?
4
u/the_real_albro Apr 05 '20
It's a built in. Go into command line mode and try
<c-f>To save some key strokes from normal mode
q:will do the safe as:<c-f>1
u/semicolonandsons Apr 06 '20
Yep, exactly. Love this feature because you can use the full power of normal mode to edit old commands.
1
1
1
u/b-man157 Apr 05 '20
!remindme 1week
1
u/RemindMeBot Apr 05 '20
I will be messaging you in 7 days on 2020-04-12 13:22:00 UTC to remind you of this link
CLICK THIS LINK to send a PM to also be reminded and to reduce spam.
Parent commenter can delete this message to hide from others.
Info Custom Your Reminders Feedback
1
u/brucifer vmap <s-J> :m '>+1<CR>gv=gv Apr 05 '20
Nice video, I learned a few new things. I have a few tricks you could use to take advantage of some cool register behavior:
The current filename is stored in the
%register, so you can insert it without bothering with the expression register by just doing:"%pThe previous
excommand is stored in the:(colon) register, so if you want to re-run the last command, you can run it as a macro without leaving normal/visual mode by doing@:(instead of:<up><cr>) and then you can use@@to quickly re-run it (previously run macro).In
exorinsertmode, you can hitCtrl-r(twice if you want to ensure backspace keypresses are preserved) and then type a register, and it will paste that register, so instead of editing the previous command to havenmap <key>in front, you can start a new command with:nmap <key> :and hitCtrl-r :to paste the previous command at the cursor.The same trick also works with macros if you want to convert a macro to a keybinding, just do
:nmap <key>thenCtrl-rtwice, then the macro's register.
1
u/rnevius :help user-manual Apr 06 '20
The current filename is stored in the
%register, so you can insert it without bothering with the expression register by just doing:"%pThe advantage of using
expand()is that you can trim the file path to just return the last path component (tail). The OP could have also usedexpand('%:t:r')to avoid the backspaces...but that's a bit of amouthfulhandful.2
u/brucifer vmap <s-J> :m '>+1<CR>gv=gv Apr 06 '20
It's neat that
expand()can do that, but it still feels very clunky to me. I think even if you need to strip everything but the base name, it's still faster to just use the%register and then delete the unwanted parts of the filename with text operations. Compare:" % p T / d ` . f . d e " = e x p a n d ( ' % : t : r ' ) <CR> pAnother advantage of using the register approach is that it lets you use and build muscle memory text manipulation operations instead of using the
expand()API, which I use rarely enough that I'd have to look up the documentation to be able to use it with confidence. Also, the register approach lets you see what you're doing each step of the way, so you can course-correct on the fly. (Imagine if you put in"=expand('%:r:t')<CR>pby accident: you'd be 19 keystrokes in before you noticed the mistake and then you'd have to fix it)For a plugin or a binding in your
.vimrc,expand()would probably be the right choice, because you'd care a lot about robustness and you could take the time to look up the API and test it out, but for a quick macro with a known set of constraints, I'd go with"%pfor sure.Explanation:
"%ppaste path,T/move back to the last/,d<backtick>.delete from there to where the text was pasted,f.move forward to.,dedelete the extension
1
u/L3r0GN Apr 07 '20
It is very interesting to see how others use vim so that we can learn and come up with ideas to improve our workflow!
Thank you :-)
1
0
u/fuzzymidget Some Rude Vimmer Apr 05 '20
Looks good!
Only critique is I'm not sure a macro over the args list is advanced. A minor nitpick for sure.
Perhaps the subsequent topics will move in that direction.
0
Apr 05 '20
[deleted]
2
u/semicolonandsons Apr 06 '20
Thanks for a wonderfully motivating comment.
I'm leaning towards your point of view about keeping my Vim fully featured. For one, as you say, it fits with the philosophy of what I wish to convey in these screencasts ("real life codebases"). Secondly, I think there are some really magic materials already out there that cover pure vim - like Vimcasts, Derek Wyatt. I can't add much to what these guys have already created.
The bit that's taking up a lot of time isn't so much my mistakes. Sure I had a few that I cut out and you're right, there's no harm leaving them in because recovering from flubs is part of the coding experience. The issue is more that I freak out when the microphone is recording and end up randomly blanking mid-sentence, mis-speaking, or word-derping otherwise. Perhaps my biggest personal motivation for this project is to address this nervousness by repeated exposure. I've only done two so far. I hope, like most things, it'll get easier with practice.
2
u/IReallyNeedANewName Apr 05 '20
Personally disagree re production quality. Sure it doesn't have to be huge, but imo there are a lot of vim videos out there that aren't that great and re-hash the others, so I like to see an indication of quality. Otherwise I'm just not going to keep watching.
Your point about keeping the plugins was good.
0
Apr 05 '20
[deleted]
1
u/semicolonandsons Apr 06 '20
Excellent point about the SSL. Will fix.
re Cowboy: With this project, I literally have no idea what the infrastructure is. I time-boxed coding the site to about four hours so far and the fastest way I knew how to deploy was "git push heroku". Let them take care of the rest.
27
u/semicolonandsons Apr 05 '20
hi everyone. I posted here about two months ago saying I wanted to share my experiences of using vim over a long time period and asking what people would like to see me cover.
I finally got round to learning how to record and edit screencasts (man is it time-consuming!) but what with the lockdown and all in place it beats refreshing infection statistics.
I'm new to videos so open for feedback.