Silver Searcher: Excluding files in vimrc - vim

Is there a way to exclude files from an ag search by adding an array of files to the vimrc file?
Like with FuzzyFinder, file extensions are ignored by adding this:
let g:fuf_file_exclude = '\v\~$|\.o$|\.exe$|\.bak$|\.swp$|\.class$'
I actually just want to exclude my style.css as most of the time I want to locate a term in the scss working file and not the minified output in style.css.

ag will read in most VCS ignore files by default (see the --skip-vcs-ignores option -- you have to turn it off specifically). This means it will read .gitignore file (or .hgignore, or svn:ignore) in your project and ignore anything in there. Works well for my needs.
If you are having problems with compiled CSS files (or source maps, or the like) you might also want to configure your build scripts or whatever you use (grunt, gulp) to keep the .scss files in a /src directory and the .css files in /public (for instance) - and then add "public/" to .gitignore.

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 + ESLint: override the default .eslint file with a project-specific one

My Settings
I am using ESLint with vim. ESLint executable and options files (.eslintrc.js) are configured within ~/.vimrc:
let g:ale_javascript_eslint_executable="/usr/local/bin/eslint"
let g:ale_javascript_eslint_options="-c /Users/adam/team-standard/.eslintrc.js"
...
let g:ale_linters = {
\ 'javascript': ['eslint'],
\}
The team-default/.eslintrc.js is our team's standard coding style, based on a eslint-config-airbnb. It is kept in a shared github repository.
My Problem
Many GitHub projects have their own .eslintrc.js files. When I open a project with an .eslintrc.js file, I want the files within that project to be checked with the project's file, not with the default file.
In another words, I want vim to look for an .eslintrc.js file in the current file's directory hierarchy, take the one closest to the file, and revert to the default if none is found.
What Have I Tried
STFW
Looked at public .vimrc files with .eslintrc.js at github (example)
My Question
How can I configure vim, ale and ESLint to look for an .eslintrc.js file up the current js file directory hierarchy, and revert to a predefined file if none is found?
Following "Is there a way to specify a default eslint configuration file when using ALE plugin of Vim?"
The easy solution is placing the default configuration file at ~, either directly or by sym-linking, and removing the g:ale_javascript_eslint_options line from the configuration.
This way, ESLint will use the first .eslintrc.js file it finds down the directory hierarchy.

Including extra directories with Keter

I have a Yesod site and have created a handler for handling downloads and enforcing constraints. My Yesod project directory has a subdirectory called downloads, and it contains files I want the user to be able to download if they are logged in. The handler works great in my development and staging boxes, but breaks when I transfer to production. I tracked the problem down to yesod keter not archiving the files when it builds its bundle.
How do I convince keter to include the directory?
All the yesod keter command does is create a .tar.gz compressed archive file with the .keter extension containing the following subdirectories:
config: an exact copy of the identically named directory in your source tree
dist: contains a subdirectory bin containing your app's binary
static: an exact copy of the identically named directory in your source tree
Note that the path to your app's binary is set in config/keter.yml via the exec setting while the path to your static files is set via the root setting. The exact set of files included by the yesod keter command is specified in the findFiles function if you want to take a look at the source code.
If you want to customize the contents of your .keter file it is probably most straightforward to write a shell script to create the archive. With this script you can add arbitrary extra directories to the archive.
The bare minimum bash script you'd need to emulate the behaviour of yesod keter is as follows:
#!/bin/bash
tar cvf myapp.keter config/ dist/bin/ static/
You can customize this however you want to produce the correct content. Adding download/ to the end of this command line should do the trick.

Plugins in gVim not working

I need help in installing some of the popular plugins in Vim. I just started learning this editor and is very excited to use the popular plugins. I'm using gVim in Windows XP and have extracted the .vim files and copied them to the Program Files folder of Vim.
Inside my "F:\Program Files\Vim" folder, there are exactly two folders the "vim73" and the "vimfiles" folder. I put the .vim files (EasyMotion.vim) into the "plugin" folder inside the "vimfiles" folder.
When I run gVim, the plugins doesn't work, and in my case, the EasyMotion plugin is not working. I typed the "/w" to make the EasyMotion plugin work (as stated on its usage on its github account) and nothing seems to work.
Am I missing out something here? Are there extra commands to put in the vimrc file to recognize those plugins?
Cheers!
Never touch Program Files. There is a vim setting called 'runtimepath' (see the :help 'rtp') that says where Vim is going to locate the plugins. For each directory in the runtimepath, Vim will source every .vim file found in the plugin subfolder, and lookup for functions containing # in their names in the .vim files of the autoload folder. It will also lookup filetype plugins in the ftplugin folder when 'ft' is set.
Normally you should have %HOMEPATH%\Vim\vimfiles in your runtimepath (:echo &rtp to know). Unzip Easymotion there, NOT in Program Files.
Due to that structure, vim plugins mix up in the same 2-3 folders. However it is possible to install every plugin in its own subfolder if you play with runtimepath. The pathogen plugin is dedicated to that. It makes it possible to have every plugin in its own subfolder, and adds every plugin root folder to the runtimepath. The Readme is self-explanatory.
As #benoit said, you should never in general put files into your vim73 folder
(notable exceptions exist, but you'll know when you encounter them).
On windows, Vim searches for configuration files (those include _vimrc and your
plugins) in several directories, in a certain order. First it will look in
$HOME ... which is your c:\documents and settings\username\ folder
$VIM ... which is the folder where you installed or extracted Vim
$VIMRUNTIME ... which is your \vim73 folder ...
and so on ...
What this means? It means it will first look in $HOME before looking in let's
say, your Vim install folder. So it is a nice way of separating plugins which
you just want to test out before being sure you're gonna be keeping them.
For example, you could organize your Vim related files in this manner:
- install vim to c:\vim or c:\program files\vim\
(vim's program files will go in \...\vim\vim73\)
- put your _vimrc in \vim\
- put your vimfiles in \vim\vimfiles\
- and put your temporary vimfiles in c:\documents and settings\username\vimfiles\
That way when you're done with them, you can just delete that last
\username\vimfiles\ folder.

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

Resources