Vim stuck in "3 files to edit" - windows

When opening a file with vim instead of putting the whole path I accidentally just wrote the path to the directory. So instead of:
vi myDirectory/myFile.txt
I put
vi myDirectory
Now vim has taken this to mean that I want to edit all 3 files in this directory and is stuck in that mode. I can quit vim and return to the console, but when I try to open the file with the full path vi myDirectory/myFile.txt I get a blank screen with "2 more files to edit" at the bottom. And then when I return to the console the line "3 files to edit" is printed.
How can I exit this situation so that I can continue to use vim normally and edit my file?

When you attempt to :edit a directory (or pass one as a command-line argument), Vim usually shows a directory listing and lets you browse files, courtesy of the :help netrw plugin. Vim does not automatically select all files from a passed directory.
Based on your report of having additional files also when the desired file's full path is passed, I rather suspect that you somehow have two additional "hidden" arguments to Vim, which Vim interprets as passed files.
This could be caused by a shell alias (in Bash, check type vi). Within Vim, you can list the additional files with :args; if they are indeed strange, non-filename strings, that might give you a clue (or at least some text to search for).

Related

.bash_profile error "zsh: No such file or directory" on MacOS

I am trying to update my .bash_profile but the changes are not being reflected.
When I type ~/.bash_profile in command line, i get the error "zsh: No such file or directory: Users/My.Name/.bash_profile".
Why can't terminal find it? How do I help it locate the file? When I go to Users/My.Name directory and show hidden files, the .bash_profile is there.
If you type
~/.bash_profile
on your command line while using zsh, as it seems you do, if the file exists you'll receive
zsh: permission denied: /Users/username/.bash_profile
because usually the file does not have execute permission set.
You could source the file, but it's not a good idea to load init files from different shells as syntax differs.
The reason why terminal can't find your .bash_profile is because you are using zsh as your default shell, not bash. Zsh is a newer and it has its own configuration file called .zshrc. If you want to update your zsh settings, you need to edit the .zshrc file instead of the .bash_profile file.
To help terminal locate the file, you can use the full path of the file instead of the relative path. The full path starts with a slash (/) and specifies the exact location of the file in the file system. The relative path starts with a tilde (~) and specifies the location of the file relative to your home directory. For example, the full path of your .zshrc file is /Users/My.Name/.zshrc, while the relative path is ~/.zshrc.
To edit the .zshrc file, you can use any text editor of your choice, such as nano, vim, or VS Code. For example, to edit the file using nano, you can type the following command in terminal:
nano /Users/My.Name/.zshrc
This will open the file in nano, where you can make your changes and save them. To exit nano, press Ctrl+X, then Y, then Enter.
Explanation
A shell is a program that interprets your commands and runs them on your computer. There are different types of shells, such as bash, zsh, ksh, and csh. Each shell has its own syntax, features, and configuration files. You can check which shell you are using by typing the following command in terminal:
echo $SHELL
This will print the full path of your current shell. For example, if you are using zsh, it will print /bin/zsh.
A configuration file is a file that contains settings and preferences for your shell. It is usually hidden, meaning that it starts with a dot (.). It is executed every time you open a new terminal session, so it can affect your environment variables, aliases, functions, and other aspects of your shell. For example, you can use a configuration file to change your prompt, set your PATH, or enable some plugins.
The most common configuration file for bash is .bash_profile, while the most common configuration file for zsh is .zshrc. They are usually located in your home directory, which is the directory that contains your personal files and folders. You can access your home directory by typing ~ in terminal.
To edit a configuration file, you need to use a text editor, which is a program that allows you to create and modify text files. There are many text editors available, such as nano, vim, VS Code, Sublime Text, and Atom. Each text editor has its own commands, shortcuts, and features. For example, nano is a simple and easy-to-use text editor that runs in terminal, while VS Code is a powerful and modern text editor that runs in a graphical user interface.
Examples
Here are some examples of how to edit your .zshrc file using different text editors:
To edit the file using vim, type the following command in terminal:
vim /Users/My.Name/.zshrc
This will open the file in vim, where you can make your changes and save them. To exit vim, press Esc, then :, then x, then Enter.
To edit the file using VS Code, type the following command in terminal:
code /Users/My.Name/.zshrc
This will open the file in VS Code, where you can make your changes and save them. To exit VS Code, click on the red X button on the top left corner of the window.
To edit the file using Sublime Text, type the following command in terminal:
subl /Users/My.Name/.zshrc
This will open the file in Sublime Text, where you can make your changes and save them. To exit Sublime Text, click on the red X button on the top right corner of the window.

How to open the current directory in Git bash

