Note
Intern check Todo: notes., master., logger., todo. and paper notes for examples.
Maybe useful: fb mapping, argdo, bufdo, search and replace without plugins, completions, navigate functions/methods
I learned vim in a way most younger people can't imagine I didn't know any books, youtube wasn't available and I didn't know what a plugin is.
My first vim contact was a remote session from Windows via telnet to a linux machine which I couldn't figure out to quit - no joke.
Finally I did alt+F4...
But since that time I got hooked, and I didn't regret to learn it. I still use Vim today. I do almost all of my work with it.
Note
♨️ If you prefer to learn by video rather than by book then I can recommend the Vim Masterclass on Udemy. It certainly took me more years of "learning by doing" to learn what is taught in the course. It's not an affiliate link.
-
Vim help files as HTML with search: https://vimhelp.org
-
Seven habits of effective text editing: https://www.moolenaar.net/habits.html by Bram Moolenaar
-
All things Vim!: https://github.com/mhinz/vim-galore
-
Ask the great help, sometime it's a bit tricky to find the right keyword. You can take a full shot on the help file as PDF https://nathangrigg.com/vimhelp/vimhelp-a4.pdf
-
📺 Vim Tips I Wish I Knew Earlier really helpful!
-
Vim Cookbook by Steve Oualline. He wrote my first Vim book I read dated ~2000/2001/2002
-
📚 Practical Vim: Edit Text at the Speed of Thought https://www.amazon.de/Practical-Vim-Edit-Speed-Thought/dp/1680501275/
-
📚 Modern Vim: Craft Your Development Environment with Vim 8 and Neovim https://www.amazon.de/Modern-Vim-Development-Environment-Neovim/dp/168050262X/
I try to watch as few vim videos on youtube as possible because they might distract me too much from my work but there are some great youtuber's fiddling with vim/neovim e.g.:
- https://www.youtube.com/@DistroTube/search?query=vim
- https://www.youtube.com/@ElijahManor/videos
- https://www.youtube.com/@GavinFreeborn/search?query=vim
- https://www.youtube.com/@GregHurrell
- https://www.youtube.com/@LukeSmithxyz/search?query=vim
- https://www.youtube.com/@SebastianDaschnerIT/search?query=vim
- https://www.youtube.com/@SeniorMarsTries/search?query=vim
- https://www.youtube.com/@TheNycRat/search?query=vim
- https://www.youtube.com/@ThePrimeagen/search?query=vim
- https://www.youtube.com/@bawad/search?query=vim
- https://www.youtube.com/@chrisatmachine/videos
- https://www.youtube.com/@denvaar/search?query=vim
- https://www.youtube.com/@devaslife/videos
- https://www.youtube.com/@devopstoolbox/videos
- https://www.youtube.com/@leeren_/videos
- https://www.youtube.com/@nirlichtman/search?query=vim
- https://www.youtube.com/@rwxrob/search?query=vim
- https://www.youtube.com/@semicolonsons/search?query=vim
- https://www.youtube.com/@teej_dv/videos
- https://www.youtube.com/@theena/search?query=vim
- https://www.youtube.com/@typecraft_dev/videos
- https://www.youtube.com/@vimjoyer/search?query=vim
- https://www.youtube.com/@yukiuthman8358/videos
Recently I came across a video series that is a kind of quantum leap for me ...
- Problem Solving with Vim - 1 (expression register)
- Problem Solving with Vim - 2 (substitute, match group, expression register)
- Problem Solving with Vim - 3 (macro, sub-replace-expression)
- Problem Solving with Vim - 4 (more expression substitution)
- Problem Solving with Vim - 5
- Problem Solving with Vim - 6 (Regular expression, scriptin arg)
- Problem Solving with Vim - 7
- Problem Solving with Vim - 8 (Abusing Vim)
- Problem Solving with Vim (9th edition) My favorite substitute
- Problem Solving with Vim (10th edition) - Key Code Hell
open file todo.md and jump to line 39
vim +39 todo.md
delete from current line to last line visible on screen
dL
delete from current cursor position up to PATTERN
d/PATTERN
display the character count of the current file
g CTRL-G
To turn off highlighting until the next search
:noh
Indent text
- insert mode: ctrl-t / ctrl-d
- normal mode: >> / <<
Movement command in insert mode e.g. to go forward one word type
ctrl+o w
jump to next / previous empty line
} / {
cancel auto completion
ctrl + e
Pipe result to vim
e.g.:
rg -i PATTERN | vim -
python abr.py | vim -
Paste clipboard content while in insert mode
(depends on OS and compile options listed :version)
ctrl+r *
ctrl+r "
send current line to vim terminal
1. copy current line with yy
2. :term
3. ctrl+w ""
Substiute with confirmation
:%s/foo/bar/gc
Count number of matches of a pattern
:%s/pattern//n
Show content of registers
:reg
Insert from register e.g. m
"mp
To run your last search again
//
gg -> jump to begin of file
G -> jump to end of file
H -> buffer viewport high
M -> buffer viewport middle
L -> buffer viewport low
0 -> jump to begin of line
_ -> jump to begin of first char in line
$ -> jump to end of line
[[, ]] -> jump between methods
]c, c] -> jump between changes
]g, g] -> jump between warning/error messages (lsp needed)
ctrl+o, ctrl+i -> jump using jumplist
:set background=light
:TOhtml
In insert mode
ctrl + k
followed by >>
will result in: »
<< «
Rg ®
TM ™
Co ©
OK ✓
:dig
- To insert a Unicode character while in insert mode, type
ctrl+vuxxxx
e.g.ctrl+vu2713
. - A table of digraphs can be shown with:
:h digraph-table
- to search for digrpahs, take a look at the Unicode-Plugin https://github.com/chrisbra/unicode.vim written by Christian Brabandt.
- More: https://devhints.io/vim-digraphs
Remove encryption key from file which was set with :X
:set key=
:w
Info: https://vi.stackexchange.com/questions/2003/how-do-i-debug-my-vimrc-file
vim -u NONE -U NONE -N
Capture ex command output to buffer e.g. :version
:redir @m | silent version | redir END
"mp
NOTE: untested :g can possibly be omitted
Add " to the begin of the line -> : instead of / used for better readability
:%s:^:":g
Add " to the end of the line -> : instead of / used for better readability
:%s:$:":g
vimgrep /PATTERN/f % | copen
vimgrep - grep for
/PATTERN/ - PATTERN
f - with fuzzy mode
% - in current file
| copen - open quickfix window for results
- Cursor on char
- typing
ga
to identify what it is - Use
\%u
pattern to search for the four digits hex e.g.%s/\%ufb01//gn
to remove fb01
za
toggle fold under cursorzR
open all foldszM
close all folds
Mapping in vimrc to toggle a fold when cursor is on the fold
nmap <space> zA
:buffers
:Buffers (if fzf plugin is used :BLines to search in buffer)
jump between last and current buffer
ctrl+6 or :b#
alle Buffer schließen, bis auf die die noch nicht gespeichert sind
:%bd
Split buffer vertical
ctrl+wv
Split buffer horizontal
ctrl+ws
show current marks
:marks
set mark m at current cursor location
mm
jump to line of mark m
'm
jump to position (row and column) of mark m
`m
yank text to from cursor to position of mark m
y`m
delete from current line to line of mark m
d'm
delete from current cursor position to mark m position
d`m
vim -d old.txt new.txt -c TOhtml -c "w! diff.html" -c q! -c q! -c q!
Source: https://stackoverflow.com/questions/390174/in-vim-how-do-i-apply-a-macro-to-a-set-of-lines
Execute the macro stored in register a on lines 5 through 10.
:5,10norm! @a
Execute the macro stored in register a on lines 5 through the end of the file.
:5,$norm! @a
Execute the macro stored in register a on all lines.
:%norm! @a
oder
:%normal @a
Execute the macro store in register a on all lines matching pattern.
:g/pattern/norm! @a
To execute the macro on visually selected lines, press V and the j or k
until the desired region is selected. Then type :norm! @a and observe
the that following input line is shown.
:'<,'>norm! @a
vim -w script.vim
Additional info: https://stackoverflow.com/questions/3981535/using-the-w-option-of-vim
conv.vim:
:%s/ö/ö/g
:%s/ä/ä/g
:%s/ü/ü/g
:%s/ß/ß/g
in vimrc
command! CONV :so d:\vim\vimscripts\conv.vim
:help index
:map
:verbose map
If you just want to see what mappings you have that are prefixed by a
certain key, you can do
:map <key>
to list them all.
Very very, crude way!
new | r! java -Dfile.encoding=UTF-8 -jar d:\apps\LanguageTool-5.1\languagetool-commandline.jar -c utf-8 -d WHITESPACE_RULE,EN_QUOTES -l de-DE
Check if Python and Vim are the same bit (64), not mixed!
Python dependencies and Anaconda on Win OS
chechk if `pythonhome=c:\Anaconda3` is set
check if defined in vimrc
let &pythonthreedll = 'C:\Anaconda3\python36.dll'
in vim
:echo has('python3')
vim --startuptime perf
:%s/pattern.*//g
Let pattern be ?utm
:
:%s/?utm.*$//g
:%s
replace in whole buffer?utm.*$
is the search pattern that will match from starting?utm
up to the end of the line.//
pattern which replace the match in this case it's empty.g
means global, will replace multiple occurences in line. Could be omitted because we replace from pattern start till end of line, but it's my (bad) habit.
before:
a
b
c
after:
a TEXT
b TEXT
c TEXT
- visual select lines
- type
:norm A TEXT
, this will add TEXT to the end of all lines visually selected
- used
:
insted of/
for better readability - lines are marked visually
'<,'>
before:
a
b
c
:'<,'>s:^:before
after:
before a
before b
before c
before:
before a
before b
before c
:'<,'>s:$: after:
after:
before a after
before b after
before c after
g:PATTERN:m0
qaq -- to make sure named register a is empty
:g/match/y A -- to yank all matching lines into named register a (capital a to append)
:b2 -- to switch buffer
"ap -- to paste named register a
source https://www.reddit.com/r/vim/comments/1fmq9c8/comment/loch0vq/
If you find this notes helpful and want to support me, you can do so by Buy me a coffee! ☕ it will keep my motivation high and I will be really thankful.