How can I make cygwin autocomplete windows paths? - cygwin

I don't want to type /cygdrive/c/path/to/stuff, especially when using tools that don't know anything about cygwin. Is there a way to configure cygwin to autocomplete "c:\path\to\stuff" or even "c:/path/to/stuff"?

For tools that can't understand cygwin paths, you'll need to convert them to windows paths. The cygpath utility can do this for you:
notepad $(cygpath -w /cygdrive/c/path/to/stuff)
You can probably create aliases or wrapper scripts for commonly-used windows executables.

Autocomplete should be working after the /cygdrive/c bit. Make a symlink for "/cygdrive/c/" to something else, like "ln -s /cygdrive/c /c". Also, make sure your inputrc is set up correctly.

Windows itself can autocomplete paths, with some minor registry tweaks. Or am I missing something in this question?

use alias:
Open the .bashrc file already copied in your home directory 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"
you can use any path here. 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.

Related

Change location of vimrc

I'm trying to unclutter $HOME, and want to move my .vimrc into ~/.vim. I've already looked at this and this, but none of the solutions presented are what I'm looking for.
I do not want to alias vim with the -u flag because it won't be appropriately set if it is opened in some other way than from the shell.
I do not want to use a symbolic link because it still shows up in $HOME.
I will not compile it from source, I'd rather just use a symlink (which is what I'm currently doing) than deal with that mess.
Can anyone offer some new ideas?
If you are using 7.4, you can simply move your ~/.vimrc file into your ~/.vim/ directory:
~/.vim/vimrc <--- "vimrc", not ".vimrc"
Try this method if you don't use 7.4.

Referencing the HOME path in Cygwin aliases

I use a lot of aliases in my Cygwin .bash_profile as a way to cd to various lengthy network drives. I am also modifying this .bash_profile file frequently as new drives need to be accessed.
I'm trying to create an alias that will open my .bash_profile in a text editor and allow me to quickly edit it from anywhere. Let's use the following as an example:
alias editbash='subl ~/.bash_profile'
"subl" is another alias for the path to my Sublime Text executable.. this works fine.
My main issue is that when I execute this alias, it attempts to open a file at the following path:
C:\home\username\.bash_profile
... instead of...
C:\cygwin\home\username\.bash_profile
I have attempted to modify this alias to use the following:
alias editbash='subl /cygwin/home/username/.bash_profile'
This works, but only if I'm currently viewing something in my C: drive, which I am often not.
How can I update this alias to always reference my Cygwin user home directory, rather than the Windows home directory? Or, if it's easier, how can I always reference the C: drive in my latter example?
Try referencing the home directory as /cygdrive/c/cygwin/home/username
That should solve the problem.
You can edit you home variable in the /etc/passwd file. Use pwd to find out where you are. Then the tilde can point where you actually want it to.
The shellslash option seemed worth a try in spite of the warnings about it breaking things.
So before that, I tried a few different aliases in .bashrc - AND ONE SIMPLE THING WORKED by prepending a backslash:
alias vib='vi "\$HOME/.bashrc"'
... and works just as I wanted - Thanks!

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,

Perforce changing the default editor

I use perforce for my revision control, when I hit 'p4 change' it always opens up the list on emacs, and we all know the pain of deleting text in it. How do i change it to gedit or vim or anything else? My default text editor is gedit.
On the command line, set P4EDITOR either as an environment variable or in the P4CONFIG file.
From the command line,
p4 set P4EDITOR="C:\File Editor\editor.exe"
You can test that this was successfull by running the following command after, which should launch your desired editor.
p4 workspace
I had similar problem on my Windows system.
It always used to open clumsy notepad.
I am more comfortable with TextPad, so to change default perforce editor, I made following changes:
I opened System Properties and added new environment variable as following:
Name: `P4EDITOR`
Value: `C:\Program Files (x86)\TextPad 4\TextPad.exe`
After that open a new CMD and there you go !!!
For Notepad++ I needed to use this command -multiInst to trigger edits.
p4 set P4EDITOR="C:\Program Files (x86)\Notepad++\notepad++.exe -multiInst"
Try setting the EDITOR environment variable. Also, the command line p4 should have an option to specify an editor. Also, the .p4config file might have something as well.
Also need to check if EDITOR/P4EDITOR path is correct. If path is wrong, perforce will choose previously working editor.
In the case of WSL, likely your p4 binary is provided for Windows platform as the path and operations are most compatible there, so it's p4.exe most likely. Then simple wawy of setting editor in P4EDITOR is not just enough, we have to convert input argument of filepath which is provided in Windows-based into Linux path.
This solution dated back 19 years ago still works
The concept is to
Create a bash/shell script that accept the argument.
Then in the script we can use wslpath $1 to convert Windows path into Linux path.
The script can be just
#!/bin/bash
vim `wslpath $1`
I thought I might not be able to use Vim to edit change, or client spec of perforce and have to end up using whatever provided like Notepad (not against it, but I just want to use Vim). This solution works for me.

