Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Vimscript edits your Vimrc file


May 24, 2021 Vim


Table of contents


Before we move on to Vimscript, let's find a more convenient way to add a new map to the ~/.vimrc file.

Sometimes you're coding crazy and suddenly you find that a mapping will speed up your progress. You need to add it immediately ~/.vimrc prevent forgetting, but you don't want to exit the current file because the inspiration is fleeting.

The theme of this chapter is that you want to make editing files easier and easier.

It's a bit of a winding, but I didn't misspel it. Read it again.

The theme of this chapter is that you want to make ((editing files) easier).

Edit the map

We open the ~/.vimrc quickly edit the added map, and then exit the continue encoding. Run the command:

:nnoremap <leader>ev :vsplit $MYVIMRC<cr>

I call this command "Edit my vimrc file."

$MYVIMRC to specify a ~/.vimrc file. Don't worry now, believe me there will be no problem.

:vsplit opens a new portrait split screen. If you like a horizontal split screen, you can :split

Take a minute to fully understand the mapping command. T he purpose of the command is to open my ~/.vimrc H ow does it work? Is every character in the map essential?

By which mapping, you can open your ~/.vimrc As long as you use it a few more times, you can knock out the command in half a second.

When you're coding, it suddenly comes to the idea that a new map that can improve efficiency is going to be added to the ~/.vimrc file, and now it's a piece of cake for you.

Reread the mapping configuration

~/.vimrc file is not immediately effective. ~/.vimrc will only be read when you start Vim. That means you'll need to spell that complete command again in pain in the current session.

Let's add a map to solve this problem:

:nnoremap <leader>sv :source $MYVIMRC<cr>

I call this command "Reread my vimrc file."

source command tells Vim to read the specified file and execute it as Vimscript.

Now you can easily add new maps when coding.

  • <leader>ev profile.
  • Add a map.
  • Save the file and close the split screen to go back to the previous file using :wq<cr> or ZZ
  • Reread <leader>sv for the modification to take effect.

It takes 8 keystrokes to define a map. Reduces the likelihood of interruption of thinking.

Practice

Add ~/.vimrc file and review the "Edit ~/.vimrc and "Reread ~/.vimrc processes.

Practice a few more times and add meaningless maps at will.

Read: :help myvimrc .