Skip to content

Latest commit

 

History

History
589 lines (534 loc) · 44.8 KB

vim_notes.md

File metadata and controls

589 lines (534 loc) · 44.8 KB

VIM

Installing Vim

sudo apt install vim on Debian based Linux distros, brew install vim on Mac OS.

Starting Vim

vim example.md will open example.md positioning the cursor at the start of the file.
Add the following line to your .vimrc to ensure Vim opens each file with the cursor positioned at the last edited line:
au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
vim example.md +33 will open example.md with cursor positioned at line 33. vim +33 example.md works as well.
vim +/Pinguine example.md opens example.md at the first appearance of the pattern Pinguine.
It's functioning like a regular search, so pressing the n key will jump to the next pattern-match.
vim example.md +"152d|x" will delete line 152 of example.md and close the file before you even realize it has been opened.
vim example.md +"152d" will delete line 152 and leave the file open. u to undo the deletion will work in that case.

Command types

There are three types of commands in vim:
Ex commands like :set nonu to deactivate line numbers or :set nu to switch them back on again.
:help ex-cmd-index will show the entire list of ex commands.
Mapped commands are more complex commands which are mapped ore bind to keys for easier access.
Those commands are usually added to your .vimrc file.
Editing Commands are usually used in normal or insert mode – like d4w to delete four words.

Opening files

vim filename to open the file filename in vim.
vim to open vim and then :e filename to open filename from vim.

Close & save files / exiting Vim

Vim has different modes in which it is operating.
To ensure you're in the normal mode – from which you can exit – press ESC
Type : then q then ! and hit ENTER to exit Vim without saving.
Type : then w then q and hit ENTER to save and exit.
Type : then w and hit ENTER to save without exiting.
:w example.md to save file as example.md – :w! example.md to overwrite if example.md already exists.
Type : then x and hit ENTER to leave vim and save (only if file has been changed).
Z Z is another way to quit Vim from normal mode with saving the file.

Navigation in Vim

To move the cursor use the h,j,k,l keys in the middle of the keyboard.
k The k key moves up.
j The j key moves down.
h The h key moves left.
l The l key moves right.
6 j will move you six lines down, 6 k six lines up.
22 h will move you 22 cursor positions left, 22 l 22 positions right.
0 then ENTER will bring you to the start of the line.
$ then ENTER will bring you to the end of the line.
} then ENTER will bring you to the next empty line after a block of text.
{ then ENTER will bring you to the next empty line before a block of text.
A number then w will jump number of words forward (2w will jump two words).
3 then e will jump to the end of the third word from where the cursor is.
CTRL g will show your position in the document.
Jump to document start by typing g g.
Type G to jump to to the file bottom.
50% ENTER will bring you to the middle of the document.
% over any kind of bracket will flip cursor to the matching part.
4 2 G will bring you to line 42.
4 2 g g will bring you to line 42.
: 4 2 will bring you to line 42.
g j moves down to a blank line (only j skips those lines).
Capital W and B move you word by word - but don't count brackets and stuff as words like w and b do.
f + letter takes you to the next appearance of that letter in this line.
F + letter takes you to the last appearance of that letter in this line.
CTRL f for page down. CTRL b for page up.

The read command

When we want to get content from an other file into our currently open file, we are loading it into Vim's buffer.
A command to do that is the read command – :read or the short form :r.
:r example.md will insert full content of example.md below the cursor.
:30r example.md will insert full content of example.md below line 30.
:0r example.md will insert full content of example.md before line 1.
:31r!sed -n 56,62p ~/test/example.md will combine read and sed to insert line 56-62 from example.md below line 31 in current buffer.
You can load any command output into buffer that way: r!ls ~/test to list files from the text directory or r!man man to load the whole man manpage.
: then read !echo "Hello" would print "Hello" at the cursors position.
Or : read !ps aux would paste a list of running processes into the file.
This doesn't only work with standard commands, but also with any executable or exported functions.

Executing Code in Vim

If you have a code block of bash in your document, and you want to see the outcome of it, press ! }. It get's translated into an x-command and when you now type "bash" and hit ENTER, the code block will get replaced with its actual output.

