📜 ⬆️ ⬇️

Customize the Vim start screen

Introduction


The Vim start screen contains only information on how to start reading the documentation for this editor and how to exit it correctly. After all, as you know, many tools have a steep entry curve, and Vim is also a steep exit curve. Those who have already learned to exit Vim will probably want to make the start screen more informative and useful. What we do.

Installation and Basic Setup


And help us in this plugin Startify .

I use Vundle to control Vim's plugins, so I added the following snippet to .vimrc:
')
Plugin 'mhinz/vim-startify' " Nice start screen 

When you start Vim without specifying files to open, this plugin shows the start screen, which lists the files that were recently edited, as well as Vim's sessions. You can also specify a list of files that will always be present (bookmarks or bookmarks):

image

To open a file it is now enough to dial a number, which is located next to the file in square dogs. A number of commands are also defined, for example:
e - create empty buffer
i - create empty buffer and switch to Insert-mode
q - exit Vim

To specify files for bookmarks, you need to register in .vimrc:

 let g:startify_bookmarks = ['~/.vimrc',] 

Additional settings


The plugin also allows you to specify the title of the start screen and the footer. The documentation gives as an example the use of the fortun and the cow:

 let g:startify_custom_header = map(split(system('fortune | cowsay'), '\n'), '" ". v:val') + ['',''] 

image

However, I do not quite like this option. First, fortuni can sometimes contain quite a few lines and, as a result, occupy almost the entire screen. Secondly, I want to have themed fortuni with tips on Vim. So I took the vim-fortun file from the vimtips-fortune project, put it in ~ / .vim / fortunes and formed a dat-file:

 strfile vimtips 

After that added the following line in .vimrc
 let g:startify_custom_header = \ map(split(system('fortune ~/.vim/fortunes | cowsay -W 60'), '\n'), '" ". v:val') + ['',''] 

Thus, we get a pretty good start screen:
image

I also started to make my fortune file with tips on the plugins I use.

Setting up a working directory


By default, the plug-in when opening a file sets Vim's working directory to the directory of the file being opened. Also, the plugin can be configured so that it switches to the root directory of the version control system of this project:

 let g:startify_change_to_vcs_root = 1 

Currently supported: git , hg , bzr , svn .

This behavior is also not always advisable. For example, in several of my projects there are subprojects written in python. These files are located in separate subdirectories. When opening such python files, it would be more logical to switch to this subdirectory, and not to the root git. To implement this functionality, I use the vim-rooter plugin , which also changes the working directory when opening a file. The plugin can specify a list of marker files to be searched. Since in my python-subdirectories the tags tags files are located, I added it to the list:

 let g:rooter_patterns = ['tags', '.git', '.git/'] 

Thus, with the help of the considered plug-ins, you can optimize the work with Vim.

In my .vimrc fragment with settings for vim-startify and vim-rooter:

 " Startify let g:startify_change_to_dir = 0 let g:startify_files_number = 8 let g:startify_bookmarks = ['~/.vimrc',] let g:startify_skiplist = ['vimrc',] let g:startify_custom_header = map(split(system('fortune ~/.vim/fortunes | cowsay -W 60'), '\n'), '" ". v:val') + ['',''] " Rooter let g:rooter_patterns = ['tags', '.git', '.git/'] 

I hope someone will find the information presented useful for themselves.

Source: https://habr.com/ru/post/239579/


All Articles