Vim as the default editor - windows

I'm on Windows XP and I just installed GVim 7.3. How do I make the default editor? How can I make it run using the command prompt
e.g.
c:\Windows>gvim boot.ini
open this file in gvim.
Thanks a lot

Add Gvim to your PATH variable
To be able to call Gvim from the command line, you have to add the installation directory of Vim to your PATH variable. To do that, right click on My Computer on the desktop (or in Explorer) → Properties → Advanced Tab → Click on Button Environment Variables.
In the Dialog, go to the User Variables field and search if there is already a PATH variable. If there is a PATH Variable, select it, click Edit and change it as follows:
%PATH%;C:/Program Files/Vim/Vim73
(or whatever the installation directory of Gvim is).
If there is no PATH variable set, create a new one with the content written above.
Confirm everything with OK, then open a new command window (important!), navigate to the desired directory and type
gvim somefile.txt
This should bring up your favourite editor.
Set Gvim as default editor for a certain file type
Adding Gvim to your PATH doesn't make Gvim the default editor for a certain file type. This can be achieved the following way:
In Explorer, right click on any file and select Open With → Choose Program
in the upcoming window, select Vi improved - A Text Editor or browse for gvim.exe if the entry is not already there
select the Always use the selected program ... checkbox and click OK
from now on, every time you double-click the file, it will be opened with Gvim
The easiest way
If you install Gvim, be sure to check the Add to context menu option. If you did that, you can right click on any file in the Windows Explorer and select Edit with Vim.

Right click the any file you want to open -> select Open or Open With ->check always open with the following editor.

After installing vim the "Edit with vim..." menu item appears in the context menu (RMB click on any file to check). Thus you can edit any file (not only text file) with just selecting this menu item
Add gvim to the PATH variable and you can run it right as you want:
c:\Windows>gvim boot.ini

Related

How can I open .bash_profile without a command-line editor?

I am able to get to and edit my .bash_profile, but only using nano which lacks features I would like. How can I edit my .bash_profile in an external app, such as vscode?
I am using Windows 10 and it won't show up in search or when I check "Hidden items" in my home directory in explorer
You could try this in the terminal "code .bash_profile" to open it in the vscode, "pluma .bash_profile" to open it with pluma etc
or you could ctrl+h to view hidden files then in the file manager, [right click or is it left click] choose open with and then open it with a different program of your choice.

Open a folder in vscode through Finder in macOS?