Search

To search for type / then any phrase then ENTER.
n jumps down to the next search hit, N jumps up.
You can start a search with ? as well – n and N move in the opposite direction then.
CTRL o will bring you back to where you started the search.
CTRL i will jump back to next cursor position.
Press * in normal mode to search forwards for the word under the cursor.
Press # in normal mode to search backwards for the word under the cursor.
* and # will only search for the exact pattern. If the cursor is on the word for and you also want to find forwards, type g * or g #.
5* will jump to the 5th occurrence of the word under the cursor.
If you want to edit the word under the cursor before editing, press / then CTRL r then CTRL w.
:set ic will ignore case sensitivity.
A search for /ignore will show ignore, IGNORE or Ignore than.
If you want to ignore case sensitivity for just one search type /ignore\c.
:set hls is will activate search highlighting.
:nohlsearch or short :noh will deactivate it.
:no + command will disable all :set commands.
Match a string
A command close search to search is match – if you'd like to highlight the patter something, type :match ErrorMsg /something/.
The highlight color depends on your color scheme, try: ErrorMsg, WarningMsg, ModeMsg or MoreMsg.

Search multiple files

To search for the pattern maker within all files in your working directory, type :vimgrep maker *
Use :clist to get a list of all files containing that pattern. cc 2 jumps to the 2nd second list entry.
Jump to the next match with :cn or to the previous with :cN

The global command

:g/bla/d deletes all lines in the document that contain bla with.
:g!/bla/d deletes all lines in the document that do not contain bla with.
:g/^\s*$/d deletes all blank lines in current file.
:g/bla/s/text/TEXT/g will change text to TEXT in every line which contains the pattern bla.

Replace

Substitue flags: c confirm, g all occurrences in line, i ignore case, I don't ignore case
:s/thee/the will replace the first thee in the line with the.
:s/thee/the/g will replace all thee in the line with the.
:%s/thee/the/g will replace all thee in the file with the.
:%s/thee/the/gc finds all thee in the file and gives y/n option for each to replace with the.
:545,555s/bold/old/g will replace all bold with old in between line 545 and 555.
:23s/one/two/g will replace all one with two in line 23.
:23s/one/two/g will replace all one, ONE, One, oNe and so on with two in line 23.
:23,$s/one/two/g will replace all one with two from line 23 until the end of the document.
:?start?,/end/s/bla/blubb/g replaces all bla with blubb between pattern start and end

NOTE: The shown examples will replace the search pattern wherever they find it!
Example: Let's change the string "Game of thrones season one" to "Game of thrones season two".
:s/one/two/g will do the trick, right? Unfortunately the outcome will be: Game of thrtwos season two.
To replace only whole words you have to tag them: :s/\<one\>/two/g will replace one with two and leave thrones as it is.

You can also replace multiple pattern with the same string in only one go:
Let's say our line is "Replace this and that with some variables." and we want to replace this and that with some identical variable …
The command :s/\(this\|that\)/\{!object.field\}/g would result in "Replace {!object.field} and {!object.field} with some variables."

Delete

