Vim, one of the oldest contestants in the text editor war, ever since its release in 1991. It has been a friend to many and a foe to many, wanna find out what it will be for you? Then, let's try it out! I have been using Vim for about a month and a half now, and I have been loving it (the first week was a bit painful though). In this article, I'll be discussing why to use Vim, how to set it up, and some basics of Vim. Why Use Vim? Now, don't fight with me, I am not comparing Vim with any other text editor. I am just telling you what Vim has to offer: - It means you have full control, some people even make it look like vscode (I personally like to keep it minimal though) Fully customizable - Well, in the beginning, your productivity would decline but as you start getting used to Vim and its keybindings, it will increase for sure Productivity (you can use a mouse though if you set the preference) - This may or may not be a good thing for you Keyboard-driven Looks cool Neovim Don't freak out if you haven't heard of Neovim, it's nothing scary. Neovim is just an implementation of Vim but more focused on extensions and plugins, a bit less customizable than Vim. Often people don't say they use Neovim, they just call it Vim. It really doesn't make much of a difference, just that Neovim has more support for plugins. Also, the default keybindings and commands for both are the same, so, if you learn Neovim keybindings you can as well use Vim. Installation Mac & Linux For Mac & Linux machines, do either of the following depending on your package manager: sudo apt install neovim or brew install neovim Vim (not Neovim) is installed by default on most Linux machines. You can run it by typing or . vi vim Just in case, you opened it right now without knowing the keybindings and are now freaking out, just type and press enter to exit. :q! Windows For Windows users, you have two options: You can use wsl (Windows Subsystem for Linux) and follow the same steps as for Linux systems. I won't go into details about installing wsl here. Use Powershell (not Windows Powershell), you can download it from the Microsoft store, and install Neovim using scoop (A package manager for windows): To install scoop, type the following into your terminal: winget install scoop winget is another package manager that comes pre-installed in windows nowadays. scoop install neovim If it tells you to install additional , do it too. buckets Close and reopen your terminal and you can open Neovim by typing . nvim Just in case, you opened it right now without knowing the keybindings and are now freaking out, just type and press enter to exit. :q! First Look This is how it looks right now: Right now that doesn't look very good, does it? Let's configure it! Configuration Now, there are many good pre-configured neovim setups out there like and , but I advise you to first at least try out your own configuration. I personally don't use the pre-configured ones, I prefer to use my own configuration. NvChad AstroNvim You will have to create a configuration file for neovim first. For Linux & Mac Users, the config file should be created at . ~/.config/nvim For Windows Users, the config file should be created at . ~/AppData/Local/nvim (In the above represents the home directory) ~ Open your terminal in your respective directories. Create the file, its name shall be . In this file, we will be using vimscript to write our configuration. init.vim : You can also use instead of , more about that towards the end, in this article I will be following with . Quick note init.lua init.vim init.vim Now, we are going to configure Neovim using Neovim (sounded pretty weird to me the first time). Basic Rules Go to the directory mentioned above inside your terminal, and type and press enter. nvim init.vim : If you just type without mentioning any file, it will open up something like a welcome page. If you type and does not already exist, Neovim will open it and if you save it the file will be created. The same rules apply to Vim too. Quick note nvim nvim file.md file.md Now, no need to click anything, forget you have a mouse, once that intimidating text editor is open in front of you, just press (no shift key, no ctrl key, just plain simple little ), this lets you enter insert mode. Now, you can edit your file normally. To exit insert mode or rather any mode in Vim in general, press the escape or ESC key, this doesn't exit the editor just returns you to normal mode (the default mode). i i You can also use arrow keys to navigate the file for now. : when in normal mode, to move left press 'h', to move right press 'l', to move up press 'k', and to move down press 'j'. Quick Note Before jumping on to plugins let's set up some basic rules/settings: set number " Sets line numbers set autoindent " Sets auto indentation set tabstop=2 " Sets tabstop set shiftwidth=2 " For proper indentation set smarttab " Affects how tab key presses are interpreted set softtabstop=2 " Control how many columns Vim uses when you hit tab key set mouse=a " This lets you use your mouse set wrap " Sets up line wrapping : If you don't understand what a certain setting does, just open Vim and in normal mode type, , for example for shiftwidth, do . Quick tip :help <property_name> :help shiftwidth Next, press the ESC key to exit insert mode. Now type (no need for clicking anywhere or pressing all those ctrl & shift keys) and press enter, this will write to the file (basically, it will save the file) and then exits the editor. :wq If you use just type , it just writes to the file, it doesn't exit the editor. :w If you use just type , it exits the editor, but it won't let you do that if you have unsaved changes, in that case, do , this will revert all unsaved changes and exit the editor forcefully. :q :q! If you want a property I haven't mentioned here, just search it up, I am sure you will find it. Let's set up the plugins now! Setting Up Plugins Now, there are a bunch of plugin managers (Vim/Neovim requires plugin managers to install plugins) out there but for this tutorial, we will stick with . vim-plug For Unix/Linux, you can install vim-plug with: sh -c 'curl -fLo "${XDG_DATA_HOME:-$HOME/.local/share}"/nvim/site/autoload/plug.vim --create-dirs \ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim' For Windows(Powershell), you can install vim-plug with: iwr -useb https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim |` ni "$(@($env:XDG_DATA_HOME, $env:LOCALAPPDATA)[$null -eq $env:XDG_DATA_HOME])/nvim-data/site/autoload/plug.vim" -Force Check out their install for more. instructions Now open in neovim again, and navigate to the end of the file, you can also use arrow keys, don't press this time, press , this will make a new line and enter you to insert mode. init.vim i o Now type in the following (after the basic rules): call plug#begin() " Your plugins go here call plug#end() : You can use to write single-line comments in vimscript. For example . Quick note " " This is a comment All our plugins will go in between the and . call plug#begin call plug#end Here are some of the plugins I use: - I will elaborate a bit more on this later coc.nvim - a plugin to let you show that you are using Vim on Discord presence.nvim - a light and configurable statusline/tabline plugin for Vim lightline.vim - a tree explorer plugin for vim, more about this later nerdtree - a plugin to show git status in nerdtree nerdtree-git-plugin - a plugin to show icons for your files vim-devicons - completes your parentheses, brackets and quotes auto-pairs - If you have GitHub Copilot, then you can use it with this plugin copilot.vim You can list your plugins like this: call plug#begin Plug 'neoclide/coc.nvim', {'branch': 'release'} Plug 'andweeb/presence.nvim' Plug 'itchyny/lightline.vim' Plug 'ryanoasis/vim-devicons' Plug 'preservim/nerdtree' | \ Plug 'Xuyuanp/nerdtree-git-plugin' Plug 'jiangmiao/auto-pairs' Plug 'copilot.vim' call plug#end : Always remember, before you install a plugin, do check out its docs before installing, because sometimes they may have special instructions on the setup for a plugin. Quick note Once it's done, save the file and exit Neovim (remember, use and press enter). Reopen Neovim. To install these plugins, type in normal mode and press enter. This will open another pane and start installing all the plugins, once it's done. Close the pane ( ), then close init.vim too. This exits Neovim, now, re-enter and all the plugins will start to work. :wq :PlugInstall :q : to move between panes, press ctrl+w, and then to move to the left pane and to move to the right pane Quick Tip h l & LSP coc.nvim What is LSP? Well, LSP (Language Service Provider) is the thing that gives you language support (language support in an editor means it points out your mistakes and offers suggestions while coding for a specific language). It is also built-in neovim since version 0.5. We won't be configuring the native LSP here, instead, we will use . coc.nvim What is coc.nvim ? is an ecosystem that builds beyond the native LSP, meaning you don't have to configure anything. It brings autocomplete suggestions and some other stuff. It's recommended for beginners as there is not much setup. We already installed earlier as a plugin. coc.nvim coc.nvim Well, with that out of the way, we can install the support of coc for our used languages. For example, if you want to install the support for python, just do . Most languages will have their support as coc-[language-name] but just to be sure you should just google it, you will easily find it. :CocInstall coc-python Keybindings Now, take a moment and feel proud, you have conquered a bit of the fear of vim. In vim/neovim, you can set up your own keybindings apart from the ones already there. For example, let's say I want to set up a keybinding for closing a file in Neovim. So, in general, I would have to type . :q To do that at the end of your file (after the ) add the following: init.vim call plug#end nnoremap <C-q> :q<CR> What does this mean? is a declaration that you are setting a keybinding, so you will have to put that before declaring any keybindings. nnoremap Here, in , the "C-" stands for the ctrl key, followed by whatever key you want to use in combination with it. For example, means ctrl+q and means ctrl+k. <C-q> <C-q> <C-k> In between, & is the command for which this key mapping is. <C-q> <CR> represents the enter key. So, means you have to press ctrl+q and it will be the same as typing and then pressing enter. <CR> nnoremap <C-q> :q<CR> :q Since, we installed plugins, like nerdtree, they brought their own commands for us, for example, now you have access to and . :NERDTreeToggle :CocInstall So here are some keybindings you can set up for nerdtree: nnoremap <leader>n :NERDTreeFocus<CR> nnoremap <C-n> :NERDTree<CR> nnoremap <C-t> :NERDTreeToggle<CR> nnoremap <C-f> :NERDTreeFind<CR> This keybinding is from their readme on their GitHub repo, but you are free to change it, you can make <C-n> to <C-e> if you prefer, whatever suits you. Just keep in my mind, not to have conflicting keybindings. You must be wondering though, what is that over there. That stands for , so is means you have to type and it will run command. <leader> \ nnoremap <leader>n :NERDTreeFocus<CR> :NERDTreeFocus NERDTree After setting up the keybindings for nerdtree, you can press, ctrl+t to open it up, you can navigate it just like you would a file with arrow key or [h, j, k, l] keys. To delete or rename a file, press , and it will open up a menu listing out how to do it. To create a file, navigate to the node you want it to be in, and then press to open up the menu. m m That about wraps it up. Themes You can install Themes the same way you did with plugins. You can search about the themes, there are many out there. I personally don't use any theme because my terminal's theme is good enough for me. Don't worry, I have listed some resources for you to find a good theme at the end of this article. Lua & Vimscript Earlier, I stated that you could have put your config in too. Many people prefer to use Lua because it's more logical than Vimscript. init.lua If you wish to convert your to , you can check out this by Olivier Roques. init.vim init.lua article Final look If you have followed everything in this article, your should look something like this now: init.vim " Basic Rules set number set autoindent set tabstop=2 set shiftwidth=2 set smarttab set softtabstop=2 set mouse=a set encoding=UTF-8 set wrap " Plugins call plug#begin Plug 'neoclide/coc.nvim', {'branch': 'release'} Plug 'andweeb/presence.nvim' Plug 'itchyny/lightline.vim' Plug 'ryanoasis/vim-devicons' Plug 'preservim/nerdtree' | \ Plug 'Xuyuanp/nerdtree-git-plugin' Plug 'jiangmiao/auto-pairs' Plug 'copilot.vim' call plug#end " Keymaps nnoremap <leader>n :NERDTreeFocus<CR> nnoremap <C-n> :NERDTree<CR> nnoremap <C-t> :NERDTreeToggle<CR> nnoremap <C-f> :NERDTreeFind<CR> This is how it looks now: Take a deep breath, and feel a sense of accomplishment, you are done. Now, go ahead experiment with it and make Vim your own. Common Commands in Vim - Save file :w - Close file :q - Force close file and revert unsaved changes :q! - Save and close the file :wq ESC key - Go back from any mode to normal mode i - Enter insert mode o - Next line and insert mode s - delete a character and insert dd - delete line Here is a from devhints. You can check it out for more commands. vim cheat sheet Some Tips Do not give up on Vim, at least try it for a week or two before deciding to throw it away. I know it's pretty annoying at first but a lot of people end up loving it after using it. Do not close Vim, don't exit the terminal without quitting Vim, can corrupt files sometimes Do not use ctrl+z, freezes my Vim for some reason You can use shell commands by prefixing things with ! Windows may not have some features that Linux will offer but you can install wsl. Increase your typing speed, it will help you out in general too. Use aliases for speeding up your development process. Practice. That's the best way to get used to Vim. Some Useful Tools Use a directory jumper, so you don't have to keep ing all the time. I use cd z You can use a terminal multiplexer for Linux and Mac devices. tmux is a famous one and the only one I know. Never heard of terminal multiplexers on Powershell though More Resources - A collection of wonderful neovim plugins & themes for you to try awesome-neovim - A wonderful community if you have any questions regarding Vim r/vim - Similar to r/vim r/neovim - The official documentation for Neovim neovim docs - The documentation for Vim vim docs - It lets you have more glyphs and font ligatures nerd fonts If someone wants to point out something that I missed or any other resource or just has doubts about something I wasn't able to explain properly, please comment down below. Hope you liked it! Also published . here