Phillip England
where are the casual vim users?
12/13/2024
The following article touches on these technical skills:
As I was drafting out this post, I was preparing a thumbnail for it (ai). During
which I noticed the image for my home page on this website was 1mb in size. Way
to large for a simple blog thumbnail. So, I resized it using
Image Resizer and I got to thinking, "I bet a
command line utility for this exists."
I got this image size down from 1mb to 7kb. The images in the thumbnails on this
site are 150x150px and I have no intention of scaling them over time.
NOTE TO SELF: Find a command line utility to resize images on the fly.
I know the basics. I am not an expert on the key maps or anything but I have a
general idea of how it works. I know you can do all your config in lua. I don't
really know lua, but I know it is loosely typed so we are good.
I gave nvim a good go around a year or so ago, but I think it might be time for
another stab. The main reason is I just want to run something more lightweight
on my desktop. Sometimes she can't keep up 😅.
That, and honestly, the amount of die-hard vim users is curious to me. Am I
missing something? Plus, I get a chance to look a little bit closer at a
well-known software. Here we go.
I found installing a bit of a pain as version as version 0.7.2 was installed
by default on WSL when running:
1sudo apt-get install neovim
Let's uninstall, update, and reinstall:
1sudo apt-get remove neovim
2sudo apt-get update
3sudo apt-get upgrade
4sudo apt-get install neovim
Still getting 0.7.2..
Found this
post
on reddit and tried this:
1sudo apt-get install software-properties-common
2sudo add-apt-repository ppa:neovim-ppa/stable
3sudo apt-get update
4sudo apt-get install neovim
5nvim -v
Still getting 0.7.2..
I can build from source on the
nvim release page.
I ended up doing:
1wget https://github.com/neovim/neovim/releases/download/v0.10.2/nvim-linux64.tar.gz
2tar -xvzf nvim-linux64.tar.gz
3mv nvim-linux64 nvim
I am not 100% sure where this needs to go on my system. I know neovim is
config-heavy so I want to be sure I set this up right.
...
Okay I see /usr/bin and ~/.config/nvim
might be options?
/usr/bin makes the most sense lets try it:
1mv nvim /usr/bin
2nvim
Now, nvim was an installation directory, so it has the actual binary within. I
had issues getting it to work unless I kept the nvim directory within
/usr/bin.
/usr/bin normally has all of your system binaries, so having a directory in
there feels a little off.
I ended up having to change /usr/bin/nvim to /usr/bin/nvim-dir and adding
/usr/bin/nvim-dir/bin to my PATH as a solution.
Now we are on version 0.10.2 😀
We gotta get some plugins installed. A little research and I found that package
manager lazy.nvim.
I went ahead and followed the docs to setup some basic configuration I stashed
in this repo.
That repo might change as I find my favorite custom config.
At this point in the post, I swapped from vscode to neovim.
I think the plugin I am most concerned about getting up and running is my LSP
support. I am going to do some research and see what I can find.
I found this page in the neovim docs. It
looks like language servers are installed using a package manager.
I checked out
this page where I
see we can go through the process of install language severs one-by-one, but I
think a better way might be out there.
I found this repo which is
maintained and looks promising. We still manage installing servers, but this
makes it easy to get them working in our projects.
I already have gopls installed, so I'll just try to get it working with that.
Adding this line to ~/.config/nvim/init.lua:
1require'lspconfig'.gopls.setup{}
After digging around with LSP details and a few other plugins, I decided it
would be best to use a drop in configuration with good defaults. I decided to go
with NvChad which has super easy
installation instructions.
It has good defaults and I think it'll work for the time being.
I got it up and running and it is doing fine. I have not had any issues so far
and was able to change over my theme.
I am going to spend a little bit of time learning how to getting around in
neovim. I am already confident in things like insert mode. For selecting, I am
just using the mouse. But I know select mode is a thing. Just going to dive in
and look for the most useful things to know.
Here is an entry from Claude:
I'll share the most crucial Vim navigation skills that will dramatically improve
your text editing efficiency:
Basic Movement Keys:
h, j, k, l are your fundamental movement keys
h: Move leftj: Move downk: Move upl: Move rightWord-Based Movement:
w: Move forward to the start of the next wordb: Move backward to the start of the previous worde: Move to the end of the current wordW, B, E: Similar to w, b, e, but move by WORD (ignore punctuation)Line Movement:
0: Jump to the start of the line$: Jump to the end of the line^: Jump to the first non-blank character of the lineScreen Movement:
Ctrl + f: Page downCtrl + b: Page upH: Move to the top of the screenM: Move to the middle of the screenL: Move to the bottom of the screenAdvanced Movement:
gg: Go to the first line of the documentG: Go to the last line of the document{number}G: Go to a specific line numberSearch Movement:
/{pattern}: Search forward for a pattern?{pattern}: Search backward for a patternn: Repeat the last search forwardN: Repeat the last search backwardQuick Jumps:
(: Move to the start of the previous sentence): Move to the start of the next sentence{: Move to the previous paragraph}: Move to the next paragraphPro Tips:
5j moves 5 linesd (delete) or c (change) forBonus Tip: Use vimtutor in your terminal for an interactive tutorial that will
help you master these skills quickly!
Would you like me to elaborate on any of these navigation techniques?
Then, I questioned Calude about how to easily find and
replace text within a document using nvim. Here is the response:
I'll cover find and replace in Vim, which is extremely powerful:
Basic Find and Replace:
s/old/new: Replace first occurrences/old/new/g: Replace all occurrences on current line:%s/old/new: Replace first occurrence in entire file:%s/old/new/g: Replace ALL occurrences in entire file:%s/old/new/gc: Replace with confirmation prompt before each replacementAdvanced Options:
:%s/old/new/gi: Case-insensitive replacement
:%s/old/new/gI: Case-sensitive replacement
`:%s/<old## Points of learning The following article touches on these
technical skills:
installing binaries and moving them around on your system
learn the basics of vim motions
gain exposure to find and replace methods in nvim
install a precustomized nvim version, NvChad>/new/g`:
Whole word replacement (matches 'old' exactly)
Regex Power:
:%s/\v(pattern1)(pattern2)/\2\1/g: Swap patterns:%s/\v(\d+)/number: \1/g: Add prefix to numbersSpecial Characters:
\n: Newline in replacement\r: Carriage return\t: TabScoped Replacements:
:10,20s/old/new/g: Replace between lines 10-20:'<,'>s/old/new/g: Replace in visual selectionPro Tips:
/g to replace all occurrencesgc when making significant changesWant me to elaborate on any of these techniques?
I think reading
this post
on StackExchange really helped me to 'get the point' a little bit more. I was
trying to taking this post and run it through AI for a spellcheck when I
realized I didn't know how to do that in nvim.
So, in that post we see ggVG is the combination of commands to select all the
text in a file. It doesn't feel intuitive, but man does it feel cool 😎.
I think my favorite commands are / and ? for searching forwards and
backwards in a file. Instead of using my keyboard to move my cursor around the
file, I notice it is way quicker to spot where you want to go, and then to
search jump there using / or ? depending if you are moving forwards or
backwards in the file based on your current cursor position.
I think this is where nvim shines. It's ability to allow you to quickly jump
around a file without having to use the mouse is really the point.
For example, let's say I want to grab this current block of text. Mind you, this
is off the dome, I did not reaseach this bit I am just rolling here.
Okay, that block right there ^, lets copy it real quick. I'm thinking we do
?For example to jump back in the file to the start of the block. Then we enter
visual mode using v. Then we can run /here. to jump to the end of the line.
Now that I say that out loud I know you can also run $ to go to the end of the
line. Then you can yank the line using y.
So, you have the ability to on the fly combine commands to avoid using the mouse
and that is an example of how we can do it. I think that is the point of nvim.
I do think getting around the document can be more effcient with nvim. I think
it really boils down to taking the time to learn the mappings and then just
forcing yourself to use the editor for a period of time. I think that is
probably what I will commit to to give it a fair shake.
Setting things up can be time-consuming, but it is a good process if you are
wanting to learn more about computers in general. For me, I don't think taking
the time to get the most pristine customization is really where my time is best
suited, so I opted in for a precustomized-install.
I did learn more about LSP's and it did make me interested in what it would look
like to design my own LSP.
I was recently working on GTML and it
has been the closest thing to make getting into compilers and interpreters. My
lack of understanding of LSP's did limit my creative potential in that project.
NOTE TO SELF: Did you learn how LSPs work?
All my notes I take on this topic will go here.
I found it was annoying when I was using telescope to open up new files in vim
because tons of them would collect. You can run :bd to drop the current
buffer. This is useful.
I noticed it you could not indent blocks of text by using tab. So, I did a
little research and learned you can use SELECT mode to highlight a block of
text and then use < or > to shift things.
I always find myself doing CRTL+BACKSPACE to delete words in vscode. I learned
you can run Bciw to change the inner word which is a vim command which more or
less does the same thing.
I found it was a little bit difficult to get rust-analyzer working with
NvChad as it did not come preinstalled. However, I was able to get it up and
running and here is the
page
where I found my solution.
I discovered I could not use CTRL+/ to comment out a highlighted section of
text. NvChad comes with the ability to use gc to comment out blocks of text
instead.
Bruh, A brings you to the end of the line in insert mode. I've been doing $i
my gosh.