I regularly need to edit system config files - take /etc/sanoid/sanoid.conf as
an example… I’ll want to play with something but if I don’t start Neovim as
root then I get in trouble making edits I can’t save! So
suda.vim gives me
:SudaWrite which let’s me write that buffer with sudo privileges even though
I’m Neovim is running with my login user!
Posts tagged: vim
All posts with the tag "vim"
I wanted to break down some long lines in a Markdown table cell to make it look
nicer on my blog but \n didn’t do anything for me… turns out
is the
magic sauce
| Column 1 | Column 2 |
|---|---|
| Key | Doggo ipsum many pats. Borkdrive borking doggo doing me a frighten doggorino, noodle horse heckin. what a nice floof. Pupper borking doggo you are doing me a frighten, much ruin diet. |
| — | — |
| Column 1 | Column 2 |
|---|---|
| Key | Doggo ipsum many pats. Borkdrive borking doggo doing me a frighten doggorino, noodle horse heckin. what a nice floof. Pupper borking doggo you are doing me a frighten, much ruin diet. |
| — | — |
Description of my proposed vimconf 2022 talk
/mysearch\c will match mysearch, MYSEARCH, mYSeArCh…
If you think glepnir/lspsaga.nvim config will work with tali5/lspsaga.nvim installed… you’re in for a rude awakening. Double check your forks folks!
import this; print(this); print("what is taking so long black!!")
In vim G clog % does a git clog {current file}. You get every commit that the target file is apart of (so there might be info in those commits unrelated)
:PlugSnapshot, :w ~/dotfiles/nvim/snapshot.vim… keep your config safe with git!
I’ve had Plug 'hrsh7th/cmp-path' in my plugins for ever but didn’t notice
until recently that I wasn’t getting any filepath completion in vim!
Fuller setup instructions below the TLDR
TL;DR
Turns out I need to not be a dope and configure nvim-cmp to actually use it…
local cmp = require'cmp'
cmp.setup({
-- removed rest of setup - see the rest in my dotfiles
sources = cmp.config.sources({
{ name = 'path' }, -- This needs to be here!
})
})
My Setup
For the sake of completeness here is how I currently (May 2022) configure completion in Neovim usin nvim-cmp
Plugins #
I keep all my plugins in plugins.vim
call plug#begin(s:plug_dir)
Plug 'neovim/nvim-lspconfig'
Plug 'hrsh7th/cmp-nvim-lsp'
Plug 'hrsh7th/cmp-buffer'
Plug 'hrsh7th/cmp-path'
Plug 'hrsh7th/cmp-cmdline'
Plug 'hrsh7th/nvim-cmp'
" For ultisnips users.
<!-- " Plug 'SirVer/ultisnips' -->
<!-- " Plug 'quangnguyen30192/cmp-nvim-ultisnips' -->
call plug#end()
Vim Settings #
My vim settings are also kept in their own file, settings.vim
set completeopt=menu,menuone,noselect
nvim-cmp configuration #
I have a cmp.lua file that gets sourced in init.lua (file structure explained below) for configuring cmp.
-- Setup nvim-cmp.
local cmp = require'cmp'
cmp.setup({
snippet = {
-- REQUIRED - you must specify a snippet engine
expand = function(args)
-- For `ultisnips` user.
vim.fn["UltiSnips#Anon"](args.body)
end,
},
window = {
completion = cmp.config.window.bordered(),
},
mapping = {
['<Down>'] = cmp.mapping.select_next_item({ behavior = cmp.SelectBehavior.Select }),
['<Up>'] = cmp.mapping.select_prev_item({ behavior = cmp.SelectBehavior.Select }),
['<C-d>'] = cmp.mapping.scroll_docs(-4),
['<C-f>'] = cmp.mapping.scroll_docs(4),
['<C-Space>'] = cmp.mapping.complete(),
['<C-e>'] = cmp.mapping.close(),
['<Tab>'] = cmp.mapping(cmp.mapping.select_next_item(), { 'i', 's' }),
['<CR>'] = cmp.mapping.confirm({
behavior = cmp.ConfirmBehavior.Replace,
select = true,
})
},
sources = cmp.config.sources({
{ name = 'nvim_lsp' },
{ name = 'ultisnips' },
{ name = 'buffer' },
{ name = 'path' },
{ name = 'tmux' },
})
})
The sources section is what was key for this post…
Piecing it together!
My init.vim sources plugins and then settings and then finally calls init.lua.
init.lua sources my cmp.lua file and BANG! auto-completion.
More sources #
hrsh7th’s wiki for nvim-cmp is here and has example configs as well as a list of sources…
Don’t forget to configure and not just install!
Did you know you can spell check in Vim?!
Without... #
Here is a missspelled word.
<h3>With!</h3>
<p>Here is a <u>missspelled</u> word.</p>
What is this magic??? #
set: spell spelllang=en_us
Custom words? #
Sometimes there’s things that are words to you but not the default spell checker…
Common example: package names!
plotly, streamlit, psutil, etc etc…
You can easily add these to your vim config by hitting zw ontop of the word!
I ran into an issue where I had some copy-pasta markdown tables in a docstring but the generator I used to make the table gave me tabs instead of spaces in odd places which caused black to throw a fit.
Instead of manually changing all tabs to spaes, or trying some goofy :%s/<magic tab character>/<%20 maybe?>/g I learned that Vim has my back…
:retab