rgroli / other.nvim Goto Github PK
View Code? Open in Web Editor NEWOpen alternative files for the current buffer
License: MIT License
Open alternative files for the current buffer
License: MIT License
I've been thinking of creating something similar for a while so I already love this plugin very much. Thank you!
However, at work for python projects we can have the following
module1.py
test_module1.py
or
module2.py
module2_test.py
and I was wondering if there was a way for the target mapping to accept different matching patterns with a regex or a list of patterns or something along these lines.
Thank you for this plugin.
This would be similar to the behavior of onOpenFile
, allowing users to handle the event themselves.
If I have multiple targets for one pattern, but the target files have the same file name, I cannot differentiate them in the file picker.
Example:
pattern: (.*)/views/(.*).html
targets: %1/models/%2.php, %1/controllers/%2.php
Directory structure:
views/
user.html
models/
user.php
controllers/
user.php
If I'm in the view and call :Other
, than I see a file picker with the following files:
user.php
user.php
So I don't know which file is the model and which one is the controller.
So an idea would be to define a name in the mapping like this:
{
pattern = "(.*)/views/(.*).html",
target = "%1/models/%2.php",
name = "Model"
},
{
pattern = "(.*)/views/(.*).html",
target = "%1/models/%2.php",
name = "Controller"
}
And the file picker could than use the name and show it next to the file like
user.php / Model
user.php / Controller
First off, fantastic plugin!
This should fit the bill for the issues I'm having with vim-projectionist and irregular folder patterns between like/other-files.
I was wondering if you had considered introducing the templating features of vim-projectionist?
Hi, first of all: awesome plugin!
I'm looking for a way to always open the file picker, even after I picked an alternate for a file but without having to clear the internal reference.
For example, I want to use the spec file of a certain Rails model as an alternate to quickly switch between them, but from time to time I want to pick the related controller.
Is there a way to do this?
Use case: I am editing a source code file and I want to create the test file that doesn't exist yet.
It would be handy if other.nvim would support creating the other file.
Thanks for this amazing plugin.
I would like to note that many rspec
users use spec
instead of test
folder and suffix.
It's well handled when going from a source file to a spec file, but the other way around isn't a default.
I added these mappings in order to make it work for me.
{
pattern = '(.+)/spec/(.*)/(.*)/(.*)_spec.rb',
target = {
{ context = "source", target = '%1/db/%3/%4.rb' },
{ context = "source", target = '%1/app/%3/%4.rb' },
{ context = "source", target = '%1/%3/%4.rb' },
},
},
{
pattern = '(.+)/spec/(.*)/(.*)_spec.rb',
target = {
{ context = "source", target = '%1/db/%2/%3.rb' },
{ context = "source", target = '%1/app/%2/%3.rb' },
{ context = "source", target = '%1/lib/%2/%3.rb' },
},
},
{
pattern = '(.+)/spec/(.*)/(.*)_(.*)_spec.rb',
target = {
{ context = "source", target = '%1/app/%4s/%3_%4.rb' },
},
}
I can create a PR if you're open to it
I have a question because I can't seem to get the plugin working and maybe I failed to understand how the matching is done.
This is currently my setup
require('other-nvim').setup {
mappings = {
{
pattern = '/foo/bar/v10/some-folder/(.*).ts$',
target = '/foo/bar/v10/tests/some-folder/%1.test.ts',
},
{
pattern = '/foo/bar/v10/tests/some-folder/(.*).test.ts$',
target = '/foo/bar/v10/some-folder/%1.ts',
},
},
}
These patterns are part of the absolute path of the file, which is how I understand that it should work. If I add a print
here
other.nvim/lua/other-nvim/init.lua
Line 43 in 71082fd
nil
but filename
here is an absolute path.
It only works if I match against (.*).ts$
which is of course not what I want to do.
I even ran this manually on the file outside
vim.pretty_print(
(
'/Users/ahmed/Some/deeply/nested/folder/structure/here/foo/bar/v10/some-folder/file.ts'
):match '/foo/bar/v10/some-folder/(.*).ts$'
)
And this also returns nil
, so I'm a bit confused about how it works.
Hi there, the plugin is very useful to navigate to the Python test file (in my use case).
I have created the following mapping for my Python files:
{
pattern = '(.*)/src/(.*)/(.*).py',
target = '%1/test/%2/test_%3.py',
context = 'test',
}
I was wondering if there's a way to go "back" to my main file (basically to alternate between them).
I know I can use [Neo]vim's built-in C-^
mapping for this, but it could really be useful if I can use this plugin to do that.
Hello! Apologies if this is documented somewhere, but I tried following the examples and did have much like trying to map the following for python -> python test files.
If we have a file with the following path:
my/code/files/foo.py
Then it should map to:
tests/my/code/files/test_foo.py
This is a fairly standard pattern in python projects.
However I am struggling getting other.nvim to match the "current" project directory generically.
I've tried the following:
require("other-nvim").setup({
-- [...]
mappings = {
-- custom mapping
{
pattern = "/(.*)/(.*).py$",
target = "/test/%1/test_%2.py",
context = "tests"
}
},
-- [...]
})
But I quickly realised this would map the example I gave you to /tests/absolute/path/to/project/my/code/files/test_foo.py
Is there a way to get other.nvim
to specify the "current directory" as part of the pattern and target configuration?
I am trying to use a pattern to find non-test files and point them to the test using the following configuration but it is not finding the file in the pattern:
{
context = "test",
pattern = "^(.*?)(?<!test).([^.]*?)$",
target = "%1.test.%2",
},
Besides opening as split and vertical split, what about open as tab?
btw: great plugin! using it for django
Broken out from #16 (comment)
--
Would it be possible to add configuration to make the selection window larger, so that one can see a bit more of the path?
Something like:
mappings = {
{ pattern ="...", target = "...", context = "...", shortcut = "x" }
}
This would make it very easy to quickly switch to another file when you have multiple targets.
Hey ๐๐พ
I'm very sorry if this is a duplicate, but I wonder if something like this is possible:
require('other-nvim').setup({
mappings = {
{
pattern = 'src/.*/(.*).ext',
target = 'test/.*/%2.spec.ext',
},
})
So I want it to be possible that these two files are matching:
src/some/path/specific-file-name.ext
test/a/different/path/specific-file-name.spec.ext
Is that somehow possible to achieve?
First of; many thanks for this plugin, I'm so glad that I have discovered this! I used to use the AltN8 plugin when I was on Intellij. Now that I'm back on (Neo)Vim again full-time this is a plugin that I've been missing!
For the feature request;
It would be great to have built-in mappings for a test
context for rails as well.
I have the following mappings below that lets you me jump from test
to src
in a rails app using Minitest. I'm sure some of the rules e.g. unit
ones could be expressed with fewer entries, but I wanted to make sure that I really get the expected files.
Maybe these could be a starter/inspiration for adding mappings for test files to the plugin built-in rails mappings. As another popular testing framework for Rails is rspec with different paths, maybe the plugin could provide two built-in mappings for the user to chose: "rails-minitest"
& "rails-rspec"
.
-- custom mappings: rails src->test
{
pattern = "/app/models/(.*).rb",
target = "/test/unit/models/%1_test.rb",
context = "test"
},
{
pattern = "/app/controllers/(.*).rb",
target = "/test/integration/%1_test.rb",
context = "test"
},
{
pattern = "/app/controllers/(.*).rb",
target = "/test/functional/%1_test.rb",
context = "test"
},
{
pattern = "/app/controllers/(.*).rb",
target = "/test/unit/controllers/%1_test.rb",
context = "test"
},
{
pattern = "/app/channels/(.*).rb",
target = "/test/channels/%1_test.rb",
context = "test"
},
{
pattern = "/app/mailers/(.*).rb",
target = "/test/unit/mailers/%1_test.rb",
context = "test"
},
{
pattern = "/app/serializers/(.*).rb",
target = "/test/unit/serializers/%1_test.rb",
context = "test"
},
{
pattern = "/app/services/(.*).rb",
target = "/test/unit/services/%1_test.rb",
context = "test"
},
{
pattern = "/app/workers/(.*).rb",
target = "/test/unit/workers/%1_test.rb",
context = "test"
},
{
pattern = "/lib/(.*).rb",
target = "/test/unit/lib/%1_test.rb",
context = "test"
},
-- custom mappings: rails test->src
{
pattern = "/test/unit/models/(.*)_test.rb",
target = "/app/models/%1.rb",
context = "src"
},
{
pattern = "/test/integration/(.*)_test.rb",
target = "/app/controllers/%1.rb",
context = "src"
},
{
pattern = "/test/functional/(.*)_test.rb",
target = "/app/controllers/%1.rb",
context = "src"
},
{
pattern = "/test/unit/controllers/(.*)_test.rb",
target = "/app/controllers/%1.rb",
context = "src"
},
{
pattern = "/test/channels/(.*)_test.rb",
target = "/app/channels/%1.rb",
context = "src"
},
{
pattern = "/test/unit/mailers/(.*)_test.rb",
target = "/app/mailers/%1.rb",
context = "src"
},
{
pattern = "/test/unit/serializers/(.*)_test.rb",
target = "/app/serializers/%1.rb",
context = "src"
},
{
pattern = "/test/unit/services/(.*)_test.rb",
target = "/app/services/%1.rb",
context = "src"
},
{
pattern = "/test/unit/workers/(.*)_test.rb",
target = "/app/workers/%1.rb",
context = "src"
},
{
pattern = "/test/unit/lib/(.*)_test.rb",
target = "/lib/%1.rb",
context = "src"
},
Not sure if I am doing something wrong with my mappings however it seems that "Other" is suggesting a forever repeating pattern of *.spec.ts
to *.spec.spec.ts
, etc... I've looked at the builtin golang mapping and tried to replicate it for my typescript project.
return {
"rgroli/other.nvim",
keys = {
{ "<leader>ll", "<cmd>:Other<CR>", desc = "Other: File" },
{ "<leader>lp", "<cmd>:OtherSplit<CR>", desc = "Other: Split" },
{ "<leader>lv", "<cmd>:OtherVSplit<CR>", desc = "Other: V Split" },
{ "<leader>lc", "<cmd>:OtherClear<CR>", desc = "Other: Clear" },
},
config = function()
require("other-nvim").setup({
mappings = {
{
pattern = "(.*).spec.ts$",
target = "%1.ts",
context = "implementation",
},
{
pattern = "(.*).ts$",
target = "%1.spec.ts",
context = "test",
},
},
})
end,
}
When using :Other
in a spec.ts
file, it suggests the following:
Obviously spec.spec.ts
is incorrect so how would I configure it to make sure this doesn't happen?
Could the mappings be "auto reversible" where if a pattern matches a target, then the target should also match the pattern?
Thanks in advance!
Hi, thanks for this useful small plugin.
So I have these two rules:
{
context = "lua main module",
pattern = ".*.lua$",
target = ".*/init.lua",
},
{
context = "file of same name, but in different directory",
pattern = ".*/(.-)$",
target = ".*/%1",
},
The first one should switch from any lua file to the main module. It works fine, and the pattern work as expected.
However, the second case does not work as expected, given a file foobar.lua
, it should switch to a different file with the same name, but in an (unspecified) other directory, for example:
pwd: ~/.config/nvim
# current
lua/foo/foobar.lua
# target
lua/baz/foobar.lua
Trying the pattern manually with vim.fn.expand("%"):match(".*/(.-)$")
gives the expected result of foobar.lua
, and then trying vim.fn.expand("%"):match(".*/foobar.lua$")
matches the target file.
I am not sure whether I am misunderstanding something here about how the patterns work in this plugin or whether this is a bug with the matching implementation of this plugin? ๐ค
I was looking to shift over to this plug from projectionist but nothing something weird related to path. When I trigger :Other
I see the full path on my machine:
And when opened, it shows the full path as seen in my airline plugin, as well:
Where normally it only shows the local path scoped to the repo I am working on, for example:
Is there any more info I can provide to debug this? I don't know that this is an issue, but annoying/distracting, thanks!
Not sure what I'm doing wrong here ๐ค Would appreciate any help here ๐
I'm trying trying to match /lib/app/entities/account.rb
to /lib/some/folders/repositories/account.rb
I tried this but it's not working, what am i missing?
{
pattern = "/lib/.*/(.*).rb",
target = "/lib/.*/repositories/%1.rb",
context = "repository",
},
First of all - thanks for creating this plugin. It is something I find very useful in my workflow as a FE developer.
I noticed it is a young project and thought I could give some suggestions for further development. I know that these may be only relevant to me, but hey it may be worth a shot.
To give some context - as a FE developer(React) I constantly have to switch between .tsx
and .scss
files. I have an issue though - I am working on a legacy code base and sometimes the styles file is .css
(and not .scss
). With that in mind here are my suggestions for further development:
Allow for the target to be regex. This would help when I just want the "other" file to be either .css
or .scss
. If both .css
and .scss
are present - show a file picker.
By default if the "other" file is not present it is being silently created. While this seems convenient, I guess having the option to disable this behaviour in the setup
function would be nice. For example if I have the plugin configured to not create the missing "other" file I would expect to see (ideally) a floating window which tells me the "other" file does not exist and asking me if I want to create it.
Thanks again for creating this plugin and keep up the good work!
It would be cool to have the possibility to define multiple targets for one pattern and also with different transformers:
{
pattern = "(.*).ts$",
targets = {
"%1.spec.ts",
{
target = "%1.html",
transformer = "camelToKebap"
}
}
}
{
pattern = "/lua/plugins.lua",
target = "/lua/plugin-config/(.*).lua",
},
I wonder if it is possible to show all the lua files in /lua/plugin-config/
when I am editing /lua/plugins.lua
?
In a c or project, often times you will find c or cpp files bearing the same name and path as a neighbor h or hpp file, respectively. I saw that there are builtin mappings, so I figured it would be nice to have one of those for c and cpp.
Currently, highlights are hard-coded to built-in highlight groups. This means users can't customize the appearance of the Other.nvim specifically, it might look quite bad:
It would be better if there were Other.nvim-specific highlight groups so that users could override them.
Sometimes you do not want to map a pattern for maybe a single file, and you just want to teach :Other
that the following file is the 'other' file that I always want you to open.
At the moment passing anything other than the context to :Other returns No 'other' file found
Would be nice to be able to do the following :Other my/new/file/path.rb
and the plugin will store that as the 'other' file for this current file. Now the next time I will just need to type :Other
and it'll open my/new/file/path.rb
Hi!
I found that the latest version of other.nvim does not work for my configuration.
I found that this happens after 6913629 commit.
How to reproduce
ex
โโโ +page.server.ts
โโโ +page.svelte
โโโ +page.ts
If I run OtherSplit
and the picker shows up, it would be nice to be able to press <Cr>
and open in a vsplit rather than in the current window. This doesn't seem possible currently, so I need to consciously remember to hit s
to open in a split, which I usually forget to do.
Perhaps a new open_file_default
action could be added which would use whatever openCommand Other was invoked with:
keybindings = {
['<Cr>'] = 'open_file_default()',
o = 'open_file()',
t = 'open_file_tabnew()',
v = 'open_file_vs()',
s = 'open_file_sp()',
},
The convention for Golang is to have the test file in the same directory as the source file, but with a _test.go
suffix. For example /some/dir/impl.go
-> /some/dir/impl_test.go
.
Thus it should be easy to add a built-in mapping preset for Golang to this plugin. I think it could be something as simple as
{
context = "test",
pattern = "(.*).go$",
target = "%1_test.go",
},
{
context = "implementation",
pattern = "(.*)_test.go$",
target = "%1.go",
},
At least it seems to work on the first usages!
I try to match all lua file wihtin workspace(just for experiment), but I got no match at all, which is weird. Can I use regex in target field?
{
pattern = "(.*).py",
target = ".*lua$"
}
I just built an similar plug telescope-switch.nvim based on telescope.
Thanks for your inspiration. ๐
I just noticed that when there are multiple other files and one selects with the pop-up menu, then the horizontal or vertical splits are not used but the selected other file opens in the current window. See video recording:
In this video I select "a" in the menu for both tries of the split commands.
The mappings seem like they could be represented in json. Do you think it'd be a good idea to look for something like .mappings.json
in the project root as a place to do custom mappings?
Hi @rgroli , thank you very much for this awesome plugin!
I'd like to contribute, but I've not contributed or set up a Lua project before.
If you can add a section on how to set up this project locally, how to run tests, and how to contribute, etc, that will help!
I am using other.nvim, and when the file path like this:
src/routes/[slug]/+page.js
src/routes/[slug]/+page.svelte
other.nvim does not recognize the relevant files.
Maybe regex problem?
I would like to build a function where i can ripgrep within both current file and list of other files. But this is not possible because findOther method is local. If you expose this method, this plugin will be more usable.
Great plugin! I really appreciate you've taken the time to write it.
Something I'd find very useful is if for Angular it also supported Services.
Essentially when inside of a *.service.ts
file, you'd have the option of :Other test
which takes you to the spec file.
And when inside of a *.service.spec.ts
file, you'd have the option of :Other service
(rather than component
).
Thanks again!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.