Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Storing vim settings with a document

Tags:

vim

settings

Is there any way to save the state of vim settings with a document?

To clarify: I'm editing a document and I change a bunch of settings. I don't necessarily recall which; and I don't want to use these settings again, except for the current document. I don't want to manually try to remember what I've changed; or what the magic abbreviations are for the settings I've changed. I just want to have, say, for "mydoc.txt", a "mydoc.vim" file that puts me back where I left off, and the settings file would be saved automatically based on a vim setting, say, or maybe a ctrl-key does it before I exit. It would be handy if vim could automatically look for such a file.

And it would be preferable not to have to edit the settings into and out of the document itself.

like image 924
dkretz Avatar asked Nov 24 '08 05:11

dkretz


People also ask

Where are Vim settings stored?

A default Vim installation will feature a file containing Vim's core global settings called vimrc. This file will be located at either /etc/vim/vimrc or etc/vimrc , depending on your Linux distribution.

How do I permanently change Vim settings?

Enable the options for an individual file inside the Vim session using :set Open the desired file in Vim, type any option using the :set command in the Normal mode, and press Enter. 2. Enable the options permanently for all the files by specifying them in the local Vim configuration file ~/. vimrc.

What is a vimrc file?

Settings file used by Vim, a text editing program often used by source code developers and system administrators; saves the default settings for the editor when it is opened; allows users to customize options for the editor. VIMRC files are saved in a plain text format.


2 Answers

Yes, vim settings can be included within the document.

They are mostly found within comments, so they don't mess up the original file. An example for tab-specific settings is:

/* ex: set tabstop=8 expandtab: */ 

Note that this command works in most cases, however, servers are often setup without modeline turned on for security reasons. To turn on that feature add the following in your $HOME/.vimrc or the system $VIM/vimrc:

set modeline 
like image 149
ypnos Avatar answered Sep 22 '22 01:09

ypnos


You can use Vim's Session support:

:mksession 

you can later load this by either running vim -S Session.vim, or using source Session.vim

There are also vim addons to automate session loading/saving

like image 34
Hasturkun Avatar answered Sep 19 '22 01:09

Hasturkun