How do I get gvim/vim to open a file in a path with non-ascii characters? - vim

At first I had this path to one of my files in Windows:
C:\mine\NOTES
I renamed it such that the last part of the path i.e 'NOTES' had the U+2588 FULL BLOCK=solid
before and after it. I inserted the character using the key combination ALT+219(alt code) which is an extended ascii drawing character. I did this so that the folder could stand out from the 20 plus folders in the directory. At this point, I'm quite happy that it looks cool and does stand out. However, when the files in the folder using a text editor all hell breaks loose. These are the results when I try to open the file scheme_notes.scm in different editors:
path="C:\mine\&#brevbar NOTES &#brevbar"
(The solid character is rendered as a &#brevbar character instead of a solid block.
GVIM prints:
"path" [New directory]`
"path" E212: Can't open file for writing.
Python(IDLE) opens the file but does not display the contents which the file has and prints the following error when you try to run it(I know it's not a python file, I was testing)
IOError: [Errno 2] No such file or directory: 'C:\\mine\\\xa6 NOTES \xa6\\python_notes.py'
(The \xa6 is a &#brevbar character)
Pspad does not allow you to edit the file:
File has set attributes: Hidden ReadOnly System
Save Changes Made to File?`
Scite displays a dialog saying:
Cannot save under this name. Save under different name?
If you click yes, the dialog keeps popping up repeatedly. I had to kill the program using
powershell after there were 15 plus dialogs on the window.(and it hadn't stopped)
Jedit prints:
The following I/O operation could not be completed:
Cannot save: "path" (The system cannot find the path specified)
Netbeans:
Failed to set current directory to "path" The system cannot find the file
specified.
I want Vim to be able to open the file without resorting to renaming the folder. Does vim have a setting for opening paths with unicode characters?
I'm asking this because python was able to change to that directory when I did this:
import os
os.chdir(u"\u2588 NOTES \u2588")
os.listdir('.')`<br> `==> ['scheme_notes.scm','python_struff.py']

Related

How does File Explorer open files?

It's maybe stupid question, but what happens behind the scenes when i double click the word app, or .exe app?
For 'Non-Developer' it just opens the file in right environment after doubleclicking. But I would like to know, how is it done, how can the file manager know what to open? (.docx in word, .txt in texteditor,etc...)
+ I would like to know how can I do that in Node.js, is it the best way to use child_process and if statements for every suffixes?
There is a file association to tell Windows how to treat a certain file extension. You can type assoc in a Windows Command Prompt to see them. As an example:
C:\test>assoc .txt
.txt=txtfile
So Windows knows now, that the file with the extension .txt is a txtfile.
ftype defines, how that filetype is to be handled:
C:\test>ftype txtfile
txtfile=%SystemRoot%\system32\NOTEPAD.EXE %1
So whenever you doubleclick on a file, Windows checks if it is associated with any filetype. Then it looks up, how to handle that filetype and executes that command (in the example above, it opens Notepad with the filename as a parameter).
Both assoc and ftype are able to change the settings (for example to open .txt files with another editor). But if you try that, do yourself a favor and note the original settings, so you are able to revert your changes when needed.
The changes can also be done directly in the registry (not recommended, when you are not experienced in handling the registry)
For Node.js, you can use child_process to shell out to the start command which does similar things as the File Explorer.
E.g. start some/path/to/file.docx will open that file in the default program associated with the format.

How to avoid .pyc file listing in open File Dialog sublime text

i am trying to find if any possible configuration is available in sublime-text editor that can ignore the listing of *.pyc files in OPEN FILE DIALOG because,
its problematic and slow when Press Ctrl+O and type file name and its select file with *.pyc format. and we require to select next file to to open actual *.py file.
I tried file names in ascending order in Open file Dialog that lists *.py files first & *.pyc second. but i work with files mostly starts with a,x,y,w and that's why i require solution.
Sublime uses the underlying Open dialog of whatever operating system you're running it on, which means that it's technically up to the operating system in general to provide the capability to provide that kind of filtering.
If you're using Windows, you can change the file filter to Python, which will exclude *.pyc files. You can also enter *.py in the file name box and hit enter to get the dialog to show you only files with that extension.
On MacOS you can enter *.py in the search box in the top right of the open dialog to find files of that type. As far as I'm aware that's always going to search your whole Mac for files of that type and not just the folder that you're currently looking in, though (I don't use this particular feature of MacOS).
On Linux, well, that's going to depend on your Linux distribution in general. On my particular Linux machine, the dialog has a Search button that works similar to the one on MacOS, finding all files everywhere that match instead of just filtering the current location. Other distributions may have something similar to this or Windows.

How do configure Sublime Text to always convert to Unix line endings on save?

I want all files that I ever save in Sublime Text to be in Unix line ending format, even when I open files that were originally saved in a different format that I later edited in Sublime Text?
Simply setting "default_line_ending": "unix" is not enough, because that doesn't convert Windows files as I mentioned. How do I do that?
In SublimeText3 (possibly other versions) you can define this in your User Preferences.
On the menu bar open "Preferences -> Settings"
In the right window pane that opens you will find you are editing "Preferences.sublime-settings -- User". In that pane enter the following JSON formatted options:
{
// Determines what character(s) are used to terminate each line in new files.
// Valid values are 'system' (whatever the OS uses), 'windows' (CRLF) and
// 'unix' (LF only).
"default_line_ending": "unix",
// Display file encoding in the status bar
"show_encoding": true,
// Display line endings in the status bar
"show_line_endings": true
}
NOTE: I added a couple extra features here. One to tell you what format of file you are working with and that files encoding format. These will appear in the tool bar in the bottom of your ST3 application.
Here's a quick plugin to do the job:
import sublime_plugin
class SetUnixLineEndingsCommand(sublime_plugin.TextCommand):
def run(self, edit):
self.view.set_line_endings("unix")
class SetLineEndings(sublime_plugin.EventListener):
def on_pre_save(self, view):
view.run_command("set_unix_line_endings")
In Sublime, select Tools → Developer → New Plugin…. In the window that opens, delete everything that's there and replace it with the program above. Hit Save, and the save file dialog should open in your Packages/User directory, whose location varies by OS and type of install:
Linux: ~/.config/sublime-text-3/Packages
OS X: ~/Library/Application Support/Sublime Text 3/Packages
Windows Regular Install: C:\Users\YourUserName\AppData\Roaming\Sublime Text 3\Packages
Windows Portable Install: InstallationFolder\Sublime Text 3\Data\Packages
Save the file as set_unix_line_endings.py and it will activate immediately.
The plugin will only change the line endings of a file if you edit the contents and then save it. Just opening a file to view won't change anything.
If you no longer want the plugin active, just enter your Packages/User directory and either delete the file or change its suffix to something other than .py - set_unix_line_endings.py.bak works well for me.

How can I get a file or directory name from a file open dialog in PyQt4?

I am writing a PyQt4 application and one of the file types I wish to open is an Esri Grid format which, rather unusually, is a directory. I also wish to open other GIS filetypes that are just files (e.g. geotiffs). I can open these filetypes OK with the GDAL library by passing either a file or directory name and GDAL figures it out.
The problem I have is making the GUI. I want to open a file open dialog and get either a file name, or directory name. The problem is that the file dialog won't let me choose a directory - only files. I need the dialog to return a path to either. I've tried it on Mac and Linux.
I know PySide has a method called getExistingDirectory
http://pyside.github.io/docs/pyside/PySide/QtGui/QFileDialog.html
PyQt is basically the same, so it should have a similar method. http://pyqt.sourceforge.net/Docs/PyQt4/qfiledialog.html It is in the static methods section.
I think I've cracked it. This snippet tests the functionality I need:
dlg=QtGui.QFileDialog()
dlg.setFileMode(QtGui.QFileDialog.AnyFile);
e=dlg.exec_()
print dlg.selectedFiles()[0]
The solution was to set the file mode to 'AnyFile'. This allows the file dialog to return both directory and file names.

strange behavior saving a file with vim on Windows in a folder that requires elevated permission

I'm editing the apache2.conf configuration file under the 'C:\Program Files...' folder. This folder requires elevated permission ("Start program as administrator") for writing to anywhere on this folder.
Opening the file by mistake with vim without elevation - didn't show any warning. Moreover, I was able to save the file (':wq') just fine without any warning. Opening the file again with vim - showed me the modified file. However - no changes in the behavior of Apache (of course).
Trying to open the file with Notepad - show me the file was not modified.
Then, trying to open the file with vim from an elevated shell - I got the original file (just like notepad), but this time, I was able to edit the file, and save it.
I know have two versions of the file. The real file (shown by notepad, elevated shell, just 'type' and seen by apache httpd), and the file I edited and saved from an unelevated shell - stored somewhere (where???).
This is very uncomfortable, as sometime I open this file by mistake from a regular shell (even just for read).
What is going on? How do I exit this state?
I was hit by a Windows feature called "Virtual Store". Underneath the unaware application (that is, vim in this case), the OS running in compatibility mode will save the files in a folder named "Virtual Store", at this location: C:\Users\<login name>\AppData\Local\VirtualStore\.... The application will not be aware the file went there. Subsequent reads will read from that Virtual Store location.
It seems vim isn't UAC aware and it is running in compatibility mode - which could be fixed, but as for version 7.4 it hasn't.

Resources