DEV Community

A month of using Vim

Erica Pisani on September 16, 2024

I've wanted to dedicate time to learning Vim for probably a decade now. When I was just getting started as a junior developer, I remember thinkin...
Collapse
 
jimmymcbride profile image
Jimmy McBride

I love it when I see setups where people put everything together from the ground up. LazyVim is just an alternative to I think it's Packer that Prime uses. Did you mean NVChad? I've done the whole ground up thing, but NVChad is just too good!

Dreams of Code on YouTube has a bunch of amazing NVChad tutorials, If you haven't seen them, I'd highly recommend them :)

Keep on trucking and learning! I love seeing people who are willing to put in a little extra work for something they think is cool!

Collapse
 
ericapisani profile image
Erica Pisani

I haven't heard of NVChat but thanks for sending those tutorials! I'll have to check them out one of these days.

Collapse
 
moopet profile image
Ben Sinclair

LazyVim is a "distro" like NVChad, "Lazy.nvim" is a plugin manager used by LazyVim comparable to Packer. It's a confusing choice of name, but they do pretty much the same thing.

Collapse
 
jimmymcbride profile image
Jimmy McBride

Oh wow. Everything makes sense now πŸ˜‚

Collapse
 
jesii profile image
Jon Seidel • Edited

:h window{Ctrl-D} - this took me forever to find, but it was a game-changer for me. Without Ctrl-D, you just get the basic vim introduction and the definition of a window. When you type Ctrl-D rather than just Enter, you get a list of references to all help entries that include the word β€˜window’. Now you see that there are help entries for β€˜window-moving’, β€˜window-resize’ and a host of other options. I used to think :h was not much help until I started using this.

Collapse
 
gabeguz profile image
Gabriel Guzman

Great to see new people picking up vim!

Collapse
 
viv_collins_06769444a1acd profile image
Viv Collins

Great article and thank you for posting.

When you said:

the need for plugins for most of the things e.g.: editing multiple instances of a word in a file at the same time

You are absolutely correct. However, and If I understand you correctly, you do not need to use any plugins in this particular scenario. You could do:
%s/foo/bar/g
To search and replace all instances of foo with bar in a file.

To see more checkout this page

Have a nice day!

Collapse
 
ericapisani profile image
Erica Pisani

You did understand me correctly and I had no idea that I could do that without a plugin! Thank you for sharing that!

Collapse
 
scott_wade_2112 profile image
Scott Wade • Edited

Oh wow, welcome to Vim! If you are just getting to %s, many wonders await you ahead. Here's something might be of use on that journey. I forgot to note the source for some of these below... as always, <C-g> means hold down the CTRL key while then pressing 'g'... start the first session of your day with a... :smile - optional.)

Now the useful. Open Vim and press <C-o-o>. It will take you directly to your last opened file and last location of the cursor. Yes!

Having a shortcut to switch between the last edited buffer and your current one would be very handy. Vim actually has the shortcut for this: <C-^>. However, it feels much better if you map this command to Backspace YMMV, for example:
nnoremap <bs> <C-^>

q: # list of vim command history
q/ # window of search history edit/run goto previous searches
gi # put into INSERT mode with cursor at end of last insert you did
gf # open file whose name is under curor or after
ga # show ASCII value of character under the cursor in decimal, hex, octal
g<C-g> # show file specs info current file, num of words, how many bytes

. # current line
$ # last line
% # all lines - same as :[1,$].

:[range]g/pattern/command # [range] is optional, by default it's the whole file, for the command.
pattern # pattern looking to match
command # Ex command to be executed for each line matching the pattern

:g/error/d # delete all lines matching pattern
:g!/important/d # delete all lines NOT matching pattern
:3,9t20 # copy lines 3 - 9 after line 20, regardless where cursor is
:3,9t$ # copy 3 - 9 to the end
:3,9m20 # move lines 3 - 9 to line 20

Collapse
 