Context: I am a total command line noob. I am following this tutorial to get started on Git: https://www.youtube.com/watch?v=QqP7YZlZEOo. I am a windows user.
I have just installed Git and added PyCharm as my default text editor. I then opened the "Git Bash" at the end of installation. I successfully made the new directory "git-work-flow", just as he did in the video. I then used "cd" to move to the new folder. Where I lose him is when he opens the new directory in his default text editor, Sublime.
I cannot find the corresponding command to open it with my default editor, PyCharm.
PyCharm documentation says use "PyCharm .", but this does not work. Neither does 'pycharm64 .' or any other combination or permutation of answers shotgunned all over this site. Some have mentioned some extra set-up required but no documentation is found that I can follow, being a total noob.
How can I do this?
One interpretation of the question title is "What is (or how to find) the current directory in git bash?". Linux syntax is likely to be unfamiliar to long-time Windows users, so you may be interested in the command:
$ explorer .
This opens Windows Explorer pointing to the current directory (i.e. wherever you happen to be in bash).
The "." at the end means "current directory" so you just have to have a program which accepts paths as parameter, e.g. pycharm.
If it doesn't work it means probably it's not in the path, as Poojan suggested, so either one can:
type the full path to the executable for it, e.g. something like (double quotes actually necessary because of space in path)
"c:\program files\pycharm\bin\pycharm64" .
or put the path in the PATH environment variable, e.g.
Startmenu->run->SystemPropertiesAdvanced
Environment variables
double click PATH
add the path, e.g. c:\program files\pycharm\bin\pycharm64

Running a selfwritten ruby program outside of an IDE

I was wondering if it was possible to run a selfwritten ruby program just like any other program by double-clicking an icon of some sort.
And if it's possible, how do I do it?
I wrote a little program for a friend but I don't want him to have to use the command line to run it, because that's rather inconvenient (unless there is a way to just double-click and the command line opens the program itself..).
Thanks for your help!
The simple answer that should work for all versions of Windows is to just create a simple batch launcher.
Create a .bat file. I usually just create a new .txt file via "right click > new > text document". Then rename it, highlight everything, including the extension, and rename it to something like run.bat. The .bat part is important. Once you rename it, the icon should change to gears. If you can't overwrite the extension, or Windows is still treating it as a text document, you'll need to either manually save it as a bat, or disable "hide file extensions" in the explorer settings so the extension can be changed.
Edit the bat file, and put into it something like:
#echo off
YOUR RUN COMMAND HERE THAT YOU WOULD NORMALLY TYPE MANUALLY
pause
Paste the command that you would normally run manually where the capital text is. The first line is so it doesn't repeat the commands back, and the pause is so if an error happens, the command prompt doesn't immediately close. This gives you a chance to read the error.
Save it and close it. Now, if you double click on the bat file, your program should run.
Multiple ways
if it's for occasional use and for one script only I would pack it
to a Windows executable with Ocra, then you can double click
the .exe itself or a link to it
same as above but use jRuby and create a .jar file, not for beginners though
the easiest: if you configure Windows to start/run .rb files with your ruby.exe you can double click the .rb files itself and they
will execute, they will have the red Ruby stone icon
if you run a .reg file to enable drap and drop on .rb files you can combine the previous technique to drop files on the script and
they will be the parameters to the script, see my answer here for the reg file
my favorite: copy the .rb to your windows "C:\Users\your_user\AppData\Roaming\Microsoft\Windows\SendTo\"
folder, then you can right click file(s) or folder(s) and select
sendto and select your script, the files or folder will again be the
parameters for your script
you can create a .bat or .cmd file that starts with the path to your ruby.exe and the script as parameter, use rubyw.exe if you
don't want output

Does drag and drop leave the filename in an accessible place (macos)?

After I drag-and-drop a file, say from Finder, to say, Terminal running macos bash, is that value still accessible somewhere via a keyboard binding or an environment variable or some function or command? I know I could kill and yank the command line after the drag-and-drop lands on the command line, but I'd like something more direct if possible.
If you drag a file from Finder to the terminal the file name along with its path is displayed on the command line. It is not stored in any variable unless you write a code or script to read the file path and name. If you hit return after the name prints on the command line you'll probably get a "Permission denied" message (unless the name is an executable) but the path and file name will then appear in the history of commands. Typing history on the command line will show you the command you attempted to run. While not stored in a variable you should have temporary access to the info thru history.

How can I use gvim for svn commit messages under Windows?

Under *nix I can set SVN_EDITOR to gvim --nofork to do the trick, but that doesn't seem to work under Windows. Is there any solution for that?
If you have installed the batch files (c:\windows\gvim.bat), just set EDITOR to gvim -f, the batch file processes the -f argument and sets the no-fork option.
The trick in the batch file is running START /WAIT path\to\gvim.exe %* (see the /WAIT argument).
If you don't have the batch files, just create a new one with the command above, and set EDITOR to the newly create batch file.
This answer was written for Git, but should directly apply.
To make this work, try the following.
Create a one-line batch file (named svn_editor.bat) which contains the following:
"path/to/gvim.exe" --nofork "%*"
Place svn_editor.bat on your PATH.
Set SVN_EDITOR=svn_editor.bat
With this done, SVN should correctly invoke the gvim executable.
NOTE 1: The --nofork option to gvim insures that it blocks until the commit message has been written.
NOTE 2: The quotes around the path to gvim is required if you have spaces in the path.
NOTE 3: The quotes around "%*" are needed just in case git passes a file path with spaces.
If the problem is passing parameters to prevent forking to gvim (your question was a little vague), then you can either create a batch file that calls gvim with the required parameters or you could simply add the following to your vimrc (NOT gvimrc) and point SVN_EDITOR at gvim.exe:
set guioptions+=f
This tells vim not to fork when creating the GUI and has the advantage of not having to mess around with batch files. For more information, see:
:help gui-fork

Resources