Hi there, this is yet another how to tutorial that I wrote when bored again...
After reading this, you will be able to:
1. Use vim like a boss.
2. Stop using shit windows text editors.
3. Use Linux correctly like a G6.
5. Multitask like a pro, edit over 9000 files at the same time without much effort like in Notepad++.
Things to consider before diving in:
vim is "hard" but it's features are endless.
Download what you will need:
1. Install vim:
For Debian based users:
$ sudo apt-get install vim
Arch Linux users:
$ sudo pacman -S vim
Windows users can download a binary from Vim's download page: http://www.vim.org/download.php
2. Configure vim
3. Install git
Debian-based users:
$ sudo apt-get install git-core
Arch Linux users:
$ sudo pacman -S git
Windows users can download a binary from Git's website: http://git-scm.com/download/win
2. Install some useful vim plugins that will save you some time writing config files etc.
- Option 1, use a minimal one:
- Option 2, use a more advanced one:
WARNING: This one may be "bloated" as it may contain stuff you might not find useful. See also https://github.com/edubart/vimfiles for more information on stuff included.
Frequently used vim commands are:
1. ESC (command mode)
2. i (shortcut for INSERT)
3. :vsplit :split (Can only be used in command mode)
4. v (command mode - select text)
5. y (Yank selected text "copy it") - NOTE: This doesn't not copy to the X clipboard but the middle mouse button clipboard.
6. p (Paste text) - NOTE: this doesn't paste from clipboard. To paste from clipboard, use the middle mouse button.
7. u (undo last action) - This is infinite, you can undo as much as you want.
8. dd (cut current line, see also 6.)
9. :w (saves current file)
10. :q (quit vim)
- :q! (quit without saving changes)
- :wq (save & quit)
11. /<text> (searches for <text> in the current file).
12. :%s/<text>/<replacement>/ (searches for <text> and replaces with <replacement>).
Now, we can start.
I'll be using ~/vi_tut/ for the files i'm going to create with vim and edit.
$ cd ~/vi_tut
$ vim tut1.c
Which should hopefully, show something like this:
Now press i to go for INSERT mode, which should enable you to edit the file.
Now, you should write stuff in the file:
Save it:
1. first go command mode (press ESC)
2. type ":w" then enter.
Which should hopefully, show up something like so:
So now, you've learned how to create a new file etc. how to for example, compile the code when you're in vim?
simply go to the command mode (press ESC) and type:
:make tut1
Should output:
cc tut1.c -o tut1
Simple process isn't it? Now it's time to learn some epic multitasking.
Open some file or a directory. In my case I'll open a whole directory then open files from there.
$ vim vi_tut/
Enter command mode and type ":split <filename>" or "vsplit" any work:
If you're done with a file and want to close it, first make sure it's the selected one, i.e select some text in it using your mouse, then safely type ":q" or whatever, see FAQ #10.
Where to go from here?
Vim Tips Wiki best place to learn more about vim.
The Vim commands cheat sheet is a good table for vim commands and is straight forward.
Questions, feedback, etc... are always welcome.
After reading this, you will be able to:
1. Use vim like a boss.
2. Stop using shit windows text editors.
3. Use Linux correctly like a G6.
5. Multitask like a pro, edit over 9000 files at the same time without much effort like in Notepad++.
Things to consider before diving in:
vim is "hard" but it's features are endless.
Download what you will need:
1. Install vim:
For Debian based users:
$ sudo apt-get install vim
Arch Linux users:
$ sudo pacman -S vim
Windows users can download a binary from Vim's download page: http://www.vim.org/download.php
2. Configure vim
3. Install git
Debian-based users:
$ sudo apt-get install git-core
Arch Linux users:
$ sudo pacman -S git
Windows users can download a binary from Git's website: http://git-scm.com/download/win
2. Install some useful vim plugins that will save you some time writing config files etc.
- Option 1, use a minimal one:
Code:
git clone https://github.com/scrooloose/vimfiles.git ~/.vim
cd ~/.vim && git submodule init && git submodule update
ln -s ~/.vim/vimrc ~/.vimrc
WARNING: This one may be "bloated" as it may contain stuff you might not find useful. See also https://github.com/edubart/vimfiles for more information on stuff included.
Code:
git clone https://github.com/edubart/vimfiles.git ~/.vim
cd .vim && git submodule init && git submodule update
ln -s ~/.vim/vimrc ~/.vimrc
Frequently used vim commands are:
1. ESC (command mode)
2. i (shortcut for INSERT)
3. :vsplit :split (Can only be used in command mode)
4. v (command mode - select text)
5. y (Yank selected text "copy it") - NOTE: This doesn't not copy to the X clipboard but the middle mouse button clipboard.
6. p (Paste text) - NOTE: this doesn't paste from clipboard. To paste from clipboard, use the middle mouse button.
7. u (undo last action) - This is infinite, you can undo as much as you want.
8. dd (cut current line, see also 6.)
9. :w (saves current file)
10. :q (quit vim)
- :q! (quit without saving changes)
- :wq (save & quit)
11. /<text> (searches for <text> in the current file).
12. :%s/<text>/<replacement>/ (searches for <text> and replaces with <replacement>).
Now, we can start.
I'll be using ~/vi_tut/ for the files i'm going to create with vim and edit.
$ cd ~/vi_tut
$ vim tut1.c
Which should hopefully, show something like this:
Now press i to go for INSERT mode, which should enable you to edit the file.
Now, you should write stuff in the file:
Save it:
1. first go command mode (press ESC)
2. type ":w" then enter.
Which should hopefully, show up something like so:
So now, you've learned how to create a new file etc. how to for example, compile the code when you're in vim?
simply go to the command mode (press ESC) and type:
:make tut1
Should output:
cc tut1.c -o tut1
Simple process isn't it? Now it's time to learn some epic multitasking.
Open some file or a directory. In my case I'll open a whole directory then open files from there.
$ vim vi_tut/
Enter command mode and type ":split <filename>" or "vsplit" any work:
If you're done with a file and want to close it, first make sure it's the selected one, i.e select some text in it using your mouse, then safely type ":q" or whatever, see FAQ #10.
Where to go from here?
Vim Tips Wiki best place to learn more about vim.
The Vim commands cheat sheet is a good table for vim commands and is straight forward.
Questions, feedback, etc... are always welcome.
Last edited: