Is there a good way to open a file from within Neovim in a VSCode project? - visual-studio-code

Say I have a project in a directory called project-foo. This project has multiple files and subdirectories.
In vim/neovim, my pwd is project-foo and my open buffer is project-foo/src/test/bar.js.
How can I open this file in VSCode in the project context (not individual file by itself)?
Another way to ask: is there a way to get VSCode to open with the project context and specifically focus a particular file?
Expanding on this, let's say I want to open the specific file project-foo/src/test/bar.js. I could type `code project-foo/src/test/bar.js'. But that opens VSCode with only awareness of that specific file unless VSCode already has this project open.
I essentially want the equivalent of:
> cd project-foo
> code .
(in VSCode) ⌘+p src/test/bar.js <enter>
but in command line form.

Given it'll open the file in the context of the project if VSCode is already open to the project, you can accomplish this (and handle when VSCode isn't launched) with the following semi-hack:
> cd project-off
> code . && code -g ./src/test/bar.js
In vim/neovim, you could add a keymap that executes the following
:!code . && code -g %
Explanation:
! will run the proceeding text as a shell command
code . will open the current project
&& code % will then execute vscode again but with with the current buffer path (magic %)
An improvement on this if you want to navigate to a particular line and column
vim.keymap.set.("n", "<leader>ox",
function()
local r, c = unpack(vim.api.nvim_win_get_cursor(0))
vim.cmd('!code . && code -g ' .. vim.fn.expand('%') .. ':' .. r .. ':' .. c)
end,
{ desc = '[O]pen E[x]ternal editor' }
)
vim.api.nvim_win_get_cursor(0) gets you the cursor position
!code . && code -g ' .. vim.fn.expand('%') .. ':' .. r .. ':' .. c is ultimately code . && code -g [file]:[row]:[column]

Related

How do i start KX Developer

I have finished the installation, and follow this note
If you added the alias output by the installer to your shell config file (eg. .bashrc or .bash_profile), simply open a terminal and type developer to start Developer.
To start it manually, open a terminal and source the config file, then launch q and load the launcher.q_ file:
source /path-to-install-dir/config/config.profile
q /path-to-install-dir/launcher.q_
And i check /home/developer/config/config.profile file, open q add code
but i cant open KX Developer
error:
How do i do ?
How do i set .bashrc or bash_profile file?
thanks all
Your paths should not be wrapped in <>
You want:
`DEVELOPER_HOME setenv "/home/evol/developer"
`DEVELOPER_DATA setenv "/home/evol/developer/data"

How do I make zsh autocompletion remove trailing slash it returns?

I have a custom script that I pass an argument into that will create a directory in a specific folder and then cd to it, unless it already exists, then it just cd to it.
I added a zsh autocompletion that way if I want to use the command to just jump to a directory in that folder I can autocomplete the target folder and get there in less keystrokes. The only issue with my zsh autocomplete is that it leaves the tailing directory slash after the autocomplete. Is there any way to tell zsh to only return the name of the directory and leave the / off? The docs are long winded and my searching has not turned up anything useful.
Here is my zsh autocomplete
compdef '_path_files -W /home/me/dir1/dir2/folder -/ && return 0 || return 1' mycommand

How to get vim to list the PIDs of selected files that are presently being edited, avoiding recovery mode, and not list all the other files

The vim manual page contains two similar -r type commands. I'll give more background below, this question is really how to invoke the first type of -r to list the swap files, but avoid the second -r that invokes recovery
-r List swap files, with information about using them for re‐
covery.
-r {file} Recovery mode. The swap file is used to recover a crashed
editing session. The swap file is a file with the same
filename as the text file with ".swp" appended. See ":help
recovery".
The -r without filename (the first -r above ) reports on the swap files of other files too, including ones in other directories
Background:
I'm trying to have vim report the swap files of a specific file (mostly to determine if vim still editing the file). If the file is being edited ( in another window, either on linux or cygwin ) I can 'raise' that window up to the top with "\e[2t\e[1t" as I have successfully be able to do thanks to Bring Window to Front
Vim has multiple swap file names, and multiple directories that it could put a file, so I want to ask vim, please tell me the name of the swap files that are currently in use for a given file, and if there is a current vim process on the file. Unfortunately, sometimes vim will open a command file in recovery mode in unexpected ways.
I'm invoking vim like this vim -r -c :q file, well actually, I'm invoking it from script, since I want vim to see something more like a terminal, then I look at the output file, so it's more like script -q -c "vim -r -c :q foo" fooscript, then I look in the fooscript file for messages like /Note: process STILL RUNNING: (\d+)/
It is beginning to look like I need to use vim -r without a file name, and parse the output of the -r report, and that there isn't a way to get the report pre-filtered to a single file in question.
after switching my focus to just vim -r, and
Knowing that vim will try to put the swap file into the same directory as the file it's editing ( thanks to #romainl for the pointer to :help swap-file )
observing that vim -r reports on the files in the current directory first,
observing that the file name associated with the swap file is reported before the process id of the vim process, and
observing that vim appends (STILL RUNNING) if it finds the active process
I changed the current directory appropriately and ran this code after plugging in the name of the file-to-search-for
perl -lne '
last if /^\s+In directory/;
undef $f if /^\d+/;
$f = $1 if /^\s+file name:\s+(.*)\s*$/;
if ( $f =~ m#/file-to-search-for# && /^\s+ process ID:\s(\d+).*?STILL RUNNING/ ) {
print $1;
$pid //= $1;
}
END { exit !$pid; } '
The pid of the running vim process is printed, and the exit status is zero when the appropiate swap file is found, and non-zero if the file was not being edited

