Can’t open a file whose directory’s name starting with # - vim

I am using gvim on Windows10.
I use gvim as a default text editor on my PC.
When I double click and open a .txt file which is in a directory starting with “#”
For example:
C:first/second/#third/text.txt
Then gvim opens up and throws E344.
It seems accessing a wrong directory:
C:first/second#third/text.txt
How can I avoid this error without changing the name of the directory?

Related

Sublime Text: How do I rename the Directory in which I'm editing?

I opened my folder called 'Tsunami++' in sublime text and I want to be able to rename it without having to close sublime text, open file explorer, find the folder, rename it, and open sublime again.
When I right-click the folder and select the rename option, type a new name, and hit enter, I get a quick 5 second message at the bottom that says
Unable to rename: [WinError 5] Access is denied: 'C:\\Users\\ramal\\Desktop\\Tsunami++' -> 'C:\\Users\\ramal\\Desktop\\Tsunami-plus-plus'
It says access is denied, shows the path to the directory, and what the path would be with the new name
I checked if the name was valid, and it was.
I checked if there was already a folder in my Desktop folder called Tsunami-plus-plus, and there wasn't, so it's not a matter of name validity or name collisions
My end goal is to be able to change the name of my current working directory within Sublime Text. How do I do this? What do I do to fix this error?
close Sublime Text
edit ~/Library/Application Support/Sublime Text/Local/Session.sublime_session by changing dir to dir2 (making sure you avoid errors there; do this at your own risk)
rename dir to dir2
re-open Sublime Text

Get full file location in AHK called from WSL

I have used alias subl='"/mnt/c/Program Files/Sublime Text 3/subl.exe"' and subl test.txt to open a file in sublime text. This opens up sublime text on windows, with the full file path.
When I try alias subl='"/mnt/c/Users/altar/Google Drive/Files/PC/Desktop/testasda.exe"' and have a script with
f=%1%
MsgBox, %f%
Then calling subl test.txt will only display test.txt. How would I get the complete path to the file, like sublime text does?
Rather than an alias try creating a file in /usr/bin called testasda (i assume /usr/bin is on your path in wsl). Then in the file put:
/mnt/c/Users/altar/Google\ Drive/Files/PC/Desktop/testasda.exe $(wslpath -w "$(pwd)/$1") &
This should open the second argument ($1) in the current path (pwd) using the application testasda.exe
wslpath is needed to convert from the wsl path to the dos path. This should be included in the wsl install (link)

How to make a new directory and a file in Vim

When using Vim as a text editor, is there a way to create new directories and files, while in text editor mode? Instead of going back to the command line and creating a new directory and file.
If you are in the file explorer mode, you can use:
d for creating a directory
% for creating a new file
You can get into the explorer mode with issuing a command :Sexplore or :Vexplore
There is no need to call external commands with !
Assuming you're running a shell, I would shell out for either of these commands. Enter command mode with Esc, and then:
:! touch new-file.txt
:! mkdir new-directory
A great plugin for these actions is vim-eunuch, which gives you syntactic sugar for shell commands. Here's the latter example, using vim-eunuch:
:Mdkir new-directory
Switch to file browsing mode
:Ex or if that is not working use :Explore
then press
d
and add the new directory name.
Assuming you just ran vim on new file in the directory that does not exist:
vim new_dir/new_file.txt
When you try :w you will get 'E212: Can't open file for writing'
To create new directory and file use this:
:!mkdir -p %:h
For the sake of completeness:
Shell out and use normal commands, such as :!mkdir my_dir and :!touch foo.txt (as mentioned in Jake's answer here) will create the directory and file in CURRENT working directory, which is the directory when you started your current vim process in the beginning, but NOT NECESSARILY the same directory of the file that you are currently editing, or the same directory that your :Explore explorer is currently viewing. When in doubt, always use :!pwd to check your current working directory first, and use relative path when necessary.
So if your project contains multiple sub-directories, a more convenient way is to:
type :Explore to enter the explorer mode first,
and then you can easily navigate to whatever sub-directory you like, by typing up-arrow or down-arrow (or j or k) to move cursor, typing Enter to enter a sub-directory, typing - to go up a level of directory. (Note that, all these navigation does NOT change your current working directory either);
Now you can type d to be prompted for a directory name, or type % to be prompted for a file name, and then they will be created in the directory currently shown on screen.
PS: These keys are actually mentioned in the built-in help F1.
Alternatively you can use :e . to get to explorer mode and then hit d .to create the new directory .Thought a shorter answer might be better

how to make cygwin build program in windows use windows path

I built and installed a program with cygwin in windows, but the program can not find windows style paths and must use /cygdrive
I just want to know how to spare this burden
The problem is this:
C:\Documents and Settings\Administrator>protoc -If:
f: warning: directory does not exist.
Missing input file.
C:\Documents and Settings\Administrator>protoc -I/cygdrive/f
Missing input file.
This is the common problem with windows stuff, it always uses spaces in paths. Two solutions:
1st. Open your cygwin (black one) terminal and type (I suppose you will be in your home directory):
cp /etc/dev/etc/skel/.bash* .
this will copy all the bash files you need to your current directory to "handle" your cygwin system. To know where you are in your cygwin (ie. the path to your current directory) type "pwd" (without the quotes) and press Enter (or Return for some people).
2nd. Open the .bashrc file already copied and type (I use "vi" editor for this but you can use "pico" which is a bit easier):
alias C="C:\Documents\ and\ Settings\Administrator"
save the .bashrc ("Ctrl+X" in pico I think, and :wq in "vi") and close the terminal. After restarting this console, typing "C" and pressing enter will send you automatically to "C:\Documents and Settings\Administrator"
To know which alias you have, just type "alias" in your terminal and all your alias will show up.
HTH,

how to make a file editable in linux without becoming root

i am working with files placed in directory /etc/asterisk using vim editor, every time i have to do some editing i have to go to terminal to become root and opens file in vim editor and performs edition,but if i do it by directly opening the file from such directory(/etc/asterisk) in gedit and perform edition in the file but it doesn't show the save option if save as option is selected message becomes "you need to become root for such operation." is there any way to open these files(placed in /etc/asterisk) directly from gedit and save the changes without going into terminal
You can always do sudo gedit from the terminal to launch gedit as root to edit the files.

Resources