When I try to create a bookmark in NERDTree (win7 with emacs installed)
:Bookmark mybookmark
I get this:
E482: Can't create file C:\emacs\home/.NERDTreeBookmarks
NERDTree is trying to write the bookmark to "$HOME/.NERDTreeBookmarks" by default. This is how it looks like in the code:
call s:initVariable("g:NERDTreeBookmarksFile", expand('$HOME') . '/.NERDTreeBookmarks')
While it's possible that you've set the "g:NERDTreeBookmarksFile" variable somewhere in the configuration, it's a lot more likely that emacs has, for some reason, set your "HOME" environment variable to "C:\emacs\home". This explains the slash/backslash mixup as well. You can try two things:
Change the $HOME variable to your home dir, "C:\Users\your-username". A quick google turns up this guide for windows 7: http://www.itechtalk.com/thread3595.html
Just set the "g:NERDTreeBookmarksFile" variable to your home dir ("C:\Users\your-username").
I'd recommend the second option, since it's definitely going to work. You may need to escape the backslashes and spaces, but I can't be sure how at the moment. Try it out in all of these ways and see which one works for you:
let g:NERDTreeBookmarksFile = "C:\Users\Your\ Username"
let g:NERDTreeBookmarksFile = "C:\\Users\\Your\ Username"
let g:NERDTreeBookmarksFile = 'C:\Users\Your Username'
Related
This seems like a trivial thing to accomplish, but I'd like to run a lua script alongside a vimscript (in the same directory).
First I tried
luafile ./somefile.lua
which doesn't work. I looked up how to get the current vimscript's directory and tried
let s:path = fnamemodify(resolve(expand('<sfile>:p')), ':h')
let s:vglua = s:path . "/somefile.lua"
luafile s:vglua
which, unsurprisingly, results in
cannot open s:vglua: No such file or directory
I know I'm doing something stupid, but Vim's helpfiles are huge and I'm not seeing anything really helpful from my initial search queries.
How would I go about running a Lua script that's in the same directory as my vimscript?
Supposing s:vglua is correctly defined, you must:
execute "luafile " . s:vglua
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.
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.)
I have this line in my .vimrc file:
set directory=~/.vim/swapfiles//
(Note that one extra slash makes the directory names to be included instead of just file names to reduce conflict)
The above config works fine on my Linux machine, but the problem is when I use the same file on Windows I get some warning about the file cannot be read. That's probably because vim is looking for ~/.vim/swapfiles/ directory, which Windows unfortunately don't have.
Is there any way to store my swap files on Windows somewhere (better if it could be in C:\Program Files\Vim\vimfiles\)?
CASE #2
If you got answer for my above question, here is the another one. I also have some lines similar to this:
autocmd filetype python source ~/path/to/file/python.vim
Windows confuses at this point too. How can I patch up?
If you don't want to introduce a $MYVIM variable as ZyX suggests, maybe an alternative is placing the runtime files in $HOME/.vim instead of the default $HOME/vimfiles on Windows. You can then use ~/.vim/... everywhere. This also helps with synchronizing the files across multiple mixed-platform machines.
" On Windows, also use '.vim' instead of 'vimfiles'; this makes synchronization
" across (heterogeneous) systems easier.
if has('win32') || has('win64')
set runtimepath=$HOME/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$HOME/.vim/after
endif
Maybe what you want is to have directory set based on the entries in runtimepath? Try this:
let &directory = substitute(&rtp, ",", "/swapfiles//,", "g")
With the default runtimepath setting on Unix-y systems you get
$HOME/.vim/swapfiles//,
$VIM/vimfiles/swapfiles//,
$VIMRUNTIME/swapfiles//,
$VIM/vimruntime/after/swapfiles//,
$HOME/.vim/after//
and on Windows
$HOME/vimfiles/swapfiles//,
$VIM/vimfiles/swapfiles//,
$VIMRUNTIME/swapfiles//,
$VIM/vimfiles/after/swapfiles//,
$HOME/vimfiles/after/swapfiles//
I agree, the after directories are unwanted, but vim will pick the first directory that exists and allows file creation so if you don't create the swapfiles sub-directory they won't be touched.
You might want to consider prepending these to the default value instead of replacing it so the defaults are available as a fallback if none of the directories exist.
I don't understand why you have the auto commands you mention. The default settings of runtimepath with filetype plugin on should take care of that for you.
Of course you always have the option of explicitly checking the platform and using different settings as in
if has("win32")
" settings for windows
elif has("win32unix")
" settings for cygwin
elif has("unix")
" settings for unix
elif has("macunix")
" settings for macosx
endif
If you want to avoid an error if a file does not exist then you can use the following definitions in your vimrc
func! Source(file)
if filereadable(a:file)
exec "source " . fnameescape(a:file)
endif
endfunction
com! -nargs=1 -complete=file Source call Source(<f-args>)
and change source to Source when the file might not exist.
First of all, vim translates all forward slashes to backward on windows thus it won’t hurt having slashes. Just in case you think it can be a source of trouble.
Second, it is not impossible to have ~/.vim and all other directories on windows, just some programs don’t want to work with names that start with a dot. You may just add this to runtimepath as it is not there by default on windows and move all user configuration there.
Third, in most places you have a filename you may use $ENV_VAR. It includes setting &rtp, &directory and using :source. So the solution may be the following:
if has('win16') || has('win95') || has('win32') || has('win64')
let $MYVIM=$HOME.'/vimfiles'
else
let $MYVIM=$HOME.'/.vim'
endif
set directory=$MYVIM/swapfiles
autocmd FileType python :source $MYVIM/after/ftplugin/python.vim
(though I agree with #Geoff Reedy that there should be no need in using the last line).
And last, modifying and storing something in C:\Program Files is not the best idea, neither for you nor for the program itself (by the way, vim won’t modify or store something there unless you told it to). It is to be modified by installation, update and uninstallation processes, not by anything else.
I fully agree with Geoff Reedy that the autocmd shouldn't be necessary. In other cases, you can use :runtime instead of :source. It will automatically search all (user and system directories in 'runtimepath'.
I'm in windows XP, and the vim TagList plugin only behaves correctly if the file I'm coding in is inside the Ctag58 folder. Otherwise it just genetats a list of my open files without tags.
I've tried adding the catalog to path and the vim command :let Tlist_Ctags_Cmd='C:\Program\Ctags58\ctags.exe'
and it didn't work but then in.
I went through the the taglist FAQ:
But the last to "dots" of part 1. of the
http://vim-taglist.sourceforge.net/faq.html
were they speak of temp and tmp variables . I can't make heads or tails of that part.
Could this be my problem? How do i tell...
Mmmm the question is not exactly clear ('it just genetats the file catalog' -- sure, that makes sense).
Without looking any further I'd suggest you add the path to the ctags.exe executable to your environment (Win+Break, advanced, environment, current user, PATH, edit, append ;C:\Program Files\Wherever\ctags\bin (of course you'd have to use the ACTUAL path not this sample).
Then you'd need to restart VIM to test it