Use Ex commands in Vim

  Рет қаралды 12,278

Dong Zhou

Dong Zhou

Күн бұрын

#vim #Ex #colon
0:00 introduction
1:16 Review of :s (substitution) command
7:50 Useful commands: d (delete), t (copy), m (move), > and $lt; (indent)
10:10 Somewhat useful :g command
- :g/re/p
- context sensitive replacement :g/re/s/old/new/g
12:56 Less useful ones: a (append), i (insert), c (replace)
- My blog post on Ex commands: nosarthur.github.io/productiv...
- Vim Universe Playlist: • Vim Universe

Пікірлер: 35
@davidh.4944
@davidh.4944 5 күн бұрын
Just to expand a bit, almost all :ex commands take optional ranges. These are usually one or two specs, "line#", "/regex/", "line#1,line#2", "line#1;line#2", "/regex/,/regex/", or some combination thereof. They can also have +n/-n line modifiers appended to them as well. There are three shortcut patterns, too: . is current line, $ is last line, % is all lines (equal to 1,$). The difference between , and ; is that a comma match always begins regex searches from the current line, while the semicolon starts on the line of the first range spec. i.e. /foo/,/bar/ will find the first line after your current line with foo, then go to the first match of bar after the curent line, while /foo/;/bar/ will find the first line with foo in the file, then go to the first line with bar after that. @5:00 Note that :s/// does not default to matching the _visual_ selection, it matches the current (last used) search term. * is a command that starts a search for the word under the cursor (or nearest to it), so that's the word that will be in the / search register when you call :s. @6:25 The :s delimiter is limited to ascii punctuation characters, with | \ " being excluded due to their special command line meanings. Note that this is a general feature available in almost all programs and languages that use s/// notation, like sed or perl, and usually with more liberal delimiter choice than vim. @11:00 :g is not a "search", it is the "global" command. It will apply a second command to all lines that match both its preceding range (optional, defaults to all lines) and following pattern (required). so grep is ":global/regular expression/print". Note also that :g! or :v inverts the match. @12:00 While you can use :g with :s , most of the time you only need to use :s with the % (all lines) range. But when you do combine them, the power of the two commands together can be impressive. @15:00 This is how the original ed/ex work, from back before full-screen editing was available. You had (have) to specify which lines to edit, then use p to print what you edited onto the screen (or w to write to file, etc.).
@Mederfish
@Mederfish 2 жыл бұрын
This is exactly what I was looking for. Knew some things about substitution but I was sure there would be more to it. Huge thanks for sharing your knowledge:)
@andrez76
@andrez76 11 ай бұрын
I would like to thank you for putting out this video. It's very rich in useful tips and delivered in a no-nonsense, to the point manner. Cheers!
@williamfish1407
@williamfish1407 2 жыл бұрын
I love your content! It's clear, deliberate and valuable. If you're a programmer, I have a feeling you're very relaxing to work with.
@mentalflow
@mentalflow 2 жыл бұрын
Thanks, hope my coworkers think so too :)
@farzadmf
@farzadmf 2 жыл бұрын
Nice video, thank you, it's been a while that I've watched these "deep-dive" into vim things that I personally know just a small amount
@mentalflow
@mentalflow 2 жыл бұрын
thanks, what do you use vim for?
@boringsloth
@boringsloth Жыл бұрын
My favourite Vim command is `:Sex!`. It's useful when you want to see both the current file and the whole file hierarchy.
@mentalflow
@mentalflow Жыл бұрын
Interesting
@mortenlund1418
@mortenlund1418 2 жыл бұрын
thank you for sharing - great video
@aruncs3438
@aruncs3438 9 ай бұрын
So Helpfull , Thankyou mann..
@AnNguyen-vd8wv
@AnNguyen-vd8wv 2 жыл бұрын
Thank you for sharing
@HannesWithoutJo
@HannesWithoutJo 2 жыл бұрын
The tip about different delimiters at 6:00 was a game changer for me, because / is awkward to type on my keyboard layout (shift + 7)
@fabricehategekimana5350
@fabricehategekimana5350 Жыл бұрын
Thanks for the video! I learned some useful things! I suscribed to your channel and I will watch your content. I will give my share: I don't know if you already know, but you can see and edit and rerun the history of some of your ":" commands with the "q:" command (not the ":q" one). You just have to edit the line you want and press [Enter] to run it. You can also do the same with the "/" commands by using "q/". You can find more about this concept with ":help q:" Will you talk about the ":normal" command or the syntax of a vim command in the future? I will be interested to learn more about. Thanks again for the video!
@mentalflow
@mentalflow Жыл бұрын
Nice trick, thanks , I didn't know that
@rogerzen8696
@rogerzen8696 2 жыл бұрын
Great coverage of the ed commands in Vim, but you need to pause a bit after each command to give us viewers a chance to see what happened and take notes. I had a hard time following it on my phone. The video felt hurried.
@mentalflow
@mentalflow 2 жыл бұрын
Thanks for the feed back. I can try to slow down next time
@nickskywalker2568
@nickskywalker2568 Жыл бұрын
Great stuff here! dj for deleting the current and below lines is the fastest :p I know you know it ;)
@mentalflow
@mentalflow Жыл бұрын
Thanks, dj makes sense but my muscle memory for dd is very strong
@StephanGelenscher
@StephanGelenscher 2 жыл бұрын
Awesome video and great tips - thank you. Which operating system are you using? I am a writer for novels but want to switch to a proper writing tool. Vim/neovim seems the best option atm. Just wondering between settling on macos or Linux. All I really need/want is a black screen I can write quickly markdown without being disturbed ^^
@mentalflow
@mentalflow 2 жыл бұрын
I use iTerm2 on Mac
@StephanGelenscher
@StephanGelenscher 2 жыл бұрын
@@mentalflow thank you so much 😀 any other advice/tipp you might have for me?
@mentalflow
@mentalflow 2 жыл бұрын
@@StephanGelenscher I bought license of an app called typora; there are probably free options like pandoc for markdown conversion and visualization
@tengun
@tengun 2 жыл бұрын
The delimiter for *:s* doesn't have to be */*. Yeah I always use an asterisk for that.
@11889music
@11889music 6 ай бұрын
How are you deleting forward from the :ex line? I've noticed the typical shell keybindings don't work there
@mentalflow
@mentalflow 6 ай бұрын
D? x?
@gjermundification
@gjermundification 10 ай бұрын
8:42 If you are already there: dj
@mentalflow
@mentalflow 10 ай бұрын
hmm, my D will delete from the cursor to the end of line ...
@mentalflow
@mentalflow 10 ай бұрын
oh, you must mean dj
@Buri13
@Buri13 9 ай бұрын
Is there a setting to prevent * from jumping to the next match automatically?
@mentalflow
@mentalflow 9 ай бұрын
yes. nnoremap * *``
@saleenapatel
@saleenapatel 4 ай бұрын
this was awesome
@nomadshiba
@nomadshiba 2 жыл бұрын
haha you use vim
@mentalflow
@mentalflow 2 жыл бұрын
Tried vscode for a while; it was pretty nice; but too lazy to set it up on all the machines
Пранк пошел не по плану…🥲
00:59
Саша Квашеная
Рет қаралды 6 МЛН
Best Toilet Gadgets and #Hacks you must try!!💩💩
00:49
Poly Holy Yow
Рет қаралды 20 МЛН
Nastya and SeanDoesMagic
00:16
Nastya
Рет қаралды 36 МЛН
Vim Navigation Commands
21:42
thoughtbot
Рет қаралды 113 М.
Why Should You Learn Vim
11:13
Sebastian Daschner
Рет қаралды 6 М.
Vim Tips I Wish I Knew Earlier
23:00
Sebastian Daschner
Рет қаралды 46 М.
Vim Tips You Probably Never Heard of
12:11
Luke Smith
Рет қаралды 115 М.
Marks in Vim Are A Game Changer
11:01
NeuralNine
Рет қаралды 15 М.
Let Vim Do the Typing
32:07
thoughtbot
Рет қаралды 212 М.
Regular Expressions (Regex): All the Basics
21:39
Luke Smith
Рет қаралды 56 М.
Advanced Vim Workflows
10:41
Semicolon & Sons
Рет қаралды 81 М.
10 Advanced Vim Features (You Probably Didn't Know)
21:47
Sebastian Daschner
Рет қаралды 69 М.
Vim Tips And Tricks Some Of My Favorite Vim Commands
17:05
DistroTube
Рет қаралды 62 М.
Rajesh ka flying dance 😂
0:11
Rajesh Kumar Shorts 14
Рет қаралды 18 МЛН
Поздравляю, ты нашел (-а) оригинал ❤️🥹
0:17
𝐈𝐭𝐬 𝐒𝐨𝐟𝐢𝐤𝐨.𝐌𝐚𝐥𝐢𝐧𝐤𝐚
Рет қаралды 6 МЛН
28 июля 2024 г.
0:20
TULPAR_KG🇰🇬
Рет қаралды 5 МЛН
Cute 💕🍭🍉🍒🤣
0:10
Koray Zeynep
Рет қаралды 7 МЛН