Nvim
up:: Programming ⚐
LSP
Inspiration
- nvim/src/mappings-leader.lua at master · echasnovski/nvim
- Making my Nvim Feel More Like Helix with Mini.nvim
Keybindings after reset
gd: Go to definition
gR: Open references
gh: Reference/implements/definition window
K: Hover doc
vim.keymap.set("n", "M", "J") -- mnemonic: [M]erge
vim.keymap.set("n", "<leader>h", "K") -- mnemonic: [h]over
vim.keymap.set("o", "ar", "a]") -- [r]ectangular bracket
vim.keymap.set("o", "ac", "a}") -- [c]urly brace
vim.keymap.set("o", "am", "aW") -- [m]assive word
vim.keymap.set("o", "aq", 'a"') -- [q]uote
vim.keymap.set("o", "az", "a'") -- [z]ingle quote
Write filename
"%p
Resources
- Great guide: https://danielmiessler.com/study/vim/
- Learn in a game: https://vim-adventures.com/
- References
- Example of vim config: https://github.com/amix/vimrc
- Video: https://youtu.be/IiwGbcd8S7I - ⏲️
0:08:30- → enable relative line numbers and just it
nj(nbeing the number) to move where you want to
- → enable relative line numbers and just it
vim tutor: Lesson 6.5- Neovim as IDE
Unread
- Vim: Tutorial on Editing, Navigation, and File Management (2018) - YouTube
- A Vid in which Vim Saves Me Hours & Hundreds of Clicks - YouTube
- My Vim-related gists
- Vim: Seven habits of effective text editing
- Vim Cheat Sheet
Regex
- Non-greedy:
\{-}
Vim as a language
- Verbs are actions that can be performed on nouns. Eg:
d: deletec: changey: yank (copy)v: visually select (V for line vs. character)
- Modifiers are used before nouns to describe how you’ll do something. Examples:
i: insidea: aroundNUM: numbert: to, searches in line and stops before itf: searches for a thing in line and lands on it/find a string (literal or Regex)
- Nouns are objects you do something to. Examples:
w: words: sentencep: paragrapht: tagb: block
You can also use nouns as motions. They define the size of your jump. Examples:
# Delete two words
d2w
# Change inside sentence (delete current and enter insert mode)
cis
# Yank inside paragraph (copy paragraph you're in)
yip
# Delete to next period
dt.Insert mode
i
Leave with Esc
Moving
-
0: Beginning of the line -
$: End of the line -
^: First non-blank character of line -
t: to, searches in line and stops before it -
f: find, for a thing in line and lands on it -
,: Repeat lastt/fjump -
;: Backwards repeat last jump -
''(two backticks): Go back to where you just were -
)move forward one sentence -
}move forward one paragraph -
Ctrl-ijump to previous -
Ctrl-ojump back to where you were
Move to line number
:<NUM>:/<NUM>gg/<NUM>G
Searching
*: Search for other instances of word under cursor- Search forward with
/ nto go to next instanceNto go to previousgnto jump to next search findcgnchanges the next find, making it great for repetitions with.
Edit mode
dd- Delete linegg- Go to topG- Go to bottom}- Cursor after block of code{- Above block of code
u- Undoo- open new line below current oneO- open new line above current one
Replacing and changing
r- replaces one character under the cursorR- enter replace mode untilEscis pressed
c- changes characters and can be combined with motions (eg.cw)
Command mode
:q!- Quit without saving:wq- Quit and save.- Quicker alias:
ZZ :w- Save
- Quicker alias:
:!<command>- execute shell script, eg:!ls
Substitutions
# Change "foo" to "bar" on every line
:%s /foo/bar/g
# Change "foo" to "bar" on current line
:s /foo/bar/g
Completion
- Type the start of a command, hit
CTRL-Dfor completing the command
Set filetype
set ft=dos
Word objects
-
words:
iwandaw -
double quotes:
i"anda" -
tags:
itandat -
sentences:
isandas -
paragraphs:
ipandap -
single quotes:
i'anda' -
back ticks:
ianda -
parenthesis:
i(anda( -
brackets:
i[anda[ -
braces:
i{anda{
Shortcuts
ctrl-g: Shows location in file
Macros
qa: Start recording a macro named “a”q: Stop recording@a: Play back macro- or, with my German keyboard:
öa
- or, with my German keyboard:
Replay macro on a visual selection by executing :normal @a
.vimrc
A minimalist take on Vim - Mijndert Stuij:
syntax on # enable syntax highlighting
set tabstop=2 # set 1 tab to 2 spaces
set shiftwidth=2 # set an indent to 2 spaces
set expandtab # convert tabs to spaces
set ai # automatic indentation
set number # enable line numbers
set hlsearch # highlight search matches
set ruler # show current row and column position
set backspace=2 # fix backspace behaviour
set wildmenu # enable autocompletion
set path=$PWD/** # set search path
set wildmode=longest:list,full # set autocompletion mode
set pastetoggle=<leader>p # toggle paste mode using \p
set nuw=3 # set left margin
set noswapfile # disable swapfiles
set clipboard=unnamed # copy to system clipboard
highlight LineNr ctermfg=DarkGrey # set linenumbers to grey
nnoremap <esc><esc> :noh<return> # clear search results using esc-esc
colorscheme nord # set colorscheme to nord
Remap ESC to jk
inoremap jk <ESC>
Some other basic stuff
syntax on # highlight syntax
set number # show line numbers
set noswapfile # disable the swapfile
set hlsearch # highlight all results
set ignorecase # ignore case in search
set incsearch # show search results as you type
Usage with German keyboard
nnoremap ß `
nnoremap ö @
inoremap üü {}<left>
inoremap öö []<left>Plugins
- Collection of plugins: Vim Awesome
- How to set up Neovim 0.5 + Modern plugins (LSP, Treesitter, Fuzzy finder, etc) | by Takuya Matsuyama | Dev as Life
Remappings to try
" H to move to the first character in a line
noremap H ^
" L to move to the last character in a line
noremap L g_
Keymappings
- Clear search highlights —
leader nh - Increment number —
leader + - Decrement number —
leader - - Split vertically —
leader sv - Split horizontally —
leader sh - Make windows equal width —
leader se - Close split window —
leader sx - Toggle window maximised —
leader sm - Change surrounding —
cs"' - Closing bracket (
() —b - Closing bracket (
{) —B - Replace copied text —
grw - Comment out line —
gcc - Comment out 2 lines down —
gc2j - Toggle tree —
leader e - Telescope find files in current directory —
leader ff - Telescope find string in current directory —
leader fs - Telescope find string under cursor in current directory —
leader fc - Snippets close suggestion —
control e
Surround
-
Surround with character —
ys + motion + charater -
Surround word with double quotes —
ysw" -
Delete surround from word —
ds" -
Change surround from word —
ds"'
Modifiers
| Modifier | macOS | Nvim |
|---|---|---|
| control | ⌃ | C- |
| option | ⌥ | M- or A- |
| shift | ⇧ | S- |
| command | ⌘ | D- |
Global search to quickfix
:Ggrep findstring
:copen
Folding
zf - create fold
za - toggle fold