How to extend the search of ctrl+p in sublime text - search

I want to have a universal folder from where I can just use ctrl+p(Quick-open files by name) and get that file.
For example the universal folder is here-> folder1/folder2/templates
and I am in suppose folder3/round-719.. so from here I want to use ctrl+P and then be able to access the files from ../templates
Note: I can use snippets, but according to my use, it isn't very effective. So, it would be good to have this sort of feature.

Related

How do I add items to a menu in Sublime 3?

I want to add a couple of items to the Edit menu in Sublime 3. In fact, I just want to copy the Find and the Replace menu items from the Find menu. Call me lazy, but I just want to use the same Alt-E menu shortcuts I've grown accustomed to across so many other programs. I don't like making the mental switch from Alt-E to Alt-I when I switch from Sublime to anything else.
Anyway, from the sublime documentation I read that I can create a file Main.sublime-menu in the Packages/Default (or Packages/User) directory. The JSON format is easy enough to follow. But the problem is that there is no such file by default. If I add one (and I did) then sumblime replaces the entire main menu, which is not the result I want.
I don't want to replace the entire menu, I just want to add two entries to the Edit menu. Ideally, I would like to copy & paste the Find and Replace entries from the Find menu. That would save me the time of figuring out the command names.
Resource files that ship with Sublime are stored in sublime-package files that exist in a special folder stored in the installation folder of Sublime (where the executable is), which keeps them safe from modification because Sublime will replace them wholesale when it updates.
You can view the content of any resource file currently known to Sublime by using the View Package File command from the command palette. It will show you a list of every resource, and you can filter the list the same as the command palette entries to drill down to find what you need:
Choosing an item from this list will open the file for you to look at. If it's coming from a sublime-package file, it will be a read-only buffer that you can't modify to remind you that you can't edit the file. Resources that come from your Packages folder directly will be editable, however (such as your User package).
The Default package is where things like the default settings, key bindings and menus are defined. So although what you see in the list depends on the packages you have installed, the item you want here is Default/Main.sublime-menu.
Note that if your intention is to just add some items, you want to put your modifications into your User package. Any items you add here will augment the existing menu; that is, you can only add items, you can't modify or remove them.
If you put the file into the Default package folder (which you may or may not have to create), the file you create will override the one that's provided inside of the sublime-package file. You would do this if you want to remove entries, change what command they execute, etc.
If you go that route, note that Sublime will use this file forever even if a future update modifies the file. In that case I would recommend the OverrideAudit package (disclaimer: I am the author of said package) as it will warn you when that happens.
If this is your intention, OverrideAudit's Create Override command will allow you to seamlessly open the file and save it to create the override, saving you the trouble of finding the right place to put the file.

Sublime Text 3 macro to open all files of certain type make some changes and save them?

I need to perform certain actions to each file and doing it manually would take a lot of time as there are manny files.
Automating this somehow would be very helpful.
Can this be done with Sublime Text 3?
Sublime macros cannot open or close groups of files, you would have to specify the exact filename of each file you want to manipulate. To do what you are asking would probably require a Python plugin instead. You can use its pattern-matching capabilities to open whatever you want (or just feed it a list of files), then it can execute API commands, built-in editor commands, or simply wait for you to make the changes manually before saving, closing, and moving on to the next file. Essentially, any Sublime menu option can be automated, and new commands built up using the API and pure Python.

Fuzzy file searching by directory?

I'm attempting to use RubyMine, but there's one feature that's consistently killing my productivity. I use this all the time in Sublime.
Say I have a hundred index.html.haml files strewn across my view folder. In Sublime Text 2, I can search for /app/views/orders/index.html.haml by hitting Cmd+t, typing "order index" and hitting enter.
But in RubyMine so far, you can't type order because directories aren't included in the search index. You can type "index.html.haml", but then I see all of the index views, and order is down around #80.
I also really prefer being able to type a portion of a file name, like the first letter of each matching file. Sublime Text 2 and PeepOpen allow you to do this easily; I'd love to have it in RubyMine.
TL:DR; Can you search for files by directories in RubyMine / IntelliJ?
I use the feature "Search in Everywhere" in RubyMine.
Here http://mrhaki.blogspot.ru/2014/02/search-for-anything-with-search.html description.

Opening the header file to a C/C++ source file with vim from multiple directories and multiple extension

