Comments (5)
Indeed. The patch isn't complicated, but tedious to write : you need to gather all UTIs that Vim supports, and there's quite a bunch of them :-) Maybe this is something that MacVim already does and that could be borrowed from there tough.
from vim.
Actually, you can do it using generic types: public.source-code, public.plain-text, public.html, public.script and public.text seem to cover practically all the interesting cases.
Now there's the question of writing OpenURL, though...
from vim.
I think that is the solution to the problem:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Per Apple's documentation : Performs the specified selector on the application's main thread during that thread's next run loop cycle.
NSURL* url = nil;
if (launchOptions && launchOptions.count) {
// Someone asked us to restart the application
// Need to extract the URL to open
url = [launchOptions valueForKey:UIApplicationLaunchOptionsURLKey];
}
gui_ios.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
gui_ios.view_controller = [[VimViewController alloc] init];
gui_ios.window.rootViewController = gui_ios.view_controller;
[gui_ios.view_controller release];
[gui_ios.window makeKeyAndVisible];
[self performSelectorOnMainThread:@selector(_VimMain:) withObject:url waitUntilDone:NO];
return YES;
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation
{
if ([gui_ios.view_controller canBecomeFirstResponder]) {
NSString* urlString = url.absoluteString;
if (url.isFileURL) {
// Find "Documents/" in the urlString.
NSRange position = [urlString rangeOfString:@"Documents/"];
if (position.location == NSNotFound) return NO;
position.location += position.length;
position.length = [urlString length] - position.location;
NSString* fileName = [urlString substringWithRange:position];
char command[255];
sprintf(command, "tabedit %s", [fileName UTF8String]);
do_cmdline_cmd((char_u *)command);
command[0] = Ctrl_L;
command[1] = 0x0;
add_to_input_buf(command, 1);
return YES;
}
}
return NO;
}
- (void)_VimMain:(NSURL *)url {
NSString * vimPath = [[NSBundle mainBundle] resourcePath];
vim_setenv((char_u *)"VIM", (char_u *)[vimPath UTF8String]);
vim_setenv((char_u *)"VIMRUNTIME", (char_u *)[[vimPath stringByAppendingPathComponent:@"runtime"] UTF8String]);
NSArray * paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
if (paths.count > 0) {
vim_setenv((char_u *)"HOME", (char_u *)[[paths objectAtIndex:0] UTF8String]);
[[NSFileManager defaultManager] changeCurrentDirectoryPath:[paths objectAtIndex:0]];
}
char * argv[2] = { "vim", nil};
int numArgs = 1;
if (url && (url != nil) && (url.isFileURL)) {
// Need to find the file name
// Find "Documents/" in the urlString.
NSString* urlString = url.absoluteString;
NSRange position = [urlString rangeOfString:@"Documents/"];
if (position.location != NSNotFound) {
position.location += position.length;
position.length = [urlString length] - position.location;
char* fileName = [[urlString substringWithRange:position] UTF8String];
argv[1] = fileName;
numArgs += 1;
}
}
VimMain(numArgs, argv);
}
I had to rewrite OpenURL, didFinishLaunchingWithOptions and _VimMain (so that it can take a parameter).
Of course, you'll also need to edit the plist to add public.text and the other file types you want.
I have tested it, and it allows me to "open with Vim" all text files. Really useful.
from vim.
@N-Holzschuch make a pull request!
👍 👍
from vim.
Related to #6
from vim.
Related Issues (20)
- Strange behavior with accented characters HOT 1
- iPhone 5 support HOT 2
- space space HOT 4
- Implement a completely new custom keyboard replacing the system-provided one. HOT 12
- high ascii character bug HOT 2
- Vim Settings HOT 1
- Change Esc key from \ to ` by default HOT 4
- Development Plans? HOT 1
- Does vimtutor work HOT 1
- High-Ascii lost in right-left overrun
- Multi-character mappings no longer work HOT 5
- App Lidium link 404 HOT 3
- :set guifont=* doesn't list fonts HOT 7
- Allow default of fewer, larger lines? HOT 1
- Fonts or text are mangled and mostly unreadable HOT 5
- Release updated version on app store HOT 1
- Add a gesture or inputAccessoryView to map <Esc>
- Reading encrypted files hanging vim HOT 1
- Space doesn't work well
- Secure connection on website fails HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from vim.