TL;DR - ish: This post is a list of options and keystrokes in Vim, if this is the first time you're getting to know them, take your time, read som...
For further actions, you may consider blocking this person and/or reporting abuse
Tim Pope's Vim Unimpaired has a nice shortcut (among some other very useful ones) to add empty lines above or below current one:
This is fantastic. That's why I love this community. Thanks buddy
Thanks to you for taking the time to write this article. #vim rocks.
B
andE
might be custom commands on your end? on a completely unmodded version of vim on my mac those commands aren't working. but the regex-ish^
and$
definitely work to move you to the beginning or end of the line in command mode.stackoverflow.com/questions/105721...
They're not custom, no.
Try
:help B' and
:help E'.Hint: WORD versus WORDS.
And 0 also takes you to the beginning of the line if you didn't know.
A small but important clarification:
0
brings the cursor to the beginning of the line, while^
brings it to the first character of the line. I.E. the first character, no matter if it's at column 1 or 1+n (that's is no matter what's the indentation of the line).weird, they don't work on mac vim out of the box. there must be a setting that gets flipped or changed that's not mentioned here.
Hey @worc any chance for an exact version?
a
vim --version
prints this:Good list; I've used vi since the 1990s and exclusively vim since the early 2000s and there were some I never considered like `dip'. A few comments though.
First of all: look at vimtutor(1) (or just try
vimtutor
at the command line).Rather than use what would be in some contexts an anchor to get to beginning of line (i.e. '') you can just use `0' instead. No need to use shift that way.
G: You can also just do G to go to line .
Arrows: Do people actually use those? Interesting... I knew they worked but I've never used them. Started out with h j l k and never looked back. Maybe it wasn't even possible in vi but I've always felt it far more natural to use the same area as if you were typing than to have to move your hand away. As for the h j l k you can also specify a count (never tried with the arrow keys for the above reasons) e.g. 5j goes down five lines.
I: Actually I often enough do insert to the beginning of the line but I tend to use 0i instead. It's just as quick if not faster and it keeps in the theme of go here and do this.
Marks: just like in the pager less (and maybe more - I've not used that in decades now...)
N: But if you're searching backwards (
?
) it is the reverse: N goes forward, n goes back.Opening a line without insert: If there is I'm unaware of it but I can say that's not what the
O
/`o' commands are designed to do - it's as you say to go into insert mode.:qw: Another way is just ':x'
s: But surely you have however used :s? I rely on it very often. The fact it supports regular expressions (so too does searching for that matter) makes it immensely valuable.
:ZZ: Just like :x (I didn't know :ZZ)
Another you didn't mention (well - not as examples):
de
or5de
(etc.)Maybe it's just a typo, but since
:
denotes VIM command mode, the "save and quit" shortcut isZZ
in normal mode and not:ZZ
. By the way, there's another normal mode combinationZQ
which acts like:q!
or "force quit without saving".Thank you!
I'm honored to read such a comment from such an experienced use.
Re arrows: you'd be surprised.. people use custom settings to disable their kb arrows just for that.
Re "I" personally I use it when it comes up, and I always prefer least keystrokes, that's me..
Re Marks: I use it quite often, honestly, it's always
ma
andmb
, rarely something elseRe: Correct! Will fix
Re s: nope, but that's why I do these posts, to learn or to be taught by the community ;)
With your permission, I'd like to add your corrections with the appropriate credit
Finally,
z
doesn't take care only of folding, but also of the line position in the buffer by scrolling:zz
places the line in the middle of the bufferzt
to thet
opzb
to theb
ottomThanks again for the article! Keep on spreading the world about #vim! 🤓
Important clarification and additions, with your permission I'd like to add your comment with a credit :)
Then, you can also add
H
for moving cursor, without scrolling the page, to theH
ead,T
to theT
ail andM
(I am not sure by hearth, check this last out) to theM
iddle. 😉My pleasure.
Hey there, thanks for your article. A good refresher!
By the way, I may be wrong but I think that you can open a new line above by just pressing
O
instead ofo
. But maybe I didn't quite catch what you wanted to do.They mean without going into insert mode. What is being said is both
O' and
o` take you into insert mode and often a new line without insert mode would be useful.Probably it isn't that way because by adding a line you're technically inserting into the file itself.
Nice article.
Continuing with z,
zf
will create a fold on what is selected.za
will toggle folds. I use those all the time.Also,
zl
will scroll right (good for long lines).and
zh
goes left.You can also scroll more than 1 character at a time like so:
z20l
.Happy Viming.
Thanks for the additions! Some stuff, like folds (which I also use from time to time) I left out to try and focus on things that matter and make phonetic logic. I linked to my Vim notebook on Github where it goes further to explain.
Great list! One correction: B and E move by word blocks (like W) and not to the beginning or end of the line.
Can't wait to see more of your Vim-related content. Learning Vim has been one of the funnest sagas in my development journey.
Thanks!
You are 100% correct, I think most / some Vim "flavors" (non-vanilla Vim configurations people start with) are already preconfigured with
B
/E
actually targetting the end / beginning of the line. I'll double-check myself and fix, but as far as the docs go you are totally right!Regarding the next posts: I have one waiting to be completed discussing macros. It would be much shorter though :)
If you've got any ideas / things you'd like me to cover let me know! I'm getting to learn so much myself doing these it's incredible
J: Join line below cursor to current line.
I find myself using this often when refactoring code.
You're right! Using it myself quite often. Adding to the list.
Cheers
This is awesome! Thanks 😁
You're welcome! :)
Hi. Very good list but you have a mistake:
dg
- "delete from here up" must bedgg
.Thanks man!
Fixed
F for search is one I never use but will start to use thanks to this post
"the [j] key on a keyboard happens to be quite far considering its extensive use"
It's literally the right hand pointer finger...