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.

* Ctrl-R= is useful to insert the result of an expression, which can be a function. I need to get better at writing Vimscript.

* Ctrl-R/ inserts the last search expression. Ctrl-R_Ctrl-R/ will insert it literally (e.g. uninterpreted control chars).

* Ctrl-R% inserts the current filename, Ctrl-R# inserts the alternate buffer's filename.

* Ctrl-R* inserts the content of the system clipboard.

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

Insert Mode

* Ctrl-] - trigger expansion of abbreviations defined with :abbreviate

* Ctrl-T & Ctrl-D - add and remove indents at the start of the current line.

* Ctrl-Y - insert the char that's above the cursor, Ctrl-E is same from below the cursor.

* Ctrl-V - insert the next control character literally (e.g. Ctrl-V Ctrl-M)

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.

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!

Useful Vim stuff

Quick Reference

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.