Lets get started!
To check whether Vim is installed:
-
Launch a Terminal Window
-
Type "vim"
If you're looking at the Vim splash page Then you're in luck!
Otherwise type:
Debian-Based Distributions:
sudo apt install vim
Arch-Based Distributions:
sudo pacman -S vim
Fedora-Based Distributions:
sudo dnf install vim-enhanced
Windows:
Go to: https://www.vim.org/download.php#pc
Download and install the "self-installing-executable"
No answer needed
Launch Vim
No answer needed
Modes
There are three basic modes in Vim:
- Command mode is where you can run commands. This is the default mode in which Vim starts up
- Insert mode is where you insert i.e. write the text
- Visual mode is where you visually select a bunch of text so that you can run a command/operation only on that part of the text.
- These form the pillars of navigating and using Vim. Try and answer the questions and work out how to begin creating a basic text document in Vim.
Navigation
Now that you know how to start creating a text document, you're going to need to know how to navigate it.
- left
- right
- up
- down
- jump to the start of a word
- jump to the end of a word Hint, focus on key clusters, not combinations of keys for this.
Inserting Text
Now you're comfortable in basic typing and navigating the document, lets get into using vim in a more powerful way!
The shortcuts for appending and inserting are crucial, I suggest trying to implement them into your typing routine so that they really stick.
FOR HELP WITH THE QUESTIONS
The easiest way to ask for help is to start with executing :help during a Vim session. This will drop us into the main help file which has an overview of the basics.
To get help with a specific command, we can provide that command as an argument to the :help command. By invoking :help gg, we learn more details about gg including that does the same thing and that by providing a [count], we can use gg to jump anywhere in a file.
i
typing
esc
h
l
k
j
w
e
i
I
a
A
o
No answer needed
Congratulations!
You can now type in, utilise functions of and move around in a Vim document! Congratulations. You're now an order of magnitude more capable than you were before! Remember, repetition is key so keep going!
Now lets learn how to exit vim...
There are six ways to exit vim, hold on, don't run away. They are:
write the file, but don't exit [equivalent to save] ^ as root write and quit [equivalent to save and exit] quit [fails if there is unsaved changes] force quit [will exit with unsaved changes] save and quit [all active tabs]
Guide
I suggest making a small learning directory, and writing a few small documents, in Vim of course, to test these out on- if you get stuck, there's the help guide outlined in the last task- or you can use google.
:w
:w !sudo tee %
:wq
:q
:q!
:wqa
Before we get going...
You're doing really well! Keep it up! With practice you'll be an extremely competent Vim user!
One of the most common usages for a text editor is to copy, cut and paste things in and out of the editor- knowing how to do this is essential to being able to collate and use text in Vim.
These questions will focus on three commands:
- cut
- copy
- paste Tackle these questions, and remember- once you've completed them keep practising!
Guide
I suggest making a small learning directory, and writing a few small documents, in Vim of course, to test these out on- if you get stuck, there's the help guide outlined in the last task- or you can use google.
yy
2yy
y$
p
P
dd
2dd
D
x
Onto one of the last key things about using Vim, finding and replacing patterns.
Keep going!
We can use Vim to search for any literal pattern in the text, allowing you to search through large text files with ease. As well as allowing for replacing of patterns, or just repeat characters / white space.
vimgrep
You can also use "vimgrep" to use grep inside vim, allowing you to search using grep syntax and regex if you so desire.
Guide
I suggest making a small learning directory, and writing a few small documents, in Vim of course, to test these out on- if you get stuck, there's the help guide outlined in the last task- or you can use google.
/pattern
?pattern
n
N
:%s/old/new/g
:vimgrep