How To Make VIM A Perfect Code Editor ?

Programming & Tech

How To Make VIM A Perfect Code Editor ?

Can you make VIM a Perfect code editor ?, should you?

If you are using Linux or tried using WSL for your development but didn’t have the user interface to do so, we are here to help. Though i personally wouldn’t use this as my code editor because it doesn’t offer the extra features that i use often in VS2019.

It is still cool to use when needing to change a line of code or a connection string in your deployed project.

Basic Code Editor Functionality

We will be mostly customizing vim on the user level.

To edit vim we will modify the .vimrc file in the home directory

So let’s get started with basic functionality :

We first have to create the file using the following command :

touch .vimrc

though it would be ironic to modify the file with vim itself we won’t be doing that today.

Let’s add Syntax Highlights For supported languages *** though it will highlight everything *** :

echo "syntax on" >> .vimrc

Adding The auto Indentation :

echo "set autoindent" >> .vimrc
echo "set smartindent" >> .vimrc

Let’s display the number of Lines :

echo "set number" >> .vimrc

Let’s also enable mouse usage :

echo "set mouse=a" >> .vimrc

so far we have achieved basic text editor standard with a bit of highlights :

A Basic Code Editor ? or is it VIM

before we finish our basic editor setup we will add a theme :

first let’s create the following folders and let’s go into it:

mkdir -p .vim/colors ; cd .vim/colors

Then go to google and look for a good vim theme that you find nice and want to use. download the .vim file and put it in the colors folder.

curl >> gruvbox.vim

Go back to the home directory and add the theme to the file and use the dark theme one.

echo "colorscheme gruvbox" >> .vimrc
echo "set background=dark" >> .vimrc 

And There you go we now have a beautiful theme.

More Details

highlight the line you are in :

echo "set cursorline" >> .vimrc 
VIM + Theme

To Customize the search functions here are some commands :

While searching though a file incrementally highlight matching characters as you type.
set incsearch

" Ignore capital letters during search.
set ignorecase

" Override the ignorecase option if searching for capital letters.
" This will allow you to search specifically for capital letters.
set smartcase

" Show matching words during a search.
set showmatch

" Use highlighting when doing a search.
set hlsearch

Also to group long code files add this to the vimrc file :

augroup filetype_vim
    autocmd FileType vim setlocal foldmethod=marker
augroup END

For some very extensive customization you can check the freecodecamp post about this.

read more blogposts.

Tags: , , , , ,

Leave a Reply