←
Learn Vim1,440 posts
Learn Vim avatar

Learn Vim

@learnvim

Vim tips + tricks Want to support this page AND learn Vim? Check out leanpub.com/gourmetvim OR leanpub.com/learnvim Owned by @iggredible

◷ Joined November 2019▧ 362 Photos and videos
DHH avatar
⟳ Learn Vim retweeted
DHH@dhh·27 Feb 2024

As much as I love TextMate, I've come to realize the folly of being tied to one commercial OS on the basis of an editor. I considered going all-in on VSCode, but if I'm going to switch editor after 20 years, I'd like it to be my last change. Vim will be here and free in 100 years

Learn Vim avatar
Learn Vim@learnvim·13 Jan 2024

If you have the jq command github.com/jqlang/jq installed, you can use it to format JSON in Vim! On the line where you have a large JSON object: { "foo": { "bar": { "foo_id": null, "bar_id": 98765, "baz_id": 12345 } } } Run: :.!jq . Vim bang operator/cmd: :h ! #vim

Post attachment
Learn Vim avatar
Learn Vim@learnvim·15 Dec 2023

If you have one large window and one small window, you can make them equal size with Ctrl-w + = :h CTRL-W_= #vim

Post attachment
Learn Vim avatar
Learn Vim@learnvim·13 Dec 2023

You can "swap" windows with Ctrl-w + r (technically it's down/right-ward rotation, but works like a swap with only 2 windows) :h CTRL-W_r #vim

Post attachmentPost attachment
Learn Vim avatar
Learn Vim@learnvim·6 Dec 2023

There are 5 different history commands in Vim: :his c or : - command-line history (q:) :his s or / or ? - search history (q/ or q?) :his e or = - expression history :his i or @ - input history :his d or > - debug history #vim

Learn Vim avatar
Learn Vim@learnvim·4 Dec 2023

= is the filter operator (by default it indents). If you want to indent the entire buffer, run: gg=G - gg goes to the top - =G indent operator + all the way to the bottom Use `` to go back to the original location. Try: gg=G`` More: stackoverflow.com/questions/… :h = #vim

Learn Vim avatar
Learn Vim@learnvim·3 Dec 2023

Press Ctrl-W o`` to zoom the current window and close other open windows (You can also run `:on`) #vim

Learn Vim avatar
Learn Vim@learnvim·16 Oct 2023

If you use fugitive.vim, you can use git grep to use a keyword in a specific branch / SHA :Ggrep MY_FOO some-branch :Ggrep MY_FOO some-sha Useful if you want to see if / how a text looks like in a different branch :h :Ggrep github.com/tpope/vim-fugitiv… #vim

Learn Vim avatar
Learn Vim@learnvim·14 Oct 2023

To reverse two words, you can use this substitution: :s/\(\w\+\) \(\w\+\)/\2 \1/g This will reverse "strawberry chocolate" into "chocolate strawberry" If you think there's too many backslash, you can use \v: :s/\v(\w+) (\w+)/\2 \1/g #vim

Learn Vim avatar
Learn Vim@learnvim·12 Oct 2023

To generate 100 lines of "100 bottles of milk", you can run: :for i in range(100, 0, -1) | put = i . ' bottles of milk 🥛' | endfor #vim

Post attachment
Learn Vim avatar
Learn Vim@learnvim·9 Oct 2023

Let's say you have: apples oranges apples bananas To search for apples FOLLOWED BY bananas (and not apples followed by oranges), you can use a multi-line search /apples\_.bananas :h \_x #vim