anitagraham profile image
Anita Graham

Has there ever been a screen-based editor where you could not do that directly?

I've been editing code for over 40 years and I don't remember one that didn't have some sort of find/replace-all functionality.

How old is teco now? Wikipedia says it was developed in 1962, so would be 62 years old. It was available on a screen in 1964. Teco was line based, iirc, and was a mature tool when I first met it, perhaps around 1979-80.

It had a flexible find/replace which did more than you would imagine. EMACS was originally written in teco macros.

History: This has been your history lesson for today
Moral: Explore the editor before you start adding plugin-ins

Collapse
 
brianmasinick profile image
Brian Masinick

I was also wondering about the use of plugins. Sure, you can use them if you wish, but here are a few things that can get you around rapidly!
First press Esc to make sure you are in command mode rather than input mode.
1G - navigate to the top of the file or buffer, regardless of where you are.
Similarly
G - navigate to the bottom of the file or buffer, regardless of where you are.
19G - navigate to line 19; change the number and you can navigate anywhere.
Similarly, w moves forward a word, 5w moves forward 5 words and so on.
h moves left one character; 8h moves left 8 characters.
l moves right one character; *l moves right * characters.
j moves down one line; *j moves down * lines.
k moves up one line; *k moves up * lines.
w moves forward to the beginning of the next word; *w moves forward * words to the beginning of the *th next word.
b moves backward to the previous word boundary; e moves forward to the end of the next word boundary.

:w writes out the buffer.
:q quits the buffer
Wx saves and exits.

To input text, there are multiple input commands; the basic one is i, input mode. Using a instead of i puts you in input mode after the current location; think of it like "append" instead of input.

Thread Thread
 
brianmasinick profile image
Brian Masinick

thegeekdiary.com/basic-vi-commands... is a quick vi cheat sheet.
cheatography.com/dcschmid/cheat-sh... is a similar cheat sheet for nvim - Neovim.

Thread Thread
 
brianmasinick profile image
Brian Masinick
Thread Thread
 
jesii profile image
Jon Seidel

gg β€” for top of file is my preferred approach. Quicker than going for the number key.

Collapse
 
scott_wade_2112 profile image
Scott Wade

Great page. 😎

Collapse
 
moopet profile image
Ben Sinclair

I remember thinking that the people who used it in their day-to-day were "so cool"

Damn right we are. Welcome to Coolsville.

Collapse
 
wiktorwandachowicz profile image
Wiktor Wandachowicz

Vim Visual Cheat Sheet - hamwaves.com/vim.tutorial/

  • includes graphical cheat sheet tutorial, a PDF with step by step "lessons"
  • Vim game / VIM Adventures - vim-adventures.com/
Collapse
 
pengeszikra profile image
Peter Vivo • Edited

Try vim on adroid phone , in temux. i can surprise how easy to write at least document with screen keyboard. temux are give secret to proper use of vim.The vim h-j-k-l is great because on that key don't have arrowkeys.
My favorit is: u.

Collapse
 
raguay profile image
Richard Guay

Welcome to all you that are just starting in vim/neovim. Here is the best book to help get you started (I've read many of them): wizardsusevim.com/

It is a great resource for new vimers and long time users.

Collapse
 
boby_tiwari_fd03ffa35b156 profile image
Boby Tiwari

Great, I am using kickstart.nvim for neovim

Collapse
 
abhishek_writes profile image
Abhishek Kumar

I am also exploring VIM these days .

Collapse
 
benborla profile image
Ben Borla

Enjoy your journey, and savor the process. You'll love it. :-)

Best of luck!

Collapse
 
crenshinibon profile image
Dirk Porsche

Welcome to the journey, I might have started exactly at the same time ...

Collapse
 
clochs profile image
Sam Ryan

I’m just starting my coding journey and I found out about Vim through Primeagen. Right now I’m just using Vim motions in VS Code but so far I love it! I can’t wait to make the full switch to NeoVim.