Vim is an advanced text editor for Linux and Unix operating systems. Recently rated the number one Linux publisher 1 around the world, Vim is open source and free. This post will show you how to create a great .vimrc profile.
What is it Push?
First, if new to vim: Welcome! You have just started the great journey of learning to be one of the best and most convenient editors in the world..
Bram Moolenaar creó I came, the much-loved Linux terminal-based editor, on 1991. came means I saw improved, Y vi
was the classic old school text editor for Unix, developed in 1976. Vim's popularity has increased a lot, and the publisher was recently named the number one Linux publisher worldwide by a major Linux forum. In general, Vim is also pre-installed as the default editor on many Linux distributions..
Vim enables users to edit files in two sets of modes, the Edit mode and the command way, so to speak, which will probably make navigating in Vim a challenge for new users. Users are likely used to being in edit mode in most other popular text editors (OpenOffice writer, etc.), but not in command mode. And command mode is the default mode in which Vim will start.
To give an example, if you open a file with Vim (using a command at your terminal prompt like vi my_story.txt
), will enter Vim in command mode. Now you can write the lyrics i
(a command vi) to enter edit (or specifically for this case insert) way (-- INSERT --
it will generally appear on the last line of the terminal to highlight the mode it is in) and start writing your test. When you finish, you press ESC
(escape key) to return to command mode.
You can then re-enter edit mode, as an example, tying a
(another command saw) to enter edit mode again (a
for this case it means to attach and the cursor will jump one character to the right when you enter edit mode using a
instead of i
). When I'm done with editing (which enables full editing capabilities like pressing cursor up/down
, cursor left/right
etc.) you can press the ESC
to return to command mode.
When you have finished editing the file in total, make sure you are in command mode (Press the button ESC
key again to make sure if you want) and type the key sequence :wq!
. This will write (w
) the file and exit (q
). If you have never used Vim before, well done! This was your first Vim session 😉
The Vim editor is one of the few editors with such a steep initial learning curve. Despite this, after the initial learning curve, knowledge of editor commands and their use continues to grow with a person over time in a more or less linear format. I write all my scripts, posts and data in Vim, using them in combination with AutoKey to easily insert my template and HTML tags where needed.
For more information about AutoKey, you can read our post AutoKey: How to replace characters with predefined text automatically in Linux.
Defining a large .vimrc profile
If you have previously used Vim on multiple Linux distributions, you may have noticed how some distros seem to fail when setting up a correct Vim profile, leading to some strange behavior when using Vim.
One of the things you can see (specifically in Mint 19 and some older versions of Ubuntu) is that when you press cursor right you must press another key for the cursor to truly jump, and this especially around the highlighted syntax / colored (and shell scripts, as an example). Another oddity is the strange behavior of mouse clicks or when using tabs..
If you see any of these oddities or similar, it's truly time to set up a great default .vimrc profile. The file / profile .vimrc contains all the settings that Vim will read and use every time it starts. Through the years of using Vim, and especially at the time when i logged an error for one of these weird behavior items, I made a short .vimrc profile that denies these issues.
the .vimrc
The file will be stored and should be stored in your home directory. Let's create the file using vim
itself. Note that in general you can use vi
to start vim
. First, we open the .vimrc
file in our home directory (which in Linux is represented by the tilde, In other words ~
, symbol) running:
vi ~/.vimrc
On the command line. This should bring the Push editor. Now press the i
to enter edit mode / insertion. One you see -- INSERT --
on the last line of your terminal (shown in most cases) knows it is in insert mode. Then copy and paste the text block below, and right-click on the terminal window where Push Is running. Then click Catch.
set nocompatible
colo torte
syntax on
set tabstop =2
set softtabstop =2
set shiftwidth =2
set expandtab
You should now see a screen similar to the next one:
If you generally use four spaces instead of two (for your coding work), just replace all =2
by =4
.
Now press ESC
to exit edit mode and, next, type the key sequence that was seen previously: :wq!
. This will write the file ~/.vimrc
and leave the Push editor. If you want to check the content of the file, can execute cat ~/.vimrc
on the command line.
The next time I log in Push, Vim will automatically load all these settings from your ~/.vimrc
proceedings.
At the same time to determine a nice color combination with the command colo torte
, we also activate syntax highlighting with syntax on
. We established some better tab width handling alternatives (in a general way indicating that we want two, or four as previously described, spaces like tabs).
Note that thetorte
The color scheme does not seem to be available in Linux Mint 20.1, even when it is enabled in some older versions of Mint. If this is applicable to your system, you will receive a message with the same effect. Just hit enter and edit~/.vimrc
to remove this line.
the set expandtab
option specifically ensures that each time we press tab instead, will automatically translate to spaces. You can remove this line if you don't like it (tip: use Push to do it and you can press dd
in a line, while in edit mode, to remove the entire line, even without entering edit mode).
Despite this, the most important option is the first line. the set nocompatible
ensures that several things, as previously described, work much better and without unclear behavior.
There is some discussion online about the perceived need not to configure this option as this setting is considered to be automatically enabled as soon as a .vimrc file is used, despite this, the setting will ensure that this setting is enabled and there is no negative result. side effect to set it [again]. In other words, there is a potential advantage to defining it hard-coded / static, while doing it has no drawbacks.
Ending
This post put Vim and Vi in historical context and described their popularity.. After that, We provide a short introduction to command and edit modes in Vim and discuss creating a ~/.vimrc
configuration file for Vim which will ensure a greatly improved Vim user experience by reconfiguring the width of the tabs, the configuration of the space, syntax highlighting, establishing a color scheme and, what is more important, avoid buggy Vim behavior / unclear on various Linux distributions.
Enjoy!