gist-vim: change token location - vim

I use gist-vim from mattn together with gVim. Works great and everything but I don't appreciate the auth token laying around in my home directory.
So I started looking around in the plugin files and found the variable called s:configfile which the dev sets to expand('~/.gist-vim').
Which makes me believe I can include let s:configfile = expand('~/some/other/path/gist-vim') in my vimrc to change the location of my token.
But it doesn't work. Is the devs command called again when I run :Gist, so my setting gets overwritten? Just thought I need to ask before I start forking and tinkering with the code.

The .gist-vim config file name is not open for customization.
You could ask the plugin author to make it customizable.
Why can't you set the variable in your vimrc though, you may want to know. First, you need to learn about Vim's variable name namespaces, documented at :h internal-variables.
Variables prefixed with s: are variables local to a script. See :h script-variable. Thus you cannot access those from your vimrc.

Related

goto-file (gf) prioritize directory instead of filename

I'm trying to configure gf to open files under the cursor.
It works always... almost.
I found an issue when the text under the cursor has unfortunately a corresponding directory. In that case, netrw plugin is opened.
Let me give you an example. I am in this code:
[...], MyObject myobject, [...]
I am over MyObject and press gf.
Unfortunately I have in a folder:
myobject <-- a directory
MyObject.java <-- the file to open
netrw is activated.
I tried to check doc to tinker a little bit (suffixesadd, ...), but probably I am missing how to do it properly.
I found this answer, but it is a little bit different in my opinion because in that case the match of the text and the directory were the only 1st one and it was perfect.
Any help?
P.S. what I am trying to do is creating a small vim plugin that could be used to navigate Java projects based on Maven (it's called vim-java-maven).
Just for learning VIM.
As silly as it may sound, Vim considers directories as valid targets so…
:help 'suffixesadd' doesn't help because the directory name is an exact match,
:help 'includeexpr', which is only invoked if there is no match, is not invoked since there is a match.
That behaviour is hardcoded and there is no way to affect it at runtime. The only solution is to write your own Gf() that handles directories more sensibly and map it to gf.

If you change a global variable in a vim plugin (python-mode) and reload it, isn’t it equivalent to just loading the .vimrc at startup?

Using Vim version: 7.4
In this line of the Python-mode documentation: https://github.com/python-mode/python-mode/blob/01c3131343aaa3c76f8cb656b5e9f54ac90ca04b/doc/pymode.txt#L234
it says that I can turn-on the variable (g:pymode_run) using
let g:pymode_run=1,
to run my python file using “:PymodeRun” or use it via ‘<leader>r’
If there is no modification to my Vimrc file, the default setting is:
let g:pymode_run=1
However, if the default setting in your vimrc file is
let g:pymode_run=0,
you load your .vimrc, and attempt to then change the variable using
let pymode_run=1 or let g:pymode_run=1 (both of this is equivalent, as we are dealing with the global variable here),
:PymodeRun doesn’t work.
If you do “:so ~/.vimrc” after changing let g:pymode_run=1, it doesn’t work either.
The only solution to this, that I found, is to change to “let g:pymode_run=1” in your ~/.vimrc, shutdown VIM and restart vim.
Then it works as expected.
Since pymode_run is a variable which determines whether :PymodeRun should run or not, shouldn’t changing the variable pymode_run from 0 to 1 in the current VIM session, also enable running :PymodeRun, withough having to reload VIM?
g:pymode_run seems to be used here, which means that the variable is used to decide if the command :PymodeRun (and related bindings) should be defined or not in the first place. In other words, it isn't checked when calling :PymodeRun, but is checked on editing python files. This is why setting the value afterwards doesn't work. This is probably because changing the option while editing is not expected (I don't see much rationale either).
As this variable is checked in ftplugin, I believe reloading the file (:ed %) suffices for let g:pymode_run=1 to take effect.

Showing NERDTree bookmark relative to project/directory

NERDTree keeps list of all bookmark in $HOME/.NERDTreeBookmarks file .When I hit B it show all entries from that file.So I tried having a local copy of this file with project specific bookmark but this does not work :(
Is there a way to see only project related bookmark in NERDTree ?
Here's what I use for git repo specific NERDTree bookmarks.
if isdirectory(expand(".git"))
let g:NERDTreeBookmarksFile = '.git/.nerdtree-bookmarks'
endif
Since there's no way to tell how a project directory is structured, it seems like the use of a shell environment variable is the easiest solution.
First, add path to your bookmarks:
export NERDTREE_BOOKMARKS="/full/path/.NERDTreeBookmarks"
Then add this to your ~/.vimrc or similar:
if !empty($NERDTREE_BOOKMARKS)
if filereadable($NERDTREE_BOOKMARKS)
let g:NERDTreeBookmarksFile = $NERDTREE_BOOKMARKS
endif
endif
Depending on how you develop, the use of environment variables may or may not be a suitable solution. I.e. if you open/close your shell all the time, or have a multitude of shells open at once.
A simpler alternative could be something like this, but it'll only work if you open vim/a file with vim in the directory the bookmarks are located.
if filereadable(".NERDTreeBookmarks")
let g:NERDTreeBookmarksFile = ".NERDTreeBookmarks"
endif
As timss already pointed out, the key setting is the g:NERDTreeBookmarksFile config variable. You need to find a way to manipulate that (global) setting depending on the project that is currently open. Using external environment variables is one solution; I would rather solve this with one of the local vimrc plugins that are available on vim.org; I use localrc.vim - Enable configuration file of each directory myself.
In each different project dir, you create a .local.vimrc script that sets the above variable to the project's bookmark file. (This only works reliably when you only ever open one project at a time in Vim.)

Making AutoComplPop search entire project (or open buffers)?

I started using AutoComplPop for automatic code completions. It works great on the single file I am editing, but if file1 is making a reference to a method defined in file2, it doesn't find it.
The docs don't specify if there is a way to make it search a whole project directory, or even just all open buffers, so I can't tell if this is simply not something the plugin does, or if I need to enable something.
I was testing it out on two Ruby files, if that's relevant. Thanks!
Looks like that the cause of the problem is that ACP set the complete option for its purposes to .,w,b,k (see line #125 in autocomplpop/plugin/acp.vim),
call l9#defineVariableDefault('g:acp_completeOption', '.,w,b,k')
while the default value that is used when pressing \<C-n> is .,w,b,u,t,i. And it appears that the very last letter i actually makes the difference: for some reason vim would not use word from an include file opened in a buffer to complete words in another buffer. So, b option is not enough, i must also be included. Adding the following line into my .vimrc helped
let g:acp_completeOption = '.,w,b,u,t,i'
At least it worked for C++ files, but I'm not sure it fixes the problem for the case of Ruby scripts.
Depending on what is on the left of the cursor, ACP (like all the alternatives) decides what completion mechanism to use.
But ACP only uses Vim's default completion mechanisms: if <C-x><C-o> and <C-n>/<C-p> don't provide what you are looking for, ACP won't help. Try them out first.
Oh cool, this plugin looks a lot like neocomplcache but maybe cleaner...looks a little old. Little concerning that there are so many open tickets on that project and no updates in two years.
Anyway, according to the documentation it doesn't...really...say. Very likely its one of the following things:
Your pwd. If the root directory for your source is some/path then that should also be your current working directory. Try typing :cd some/path to see if that makes a difference.
The runtime path rtp. See if adding the directory with your source files to &rtp does the trick.
The path. Same deal as the &rtp setting.
Very likely this plugin is just falling back on the built in ruby omni completion functions bundled with vim. Try help ft-ruby-omni.
I just had the same problem, and I actually found a solution for this.
Apparently you have to set in your .vimrc file the following:
let g:acp_behaviorKeywordCommand = "\<C-x>\<C-i>"
This will make acp look in every file included by your source for completions, as if you were actually typing <C-p>. However, it is slow, after trying it I decided to revert using <C-p> when there are no matches and default behaviour in the other cases.

vimscript using another file instead of .viminfo

I installed a vimscript written by expert in this question.
But there is one problem in the script. When I restart the computer, the bookmarks saved by the script will disappear.
Is it possible to store the bookmarks to another file (e.g. mybookmarks.txt) instead of .viminfo file? Bookmarks stored in .viminfo disappear unpredictably.
Yes. Use the 'viminfo n' option.
From :he 'viminfo':
Name of the viminfo file. The name must immediately follow
the 'n'. Must be the last one! If the "-i" argument was
given when starting Vim, that file name overrides the one
given here with 'viminfo'. Environment variables are expanded
when opening the file, not when setting the option.
Since it seems like a good tool in general, I extracted it to a plugin: http://www.vim.org/scripts/script.php?script_id=3826. This would store bookmarks only, regardless of viminfo settings, in ~/.vim_bookmarks. The filename is configurable by changing g:simple_bookmarks_filename.
Since it's a full blown plugin now, you can send bug reports on the issue tracker, so if it's not working quite right, let me know.
Cheers.

Resources