On my windows pc, I would just double click a folder and click "Open in VS Code" to a open a folder, which saved time for me when looking through lots of code online. With Mac, however, I do not have this option. I have to directly open vscode and click "Open" to open a new folder. How do I directly open a file in vscode through finder in macOS?
2023 Update - Use Native Method
Open the Command Palette (Cmd+Shift+P) and type shell command to find the Shell Command: Install 'code' command in PATH command.
Restart all terminal sessions for the new $PATH value to take effect.
You'll be able to type code . in any folder to start editing files in that folder.
If you want to do it in Finder, you can write an Automator script to do it (it's easier than it sounds, AND shows you the power of the OS).
Launch Automator
Create New Document
Create a new Quick Action
Add the Action... (New Method - 10.13+)
Workflow receives current files or folders from Finder.
Add a new "Open Finder Items" action to the workflow. (drag the "Open Finder Items" object, highlighted in the screenshot, to the empty window on the right)
Select "Visual Studio Code" from the list.
Add the Action... (Old Method)
Workflow receives current files or folders from Finder.
Add a new Run Shell Script action to the workflow. (drag the "Run Shell Script" object, highlighted in the screenshot, to the empty window on the right)
Configure the Workflow (Old Method)
Set the Pass Input to be as arguments
Paste the following in the input box:
open -n -b "com.microsoft.VSCode" --args "$*"
Save the action using a name like Open in Visual Studio Code.
You may now right-click on the folder and find your newly created task under Quick Actions.
The simplest solution is to create a Quick Action with Open Finder Items:
This way you don't need a shell script that might break with an OS update or VS Code update
Launch Automator and select Quick Action or File > New > Quick Action If Automator is already open.
Set Quick Action receives selected to files or folders and in to Finder.
Choose an Image (icon) select Choose.. and double click Visual Studio Code in the window that pops up, this will set your quick action icon to the same as VS Code
Add Open Finder Items, Choose open with as Other.. select Visual Studio Code and save your Quick Action as Open in VSCode optionally choose an Image for your Quick Action job done.
Finally just hit Cmd+S to save and name it Open with VSCode
Well you need to understand. macOS has different ways to do things than windows and initially it might be a challenge. For starters you start to make use of Terminal. its beautiful.
Now answering your question.
Open your VS code and then, press CMD + SHIFT + P, type shell command and select Install code command in path. Afterwards, navigate to any project from the terminal and type code . from the directory to launch the project using VS Code.
Using the new shortcuts app.
Download:https://github.com/gluedpixel/shortcuts
Or create it by yourself
Open Shortcuts app > Quick Actions
Change from receive any to Files and Folders
Add run shell script action
Paste the code open -n -b "com.microsoft.VSCode" --args "$*"
Change input to Shortcut input
Click on Shortcut input and set type to "Folder" & Get to File Path
There are some ways suggested here in the VS Code GitHub Issues tracker, but I would go with the first option of dragging the folder onto the app icon if you have VS Code icon in your dock!
If you really want to be able to do so from a right click, then this repository has a workflow solution. https://github.com/Sankra/OpenFolderInVSCode
Drag and drop the folder from Finder onto an empty VSCode window.
Found a way to achieve a 'Quick Action' that met my needs using the following steps using MacOS' Shortcuts app (No Automator needed):
if you are looking for screenshots as well, I wrote a small Notion page
Open the ‘Shortcuts’ app on your Mac
On the Left Pane, navigate to ‘Quick Actions’
On the top bar, press the ➕ button to add New Shortcut.
Click on ‘Any’ and change to ‘Files and Folders’ by selecting only those from the dropdown that appears on clicking the ‘Any’ field.
Click on ‘Action Library’ on the right pane and search for ‘shell’. Drag and drop the ‘Run Shell Script’ onto the main pane. This will add the action to the Shortcut’s flow.
In the shortcut details (on the right pane), make sure Use as Quick Action is ticked and so are ‘Finder’ and ‘Service Menu’.
In the newly added action called ‘Run Shell Script’ write “code “ and right-click to get the below pop-up, go ahead ‘Insert variable’ and then ‘Shortcut Input’.
Click on the ‘Shortcut Input’ tag that appears. A pop must appear, choose ‘File Path’ and just click anywhere else. This will change the tag to ‘File Path’.
Set ‘Pass Input:’ option to ‘as arguments’.
Be sure to set a cool name for your new Shortcut! I named mine a boring “Open in VSCode”.
Open a new ‘Finder’ Instance, right-click on a folder, go to ‘Quick Actions’ > ‘Customize...’
Make sure your Shortcut’s Name is selected. Exit the dialogue and Test!
There is a Terminal command named code, I would stick with it and you should get used to it as well if you are regularly using VS.
Follow the one-time setup with-in VS Code
Open your VS code and press ⌘ CMD + SHIFT + P
Type shell, and select Shell Command: Install 'code' command in PATH from the list
Open Terminal and hit any of the commands below:
code <path-to-folder>
OR
cd <path-to-folder>
code .
OR
cd <path-to-folder> && code .
I've actually managed to have it as an icon you can just add to the Finder window as such:
The script will allow you to open the current folder path in VSCode.
The steps to do so are:
Create a new Application with Automator
Select the "Run shell script" from the menu and drag it to the editor
Paste the following small script to the text area:
finderPath=`osascript -e 'tell application "Finder" to get the POSIX path of (target of front window as alias)'`
open -n -b "com.microsoft.VSCode" --args "$finderPath"
Save the Application to the Applications folder
Right click the app and drag and drop your desired VSCode icon to the blank area to the left of the name and close the Get Info window
Press and hold the Command key and drag the Application to an empty space in the Finder title row like in the picture
Test that it works by pressing on the icon. VSCode should now open with the content of the current folder in the navigation bar
Here is an alternative derived from the accepted answer.
Indeed the accepted solution by #jnovack just opens VS Code for me, but not the desired folder. If VS Code is already running it just switches the focus to a running instance of VS Code.
Solution
Provided that you have the code CLI command installed (if not, go to VS Code and do CMD+SHIT+P>"Shell Command: install 'code' in PATH")
Then open a terminal and run which code. You should get the code executable path looking somethin like /usr/local/bin/code
Then, as per #jnovack 's answer,
Open Automator
Create a new Document (CMD+N)
Create a new Quick Action
Workflow receives current files and folders from Finder.
Add a new Run Shell Script action to the workflow. (drag and drop the "Run Shell Script" object)
Pass input as arguments
Paste this code in the shell command field /usr/local/bin/code -n "$*" or replace with your path to the code executable if it differs from this one.
Save the action
Tbh. I would have expected to be able to use just code -n "$*", but for some reason, the PATH used by the automator's shell seems to be different from that used in the terminal. I'd welcome some input on that matter.
I find this to be the best solution out there:
https://github.com/RoadToDream/SzContext

How do i open a file via terminal with a specific editor?

How do i set a default application to open a file with my preferred text editor? I am currently trying open file.rb. It opens text wrangler, but I want to open with another. How do i do this?
Go to finder, right click on your file.rb file and select Get Info.
In the Info Window you'll see a section that says Open with, expand that section. There you can change the default application to open that particular file. There's also a button labeled Change All... This button allows you to use the specified application for all similar filetypes (*.rb).
You want to use the name of the editor you want to open with, i.e. gedit file.rb, or vim file.rb. You can probably also change your default editor associated with that file type, depending on your OS, etc.

How to use nerdtree and mvim behave like netbeans or eclipse?

I want to use mvim as my general purpose text editor for code development. I want the default view to directory list view on the left vertical split pane and the file I double click on will be in the right vertical split pane. This is much the same in netbeans or eclipse. Is there anyway to set this to be the default mvim view, or hotkeys to put it in this mode?
on my macbook pro, I can open mvim by typing:
mvim .
This opens a directory tree view of the current directory (not split pane). If I double click on any files, the whole screen is replaced with that file and my directory listing goes away. I want to keep it.
If I highlight a file from within the directory listing and click "t" hotkey, a new tab is opened showing the contents of that file (again, not split pane, but whole file in it's own tab). However, if I highlight a folder and click "t" hotkey, a new tab is opened BUT it has a new vertical split with directory listing on the left. Furthermore if I double click on the files in that directory listing, they go in the right pane, which is what I want.
Is there any command line arguments that set that up which I can alias?
You seem to be describing NERDTree plugin almost to the "T". You might need to tweak some variables in your $VIMRUNTIME for it work exactly as you describe (e.g., 'let NERDTreeQuitOnOpen=0'), but with a little bit of time with the docs you should be able to get what you want.
I insert the following code in my ~/.vimrc
nmap <silent> <c-n> :NERDTreeToggle<CR>
Then, I use ctrl+n to switch to dual mode.

How to change file associations in Mac OS X

So I used Xcode and all. Now, whenever I open my text files it opens automatically with Xcode. How do I undo this?
RightClick on the file name -> Open With -> Choose the editor you wish to open with this kind of file. And that sets to be default editor for opening files with that particular file extension ( i.e., .txt ) when opened in future.
Edit: The above procedure is not a permanent one. Try this -
Right click on the file name.
Choose Get Info
Choose one from the Open With drop down. This will be set as default application and is used in future if opened the .txt file.
Right-click any text-file an select "Get-info", then choose your preferred Text-editor under "Open with" and click "Change all..."
You can change program association by right clicking on your file and clicking on "Get Info". This will bring up another dialog in which you can change the program associated with that file type.
You can find visual instructions here: http://osxdaily.com/2009/10/25/change-file-associations-in-mac-os-x/

Resources