Press x in normal mode to delete the character under the cursor and continue left.
X to delete the character under the cursor and continue right.
So if the cursor is on m in example, x x will result in exale, X X in emple.
s deletes the character under the cursor like x, but it leaves you in insert mode afterwards.
Park the cursor on the first letter of a word you'd like to delete and press d then w.
The e instead of the w to leave the space after the word.
Press d then $ then ENTER to delete from where your cursor is to the end of the line.
d d deletes the whole line.
3 d d deletes three lines.
d 3 w will delete the word under the cursor plus the next two words.
3 d d deletes the line where cursor is plus the next two lines.
D deletes from cursor position to the end of the line. d $ does the same.
When you're in line 15 ant type d : 3 0 ENTER 15 lines (15-30) will be deleted.
d } will delete a whole block to the next empty line below, d { above the cursor.
You can delete until something by adding the t modifier: d t ? deletes everything from the cursor's position until the next question mark.

Delete in insert mode

CTRL h to delete the last letter before the cursor.
CTRL w to delete the last word before the cursor.
CTRL u to delete the everything back to the start of the line.

Until pattern

Interesting on VimTricks: Operate until pattern
To try out those methods I've created a test file repeating the sentence:

This is a text test to test some vim stuff 12345 blablabla great test file.

until single character
So dtt deletes everything in the line until the first t:
text test to test some vim stuff 12345 blablabla great test file.
ctt does the same, but leaves you in insert mode before the word test.
yt1 copies everything until the first 1. So with our sentence p gives you:
This is a text test to test some vim stuff

until pattern
d/test enter deletes everything until the first test:
test to test some vim stuff 12345 blablabla great test file.
c/test some enter deletes everything until the test some and leaves you in insert mode before test:
test some vim stuff 12345 blablabla great test file.
So in this example we have skipped the first test by given the command the pattern of the second test which is followed by some.
To write out some is not really necessary, c/test s enter would do the job just as well.
y/stuff enter copies everything until stuff:
This is a text test to test some vim

Change inside

Change inside quotes
Write this sentence in a Vim file: Vim is the most "complicated" editor in the galaxy.
Place the cursor somewhere before the word complicated in that line and type c i " then type the word powerful and hit ESC.
Change inside tags
To change the content within tags like <h1>Super cool title here</h1>, press c i t somewhere in the line to get <h1></h1> and the cursor within, ready to insert new content.
Change inside sentence
c i s within a block of text, will delete all words between punctuation characters.
Example: This is a sentence. Is this another one? Of course it is!
Type c i s while the cursor is on another to delete Is this another one? and leave This is a sentence. Of course it is! with the cursor before Of and in insert mode.
c i p for change inside paragraph will delete a whole block of text between two empty lines.
c i w for change inside word is a bit useless as c w or c e will do the same with one keystroke less.
It actually makes sense when the cursor is positioned in the middle of a long word you'd like to change, as those other commands require the cursor to be positioned at the beginning of the word.
c i ( or c i { or c i [ work as well, but the cursor has to be positioned on the (, {, [ when entering the command.

Copy, cut, paste and move

Good summary: https://vim.fandom.com/wiki/Copy,_cut_and_paste There is no ctrl+x style cut and paste in Vim --> because it keeps the last deleted line in the cache. So to cut and past just delete whatever you want to cut and it is ready to be pasted. The so called cut command is not really for pasting, it is good for deleting and change into edit mode at the same time. p the put command can be used to place prior deleted lines or words at cursor position.
2 p will paste the prior deleted string two times.
y7w will copy seven works from the cursors position.
2y will copy two lines from the cursors position.
y$ will copy from cursor to the end y0 to beginning of the line.
:23m42 will move line 23 to line 42.
:23,42m108 will move line 23-42 to line 108.
The move command will work on any line specified without the need to place the cursor there.
However, you can move the line where your cursor is placed with :m10 – which will move this line to line 10.
:195co. will copy the content of line 195 below the line where the cursor is positioned.
:195,199co207 to copy and paste the specified range below line 207.
Hot: 195,co. will copy everything from line 195 to your current cursor position and place it in the line below.

Copy or move lines when using relative line numbers

:-15co will c&p the content from 15 lines above and place it one line below.
:+15co will c&p the content from 15 lines below and place it one line below.
:-15,co will copy all content from 15 lines above until the cursor position and place it one below.
:+15,co will copy all content from 15 lines below until the cursor position and place it one below.
:+1,+2m+3 will move line 1-2 below your cursor to line 3 below it.
:+0m+3 will move to current line to 3 lines below.
:-6m219 will move the 6th line above the cursor to line 219.

t is an alias to co – so all the above shown examples work like this 195,t. as well.

Ways to change into insert mode

Press a in Normal mode to start appending letters where you are.
Press A in Normal mode to start appending at the end of the line.
c e will delete from where the cursor is to the end of the word and put you in insert mode.
c $ will delete everything from where the cursor is to the end of the line and put you in insert mode.
2 c c will delete the two lines after the cursor and put you in insert mode.
o will open a new line below the cursor and put you in insert mode.
O will do the same but above the cursor position.
e will make the cursor jump to the last letter of the next word.
Use e in combination with a to jump to last letter before your insert, so you can straight start typing.
s will delete the letter under the cursor and put you in insert mode.
S will delete the line under the cursor and put you in insert mode.
I will start insert mode at the beginning of the line.
While in insert mode press CTRL o to execute one normal mode command before switching back into insert.

Undo, redo

u will undo the last change, the next u undoes the prior change and so on …
U will undo all changes on the last edited line.
CTRL + r redoes the changes if you undid something by mistake.
Redo doesn't work after capital U.
R will enter replace mode where you can override everything under the cursor.
5 u will undo the last five operations.
Use the :earlier command (short :ea) to set your document back to a state it had a specific time ago:
:earlier 3d or :ea 3d will show how your doc looked 3 days ago.
:ea 3h will set it back 3 hours, :ea 3m 3 minutes, :ea 30s 30 seconds.
Go back forward in time with the :later (short :lat) command.
Use :ea 10 or lat 10 without a time option to undo/redo the ten last edits.
Additional to the time options there is f – for file state – which counts every time you saved.
:ea 3f undoes all changes since the last 3x you saved, :lat 3f redoes all that.
Undo branches: When you use undo/redo operations, Vim will create a branch at any undo point.
You can switch between branches by typing g- or g+.
Persistent undo: the undo command u is usually restricted to the current session.
You can activate session overarching undo by adding set undofile in your .vimrc
Vim will create a hidden undofile for each edited file in the directory where that file is located.
You can specify a storage location for those files in your .vimrc, like I have here: set undodir=~/.vim/undo.

The Dot

. will repeat the last used command. So if you typed d w to deleted a word, you only need to press . to continue deleting word by word.
The dot can also be used to repeat more complex operations like the change of a word:
If you press c e on the word "bank" and replace it with "financial institution", then exit insert mode with ESC and press n, your cursor will jump to the next appearance of the word "bank". A press on . will then repeat the change and replace it with "financial institution". That way you can jump from "bank" to "bank" by pressing n and change those where it is required.
To out-commend a line of bash code, press 0 i # – this can be repeated at each following line to quickly commend a block of text.

Indentation

> > in normal mode to indent a line.
< < to take that line back.
5 > > to indent five lines from the cursors position.

Command mode

: ! will set Vim in the mode to execute any external command.
:!ls will for example show a list of the current directory.
:w filename will save a copy of the edited file with name filename.
v brings you in visual mode. All moves you make in visual mode mark the text you're passing by.
You can use commands like d to delete the selected text or press : for external commands.
:w TEST will for example write the selected text into a file named TEST.
The command promt looks a bit different in visual mode, the above will appear like :'<,'>w TEST.
:r TEST will insert the content of TEST at the cursor position.
Outputs of external commands can be inserted as well, example: :r !ls.
If :e is entered - or any other first letter - and CTRL + d is pressed the all command starting wit e will show.

Visual mode

v for visual mode, where you can mark text by moving around with the cursor or use keys like $ to jump to the end of teh line. >vr When you're done selecting your areal, press y to yank the selsction od d to delete the marked text.
V will start into visual mode by selecting the whole line of the cursor's position.

Visual block

If you have some table-like formatted text/code with vertical aligned strings of identical size, you can use visual block to edit them simultaneously.
Bring the cursor to the first entry you'd like to edit, press CTRL v to enter visual block mode.
Press l till the string is fully selected, then start pressing j to mark the same areal in as many lines below as you like.
When all lines are selected press c to change, enter the new text, press ESC and that change will apply to all selected lines.
This method works as well with d for delete or y for yank.
gv will re-select the last text areal which was marked in visual mode before ESC was entered.
The visual mode selection follows the cursor where it goes – but you can switch directions with o.
The cursor than jumps to the opposing site as if you'd started the other way around.

Visual mode commands

The real power of visual mode lies in command mode.
Let's say you'd like to out-comment some lines of a shell script. Press CTRL v, go down those lines …
… then press : to enter into command mode. You'll see there's already something placed ther '<,'>.
This is the prefix to use the command only on the visual marked lines. Now type norm I# and hit ENTER.
:'<,'> norm A; will append a ; at the end of each visual selected line.
:'<,'> norm . will repeat the last write action to each visual selected line.
It's important to add norm or normal to those command to switch to normal mode for their execution.
Add vnoremap . :norm.<CR> to your .vimrc to perform the dot command in visual by simply pressing . instead of typing the full command.
Add vnoremap J :m '>+1<CR>gv=gv to your .vimrc to move visual selected lines down with J
… and vnoremap K :m '<-2<CR>gv=gv to move those lines up with K.

Case folding

~ in normal mode changes the case of the letter under the cursor.

Vim tricks – magic wand

! ! to enter a mode in which Vim accepts any command / function as input and writes its output at the cursors position.
Functions should be exported to be available in Vim!

Cursor position visualisation

:set cul activates cursor line – a horizontal line indicator for the cursor position.
:set cuc activates cursor column – a vertical line indicator for the cursor position.
:set nocul or :set nocuc for to deactivate those indicators.
The styling of the cursor line can be set, example: :highlight CursorLine guibg=lightblue ctermbg=lightgrey

Spellchecking

:set spell to activate spellchecking in default language. :set nospell to deactivate it.
Use this command to set the default language :set spell spelllang=en_us – add it to your .vimrc to set it permanent
When turned on, miss-spelled word will be highlighted like search results.
] s to jump forwards through those results, [ s does the same backwards.
z = will provide a list with spelling recommendations.
You can type the list index number and ENTER and Vim will replace the word with your selection.
Just hit ENTER if no suggestion is matching to leave the listing page.
If Vim is marking correct spelled word as incorrect type z g to add that word to the dictionary.
You can as well mark a word as incorrect by using z w
Good link on spellchecking: linux.com

netrw – the Vim file manager

:Ex opens current directory with horizontal screen split (same as :Sex).
:Vex opens current directory in vertical split – directory left (same as :Lex).
I've tried :Rex but it didn't work. The book says :Vex would open directories on the right .. but for me :Lex and :Vex look exactly the same (left)
:Ex ~/repos/ opens repos directory.
:Tex opens current directory in new window.
There are different list viewing options available. Press i within the list view to change to the next one.
:q will bring you back to full screen document mode.
D in list mode to delete the file under the cursor, R to rename and X to execute it .
To create a new file press % – Vim will open an other editor in the split screen then. :wq will save that file and return to full screen.

Vim config

The line au bufnewfile,bufRead filename set filetype=sh added in Vim config will make vim interprets the file filename as a bash file.
:set nu show line numbers in vim. set nonu hides them.
:so % reloads the file without closing it (to source a file)
:set list shows you spaces tabs and stuff. :set nolist to turn it off.
:set cursorline or :set cul to show a line under current cursor position. nocursorline or nocul to switch it off.

Vim version

:version will show you the installed version and options of Vim – options marked with a + are installed those with - ain't.

Registers

A register is like a clipboard, but instead of only a single clipboard, Vim has nine different types of clipboards:

  • 1x unnamed register ""
  • 10x numbered registers "0 to "9
  • 1x small delete register "-
  • 26x named registers "a to "z or "A to "Z
  • 4x read-only registers ": ". "% "#
  • 1x expression register "=
  • 3x selection and drop registers "* "+ "~
  • 1x black hole register "_
  • 1x last search pattern register "/

Named Registers

Example:

 29 Test REGISTER a
 30 Test REGISTER b
 31 Test REGISTER c

If you have three lines as those above and you'd like to paste each in different files or different positions in the same file, you'd place the cursor on the start of line 29 and type "ayy – named register a now stores Test REGISTER a.
In line 30 type "byy – named register b now stores Test REGISTER b and in line 31 type "cyy – named register c now stores Test REGISTER c.
To paste register a's content anywhere, place the cursor at the target position in the appropriate document and type "aP.
You guessed right … "bP to paste the content of register b and "cP to paste the register c stuff right where the cursor is.
Either copy and paste process happen in normal mode. p pastes after the cursor, P pastes before the cursor.
"a vs. "A
"ay} will yank a block of text from the cursors position until the next free line into the named register a.
The command will overwrite whatever might already be stored there from previous "a commands.
"Ay} will append the content form cursor position until next empty line to the named register a.
NOTE: 26 named registers is a lot. If you ever forget, what you've stored in which register .. :registers will fresh up your mind with a preview list.
To yank a line range into a named register use command mode like this: :350,355y a

The unnamed register

You've probably used registers in Vim already without even knowing it. Whenever you yank, delete or change something, the content get's stored in the unnamed register.
Whenever you paste something, using p or P, you're taking that content out of that register.

The ". register

You've probably used the dot before. The dot is simply repeating the last edit you've made in insert mode.
That edit is stored an ". and revealed by the . command.
Note: If you need to copy your last entry 3x, you could type ESC after the insert, then . . . or just 3.

Drop registers

The above registers are dedicated to the Vim internal use only.
To send content to the system clipboard the use of a drop register is required.
"+yy will yank the current line into the clipboard and make it available for CTRL v pasting in external applications.
:370,390y + will yank the specified line range into the clipboard.
"+y} will copy everything from the cursors position until the next empty line into the clipboard.
NOTE: It might be that the drop registers won't work in your current setup.
The reason is probably that the xterm_clipboard and clipboard features are not included in the Vim version of your distro.
To check that out use the :version command. Features included are marked with a + not included features with a -.
You have basically three options if you want to use the drop registers nevertheless:

  • compile Vim including those features
  • search and install a Vim version that already includes them
  • install neovim and use – which has those features activated by default

The colon register

The colom register ": will storte the last command executed in command mode.
You can repeat the last executed command by typing @ : in normal mode.
If you've typed a command and want it to place in your .vimrc or your documentation use ":P

Buffers and Windows

  • Buffer = text of a file in memory
  • Window = view on a buffer A buffer can still be open although it's currently not visible in the window.
    To display all opened buffers type :ls – to display the buffer with list index 3 in the window use :3b.
    You can of course run that command directly, if you already know which buffer number you'd like to show.
    :ball like buffer all will open all buffers in a splitted window.
    Switch back and forward between buffers with :bnext an:d :bprevious.
    Close the current buffer with :bdbuffer delete – or for example the 2nd buffer with :bd2 Add the keybindings map <C-H> :bprev<CR> and map <C-L> :bnext<CR> to your .vimrc to jump back and forward between buffers pressing CTRL h or CTRL l.
    Vim can have horizontal or vertical splitted windows. To move between those windows use CTRL w and then j, k, h or l, to move up, down, left and right.
    Open multiple files at once: :args ~/test/*.md will open all markdown files in the test directory.

Macros

Vim allows you to record any chain of actions you're performing and store that sequence into a register. That is called a macro.
To start recording. type qa in normal mode. Example, let's record a macro to out-comment multiple lines of bash code:

  • place the cursor on the first line of your code
  • type i to change int insert mode
  • type #, then SPACE
  • press ESC to switch back to normal mode
  • j to move down, 0 to jump to the beginning of the line
  • now it's time to end the recording, by pressing q

Still in normal mode type @a to fire the recorded macro, out-comment that line and jump down to the beginning of the next one.
You might think this could faster be repeated with the dot command and you're probably right if you'd had to do this for only a few lines.
The cool thing about macros is, that it's now stored in the register and you can re-use it any time also in other buffers.
You can as add a number to it: 25@qa will fire out a-register macro 25x times and so out-comment 25 lines in a row.
Those kinds of macros come especially in handy for repetitive formating tasks.
Note: Vim will redraw the screen every time a macro has been executed. That can take time if you're do a lot of iterations.
If you're using macros frequently, add set lazyredraw to your .vimrc.

Recursive macros

You can make a macro call itself to repeat the prior recorded steps.
In our example just add @ a at the end before completing recording with q.
A that way recorded macro would out-comment everything from the cursors position until the end of the file.

Macro combinations

Let's say you want our bash out-comment macro on all the lines in the file:
:g/^/ norm @a will do the trick. Expl: g/^/ (regex /^/ – every line), norm run in normal mode, @a the macro recorded in a.
:g/bla/ norm @a will out-comment each line containing the string bla.
:10,15 norm @a will out-comment line 10 until 15.
Visual mode comes in handy with macros. At the beginning of a block type v then } to mark until next empty line.
Then type :'<,'> will already be written at the command prompt. That refers to the visual mode selected areal.
Complete the command with norm @a so that the complete command looks like this: :'<,'>norm @a
In our example the whole block will now be out-commented with the hash sign.

Edit macros

You have the option to edit a macro to do some adjustments if you don't want to record it again.
We have stored our macro in register a, so to edit it, we need to paste it into an empty line.
"aP will show the macros content – now we can edit it. ESC and 0 when finished.
"ay$ will then yank the whole line back into the register and our updated macro is ready to use.

Mappings

Use the :nmap command to map a key or combination of keys to a specific command executed in normal mode.
:nmap vc :e ~/repos/github/linux/dotfiles/vimrc<cr> will open my .vimrc file when v then c is pressed.
When entered as a command, the mapping will last only for the active session. :nunmap vc will unmap the set vc mapping.
To use a mapping permanent, independent from the current session, add it into your .vimrc.
Use :h mapping and :h key-notation to learn all about mapping and which key can be mapped.
This table showing the commands to map / unmap keys in the different modes is copied from the mapping help:

Recursive Non-recursive Unmap Modes
:map :noremap unmap Normal, Visual, Select, Operator-pending
:nmap :nnoremap nunmap Normal
:vmap :vnoremap vunmap Visual and Select
:smap :snoremap sunmap Select
:xmap :xnoremap xunmap Visual
:omap :onoremap ounmap Operator-pending
:map! :noremap! unmap! Insert and Command-line
:imap :inoremap iunmap Insert
:lmap :lnoremap lunmap Insert, Command-line, Lang-Arg
:cmap :cnoremap cunmap Command-line
:tmap :tnoremap tunmap Terminal

Note: You can list all active mappings of a mode with the initial command.
:nmap will list all normal mode, :vmap all visual mode mappings, and so on …

Good resource on mapping:
Vim Drops
Vim Tips Wiki Mapping Tutorial Part 1
Vim Tips Wiki Mapping Tutorial Part 2
Vim Tips Wiki Mapping Tutorial Part 3

Folding

There is a brought variety of folding commands and setting options ind Vim.
Folding can be adjusted generally, file, programming language or custom syntax specific.
As I'm currently not a heavy folding user, I'll cover only some very basics here.
zfap will fold the paragraph on which the cursor is placed (no matter where it is placed.
l l or zo – with the cursor on the folded line – will unfold the paragraph.

Fold the line where the cursor is placed + the next 10 lines with zf10j.
zfa{ or zfa} will fold lines of code within curly brackets.
Move to the next / previous fold with zj and zk.
zR will close zM will open all folds in current buffer.
:fold will fold all lines currently marked in visual mode.

argdo vs bufdo

arglist :args = list of items included in the initial opening command (vim file1 file2 file3).
buffers list :buffers = list of all open buffers (arglist + subsequently opened files).
:argdo commands will affect only items from the arglist, :bufdo commands apply to everything in the biffers list.
Examples: :bufdo wq write and quit all buffers. :wqa applies the same on all buffers.

:bufdo exe ":norm G\"ap" | w will do the G command in normal, paste the content of register a and write all buffers.
:bufdo exe ":norm \@b" | w will execute the macro in register b on all buffers in the buffers list and write.
:argdo %s/Test/Toast/gc | update will go through the arglist and replace all occurrences of Test with Toast after confirmation.
:argdo %s/he/she/g | update will replace all he with she in all files of the arglist.
The above command could run into a problem – if a file doesn't contain the pattern he, an error would be thrown.
:argdo %s/he/she/ge | update would solve this and go over all arglist files without throwing an error if he ain't found in a file.

Auto completion

CTRL n will auto complete typed letters into words with matching patterns by looking forward in the file.
CTRL p will do the same by looking backwards in the file.
This method will only search for matching word pattern within the same file.
You can set up a dictionary file with the command set dictionary+=/path/to/dictionary.
While in insert mode, press CTRL x, then CTRL k to search the dictionary file for a matching pattern.
You can set a thesaurus file the same way: set thesaurus+=/path/to/thesaurus.
To use the thesaurus file on a word type CTRL x, then CTRL t in insert mode.
You can load existing dictionary and thesaurus files or use plugins as discussed on stackoverflow.

Templates – or how to load other files automatically into your buffer

Remember, you can load another files content into your current buffer with the read command :r.
:0r ~/test/string will load the file string and place its content at the top (below line 0).
:122r ~/test/string will do the same, but place the string file content below line 122.

If you want to use a template every time you create a file with a certain ending ..
.. let's say a basic Salesforce Apex class header like this:

/*
* ─────────────────────────────────────────────────────────────────────────────────────────────────┐
* CLASS NAME 
*
* DESCRIPTION
*
* ──────────────────────────────────────────────────────────────────────────────────────────────────
* @author         Heiko Krämer   <[email protected]>
* @created        2021-00-00
* ─────────────────────────────────────────────────────────────────────────────────────────────────┘
*/

It would be a good practice to create a template folder mkdir ~/.vim/templates.
There you could store all template files with the ending .tpl to better identify them.
In our example this would be apex.tpl.
You'd have to add :autocmd BufNewFile *.cls 0r ~/.vim/templates/apex.tpl to your .vimrc
If you then create a new Apex class with vim MyDemoClass.cls or :e MyDemoClass.cls, the header would be loaded.

Great Vim resources

vimtutor command to open an in vim integrated tutorial
rwxrob Linux beginner boost
rwxrob magic wands
mastering Vim book (here on Twitter)
Vim tips wiki
vimgenius
learn vim progressively

Repeat pattern vertically / horizontally

In normal mode, type 3O – Vim will switch to insert mode – type / / then ESC
Vim will horizontally repeat the pattern // vertically 3 times.

//
//
//

Again in normal mode, type 9a – Vim will switch to insert mode – type , SPACE then ESC
Vim will place 9 commas separated by spaces horizontally. , , , , , , , , ,

This trick works not only with single words in one line, but also with whole test blocks / patterns.


NEOVIM

Installing Neovim

Use sudo apt install neovim on Debian based distros.

Adopting your Vim configs

You can get Neovim up and running pretty fast, if you already have a good Vim config in place.
To do so, just created a directory nvim in your .config directory mkdir ~/.config/nvim.
Create the file init.vim within that directory touch ~/.config/nvim/init.vim.
Place the following three lines in it and save to adopt your Vim settings in Neovim:

set runtimepath^=~/.vim runtimepath+=~/.vim/after
let &packpath = &runtimepath
source ~/.vimrc