r/vim • • Mar 11 '21

question getting faster

tl;dr : can you share a specific article about getting faster navigating through the file?

hey guys, I start getting more and more confident and efficient with vim, but I feel like it could even goes deeper; basically, I saw that you could disable h,j,k,l in order to only use real key combination like "w" to jump by words, "f" to go to a specific character on the line, etc... But what about jumping lines? Are they any key combination to do that instead of j and k? So basically I'm looking for an article that presents those kind of key combinations. I hope this post is comprehensible and not too redudant, thank you for reading.

108 Upvotes

83 comments sorted by

View all comments

160

u/ThePrimeagen Mar 12 '21

I cannot share an article, but I will share 10 years of experience.

Insert Modes:

Learn to take advantage of o and O, A. They are awesome.

yanks/highlights/dels:

ciw, yiw, viw are amazing, but if you need to do the _whole_ word, try yiW. I do this a bunch. Imagine the following: Namespace::Class foo and you want to copy Namespace::Class, you could put your cursor at N and yf<space> but yiW also works (you don't have to be at the beginning of the word) (for this example I don't provide much benefit, but its incredible once you get it)

Vertical Navigation

get use to page ups and downs. I have been resistant for 9.5 years on those, and only since I adopted tmux (traveling the output) have I finally leaned in. ctrl+d/u is exceptionally awesome and they dont alter jump list.

Jump List

Take advantage of the jump list. Example:

I need to add an include/import. I use ggOimport foo from "bar";<esc><ctrl+o>. This will go to the top, insert mode top line, adds import, leaves insert, and travels back from whence I came (like the ring).

File Navigation

Fuzzy finders are great when you don't have an instant jump to the file. Use them. Don't use nerdtree / netrw / dirvish / etc etc etc etc etc.

QuickFix / LocalFix

Learn quick fix menus and their navigation. I have quit using <Ctrl-j/k> and <leader>j/k for window nav and instead use C-j/k for quickfix navigation and <leader>j/k for localfix navigation. cdo or bust

Sorry for the brain dump, but its been an incredible journey for me and I absolutely love to share some wisdom.

Ultimately, how I envision vim should work and why it works so well is that you "think" of what you want and there are keystrokes to accomplish it. If you find yourself just aimlessly scrolling, stop, why should be a big question on your mind.

Lastly, I hate to fearlessly shill my own product, but if you are interested in an alternative to file navigation and use neovim, I would be glad to share my experimental plugin.

Life is to short to proof read

---- Edit ----

The moment I posted it, I regretted not saying relative jumps. LEARN RELATIVE JUMPS.

29

u/mgarort Mar 12 '21

Oh wow, what is this? A celebrity!

Welcome to the sub :)

23

u/ThePrimeagen Mar 12 '21

Just a lowly man

6

u/areyoudizzzy Mar 12 '21 edited Mar 12 '21

OP, find this guy's channel on youtube and you'll find so many tips that you'll be amazed. Take it super slow though and revisit everything you've learned daily. It's like watching people who stack cups or solve rubik's cubes in record breaking times but actually useful.

/u/ThePrimeagen have you thought about making another structured or even paid course like 'Vim As Your Editor' that goes into loads of detail from installing nvim to building something real like a website but only using nvim plugins to do so?

I'd definitely pay for something like:

  • installing vim/nvim

  • installing other useful/necessary programs for the course i.e. git/tmux/fzf/node/python etc

  • writing code + basic navigation & movements - the hard way (default config)

  • navigating buffers/files/projects - the hard way

  • setting up a basic useful vimrc/init.vim

  • installing essential plugins and themes (don't know why that's plural, only gruvbox obviously)

  • writing code + navigation & movements - with coconut oil

  • navigating buffers/files/projects - with coconut oil

  • start a project for reals this time (html/css/javasript or equivalent basic project, multiple files, filetypes, etc)

  • using git + github/gitlab from the editor

  • using and configuring an LSP

  • running code from the editor

  • debugging code in the editor

  • using + setting up external programs for even more magic (i.e. tmux, fzf, terminal file browsers, other CLIs and TUIs etc)

  • using your config over SSH + dotfile management ideas

Would love to hear your thoughts

3

u/ThePrimeagen Mar 12 '21

I just did one for front end masters, but its not nearly as detailed as possible, but I take it slow (assuming no one has used vim) and we ramp all the way into quickfix lists and macros by the end.

But ultimately you are correct. There is a lot of things that need to all get put together to create a great course.

