Executing Cygwin's "bash.exe" from different folder than "C:\cygwin64\bin" got dysfunctional BACKSPACE - cygwin

Observations:
If I launch "bash.exe" from the folder "C:\cygwin64\bin" then the shell is open in a CMD.exe terminal and everything works fine.
If I launch "bash.exe" from a different folder than "C:\cygwin64\bin" then the shell is open in a CMD.exe terminal but the BACKSPACE and other CTRL sequences are dysfunctional.
So my question is: How do I launch "bash.exe" from a different folder than "C:\cygwin64\bin" and keeping the BACKSPACE and other CTRL sequences to work correctly?
Attempts:
I temporarily renamed the "C:\cygwin64\etc" folder to rule out configurations changes but other than the colors, the results are the same.
I also copied the entire "C:\cygwin64\bin" folder somewhere else and "bash.exe" still got CTRL sequences messed up.

So apparently I need to copy the following folder:
/usr/share/terminfo
Relative to where the "bash.exe" is located. So:
X/bin/bash.exe
X/usr/share/terminfo
Although it looks like a hardcoded path, I did look for terminfo in the bash source code and I couldn't find anything. So I'm not sure how to change the location of terminfo but that's another story.

Related

After I deleted a directory, it always prompts "shell-init error retrieving current directory getcwd solve" when log on bash

I know that changing to an existing directory may solve the problem. But the thing is that what I deleted was not the home directory. I simply deleted the directory /home/desktop/zeno, which was created by root, and the $HOME variable is /home/zeno. Also took a look at ~/.bashrc, ~/.profile and even /etc/profile, but found no commands asking to initialize bash at /home/desktop/zeno. What should be examined next? Any help will be appreciated.
When opening a new shell or xterm, it's started in the working directory of the process that started it.
If you e.g. cd /proc && xterm, the new terminal will place you in /proc.
Whatever's starting your terminal had positioned itself in /home/desktop/zeno, and now all the terminals are trying to start there. If you make that process change directory (by rebooting, for example), the terminals will start in a directory that exists and you will no longer get this error.

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,

gvim: change the default working directory

when I open gvim using Alt+F2 it takes as its default working directory my home folder.
How can I change the working folder after or while running gvim? can i pass that folder as a parameter when open gvim?
You could use a shortcut.
The simplest way, though, would be to
:edit $MYVIMRC
append a line
cd /home/user/my/work/dir
save (optionally execute :w|source % to immediately reload)
Inside vim
use
:pwd
:cd some/other/dir
To view/change current working directory.
Use e.g.
:cd %:h
to change to the directory containing the file loaded in the active window.
If you need/want to do this often, consider just setting 'autochdir'
:se autochdir
From the docs:
When on, Vim will change the current working directory
whenever you open a file, switch buffers, delete a
buffer or open/close a window. It will change to the
directory containing the file which was opened or
selected. This option is provided for backward
compatibility with the Vim released with Sun ONE
Studio 4 Enterprise Edition.
Note: When this option is on some plugins may not work.
You can pass an a folder to gvim (when you have NERDTree then it will be a file tree) You can cd before start to begin in directory you want or use :cd <path> command to change current working directory, which can be passed to -c flag when running Vim:
$ [g]vim -c 'cd <path>'
You can also check current dir using :pwd command.
You can change the working directory with the :cd command. You can also pass this in a command-line option like this:
vim -c "cd wherever"
If you like the working directory to always be the file you're currently editing you can use the set autochdir option. Put that in your ~/.vimrc or see :help autochdir.
I know I'm late, but I started using CDargs which is a bash tool to mark certain directories as bookmarks, then use cdb and press tab to list all the bookmarked directories.
There is a vim plugin that interacts with the settingsfile of this tool: vim-cdargs.
This combo works really nice for me to switch between projects.
Or after opening gvim to go quickly to some bookmarked folder, then use Ctrl-p plugin to quickly find the file I want to edit.
extra hint: I don't even want to type :Cdb so I abbreviated c to expand to :Cdb by adding this to my vimrc:
cnoreabbrev c Cdb
after which typing :c followed by a space, will expand into :Cdb.
EDIT: I now use vim-startify which provides a start page for vim that shows the most recent used files. And with the option let g:startify_change_to_vcs_root = 1 it will change the working directory to the outermost vcs root folder of the file you opened. Which is almost always what I want.
Furthemore, I created my own 'plugin' with some key mappings that will switch to the closest or furthest directory, in the path of the current buffer, containing a .git directory or file. In order to easily switch between searching for files in the current git submodule or in the overal supermodule.
Also I switched to fzf with fzf-vim instead of Ctrl-p, which works significantly faster and is more highly configurable.

Setting up gVim on windows

