If you consider VSCode as a young, dynamic Saigon girl, Vim will look like a Hue girl, gentle and shy. The way of conquering will also be different. In this article I will talk about the route I used to flatter that Hue girl.
Vim is a code editor similar to Notepad ++, Sublime … Because each code editor has its own advantages and disadvantages, I will not go into the comparison of Vim with Notepad ++ or Sublime. The article is geared towards those who want and are looking to learn Vim.
The content of the article will include:
- What’s Vim good about?
- Well that’s fine but …
- How to approach Vim fastest?
- How did I setup Vim?
What’s Vim good about?
As far as I learn, people come to Vim because once they get acquainted, the speed of code with Vim is much faster than with other code editors. Actually, I see for devs, the code is a part, the main thing is still thinking. So getting a little faster coding doesn’t increase your performance much. Here are some of the benefits that I see “good” points of Vim:
- Light and strong. It is light because it is simple, strong because it can do all the actions like other code editors. Lightly, you will know when you download it at the homepage , and if you are healthy, I will talk about it in the next section.
- Supporting code on the server, this I think is the most advantageous point. Very suitable for you backends or devops.
- The plugin store is extremely complete and light: if you need colorful colors, highlight like vscode has vim-monokai-pro, want autocomplete to have coc-nvim, want to show the sidebar has nerdtree, want to comment the code with tpope / vim-commentary and much more, you can find it here vim-awesome.com .
- Bonus is another reason that the code with Vim is cool . Instead of having to use the mouse, you just need to manipulate the keyboard,
the tester sister or BA will look at it very admiring.
Well that’s fine but …
For those who are new to Vim, there are some problems as follows:
Difficult to use
This is definitely something that everyone switching to vim will encounter. When you are using the familiar VScode, open Terminal and type
<Enter> . And then what is this?
Why do people say it’s a text editor that can replace Vscode, so now
- How to import project?
- Where to run the command?
- Search files like?
- Auto complete like?
…. bewildered 1st time.
Still difficult to use
After getting familiar with vim by typing
vimtutor into the
terminal and following the instructions. You will continue to be confused which is a must to remember . All commands must remember, move the mouse pointer by which button, how to search, how to autocomplete? ….
There is only one bright spot for anyone reading this paragraph that I also start from someone who does not know anything about Vim, familiar with mouse operations, familiar with the plugin, but just
tab know the suggested functions. But I have found an approach to learning and am now completely switching to Vim.
Someone will wonder why I should try to learn what to do while being able to use VScode, easy to use, friendly. Then I will give you the last and most convincing reason:
How to approach Vim fastest
To learn the fastest, I will solve the disadvantages encountered when using Vim.
The default interface will only help us manipulate a file, so when we need to manipulate a project we will have trouble. However, the developers of Vim they already know this and released a plugin to support it.
So if you have trouble with Vim’s default interface, this might be solved. In the steps below I will talk about how to customize the interface of Vim. The results are as follows:
After customizing, you will have:
- File explorer next to
- Open files on multiple tabs
- Highlight code, highlight tag,
- The information about git ….
Look at this interface will definitely be more accessible, right
Next is learning the basic commands of Vim, this part is a lot of instructions. To start everyone can refer to the link: https://kipalog.com/posts/Lam-quen-VIM-trong-5-phut .
After the above article you will get the basic operations. After
bò , the quickest way to prepare for
đi is to delete the existing code editors. The downside is that in the next 1-2 weeks you will code more slowly. But then it will be different. Maybe you will code faster or you will reload VScode (your life, your choise). Should not be used in parallel because it is very frustrating quickly.
When I no longer have to both code and google search the command anymore, I recommend this tut: https://learnvimscriptthehardway.stevelosh.com/ (This is the work of the future, so we will use it later)
How did I setup Vim?
In this part, I will talk about how to set up Vim the most friendly. Link github for you who want to learn more. In this article I will talk about how to install and use NeoVim.
With the mac I am using will be pre-installed an editor is
vi . If you only look at the interface, it will not be much different, but do not understand that doing
vim is different.
How to install you can refer to the NeoVim homepage. Depending on the operating system, there are different ways to install.
After a successful installation, check it with the command
NeoVim’s current version is 0.4.4 and is still being upgraded.
Vim has an advantage that it is still updated after 30 years, developers also release custom plugins for each purpose. In this section we will install the
plugin for vim. All configuration files will be saved at
~/.config/nvim/init.vim , vim-bootstrap will assist you in creating this file quickly.
Go to vim-bootstrap and select the language you are coding, the interface you are most familiar with, then press the
Generate! . The file is saved in
Downloads . Then run the command:
mv ~/Downloads/generate.vim ~/.config/nvim/init.vim
Now just enter the command
then let vim do the rest
Vim & File explorer
We use NERDtree for directory and file display. To close / open the tree, press
F3 , to switch cursor between files and tree, press
F2 . This
.init.vim can be customized when you edit in
Actions on the directory tree:
- Use the
jkey to go down,
kto go up. This is similar to moving the cursor in the file.
<Enter>to close / open a folder or open a file.
mto display the options of NERDtree, for example:
ato create new file,
dto delete file …
After installing NERDtree you will be able to manipulate the files in the project without using the mouse.
Vim & terminal
As you may know, vim also has a built-in terminal from version 8.1. To use you open vim and enter
:term . Some tips can be viewed at https://www.youtube.com/watch?v=S6lK0437hQM .
Another popular plugin to use is the
floaterm . Installation instructions at https://github.com/voldikss/vim-floaterm
After installation, you should install some shortcuts when using. Mine is:
" Configuration example
let g:floaterm_keymap_new = '<F6>'
let g:floaterm_keymap_prev = '<F7>'
let g:floaterm_keymap_next = '<F8>'
let g:floaterm_keymap_toggle = '<F9>'
let g:floaterm_keymap_kill = '<F10>'
let g:floaterm_width = 0.8
let g:floaterm_height = 0.8
" Set floaterm window's background to black
hi Floaterm guibg=black
" Set floating window border line color to cyan, and background to orange
hi FloatermBorder guibg=orange guifg=cyan
The 3 important shortcuts are:
- F6 to create a new one
- F9 to hide
- F10 to kill
After installing floaterm, you will be able to operate the terminal right in vim with the buttons F6, F9.
Vim & dracula
Theme I often use when code Sublime or VScode is
dracula . And of course it’s supported on vim as well.
Installation instructions at https://draculatheme.com/vim
To list out the list, but the plugin is a lot, depending on the purpose of use, you install the appropriate plugin
Vim & more
Some of the features I often use are:
:e <tên file>to quickly open a file
- Once in the NERDtree directory tree: press
tto open the file in a new tab, press
sto open the file at and split the screen.
:Ag <tên >to search by name. Press
Ctrl+sto open the file in the two ways above.
Ctrl+Fto move the cursor quickly down.
Ctrl+Bto move the cursor quickly up.
ggfor top of page,
Gto bottom of page.
/<từ khoá>to search by keyword.
Like it or not, you have to admit that Vim is like a beautiful and difficult girl. The conquest of this girl was not overnight. Above I have given a
roadmap of me for your reference.
Wish you guys conquer this fastidious girl soon.