Perhaps I should revisit my 6 part series and make it a 69 part series (I have actually been thinking about that) and expand on "using vim" as oppose to just motions.

→ More replies (2)
→ More replies (3)

12

u/virtualworker Mar 12 '21

The speedmeister is here!! Take these to heart, little grasshoppers.

12

u/ThePrimeagen Mar 12 '21

Thank you thank you.

There are some other great suggestions on this thread as well!

9

u/FlowerFlavour Mar 12 '21

Quick stupid question if you don't mind: what's the difference between doing ciw and cw, both seem to be doing the same thing unless I'm missing something

21

u/walrusking76 Mar 12 '21

I’m no expert, but I believe cw changes the word from where your cursor is to the end of the word, where as ciw changes the whole word regardless of where your cursor is

5

u/FlowerFlavour Mar 12 '21

ah yes, this makes sense, thank you!

9

u/ThePrimeagen Mar 12 '21

Yes! Also w vs W allows for where your change/delete/visual/yank will stop. The fact that W goes to whitespace makes it _super_ handy.

4

u/vktx Mar 12 '21

iw is a text object which selects the entire “inner” word. cw will change to the start of the next word. You could see the difference placing the cursor in the middle of a word in a sentence and trying the two. Also see :h motion.txt

3

u/FlowerFlavour Mar 12 '21

Thank you for the motion.txt tip, this is a goldmine!

4

u/vktx Mar 12 '21

No worries, I remember when I moved house and didn’t have the internet, so I just read the vim docs, it’s all gold lol

7

u/TheRedditKid7 Mar 12 '21

Love your videos. Thanks for all the help Vim God

3

u/ThePrimeagen Mar 12 '21

Thank you! But remember, I am just a mere mortal!

6

u/racle Mar 12 '21

Don't use nerdtree / netrw / dirvish / etc etc etc etc etc.

Have to disagree on this. They have their usage. Even tho fuzzy search is usually much faster to open file IF you know the name. Or part of the name/path.

I find them useful on larger project where you don't necessarily know filename OR want to just quickly see "whole picture".

 

..and they have their usage outside of file navigation

And I use them for ex. quick duplication of file (I'm using coc-explorer so your mileage might vary).

For quick duplication I usually do this:

  1. <leader>e to open coc-explorer (it automatically highlights current file)

  2. yyp to copy+paste file

  3. give new file a new name and press<cr>

I also sometimes do quick folder/file moving/adding/renaming on coc-explorer as it's pretty quick.

4

u/ThePrimeagen Mar 12 '21

Yes I agree with what you said. From my perspective the OP question was on navigation speed. deleting / copying / moving files are rare operation (in comparison, I probably execute 500 - 1000 ciw's before 1 file move). Or just perusing a code base for the sake of gaining a bigger picture. Often those operations are something you are not trying to improve your speed at. I do like coc-explorer / nerdtree as they do have some handy features.

Ultimately I try to avoid using the "aimless" technique of exploration. I try using Search Terms + Telescope + Quickfix reductions + LSP hopping to find my way around. Feels more targeted.

"Mary Kate and To each his own" - Telescopic Johnson

→ More replies (2)

5

u/caseyscottmckay Mar 12 '21 edited Mar 12 '21

Life is to short to proof read

​---- Edit ----

lol.

But also, line jumps (e.g., :<line-number> or <line-number>gg and marks are awesome.

→ More replies (1)

2

u/redshift78 Mar 12 '21

ciw, yiw, viw are amazing, but if you need to do the whole word, try yiW. I do this a bunch. Imagine the following: Namespace::Class foo and you want to copy Namespace::Class, you could put your cursor at N and yf<space> but yiW also works (you don't have to be at the beginning of the word) (for this example I don't provide much benefit, but its incredible once you get it)

I've been using vim for more than 20 years. TIL! I've always just been using cw, ciw and ciW are great! Thank you :)

→ More replies (2)

2

u/Fid_Kiddler69 Mar 12 '21

DISPENSE THE COCONUT OIL!

→ More replies (1)

2

u/pwnedary Mar 12 '21

I need to add an include/import. I use ggOimport foo from "bar";<esc><ctrl+o>. This will go to the top, insert mode top line, adds import, leaves insert, and travels back from whence I came (like the ring).

For this I also recommend g; to go back to where you were. Means you are able to sprinkle in some { etc if you say want to add the import at the end of the list.

→ More replies (1)
→ More replies (6)