Home Explore Blog CI



neovim

1st chunk of `runtime/doc/usr_05.txt`
f265c38ae635f778fd6060198ee33255ed03508c38852bcf0000000100000fa5
*usr_05.txt*	Nvim

		     VIM USER MANUAL - by Bram Moolenaar

			      Set your settings


Vim can be tuned to work like you want it to.  This chapter shows you how to
make Vim start with options set to different values.  Add plugins to extend
Vim's capabilities.  Or define your own macros.

|05.1|	The vimrc file
|05.2|	Example vimrc contents
|05.3|	Simple mappings
|05.4|	Adding a package
|05.5|	Adding a plugin
|05.6|	Adding a help file
|05.7|	The option window
|05.8|	Often used options

     Next chapter: |usr_06.txt|  Using syntax highlighting
 Previous chapter: |usr_04.txt|  Making small changes
Table of contents: |usr_toc.txt|

==============================================================================
*05.1*	The vimrc file				*vimrc-intro*

You probably got tired of typing commands that you use very often.  To start
Vim with all your favorite option settings and mappings, you write them in
what is called the init.vim file.  Vim executes the commands in this file when
it starts up.

If you already have a init.vim file (e.g., when your sysadmin has one setup
for you), you can edit it this way: >

	:edit $MYVIMRC

If you don't have a vimrc file yet, see |init.vim| to find out where you can
create a vimrc file.

This file is always used and is recommended:

	~/.config/nvim/init.vim         (Unix and OSX) ~
	~/AppData/Local/nvim/init.vim   (Windows) ~

The vimrc file can contain all the commands that you type after a colon.  The
simplest ones are for setting options.  For example, if you want Vim to always
start with the 'ignorecase' option on, add this line your vimrc file: >

	set ignorecase

For this new line to take effect you need to exit Vim and start it again.
Later you will learn how to do this without exiting Vim.

This chapter only explains the most basic items.  For more information on how
to write a Vim script file: |usr_41.txt|.

==============================================================================
*05.2*	Example vimrc contents                          *vimrc_example.vim*

In the first chapter was explained how to create a vimrc file. >

	:exe 'edit' stdpath('config').'/init.vim'

In this section we will explain the various commands that can be specified in
this file.  This will give you hints about how to set up your own preferences.
Not everything will be explained though.  Use the ":help" command to find out
more.
>
	set backup

This tells Vim to keep a backup copy of a file when overwriting it. The backup
file will have the same name as the original file with "~" added.  See |07.4|
>
	set history=50
<
Keep 50 commands and 50 search patterns in the history.  Use another number if
you want to remember fewer or more lines.
>
	map Q gq

This defines a key mapping.  More about that in the next section.  This
defines the "Q" command to do formatting with the "gq" operator. Otherwise the
"Q" command repeats the last recorded register.
>
	vnoremap _g y:exe "grep /" .. escape(@", '\\/') .. "/ *.c *.h"<CR>

This mapping yanks the visually selected text and searches for it in C files.
This is a complicated mapping.  You can see that mappings can be used to do
quite complicated things.  Still, it is just a sequence of commands that are
executed like you typed them.

							*vimrc-filetype*
>
	filetype plugin indent on

This switches on three very clever mechanisms:
1. Filetype detection.
   Whenever you start editing a file, Vim will try to figure out what kind of
   file this is.  When you edit "main.c", Vim will see the ".c" extension and
   recognize this as a "c" filetype.  When you edit a file that starts with
   "#!/bin/sh", Vim will recognize it as a "sh" filetype.
   The filetype detection is used for syntax highlighting and the other two
   items below.
   See |filetypes|.

2. Using filetype plugin files
   Many different filetypes are edited with different options.  For example,
   when you edit a "c" file, it's very useful to set the 'cindent' option to
   automatically indent the lines.  These commonly

Title: Customizing Vim: Configuration and Plugins
Summary
This chapter guides users on customizing Vim through the vimrc file, mappings, and plugins. It explains how to set options, add custom commands, and extend Vim's functionality to suit individual preferences. It covers creating and editing the init.vim file, providing example configurations, and introducing filetype-specific settings and plugins.