And today's #Vim #Neovim command "de jour" is
z=
to spell check the word under the cursor (because I write a lot of text)
Today's #Vim #NeoVim tip is a feature rather than a single command.
Use marks
=========
https://vim.fandom.com/wiki/Using_marks
Amongst other things, they help you jump around a file and move arbitrary lines of text with ease. e.g.
1. find 1st line of interest and create a mark with "ma"
2. Locate end of text block
3. Delete the text block with ":`a,.d"
4. Goto new location and hit "p"
A mark allows you to record your current position so you can return to it later. There is no visible indication of where marks are set. Each file has a set of marks identified by lowercase letters (a-z). In addition there is a global set of marks identified by uppercase letters (A-Z) that identify a position within a particular file. For example, you may be editing ten files. Each file could have mark a, but only one file can have mark A. Because of their limitations, uppercase marks may at firs
Saves messing about when you open a file you don't have permission to modify.
:w !sudo tee % > /dev/null
writes the file using sudo.
See https://stackoverflow.com/a/7078429/120371. Has Vim key map ('cause it's a PITA 2 look up the details every six months)
Want the same thing in neovim using lua?
1. Install ssh-askpass
2. Update your Neovim config
vim.env.SUDO_ASKPASS='/opt/homebrew/bin/ssh-askpass'
vim.keymap.set('c', 'w!!', ':w ! sudo -A tee /dev/null %')
YMMV
Today's #Neovim tip is something I learned last night from the comments section in a YouTube Short! (h/t to Fabio Ortega)
Add this Lua fragment to your config and by default Neovim will use the system clipboard.
vim.opt.clipboard='unnamed,unnamedplus'
The Video also contains some handy hints on how to use
viw
to yank the current word
not sure if that is better that
byw ...
Today's #Neovim tip is for people who want to give the editor a real try -- maybe because they used Vim in a past life.
They might even have tried some of the Neovim distributions, but been frustrated because there was too much "magic".
Instead you want to actually *learn* how to set up Neovim.
I found this YouTube playlist helpful.
https://youtube.com/playlist?list=PLsz00TDipIffreIaUNk64KxTIkQaGguqn
A git repo with example files is also provided, which I found a great way to start my own config.
Today's #Neovim tip is mainly for people writing blocks of text.
You can reformat unitidy paragraphs with the
gwap
command. I find it makes it slightly easier to read the content.
N.B.: If using markup, e.g. Markdown, the line breaks might not always be in right place.
#Vim #Neovim has many formatting commands and options, so RTFM is recommended
Today's #Neovim (and #Vim) tips are simple, but handy if you don't know.
How to insert text at the start of the buffer, or append text to the end.
1. Insert text at the head of the buffer.
1GO
And start typing. Explainer
1G -- move to 1st line
O -- open line above (uppercase o)
2. Append to the end of a buffer
Go
and start typing
G -- move to end (default for G)
o -- open line below
Today's #Neovim stroke #Vim tip is for me!
I learned Vi back in the day and never bothered tro grok Visual mode in Vim.
This is probably a mistake, especially when you demonstrate code in your editor. Visual highlighting can make it more obvious what you are doing.
Here is a place to start if you are new to Visual mode.
https://opensource.com/article/19/2/getting-started-vim-visual-mode
I'm sure all the #Neovim hipsters will think me rather silly for still editing like it's 1985
Today's #Neovim / #Vim tip of the day is a bit wacky!
Learn Sed. (the stream editor).
========
Use Sed when you need to edit file inside a script.
Much easier than trying to script with Vim, and easier to install in a CI/CD container. Also smaller and faster than using AWK, Perl, etc
You can use in a pipeline, or edit a file in place (see the -i option).
Bonus tip: On a Mac install GNU Sed rather then use the default.
Here is an intro https://www.digitalocean.com/community/tutorials/the-basics-of-using-the-sed-stream-editor-to-manipulate-text-in-linux
#Neovim / #Vim tip of the day is to learn and use command-line mode.
It's a very powerful way to edit sets of lines (it only works on lines).
E.g. you can delete, yank, put, substitute, use external shell commands, as well as perform file operations & manage Vim, which is how most people know cmd mode.
A history buffer means if a cmd fails, undo with 'u' & try again. Useful for large search and replace operations.
More info here https://learnbyexample.github.io/vim_reference/Command-line-mode.html
Today's #Neovim / #Vim tip is simple AND useful.
Not sure what a command does? Use the built in help. For example is there a difference between `gg` and `1G`?
Try
:h G
and
:h gg
You can also confirm key mapping. e.g.
:h ctrl-]
When you are in the help text you can jump to tags with <ctrl>-] (and back with <ctrl>-o).
More info at https://freshman.tech/snippets/vim/jump-to-help-tag/
@alecthegeek It's a matter of taste I guess, but for 1 I prefer
ggO