💾 Archived View for gemini.susa.net › Vim › index.gmi captured on 2023-01-29 at 15:45:45. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2021-11-30)

-=-=-=-=-=-=-

Things I Should Work On

Here are Vim areas that I under-utilise, and need to use more broadly.

Registers

There are ten different *types* of Vim registers, and they can be really useful with Ctrl-R in Insert mode and when entering Commands.

Registers can be written to with :let @, e.g. :let @a = "In the 'a' register"

Insert Mode

Using Shift or Ctrl with arrow keys moves a word at a time, or a page at a time for up and down.

Completions

There is so much more to completions than the omni-complete that I typically use. The whole sub-mode for completion is referred to as Ctrl-X mode. From the manual:

Completion can be done for:

1. Whole lines                                          i_CTRL-X_CTRL-L
2. keywords in the current file                         i_CTRL-X_CTRL-N
3. keywords in 'dictionary'                             i_CTRL-X_CTRL-K 
4. keywords in 'thesaurus', thesaurus-style             i_CTRL-X_CTRL-T
5. keywords in the current and included files           i_CTRL-X_CTRL-I
6. tags                                                 i_CTRL-X_CTRL-]
7. file names                                           i_CTRL-X_CTRL-F
8. definitions or macros                                i_CTRL-X_CTRL-D 
9. Vim command-line                                     i_CTRL-X_CTRL-V
10. User defined completion                             i_CTRL-X_CTRL-U
11. omni completion                                     i_CTRL-X_CTRL-O
12. Spelling suggestions                                i_CTRL-X_s
13. keywords in 'complete'                              i_CTRL-N i_CTRL-P

Item 13. above refers to i_CTRL-N (and i_CTRL-P), used to trigger basic keyword completion in insert mode. The 'complete' option is a string that encodes where Vim scans for keywords (e.g. words in all open buffers, tags, and include files).

The remaining items above are the Ctrl-X mode completions, which operate independently of basic keyword completion.

The 'User defined completion' is perhaps the most useful for custom completions. The i_CTRL-X CTRL-U keystrokes invoke the function defined in 'completefunc'. This function is called twice, the first time you return where in the line you want completion to start (e.g. the column of the start of a partial word), and the subsequent calls you return the 'list' of matches (e.g. a list of words, or a list of associative array 'dictionary' items).

See ':help complete-functions' for details.

You can also, for example, imap <c-space> <C-R>=ListOfMyCompletions()<cr>, and define a corresponding function that has a 'call complete(col('.'), my_list)', allowing you to map in entirely independent completions for special cases (e.g. one-off completions lists).

Vim configs and stuff

My vimrc that's used in my Minetest container. This is about as light as it gets, and I'm increasingly drawn to not complicating my editor unneccessarily. I have too many shells to keep track of what's configured where.

vimrc_minetest

My vimrc on one of my home servers. This is a more comprehensive config based on the Debian defaults along with numerous plugins. Too heavy!

vimrc_admin1

Useful Vim stuff

Kevin Conner's Vim syntax highlighting of Gemtext

Quick Reference

Vim Cheat Sheet

Summary of Vim motions

A list of Vim's built-in functions

vim-lsp linting tips

Vim FAQ (full text document)

Vim FAQ Search

List loaded scripts (e.g. modules)

:scriptnames

This lists all scripts in the order they were loaded.

Execute a composed shell command

:execute "!ls /" . "tmp"

String concatenation

"a" .. "b" (yields "a b")

"a" . "b" (yields "ab")

Launch a terminal

:vertical terminal

Option as variable

:let &number=0

Use <current line number> in a command

:echom line(".")

Variable Scopes

buffer-variable    b:     Local to the current buffer.
window-variable    w:     Local to the current window.
tabpage-variable   t:     Local to the current tab page.
global-variable    g:     Global.
local-variable     l:     Local to a function.
script-variable    s:     Local to a :source'ed Vim script.
function-argument  a:     Function argument (only inside a function).
vim-variable       v:     Global, predefined by Vim.