art by u/astrellon3

Vi IMproved

This is just a bunch of neat stuff I find related to Vim, maybe plugins, scripts or just neat settings.
Speaking of which, I found this neat article on the history of vim:
https://twobithistory.org/2018/08/05/where-vim-came-from.html
Might be a fun read.

Plugins












Configuration


Making the most out of vanilla vim features

NetRW

Using NetRW as a file tree.
From this post
tldr:

let g:netrw_banner = 0 " Hide the banner
let g:netrw_browse_split = 3 " Open in new tab
let g:netrw_winsize = 25 " Size
let g:netrw_liststyle = 3 " Show files in tree form	

See what each option does with :help netrw-browser-settings


:Grep

Improving the :grep command to work similar to how ack.vim works
See the full gist, it explains everything
final snippet:

function! Grep(...)
	return system(join([&grepprg] + [expandcmd(join(a:000, ' '))], ' '))
endfunction
command! -nargs=+ -complete=file_in_path -bar Grep  cgetexpr Grep(<f-args>)
command! -nargs=+ -complete=file_in_path -bar LGrep lgetexpr Grep(<f-args>)
augroup quickfix
	autocmd!
	autocmd QuickFixCmdPost cgetexpr cwindow
	autocmd QuickFixCmdPost lgetexpr lwindow
augroup END	


Tab Indicator

If and only if you indent with tabs, vim can bestow upon you a slick tab line:
set list lcs=tab:\│\ " There is a space here :)


Export to HTML

This is a pretty neat capability I did not know vim had,
By the power of an included plugin, You can run :TOhtml to convert the entire current file to a HTML with all of vim's
syntax highlighted goodness,
And you can script it! Like so:

lang="$2"
f=$(mktemp)
echo "$0" | head -n -1 | nvim -n --headless \
	+"let g:html_no_progress = 0"\
	+"let g:html_ignore_folding = 0"\
	+'let g:html_prevent_copy = "fn"'\
	+"set ft=$1"\
	+"runtime! syntax/2html.vim"\
	+"wq! $f"\
	+"q!" - 1> /dev/null	

You can see more options for it here: https://vimhelp.org/syntax.txt.html#%3ATOhtml ,
Here is a example file from the make script of this website.


Improving :help and :Man

I find vim's help pages annoying to navigate since by default, its difficult to navigate between sections, this fixes it:
au FileType help,man nnoremap <buffer> <CR> <C-]>
This makes it so hitting enter in a help buffer will try to just to the currently selected word
(the world the cursor is on.)
Here are some more nice shortcuts: https://vim.fandom.com/wiki/Learn_to_use_help#Simplify_help_navigation

Using vim as a man pager

There are lots of ways to do it (documented here but
the simplest way I found is to simple alias man, like so in your shell configuration file:

man () {
	nvim +"Man $2 $1" +"only"
}	

If you use vim, remember to add this to your vimrc:
runtime ftplugin/man.vim
as :help ft-man-plugin instructs you to.


Linting

Here are a few useful gists on the topic:
https://gist.github.com/romainl/2f748f0c0079769e9532924b117f9252

https://gist.github.com/romainl/ce55ce6fdc1659c5fbc0f4224fd6ad29

What I did to get shellcheck to work:


✏ Actually I have reconsidered this, its way too painful for anything complicated over multiple lines, its a lot
simpler to just use ALE for those, fine for stuff like GCC or Shell check tho


Spell Checking & Dictionary Completion

As much as I hate to link a luke smith video, this one actually explains stuff so here you go: https://www.youtube.com/watch?v=ez1XBUqbS68
But basically:


For dictionary completion, you can use the following snippet:
You might need to rewrite it in vim script for vim...

local spell_complete = vim.api.nvim_replace_termcodes('<C-x><C-k>', true, true, true)
local M = {}
function M.spell()
	if vim.opt.spell
	and (vim.fn.pumvisible() == 0)
	and ((vim.v.char >= 'a' and vim.v.char <= 'z')
	or (vim.v.char >= 'A' and vim.v.char <= 'Z')) then
		vim.fn.feedkeys(spell_complete, 'n')
	end
end
function M.setup_spell()
	vim.opt.spell = true
	vim.cmd [[
	autocmd InsertCharPre * lua require('auto').spell() " You'll need to change this
	]]
end

-- And this too:
vim.cmd [[ au FileType markdown,html lua require('auto').setup_spell() ]]

return M	

It works, fairly well. badly, it has lots of issues when you have multiple buffers open...




~ More to come.. Maybe 🚧 ~