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.
Related
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.
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.
I'm using flake8 through syntastic in vim and I want a configuration file per project.
On the syntastic documentation it states that:
Depending on the checker, the filename of the corresponding
configuration file can be specified by setting either
g:syntastic_<filetype>_checker_file or
g:syntastic_<checker>_config_file. See the checker's documentation in
the wiki for the exact name.
The flake8 documentation says that .flake8 is a valid configuration file name. So I tried to place a valid flake8-configuration file called .flake8 in the root folder of my project. No luck.
I've also tried setting g:syntastic_flake8_config_file and g:syntastic_python_checker_file to .flake8 in my ~/.vimrc, still nothing.
What am I missing?
Just adding a .flake8 file to my working directory didn't work for me either.
But you can pass commandline options to syntastic checkers by setting the following option in your .vimrc:
let g:syntastic_LANGUAGE_CHECKER_args = 'ARGUMENT'
Flake8 accepts a --config=PATH flag to specify a config file, so in your case this would be:
let g:syntastic_python_flake8_args = '--config=PATH_TO_FLAKE8_CONFIG_FILE'
I've just downloaded the file pathogen.vim from vim.org
Where do I save this file so that it becomes part of gVim? In one of the runtimepath locations?
Does this .vim need to go in either of these locations?:
- C:\Program Files (x86)\Vim73\
- C:\Program Files (x86)\Vim\vimfiles\
You don't need pathogen to install plugins.
For the nth time this week, put your plugins into the C:\Users\username\vimfiles directory and your settings into the C:\Users\username\_vimrc file. You must create those directories/files yourself.
What you should have:
C:\Users\username\_vimrc
C:\Users\username\vimfiles\
C:\Users\username\vimfiles\autoload\
C:\Users\username\vimfiles\autoload\pathogen.vim
C:\Users\username\vimfiles\bundle\
Many Vim plugins have UNIX-oriented instructions and Vim itself is mostly UNIX-oriented so you'd better learn a thing or two about the UNIX command line.
If you are using windows, I recommend that you install your gVim into a custom directory instead of under Program Files or Program Files (x86) directories.
This makes things a lot easier going forward.
For instance, in a location like this:-
Install gvim in your user's home directory (e.g. C:\Users\whytheq\) (where whytheq is your user name) so it becomes C:\Users\whytheq\Vim73\.
Then, create a _vimrc file (with no file extension) there as well with the following contents:
set nocp
call pathogen#infect()
syntax on
filetype plugin indent on
Next, create a folder under C:\Users\whytheq\Vim73 called vimfiles with two subfolders beneath that, autoload and bundle.
Then, download the pathogen.vim file and moved it into the autoload folder.
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