I am trying to get gVim working on a windows 7 machine and am having the following problems:
Whenever I try to change the _vimrc file, I get a message saying that I don't have permission to save in this location. This is on my home pc btw.
I can't seem to change the directory where the files I edit are being saved. They are all being saved to my desktop at the moment. I tried :set dir=path to where I want to save... with no success.
I wanted to run through vimtutor; however, whenever I type vimtutor into cmd, vim flashes open for a second then closes.
How do I alter the _vimrc file and how do I set the destination for edited files?
I find many people do it differently. Here's how I organize my configurations on windows.
First note that I don't believe in mixing my vim configurations with the stock vim installation. So I don't write or modify files in %PROGRAMFILES% or %PROGRAMFILES(x86)%.
My vim configurations work on different platforms (OS X, linux, windows). And I keep them organized in a .vim folder and a .vimrc file.
Some of my windows machines have cygwin and others do not. On the ones without cygwin, I put my .vim folder and my _vimrc file in %USERPROFILE%. On the ones with cygwin, I put my .vim folder and my _vimrc file in my cygwin user's home directory.
%HOME% is not defined on windows OOTB, so I define it. I find setx.exe is easy...
Example: setx HOME %USERPROFILE% or setx HOME d:\cygwin\home\myname
Alternatively, you can add environment variables via the control panel.
Note, you can copy/store the .vim folder and _vimrc file in %HOME%. But I like to keep them in a git repo elsewhere on my machine and link to them. On windows, I use mlink /d %HOME%\.vim location_of_vim_folder to link the .vim folder. And mlink /h %HOME%\_vimrc location_of_dot_vimrc_file to link the .vimrc to _vimrc file.
Note, you should have write permissions to your %HOME% folder defined above... so this should solve your problem with permissions. (You need to be an administrator to write to %PROGRAMFILES% or %PROGRAMFILES(x86)%
In my vimrc, I have a bit of boiler plate stuff for windows:
"g:my_vim_dir is used elsewhere in my vim configurations
let g:my_vim_dir=expand("$HOME/.vim")
"$HOME/.vim and $HOME/.vim/after are in the &rtp on unix
"But on windows, they need to be added.
if has("win16") || has("win32") || has("win64")
"add g:my_vim_dir to the front of the runtimepath
execute "set rtp^=".g:my_vim_dir
"add g:my_vim_dir\after to the end of the runtimepath
execute "set rtp+=".g:my_vim_dir."\\after"
"Note, pathogen#infect() looks for the 'bundle' folder in each path
"of the &rtp, where the last dir in the '&rtp path' is not 'after'. The
"<path>\bundle\*\after folders will be added if and only if
"the corresponding <path>\after folder is in the &rtp before
"pathogen#infect() is called. So it is very important to add the above
"'after' folder.
"(This applies to vim plugins such as snipmate, tabularize, etc.. that
" are loaded by pathogen (and perhaps vundle too.))
" Not necessary, but I like to cleanup &rtp to use \ instead of /
" when on windows machines
let &rtp=substitute(&rtp,"[/]","\\","g")
"On windows, if called from cygwin or msys, the shell needs to be changed
"to cmd.exe to work with certain plugins that expect cmd.exe on windows versions
"of vim.
if &shell=~#'bash$'
set shell=$COMSPEC " sets shell to correct path for cmd.exe
endif
endif
"Then I load pathogen... (Or if you prefer, you could load vundle bundles here if you wish )
I can't seem to change the directory where the files I edit are being saved. They are all being saved to my desktop at the moment. I tried :set dir=path to where I want to save... with no success.
dir is the location for swap files, which are special backing files used by Vim at runtime.
What you want is cd or lcd which changes the current directory. Type :help cd inside of Vim for more info.
How do I alter the _vimrc file and how do I set the destination for edited files?
I have _vimrc in my Vim folder ($VIM), so when I want to put Vim on a new Windows machine I just copy my entire folder.

Change vim's current directory upon starting from command line

Vim (actually, gvim is in question, but I believe it works both ways) upon starting has its current directory in its runtime directory.
I would like to upon starting, to have its cd in let's say, c:\pro
I know I can just do :cd c:\pro, but is there a way to change it upon starting it, with
something alike gvim c:\pro (only that doesn't work :-| ?
You can use
gvim -c "cd C:/pro"
-c allows you to run commands just after Vim has finished loading.
Vim's working directory is initially set to the working directory of the process that invokes Vim.
If you're double-clicking on the .exe in Explorer, that's why it's the runtime directory.
If you're using the Start Menu shortcut, then it has the Start in path set to the runtime directory. You could change the Start in path of the shortcut.
If you use the run dialog, then vim's initial working directory is likely your Documents and Settings directcory.
Can't you put cd path in your .vimrc ?

Resources