Vim: How to load a script after /usr/share/vim/gvimrc - vim

As I asked (and answered myself) in this question, some vim script is preventing the color scheme solarized.vim to load correctly. And I have found a workaround which is to load solarized.vim in or after /usr/share/vim/gvimrc.
However, even as a workaround it's not optimal, because I hope all my customization would reside in my ~/.vim directory (or at least my $HOME directory).
So here is my question:
How to load a script after /usr/share/vim/gvimrc?
Especially, If I can create a script solarized.vim, putting a single line colo solarized in it, and let it loaded after gvimrc.

The quick and easy way: create a ~/.gvimrc and put your commands in there.
If you want to keep everything in ~/.vim, however, you could try the suggestion from http://vimdoc.sourceforge.net/htmldoc/gui.html#gvimrc and something like this to your ~/.vim/vimrc file:
If you want some commands to be executed just after opening the
GUI window, use the |GUIEnter| autocommand event. Example:
:autocmd GUIEnter * colo solarized

Related

Opening a file via Vim on GIT

I'm following a tutorial on Uniswap forking (just to learn how this works) and I'm stuck a particular step.
How does one go from:
vim migrations/2_deploy_contracts.js
to
I'm only able to see:
How do I see the folders and directories ?
The user in that particular video is using the NERDTree plugin for Vim. Vim is very powerful and extensible, and it's possible to load a variety of extensions written in Vimscript to customize the interface, add editor features (such as LSP support), or various other functionality.
They're also using a custom colorscheme which is probably based on the Solarized palette. You can also load a custom colorscheme with the :colorscheme ex command.
There is another thing to notice, besides mentioned NerdTree plugin.
I think you are running your command from the wrong place.
vim migrations/2_deploy_contracts.js
This command tries to open the file set by relative path, or creates a new file, if that does not exist. As we see from your screenshots - the file exists in the tutorial, but it does not exist on your machine (the [+] mark after the filename on the second screenshot shows that).
My guess you need to cd to the right directory first (tutorial project root) and then only run your vim command to open the file.
As for your question about seeing the files and directories, you can do it without NerdTree plugin, using built-in netrw. Just type :Ex in vim normal mode.

vim snippet default snippet file issue

I installed Vundle, got the snippetMate running. But when vim launched, the snippet it loaded is _.snippets. With my Understanding, it is the default for snippet. However, i want to use other snippet such as sh.snippets and tex.snippets. I try to run the SnippetMateOpenFile in Vim to locate the snippets file It doesn't appear. I checked and see that all of the snippet file is there.
Yes, the _.snippets contains the global snippets. In order to use the other ones, the correct filetype has to be set. The snippet plugin reuses the same mechanism that Vim uses for syntax highlighting and settings (like indent) that are specific to a certain programming language. Usually, filetype detection works automatically; you can check with
:verbose setlocal filetype?
This needs to print sh for shell scripts, to use sh.snippets. If it doesn't, you have to fix / enable filetype detection (see :help filetype-detect), or, for a one-time fix, set it manually:
:setf sh
(I'm not sure about your particular snippet plugin; I guess it's snipMate, but there are multiple variants around.)
I found out what happened. the snippets won't recognize the snippet files rightaway. So i saved and exit the text and reopen vim again. It works, yet seems like there must be a certain tag in order for vim to recognize the format of the file.

How to execute a file everytime before opening Vim

I have recently started using vim and I really like it. I have added a few easy mappings in my vimrc file.
But the problem is I get to use a lot of remote machines a lot of time and I can't copy my vimrc on to them but most of the times I won't have enough permissions to do that.
So, I was wondering if there is any way I can put all my vim mappings in a file and tell vim to run it every time it loads, just like a vimrc?
The action that is "parsing" the .vimrc is called source.
In runtime, you can reapply/reparse your .vimrc by using
:source ~/.vimrc
So if you can somehow copy your .vimrc, even if not in your home, but a folder like /tmp you should be able to source it from there, with
:source /tmp/.vimrc
This question has more details and solutions.
One option would be to specify an alternative .vimrc file while launching the program.
The vim man pages has this to say about specifying a vimrc file:
-u {vimrc}
Use the commands in the file {vimrc} for initializations. All the other initializations are skipped. Use this
to edit a special kind of files. It can also be used to skip all
initializations by giving the name "NONE".
See ":help initialization" within vim for more details.
Note that this option overrides the default vimrc file, so you'll have to specify all of your settings/options in this file.
As was mentioned in another answer, you can place your custom vimrc file anywhere you want (or have access to) and then specify the the -u option with the path to your vimrc file.
You could even combine this method with managing your custom vimrc file in an online version control system (like github) - this way you will be able to wget your file from the web instead of having to manually copy it from machine to machine.