Terminal errors - "zsh: command not found" when trying any command

I was adding a path to my zshrc file earlier on and after saving the file and re-opening up my Terminal, I've found that I am unable to use any command what so ever.
The error I get back on any command I type in is this:
No matter what I try typing in I get this error, I have not been able to reopen my zsh file either to remove the paths I added as there is obviously an issue with them.
Can anyone advise the best thing to do to fix this without having to reboot my entire OS?
Many thanks in advance
Use the macOS Finder to rename the .zshrc file to .Xzshrc or something.
.zshrc is in your home directory. One way to navigate to that directory is to enter Shift+Command+H.
Since the filename starts with ., it's a hidden file. To get Finder to display hidden files, enter Shift+Command+..
Now you can restart Terminal, and rebuild your .zshrc file, copying pieces from .Xzshrc as needed. The error is probably in a path assignment.
In NVM repository shows how to add source lines to correct profile file:
export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
Source: nvm

launch sublime text 3 in terminal with zsh

I recently purchased a new MacBook and I am trying to re-configure my system.
The app is inside the Applications folder as 'Sublime Text.app'
I have edited the sublime.plugin.zsh file via other advice I found online to 'Sublime Text 3.app' as well as 'Sublime Text.app' with no luck on either:
elif [[ $('uname') == 'Darwin' ]]; then
local _sublime_darwin_paths > /dev/null 2>&1
_sublime_darwin_paths=(
"/usr/local/bin/subl"
"/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
"/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
"/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
"$HOME/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
"$HOME/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
"$HOME/Applications/Sublime Text 3.app/Contents/SharedSupport/bin/subl"
)
for _sublime_path in $_sublime_darwin_paths; do
if [[ -a $_sublime_path ]]; then
alias subl="'$_sublime_path'"
alias st=subl
break
fi
done
fi
alias stt='st .'
I still get
zsh: command not found: st
I am simply at a loss on where to go next
I had the same problem with zsh and this did the job:
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/subl
Then you launch a open a file my_file.txt with Sublime:
subl ./my_file.txt
Don't specify any file if you just want to open Sublime. I hope this helps ;)
First, try to first launch the sublime binary manually (interactively) via zsh.
To do that, you'll have to discover where this binary is. There are two practical options here, choose what you are most comfortable with:
Check manually those listed binaries, see which of them exist.
Slightly modify your script to echo something inside your if:
if [[ -a $_sublime_path ]]; then
echo "Sublime found: $_sublime_path"
alias subl="'$_sublime_path'"
alias st=subl
break
fi
After finding the correct one, create the st alias in your .zshrc file:
alias st="/correct/path/to/subl"
If you don't find anything in the first step, then your original script is really not supposed to work.
Just moved to App in mac
Check your current path
echo $PATH
Add a sym link from Sublime App to one of your path. Choose /usr/local/bin for example
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" /usr/local/bin/sublime
Then back to terminal and run sublime. You should be open the sublime through terminal
To setup alias for mac users;
open ~/.zshrc using the below command
vi ~/.zshrc
Add the following alias
alias subl="'/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl'"
run subl . command should work properly.
Official documentation: https://www.sublimetext.com/docs/command_line.html#mac
ZSH
If using Zsh, the default starting with macOS 10.15, the following command will add the bin folder to the PATH environment variable:
echo 'export PATH="/Applications/Sublime Text.app/Contents/SharedSupport/bin:$PATH"' >> ~/.zprofile