Learn Vim
@learnvim
Vim tips + tricks Want to support this page AND learn Vim? Check out http://leanpub.com/gourmetvim OR http://leanpub.com/learnvim Owned by @iggredible
You might like
If you want to learn more Vim, check out my Learn-Vim guide on Github! (Did I tell you it's free? 😁) github.com/iggredible/Lea… #vim
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
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
The vim-yoink plugin lets you to yank multiple times and quickly choose which yanked text to paste (with Ctrl-n/Ctrl-p). If you use copy/paste often, check it out! github.com/svermeulen/vim… #vim
If you want to resize, swap, and move windows, the winresizer plugin (github.com/simeji/winresi…) can quickly resize your vim window with its resize mode. Check it out! #vim
If you have one large window and one small window, you can make them equal size with Ctrl-w + = :h CTRL-W_= #vim
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
To roll a dice 5 times: :for i in range(1,5) | put='Dice roll: ' . (rand() % 6 + 1) | endfor #vim
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
= 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/5060… :h = #vim
Press Ctrl-W o`` to zoom the current window and close other open windows (You can also run `:on`) #vim
If you want to close the current window, you can press Ctrl-w + c More: :h CTRL-W_c #vim
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-fugi… #vim
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
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
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
Last time we looked at :vimgrep to search for keywords. :vimgrep /Waffles/ app/**/*.rb To add more results into your last search, you can use :vimgrepa. To also search for Pancakes: :vimgrepa /Pancakes/ app/**/*.rb Now you have a list of Waffles AND Pancakes. #vim
Vim has an internal grep to search for texts in files, :vimgrep. If I want to search "Waffles" inside ruby files inside app/ directory: :vimgrep /Waffles/ app/**/*.rb To display the quickfix list result: :copen Try it! #vim
When you pass multiple file names when you run Vim from the terminal (vim bar.rb foobar.lua), Vim stores those files inside the argument lists, which you can access with :args You can navigate through the argument lists with :next, :prev, :first, :last. :h arglist #vim
If you want to undo your changes across multiple windows, you can run :windo undo To redo your changes, you can run: :windo redo #vim
United States Trends
- 1. #SNME 41.3K posts
- 2. Georgia 48.9K posts
- 3. Mason Thomas N/A
- 4. Drew 121K posts
- 5. Lagway 3,905 posts
- 6. Game 7 149K posts
- 7. Jade Cargill 16.6K posts
- 8. Underwood 2,918 posts
- 9. #UFCVegas110 9,403 posts
- 10. Rusev 3,061 posts
- 11. Jaire 9,889 posts
- 12. #AEWCollision 3,221 posts
- 13. Nigeria 598K posts
- 14. Tiffany 23.5K posts
- 15. Forever Young 39.5K posts
- 16. Salter 1,024 posts
- 17. Dawgs 7,852 posts
- 18. Gators 6,369 posts
- 19. Gunner Stockton 1,212 posts
- 20. Florida 77.8K posts
You might like
-
Neovim, world leader in plugin deliveries
@Neovim -
Rakesh Jain
@devops_tech -
ThePrimeagen
@ThePrimeagen -
Linux Handbook
@LinuxHandbook -
teej dv 🔭
@teej_dv -
It's FOSS
@itsfoss2 -
Canonical
@Canonical -
bashbunni
@sudobunni -
unixporn
@bot_unixporn -
Takuya 🐾 devaslife
@inkdrop_app -
VimR — Neovim GUI for macOS
@VimRefined -
Dr. Julie Gurner
@drgurner -
Copinha
@Copinha -
MicroJoan
@joan_micro -
Enzmann Archive
@EnzmannArchiv
Something went wrong.
Something went wrong.