How do I use my .vimrc file in Cygwin?

I just installed Cygwin on my work machine and would like to use the .vimrc file I use on my Linux box at home.
Is that possible, or does it need to have Cygwin-specific settings?
Where would I put the .vimrc file?
I'm a little unsure of what directory I'm being dropped into at the bash prompt under Cygwin, but I think I'd create a subdirectory called .vim there, right?
I launched vi as vi -V and got this:
chdir(/cygdrive/c/Users/johntron)
chdir(/etc)
chdir(/cygdrive/c/Users/johntron)
could not source "/etc/virc"
chdir(/cygdrive/c/Users/johntron)
chdir(/cygdrive/c/Users/johntron)
chdir(/cygdrive/c/Users/johntron)
could not source "$HOME/.virc"
chdir(/cygdrive/c/Users/johntron)
chdir(/cygdrive/c/Users/johntron)
chdir(/cygdrive/c/Users/johntron)
could not source "$HOME/.exrc"
Realizing vi was looking for .virc and not .vimrc like all the other *nix systems I've ever used, I just ran this to fix the problem:
cp ~/.vimrc ~/.virc
... or if if you've configured symlinks:
ln -s ~/.vimrc ~/.virc
I'm pretty sure this was a problem, because Cygwin installs vi, and not vi improved; however, the loading screen if you launch vi with no parameters still says vi improved. Regardless, I installed vim via setup.exe and running vim (not vi) does indeed try to load ~/.vimrc as expected. You can simply add an alias vi=vim to your ~/.profile to use the improved version by default.
Cygwin (as of version 1.7.25) installs vi (not vim!) by default. If you also install vim you will have two commands: /usr/bin/vi and /usr/bin/vim.
Unlike in other *nix (e.g. debian) both commands slightly differ in their behaviour on starting vi/vim.
Both commands will load Vi Enhanced but they differ in the files they look for to initialize the editor:
/usr/bin/vi looks first for /etc/virc and then for $HOME/.virc
/usr/bin/vim looks first for /etc/vimrc and then for $HOME/.vimrc.
Both files (in /etc and in $HOME) will be sourced if found!
You can check it yourself entering vi -V and vim -V.
Use .vimrc if you call vim and .virc if you call vi. Or simply alias vi=vim for using .vimrc
1) Yes it is possible. It doesnt need any cygwin specific settings, though you can add some windows specific ones. Just make sure to install vi (vim gvim equivalent) properly.
2) the same place as on *nix -- user home directory
Beware one thing: there is a Cygwin port of vim, and a native win32 port of vim. Both have their advantages and their flaws when dialogue with cygwin or native-win32 applications is concerned.
A category on vim.wikia is dedicated to cygwin related tips.
Some parts of file system of Cygwin use your "host" file system as its own. Within cygwin, there is a user home directory (which actually resides under your "Documents and Settings/Username" folder), so you should place it there.
Just place your .vimrc somewhere you know how to access via cygwin and do a
directory/you/know$ cp .vimrc ~/
It will work--at least worked with default vim on my Cygwin installation several months ago.
I don't see any reason why your Linux ~/.vimrc
should not work in your cygwin install.
To go to your home directory in cygwin,
cd ~
or
cd $HOME
In Windows, you can use WinSCP to connect to your Linux box, open your Linux .vimrc in the WinSCP default editor, copy the contents. Then switch to the Cgywin terminal and type
getclip > ~/.vimrc
Start vi/vim to see if your new settings have taken effect:
vi
I had to rename / symlink my .vimrc file to .virc in a directory like /home/Leo/.virc or more generally $HOME/.virc.
I just created my own and worked out of box:
1) vim ~/.vimrc
Once inside the .vimrc (blank file) I like to copy the example from:
2) :r $VIMRUNTIME/vimrc_example.vim
3) :wq
Then check any file should have lots of color and stuff
4) vim .vimrc (or whatever file, e.g. ~/.bashrc)
simply navigate to your home directory which is
c:/Users/user_name/
create the file using
vi .vimrc
set your preferences here, and they would surely reflect
like
set nu "show line numbers
set ai "auto indentations
colors blue " or elflord or whatever you like.
save and try.
I had issue with Cygwin vi tabstop. It was always defaulting to 8. While launching it was giving error "Failed to source defaults.vim" Tried to follow various solutions but below worked for me.
Create .vim directory under current user home ($HOME) directory.
Create .virc file under .vim directory.
Add below line to .virc
set tabstop=4
Cygwin version details
CYGWIN_NT-10.0-22000 3.3.5-341.x86_64 x86_64 Cygwin

Resources