Vim: The best text Editor for editing your files everywhere
June 9, 2016 ·
7 mins read
I was introduced to
vim
by one of the senior during my college. As soon as I found about it, I fell in love with it.
I liked the thinking of not moving your hand off the keyboard so I explored more about this. I used one of the great website of tech world called linux.com for the reference purpose.
Install vim on your machine
1. Install vim on your machine
2. Different Modes available in Vim
3. Moving around through the text in vim
4. Undoing and Redoing changes in vim
5. vim is slow while opening large files
6. How to check the time taken by plugins to while opening vim?
I installed this on my system by using the command.
2. Different Modes available in Vim
3. Moving around through the text in vim
4. Undoing and Redoing changes in vim
5. vim is slow while opening large files
6. How to check the time taken by plugins to while opening vim?
sudo apt-get install vim
vim
already installed on the machines.
You can use the following command to install vim on MAC.
brew install vim
Different Modes available in Vim
The first and foremost thing that one should read about is various modes present in vim. The major 4 modes present in vim are:- Command Mode
- Insert Mode
- Last-Line Mode
- Visual Mode
vim -v
:q
to quit this mode.
Whenever we open a file by placing a command
vim filename
j
to move the cursor one line down.( we will discuss more about the commands later.)
We can switch to the to insert mode by using i
key. Press i
key to open this mode. You can change anything in the document when you are in this mode.
The other mode is Last-Line mode which used for other purposes like saving the file.
You can simply use the visual mode by simply using v
while in the command mode.
Visual Mode can help you with copy-pasting the parts of the text.
Moving around through the text in vim
Most of the commands are used in command mode unless specified otherwise.Moving around the file is one of the main reason why would someone need to touch the touchpad or mouse. Vim tries to make it fairly easy for you to move around in the long and big files.
Jumping to a specific line number
:<line_number>
:500
Finding something specific in the file
/search_term
n
to find more instances of the same text.
Moving around
j
is for going down.k
is for going up.l
is for going right by one character.h
is for going left by one character.shift + g
is for going all the way to the last line of the file.$
is for going to the last character of the line.0
is for going to the first character of the line.w
is for jumping over the words.b
is for jumping over the words in opposite direction.
Undoing and Redoing changes in vim
You can simply useu
for undoing the changes and ctrl + r
to make redo the changes done.
vim is slow while opening large files
Vim is a good option to edit files of any size but as the size of the file increases, it becomes really slow to load the first screen of the vim. So, if you only want to read the file and don’t really want to make any changes, you can switch to some other alternatives which doesn’t load the full file in the memory and only loads the parts that are visible. (less
is one good alternative).
I tried to open one of the log file, with more than 20000 k
lines using vim
and less
commands to compare the time taken. It includes the time taken to open and close the files.
I used the time shell command to compare these time differences.
Time output while opening the file using vim
vim app.log 7.51s user 0.82s system 90% cpu 9.203 total
Time output while opening the file using less
less app.log 0.03s user 0.01s system 5% cpu 0.579 total
How to check the time taken by plugins to while opening vim?
As I have already shared that I have a lot of plugins installed for the local setup of vim which include things autocomplete and other features as well. I wanted to check how these plugins are performing while opening the files in vim. Here is the command which can be used for the purpose.vim --startuptime /dev/stdout +qall
times in msec
clock self+sourced self: sourced script
clock elapsed: other lines
1226.324 000.467 000.467: sourcing /Users/ranvir/.vim/plugged/vim-airline/autoload/airline/extensions/quickfix.vim
1227.984 001.364 001.364: sourcing /Users/ranvir/.vim/plugged/vim-airline/autoload/airline.vim
1229.092 000.466 000.466: sourcing /Users/ranvir/.vim/plugged/vim-airline/autoload/airline/extensions/netrw.vim
1230.380 000.636 000.636: sourcing /Users/ranvir/.vim/plugged/vim-airline/autoload/airline/extensions/term.vim
1231.202 000.555 000.555: sourcing /Users/ranvir/.vim/plugged/vim-airline/autoload/airline/extensions/hunks.vim
1232.213 000.679 000.679: sourcing /Users/ranvir/.vim/plugged/vim-airline/autoload/airline/extensions/branch.vim
1232.806 000.340 000.340: sourcing /Users/ranvir/.vim/plugged/vim-airline/autoload/airline/extensions/fugitiveline.vim
1233.603 000.519 000.519: sourcing /Users/ranvir/.vim/plugged/vim-airline/autoload/airline/extensions/whitespace.vim
1234.388 000.296 000.296: sourcing /Users/ranvir/.vim/plugged/vim-airline/autoload/airline/extensions/wordcount.vim
1235.492 000.881 000.881: sourcing /Users/ranvir/.vim/plugged/vim-airline/autoload/airline/extensions/tabline.vim
1235.966 000.261 000.261: sourcing /Users/ranvir/.vim/plugged/vim-airline/autoload/airline/extensions/tabline/autoshow.vim
1236.818 000.483 000.483: sourcing /Users/ranvir/.vim/plugged/vim-airline/autoload/airline/extensions/tabline/tabs.vim
1237.671 000.537 000.537: sourcing /Users/ranvir/.vim/plugged/vim-airline/autoload/airline/extensions/tabline/buffers.vim
1238.316 000.216 000.216: sourcing /Users/ranvir/.vim/plugged/vim-airline/autoload/airline/extensions/keymap.vim
1241.821 000.360 000.360: sourcing /Users/ranvir/.vim/plugged/vim-airline/autoload/airline/section.vim
1243.114 000.980 000.980: sourcing /Users/ranvir/.vim/plugged/vim-airline/autoload/airline/highlighter.vim
1247.465 000.286 000.286: sourcing /Users/ranvir/.vim/plugged/vim-airline/autoload/airline/themes.vim
1247.925 001.253 000.967: sourcing /Users/ranvir/.vim/plugged/vim-airline/autoload/airline/themes/dark.vim
1280.470 001.053 001.053: sourcing /Users/ranvir/.vim/plugged/vim-airline/autoload/airline/builder.vim
1281.347 000.326 000.326: sourcing /Users/ranvir/.vim/plugged/vim-airline/autoload/airline/extensions/default.vim
How to copy paste vim content to system clipboard
#vim
#bash
#productivity
September 12, 2017
2 mins read
Please share your Feedback:
Did you enjoy reading or think it can be improved? Don’t forget to leave your thoughts in the comments section below! If you liked this article, please share it with your friends, and read a few more!