First off, I was about to write a long list of if/else statements in vim and realized that 1) there was a better way to do what I was trying to do and 2) SO would be ripe with help on the subject. So! I have a variety of files spread about like
foo/src/file01.C
foo/src/file02.cc
foo/src/file03.c
foo/include/file01.hh
foo/include/file02.h
foo/include/file03.h
If you notice that the C/H, cc/hh, c/h extension may or may not match then you are keen and I'd like you to please help. I've look at things like the following vim scripts from the Vim wiki for "Easily switch between source and header file" and although I only dumped a few hours into a.vim without success, it doesn't seem that the others would work via the docs on that page. So can anyone help out on how to make this work?
A good lead I had was a quick How to Easily Switch between Header and Source topic, but still couldn't make it work.
I guess what I really want is how to avoid the multiple if statements and use real matching to do what I want. I want to look into another directory and if look for a header file of the same name with any familiar extension if it was a source C/C++ file, or look for a source file of any regular extension if it was a header file. Thanks for your help!
UPDATE: I specifically want to open the file in a new tab. I live on vim tabs!
I recommend using the FSwitch plugin. https://github.com/derekwyatt/vim-fswitch
This does exactly what you need out of the box. It is better than a.vim in more than one way, being a rewrite of the idea behind a.vim.
The link you posted presents it as a solution, too.
I have just installed it to my vim configuration and it does its job well.
Enjoy.
Just to make sure I was using the most current version, I downloaded the latest a.vim script (2.18) and copied it into my ~/.vim/plugin directory.
You can define certain variables in your ~/.vimrc file to get a.vim to recognize alternate file extensions.
To get the files in your example to match their alternates I added the following to my ~/.vimrc:
let g:alternateExtensions_C = "H,hh"
let g:alternateExtensions_hh = "C"
These are global variables that allow you to override what's already defined. You'll have to define
both relationships (they don't work both ways).
You can see what the current mappings are by typing:
:echo g:alternateExtensionsDict
If you need to define other mappings, follow the same pattern. What comes after the underscore is the file extension you're editing. What's in the double quotes is a comma-separated list of alternate extensions.
let g:alternateExtensions_<ext> = "<list,of,alt,ext>"
If you have a different directory structure, you can define what paths to search by overriding the g:alternateSearchPath variable. ../src and ../include are already included by default.
:echo g:alternateSearchPath
To open the alternate file in a new tab:
:AT
By the way, the a.vim script is pretty well documented. You might want to open it up and take a look. I found a setting or two that I didn't know about and I've been using it for years ;o)
I hope that helps.
IMO your best option is to adopt existing scripts to use :tabf instead of :e or whatever the scripts use right now to open the counterpart file. You can also try to make the change configurable and submit it to the script author. (I'm pretty sure many would find the enhancement useful.)
That reminded me of a trick I used very long time ago. Instead of guessing where the corresponding source/header files are, I have used at the top of file special comment containing relative path to the counterpart file. Switching was as simple as finding the special comment, extracting file name and opening it. Problem was similar to yours in that file extensions were not predictable. My rational solution was to stop guessing and denote counterparts explicitly in the source code. (This days I would have probably tried to put the relationship table into an external file with a standard name and look it up in VIM using the upward search.)
Two helpful things
:he 'path'
:he tabfind
So you would do
:set path=../,/usr/include/,/home/buildagent/SDKROOT/mysdk/inc
:tabfind error_codes.h
to open error_codes.h from somewhere exotic without having to specify it. Note how vim globbing is very very flexible, so you might not need mucht
:argadd ./**/*.[h,H] | tab sall
will open all header files under the current directory, regardless of how many levels deep. Be careful running this command on a large tree or with symlinks outside the tree

vim fuzzy finder subdirectory search?

Is there anyway to ask Fuzzy Finder plugin for VIM search subdirectory as well? It appears to me that no matter what mode I am in, it either search current directory, or I have to be explicit on subdirectory name for it to dive in.
Another plugin folks here mentioned in fuzzy finder textmate plugin. Unfortunately, this plugin doesn't work with current version of vim-fuzzy finder, or so it appears to me.
Any suggestions?
TIA
Oliver
Use ** to have it recurse down directories.
I use tag mode provided by fuzzyfinder to simulate behavior of Textmate. in short, generate an extra tags file with file's base name as tag, then you can locate any files in the tags file directly by file's base name.
The only drawback is you need to update the file tags file, this is a script for that.
I have been using this method for several months and it works almost perfect.
I summarize my method here
I wanted to contribute to jamessan's answer.
It is true that using **/ before your search will do a recursive search in your directory. However, I've found that it's more useful to have the recursive search enabled by default.
In order to do that, you can add ** to your mapping (mine is ]) (you have to escape the * otherwise it won't work)
map <leader>] :FuzzyFinderFile \*\*\/<CR>
Haven't used Textmate, but LustyExplorer could be what you're looking for. Demo here.

Resources