kota's memex

An extremely fast an powerful text editor with a modal interface. Vim was based on vi, which is short for visual editor. It's a funny name since today we think of all text editors as visual while ignoring vi/vim's modal interface which is certainly the most standout feature.

I've used vim for quite a few years now, but I still have much to learn. Spending time studying and applying vim's features pays off quickly. Although it can take decades to "master" vim, you can quickly become faster with it than most graphical editors relatively quickly.

plugins

lsp

netrw

marks

diagraphs

format options

key repeat speed

I high suggest increasing the default key repeat speed. If you're using xorg place this in your .xinitrc:

# increase key repeat speed
exec xset r rate 350 40 &

help

:h intro

gO - show table of contents
:h index - show current key bindings

Open help in vertical window
add the following to ~/.config/nvim/after/ftplugin/help.vim
autocmd BufWinEnter <buffer> wincmd L

text formatting

gq - Hard wrap selected text
gw - Hard wrap without moving your cursor
J - Join / unwrap selected text

clipboard

Make the unnamed register use the system clipboard
set clipboard=unnamedplus

less common motions

:h motion

* - search the current word (and goto it's next occurrence)
H - Home (goto top of current window)
M - Middle (goto middle of current window)
L - Last (goto last line of current window)
C-E - "Extend" the screen down by one line
C-Y - "Yester-line" scrolls the screen up one line
g_ - Jump to last non-blank character in a line
g^ - Jump to first non-blank character in a line
gm - Jump to the middle of the line
ge - Jump back to the end of the previous word\

function and method jumps

]m - Jump to next method (in java and similar languages)
[m - Jump to previous method
]] - Jump forward or to the next '{' in the first column (start of function)
][ - Jump forward or to the next '}' in the first column (end of function)
[[ - Jump backward or to the previous '{' in first column (start of function)
[] - Jump backward or to the previous '}' in first column (end of function)\

unmatched (){}

[( - Go to previous unmatched '('
[{ - Go to previous unmatched '{'
]) - Go to next unmatched ')'
]} - Go to next unmatched '}'

CamelCase motion plugin

Simply prefix any normal word motion command with , to move by CamelCaseWordsInstead.

spelling

:h spell

set spelllang=en - language
nnoremap <leader>s :set spell!<CR> - map spellcheck toggle to <leader>s
s - next misspelled word
zg - mark word as good
z= - list spelling suggestions

windows

:h windows

<C-W>v - new vertical split
<C-W>h - new horizontal split
<C-W>_ - maximize split vertically
<C-W>| - maximize split horizontally
<C-W>= - equalize splits

visual block mode

:help visual-block
:help visual-operators
:help blockwise-operators

From normal mode use ctrl-v to enter visual block mode:
c - change selection (delete and switch to insert mode)
I - insert in front of cursor
A - append after cursor
r - replace every character in selection
d - delete selection
o - toggle cursor to opposite corner

vimdiff

nvim -d oldfile newfile

misc

http://vimcasts.org/episodes/ http://derekwyatt.org/vim/tutorials/

Remap j and k to move by display with wrapped lines

This also allows you to move the correct number of lines when preceded with a count. Counts greater than 5 will be added to the movement history to make Control-O and Control-I work.

nnoremap <expr> j v:count ? (v:count > 5 ? "m'" . v:count : '') . 'j' : 'gj' nnoremap <expr> k v:count ? (v:count > 5 ? "m'" . v:count : '') . 'k' : 'gk'

Hard wrap lines for certain file types with textwidth.

autocmd FileType wiki setlocal tw=80

Select inner parenthesis. You can also do this with qoutes, backtick, etc.

yi)

Change markdown title case.

%s/\<./\U&/g - change to uppercase
%s/\<./\L&/g - change to lowercase

Turn one line to title case. Capitalize every word.

:s/\v<(.)(\w*)/\u\1\L\2/g

FileType specific bindings.

Create go bindings in .config/nvim/after/ftplugin/go.vim. You could use a big list in your init.vim, but this allows having your different build, test, run commands in a single place for their language.

Create a custom command.

command Date :exec 'normal a'.substitute(system("date -Iseconds"),"[\n]*$","","")

Convert tabs to spaces.

:set expandtab

Convert spaces to tabs.

:set tabstop=2      " To match the sample file
:set noexpandtab    " Use tabs, not spaces
:%retab!            " Retabulate the whole file

resources

https://this-week-in-neovim.org/

Nice weekly neovim updates.