setting custom arguments in vimrc

I've tried looking everywhere for information on this but have come up short. I want to be able to use vimrc to set my own arguments for opening vim with. The idea being that if I run "vim -#code foo.bar" then the vimrc file will set syntax highlighting and line numbers but if run "vim foo.bar" then the file will open without line numbers or syntax highlighting. This seems like an obvious thing to want to do and I'm sure I've missed a trick somewhere but I'm struggling to get vim to play nicely. It seems silly to have to set a bash alias for this when the vimrc file is designed for this kind of thing.
My vimrc currently looks like this:
if $ARGV[0] == "#code"
set nu
filetype plugin on
syntax on
endif
I have a workaround for similar situation
I have special vimrc (.coding_vimrc)
wich loads usual vimrc inside
source .vimrc
and contains all special settings for coding
Run vim with
vim -u .coding_vimrc foo.bar
PS:
assumes full path in both cases

What's going on with vim-solarized's autoload/togglebg.vim script/keymapping?

So I just installed vim-colors-solarized (using Pathogen), and discovered in the documentation that it features a script called togglebg.vim that maps <F5> to a function to toggle the background between light and dark – but I can't work out how to enable the mapping when vim starts up.
This script is located under ~/.vim/bundle/vim-colors-solarized/autoload. (I did some reading and think I understand how autoload folders work.) It contains the following function call, which maps <F5> as mentioned above:
if !exists("no_plugin_maps") && !hasmapto('<Plug>ToggleBackground')
call togglebg#map("<F5>")
endif
Since it's in an autoload folder, vim does not source the script until something else (e.g., .vimrc) calls one of its functions. Thus, the code above is not sufficient to invoke the keymapping, because it is contained within the script itself.
I know there are ways to source the script:
Renaming the script's parent directory from autoload to plugin will force vim to source it on startup.
Adding a line to .vimrc with a call to togglebg#map() will also force vim to autoload the script.
But none of this is mentioned in the documentation, which was most certainly written by people who understand vim way better than I do. All the documentation says is this:
Solarized comes with Toggle Background, a simple plugin to switch between light and dark background modes and reset the colorscheme. This is most useful for colorschemes that support both light and dark modes and in terminals or gui vim windows where the background will be properly set.
Toggle Background can be accessed by:
...
* the default mapping of <F5>
...
Toggle Background starts with a default mapping to function key <F5>. If you
are already using this in a mapping, Toggle Background will not map itself to
a default and you will have to map it manually in your .vimrc file, or
remove/change your existing <F5> mapping to another value. To customize the
keyboard mapping in your .vimrc file, use the following line, changing the
<F5> value to the key or key combination you wish to use:
call togglebg#map("<F5>")
That last line implies that I only need to call togglebg#map() if I want to map the togglebg function to a key other than <F5>, and that the <F5> keybinding should be available on installation without any further mussing and fussing.
So what am I missing here? Is there a "proper" way to source this script and enable the 'default' <F5> mapping? Could it be that somebody moves the files around in the repo and forgot to update the documentation, or vice versa? Or am I supposed to suck it up and just make a function call from .vimrc?
EDIT
It's working all of a sudden. I don't know what I changed in my .vimrc file, if anything, but it definitely wasn't working at work yesterday (gVim on Windows), and it's definitely working at home now (also gVim on Windows, vimfiles folder synced via Dropbox).
But maybe I can amend this question: If this functionality is supposed to be available by default, why is the script placed in an autoload folder?

Resources