This repository includes all the things I learned about Vim.
I am learning Vim as I would like to be a more efficient worker, and so far, using Vim also makes coding fun again.
I found that in order to learn Vim and use it more effectively, one has to learn and configure so many things, that I decided to write everything down as I go along and learn Vim.
As this document contains the things I read and learned, I do not currently accept outside contributions (except typo and grammar fixes).
- a beast that needs to be tinkered with and correctly configured, and constantly reconfigured (as you discover need for more customizations)
- strange keybindings that don't always make sense
- model system is nothing like you've ever used, it makes Vim very different from other editors
- steep learning curve
- installed by default on every Unix operating systems
- on servers, remote computers, Vim might be the only option for text editing
- very powerful tool, worth learning the ins and out, you can manipulate texts with few key strokes
- open-source and gets continuously better
- it's been around for a long time so it's easy to find resources
- Vim Adventures (solutions)
vimtutor
: takes around half an hour, it is recommended to go through it multiple times.
Modal editor
Why is Vim a "modal" editor? Because it has modes! Normal, Insert, Visual. When in doubt, stay in Normal (that's why it's called normal).
i
go to insert modeI
insert mode (ignore spaces)s
delete character undor the cursor and change to insert modeS
delete line and change to insert modeO
create new line after current line and change to insert modeo
create new line before current line and change to insert modecw
delete word and go to insert modec$
delete from cursor until the end of the line and change to insert modeC
delete from cursor until the end of the line and change to insert modey
yankyy
yank lineyw
yank wordp
put (for example yanked stuff)%
jump to matching parenthesis/
search/something<Enter>
+n
- search for something... jump to next/something<Enter>
+N
- search for something... jump to previous?
reverse searchControl o
- go back to previous positionControl i
- go back to previous positionh
,j
,k
,l
- basic navigation (left, down, up, right)gh
,gj
,gk
,gl
- move by visual lines (in case of line-wrap)gg
- to the top of the documentG
- last line of the document0
- first character of the line^
- first non-space character of the line8G
- jump to eighth linex
- delete character under cursoru
- undo- C r redo
ZZ
- quitdw
- delete wordw
- move by wordW
,E
,B
- same as w, e, b but ignores commas, parenthesis, etc...ft
- forward to character tFt
- backward to character ttt
- forward to before character tTt
- backward to after character t!ls
execute command (in this example the ls command)
- remap Esc to caps lock
- map ii to leave insert mode
I found this great article about remapping the Esc key by Adam https://medium.com/@adamregaszrethy/vim-where-to-remap-esc-6f556d11fb75. In it, he describes that we can use Karabiner Elements for the remapping. https://karabiner-elements.pqrs.org/ I downloaded the dmg file, opened it and installed Karabiner. Maybe for the next time I should add this with homebrew? Can I do that? Yes, I can https://formulae.brew.sh/cask/karabiner-elements. Anyway. Karabiner is installed.
Make sure Karabiner runs correctly. I had to enable it Security and Privacy, and I also had to restart the computer.
Next step: How do I remap this? https://spin.atomicobject.com/2020/05/15/caps-lock-escape-control/
Complex modifications > Add rule > Import more rules from the Internet > (https://ke-complex-modifications.pqrs.org/ opens in default web browser) > Expand all > Search for "Change caps_lock to Command if pressed with other keys, to escape if pressed alone."
Karabiner also supports a JSON format to describe complex modifications https://karabiner-elements.pqrs.org/docs/json/typical-complex-modifications-examples/
You can include them, but it is tricky and not well documented pqrs-org/Karabiner-Elements#1225 long story short, you need to create json files in your .config karabiner folder.
- shift i (aka I) to show hidden files in nerd tree
- new file: https://sookocheff.com/post/vim/creating-a-new-file-or-directoryin-vim-using-nerdtree/ m for menu, a
NERDTree Menu. Use j/k/enter, or the shortcuts indicated
=========================================================
> (a)dd a childnode
- run command :!unix_command
Here is a list of all the resources I used.
Random notes, todos;
- install nerd fonts, should work with vim devicons
- vifm
- alacritty