Connect with us

Hi, what are you looking for?

Programming

Vim for new users and beginner

Vim For New Users And Beginner
Vim For New Users And Beginner

This writes for beginner vim, this article consists of basic commands, perfect plugins, themes, how to customize vim.

The operating system that will be used in this article is Kali Linux, but after installing a vim, you can follow the steps here on all operating systems.

Basic Edit Command For Beginner

Vim has 2 modes for the user, the first mode is command mode, you can control command, the second mode is Insert, shortly you can write text in this mode. If you press “i” you can open Insert mode, if you press “ESC” you can open command mode.

x = to delete a single character
u = to undo the last action you took
q! = used for close without saving
wq = used for close after saving
w = used to save the file
0 = used for pass to begin of line
dd = delete all in one line
p = to paste the saved item
G = for pass to end of file
gg = for pass to begin of file
/ = After typing / you can search for the word you will enter.
y = Used to copy
: = You can access other commands with “:”

Install Vundle and Simple Command

Now, we ready to learn simple commands for vim also going to install Vundle (package manager). We install all plugin with Vundle, so first we need Vundle (Package Manager)

If you are a windows user, you have to install git. You can install git from here. Linux users do not need to install.

git clone https://github.com/gmarik/Vundle.vim.git ~/.vim/bundle/Vundle.vim

After the installation is complete, we will start editing the .vimrc file, this file can be thought of as a file with all vim customizations. You can access the .vimrc file by typing in the search bar.

set nocompatible              " required
filetype off                  " required

" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()

" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')

" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'

" add all your plugins here (note older versions of Vundle
" used Bundle instead of Plugin)

" ...

" All of your Plugins must be added before the following line
call vundle#end()            " required
filetype plugin indent on    " required

Copy this code and paste the code in .vimrc then we will install the first plugin. We will use the “:” to install the plugins. You can start a plugin setup in vim by typing, “:PluginInstall“.

Customizing Vim

Now we will work on customizing vim and making it more useful. We will install many new plugins and get new themes, most importantly we will create new shortcuts.

Code Folding

We use code folding to compress your code, and it is very useful so you can turn large functions on or off. Likewise, add the following codes to the .vimrc file.

set foldmethod=indent
set foldlevel=99

nnoremap <space> za

With the help of these codes, you can turn on and off code folding by pressing the space key (works in command mode)

Plugin 'tmhedberg/SimpylFold'

Do not forget to use the “:PluginInstall” command to install this plugin will help you a lot in code folding.

Set UTF-8 Support

Now, many languages compile codes method to this order, so we will set this for us, we can set it with a very shortcode.

set encoding=utf-8
Auto-Complete

You can install it automatically by downloading the Kite application, it is a very useful automatic editor and supports many languages.

Themes

You can also install themes with the help of Vundle, vim offers many themes support. Let’s set up the spaceduck theme.

Plugin 'sheerun/vim-polyglot'
syntax on
File Browsing

If you are someone who works with more than one code file and you need to review a lot of files, NerdTree comes to help.

NerdTree provides you with a file explorer. After installation, you can add it by typing “:NERDTree” in vim.

Plugin 'scrooloose/nerdtree'
Plugin 'jistr/vim-nerdtree-tabs'
Split Layout

Programmer sometimes works with multiple files vim offers a great customization option for this now let’s set it up for those working with multiple windows.

set splitbelow
set splitright

nnoremap <C-J> <C-W><C-J>
nnoremap <C-K> <C-W><C-K>
nnoremap <C-L> <C-W><C-L>
nnoremap <C-H> <C-W><C-H>

Now you can navigate between windows with the help of keys like ctrl + h, ctrl + l.

Ctrl + H = pass right
Ctrl + L = pass left
Ctrl + J = pass down
Ctrl + K = pass up
Line Numbering

We find the resulting errors according to the line number, so it is important to number them, let’s do the numbering and adjust the color.

set nu
:highlight LineNr ctermfg=green
PowerLine

You can install this plugin to spice up your bars and make it more useful. It shows you which mode you are in with a colorful graphic. Use with NerdTree.

Plugin 'Lokaltog/powerline', {'rtp': 'powerline/bindings/vim/'}

There are many more add-on themes and commands on Vim. With your knowledge here, you can develop your own vim environment and continue your code journey with vim.

THANKS FOR READING!

Click to comment

Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like

Programming

This article is prepared to explain concepts that will be important for programming beginners such as data types, variables, heap and stack, and operators....

Programming

This article was created for those who want to use functional programming in their career or who are learning new programming paradigms. We will...

Programming

Functions are pieces of code that combine the integrity of the code used to perform a task into a single structure. If you are...

Programming

Computers can solve an event in different ways, we call these ways algorithms, each algorithm works differently from the others and has different processing...