Modern IDEs and editors are slow. Pycharm and VSCode are some of my favorite ones to use but they didn't feel as fast as using Vim.
TLDR
We create remaps for easy save and exit.
All the information is at the bottom.
Part 1
In this post I'm going to remap saving and exiting in Vim. I will also give you a little bonus at the end for users who still prefer to use the mouse on occasion. At this point I’m assuming you have some familiarity with Vim and the .vimrc file but if not, feel free to ask me any questions.
I'll start off by making sure I have a leader key. The leader key is used to tell Vim that we are going to give it a sequence of button presses. I’m going to set my leader key as the space bar.
In your .vimrc or init.nvim (Neovim) add:
let mapleader = " "
So now that my leader key is set to the space bar, I can start to add my remaps.
On a Mac, to save a file in GUI programs you can do command + s. In Vim I’m going to do something similar. In the config file I will add the following:
nnoremap <leader>s :wr <CR>
So here we have a few things happening. I’ll explain what each section is doing.
nnoremap -
nnoremap is telling Vim to remap in normal mode.
<leader>s -
This is my space button (leader key) + the letter s.
:wr -
This how to save (write) in Vim.
<CR> -
This is the same as pressing return/enter. We need this to auto enter the full command at the end.
Now we can save the file by entering :wr in normal mode and to reflect the changes enter :source %. Now every time I press space + s it saves the file. To confirm if your file has been saved, you will see "written" in the bottom of the buffer.
Lets go ahead and knock out one more remap.
nnoremap <leader>q :q <CR>
This will remap space + q to quit the current buffer or exit Vim.
Now for the bonus part. Add the following to your config so you have the ability to do mouse movements.
set mouse=a
Having the mouse feature enabled will really help out users who are starting off with Vim.
That’s it!
I how you enjoyed this. If you have any question or feedback do let me know!
TLDR
Add this to your .vimrc or init.vim (Neovim) file.
nnoremap <leader>s :wr <CR>
nnoremap <leader>q :q <CR>
set mouse=a
My vimrc/neovim config.
Top comments (0)