setting syntax folder from vimrc - vim

Is there a way to set my syntax directory in vim to be a different folder than $VIMRUNTIME/.vim/syntax? I am currently trying to use a different python syntax file from work but I cannot install it to the general directory and would instead like to install from my own user folder (in this case, it would be ~/.vim/syntax).

The ~/.vim directory should work by default, I think. Have you tried creating it and seeing if it picks up your syntax file?
Try putting your syntax file in ~/.vim/after/syntax/. I should run that syntax file after any other ones that it finds. This will also work for other folders, like ~/.vim/after/ftplugin.
Note: You may have to create the after folder if it doesn't exist.

Related

How to set RubyMine's default working directory to the executing .rb program's subdirectory?

In RubyMine, I have a project with many subfolders, each of which contains:
One or more standalone single-file executable Ruby programs (.rb files);
An input text file.
In older versions of RubyMine, when running one of the standalone executable programs (via Cmd+Shift+R on my Mac), the default folder in which RubyMine would look for the input file would be the same directory as the .rb file currently being executed -- which worked great.
The code used to read the file is something like:
data = File.readlines('input.txt')
However, after recently updating RubyMine to v2022.3.1, the behavior has changed, such that RubyMines now seems to be looking in the project's root directory for the file, instead of the same subdirectory as the .rb file currently being run. This produces the error:
in `readlines': No such file or directory # rb_sysopen - input.txt (Errno::ENOENT)
To correct this, I've been going into Run (menu) > Edit Configurations; and in the Edit Configurations dialog, in the configuration that RubyMine auto-created for the current executable file, changing the Working Directory value from the default of the project's root directory, to the subfolder of the current .rb file.
However, this above workaround is annoying, since I need to do it once each for every individual one of the many individual .rb executable files in my project.
My question: How can I configure my project and/or RubyMine itself to go back to the older behavior of defaulting a given .rb file to use its own directory as the default Working Directory, instead of the project's root directory?
(This question and/or its solution might also apply to other JetBrains IDEs such as IntelliJ, since they all seem to work similarly.)
The previous behaviour has been changed with https://youtrack.jetbrains.com/issue/RUBY-29236. So now yes, the logic is the following:
in case of no Ruby module, project's root will be used
in case of Rails, its home folder
otherwise the module's root
There is no option to change it in RubyMine but you can configure the configuration template using some variable there as Working directory.

vim: change pwd while working with cscope

I'm currently working on project using vim+cscope.
Sometimes, to make some code-exploring tasks easier I use :cd command to navigate to a specific folder withing the project. But then, if i want to issue some cscope command such as Ctrl-] or :cscope find it won't work before i change back to my project's root directory. I understand that's because cscope just tries to open the path as it is written in the cscope_db file without any sophistication.
So how do i make cscope "remember" my project's root directory so wherever i am it will always know to open the right path?
Apparently :set csre did that for me:
basename of cscope.out location (usually the project root directory) will be used as the prefix to construct an absolute path.
Due to some misconfiguration I missed it.

:vsplit autocomplete not working with /django/ directory in VIM

Normally if I type :vsplit /path/to/some/directoryTab, the available directories will autocomplete.
After doing a reinstall of VIM, there is one directory that now will not allow autocomplete, and I can't figure out why. The directory is ~/Sites/django/. Once I type ~/Sites/, Tab will show me drupal and apps directories, but will not show django. If my working directory is inside this django directory, :vsplit won't let me autocomplete either.
I did a ls -haltr on the directory and it looks the same as the others inside the ~/Sites/ directory.
Also, when I use the CtrlP plugin inside this directory, I get the error "==NO ENTRIES==". In other places, CtrlP works fine.
Why might this be happening and how can I fix it?
The directory is getting ignored because it has /django/ in it's path...which was set by my Python linter. The linter causes Vim to ignore /*django*/. To see this, use set wildignore to see what directories are getting ignored.
I just changed the directory to /dj/ and it works fine.
I could have also changed the wildignore directories by using set wig-=my_directory command.

When open vim, search a file down a tree structure and execute it if exists

I am new at using vim daily. I am doing my best to setup an good environment. I work a lot with Django projects. And I want to simulate a project like setup when I edit a file inside a django project.
Let's asume this directory structure:
/projects
/django-app1
manage.py
settings.py
.project
/django-app1
manage.py
settings.py
.project
What I want is place a file called .project that contains vim commands that will execute if I open any file whitin the directory structure
Why? Here is my vimrc https://github.com/mariocesar/dotfiles/blob/master/.vimrc#L151 you can see that I am using a snippet to load the virtualenv if it's exist on the enviroment variables, it's very cool but I don't think is efficient to do that every time I open a file, or even better add some extra paths to sys.path, as I have projects with a site-packages directories.
So:
How Can I detect a specific named file, looking down the current directory when open a file with vim?
How Can I execute this file as a vim script?
There exist several plugins named local_vimrc that fulfil your need. Here is mine.
BTW, your question is a duplicate of Vim: apply settings on files in directory
EDIT: Recent implementations of local_vimrc plugins use vim7 capabilities. Somehow, this is equivalent to:
source <c-r>=findfile('.local_vimrc',expand('<afile>').';')<cr>
(thanks sehe for reminding me of ';')
"Somehow", because, many important features are missing:
the possibility to source all files found, in the downward order.
the optional specification of a root directory pattern (like '$HOME\|/opt/projects/ for instance)
external paths like scp://, ftp://, http:// must be handled correctly (I haven't tested how they'd behave with findfile())
it should be possible to force the execution of the local vimrc(s) before a template-expander plugin triggers the expansion of a templare-file (the typical application is the generation of header-gates in C/C++ .h files)
Hence my preference for the full plugin way, and not just a one-liner that will irritate us from time to time.
NB: my plugin is very old, it's pre-vim7. As it works (recursively), I've never feel the need to rewrite it with the modern vim7 list manipulations functions.
When starting vim
I think
vim +'source **/.project'
should do the trick nicely.
If you have a recent bash, you could also more directly
vim -S **/.project
When loading a python file
To act when opening/loading a certain file:
autocmd BufReadPost *.py source %:h/**/.project
Loads any .project file found in the subtree containing the file being opened
autocmd BufReadPost *.py source %:h/.project
Loads any .project file found in precisely the same directory containing the file being opened
To remove the above auto commands (remember: adding the same command twice will execute them twice)
autocmd! BufReadPost *.py

Linux/Ubuntu directory location ~/.vim/syntax/

Where is the default location for the folder ~/.vim/syntax/ on a Linux system? I am trying to add a Python addon.
You are looking for the 'runtimepath' option. The documentation is pretty detailed (use :help runtimepath) but I'll try and summarize it here:
The runtimepath option contains a list of paths, separated by commas, where vim looks for plugins, syntax files, etc. On unix, the first path is $HOME/.vim/ (aka ~/.vim/), which means that Vim looks for syntax files in your home folder first before it looks anywhere else. Vim looks for your extra files by searching ~/.vim/plugin/*.vim or ~/.vim/syntax/*.vim, depending on what type of add-ons it is loading.
The next path in runtimepath is usually /usr/share/vim/. Vim will also search this folder for plugins etc (vim looks for /usr/share/vim/plugin/*.vim, etc). This folder is where you should put add-ons when you want them available to every user.
The last path in runtimepath is usually /usr/share/vim/vim72/, or whever Vim was installed to. This tells vim where to find and load add-ons which came bundled with that particular version of Vim.
Now, Most add-ons have a mechanism so that once they have been loaded from, say, your ~/.vim/syntax/ folder, they cannot be loaded from anywhere else. So even though syntax/python.vim comes bundled with Vim and is available in /usr/share/vim/vim72/syntax/python.vim, if an alternative version is instead loaded from ~/.vim/syntax/python.vim, then the bundled syntax is ignored. This is how you can override bundled add-ons using your ~/.vim/ folder, and you can also override them for everyone by putting addons in /usr/share/vim/. The other advantage of this setup is that you can always download the latest versions of the default bundled plugins without overriding any custom plugins you may have added.
If you were to put all your addons into /usr/share/vim/vim72/, you can no longer update to the latest bundled addons without overriding your custom addons, so you should be putting addons for yourself into ~/.vim/, or addons for all users into /usr/share/vim/, but never into /usr/share/vim/vim72/.
~ is a UNIX shortcut that means "the currently logged-in user's home folder", which is typically something like /users/<username>. You should be able to find that folder by executing
cd ~
mkdir -p .vim/syntax
cd .vim/syntax
The mkdir command creates the directory if it doesn't already exist.
If you want to add the syntax for multiple users, ire and curses is on a better track.
From the docs:
$VIMRUNTIME/syntax
On my (Ubuntu) machine, this is /usr/share/vim/vim72/syntax/.
/usr/share/vim/vim72/syntax/
I added the file in the above location and it is working for puppet scripting

Resources