Open file in a running nvim-qt instance - vim

I want to open new files from the command line on Windows in a single nvim-qt instance that is already open.
I know the existence of the --server option, but how do I know the IP or the socket name or path of the running instance?

As el_technic0 said, the neovim-remote utility is the easiest way to get remote file opening to work. I even added an alias to it in my .bashrc file (alongside the listen address definition) for easier invocation:
export NVIM_LISTEN_ADDRESS=/tmp/nvimsocket
alias vim='nvr --remote'
This way the first call will start a new neovim instance, and subsequent calls will be forwarded to that instance.
You may also want to add the set hidden option to your init.vim configuration file, otherwise subsequent calls may fail if the current buffer contains unsaved changes.

Related

Where is the default .p4config file located?

I changed the P4PORT variable with the following command:
p4 configure set P4PORT=<local IPv4>:80
But now I am unable to connect to, or even start the perforce server. I was hoping that maybe someone would know where the default location for the .p4config file (I don't even think I know its proper name...) is so I can manually change the P4PORT value back to something that works.
p4 configure (server configurables persisted in the server db) is completely separate from P4CONFIG (client configurables persisted in a client-side text file).
If you've set P4PORT to an invalid value via p4 configure, you'll want to:
Check the log file (look for a file with log in its name in the P4ROOT directory) to confirm the error. I'm guessing you'll see an error about being unable to listen on that port.
Fix P4PORT via p4d -cset. (You don't want to mess around with db.config manually.)
Try again to restart the server, and start from step 1 if needed.
See p4d -h:
Configuration options:
-cshow
'-cset [server#]variable=value'
'-cunset [server#]variable'
This syntax provides a limited subset of the functionality of the
'p4 configure' command, and is useful for accessing the configuration
when the server is down. The '-cshow' flag displays the contents of
the db.config table, similar to 'p4 configure show allservers'.
The '-cset' and '-cunset' flags set or unset a configurable. When
using set or unset, enclose the entire expression in quotation marks,
and on Windows, use double quotation marks, not single ones.

How does File Explorer open files?

It's maybe stupid question, but what happens behind the scenes when i double click the word app, or .exe app?
For 'Non-Developer' it just opens the file in right environment after doubleclicking. But I would like to know, how is it done, how can the file manager know what to open? (.docx in word, .txt in texteditor,etc...)
+ I would like to know how can I do that in Node.js, is it the best way to use child_process and if statements for every suffixes?
There is a file association to tell Windows how to treat a certain file extension. You can type assoc in a Windows Command Prompt to see them. As an example:
C:\test>assoc .txt
.txt=txtfile
So Windows knows now, that the file with the extension .txt is a txtfile.
ftype defines, how that filetype is to be handled:
C:\test>ftype txtfile
txtfile=%SystemRoot%\system32\NOTEPAD.EXE %1
So whenever you doubleclick on a file, Windows checks if it is associated with any filetype. Then it looks up, how to handle that filetype and executes that command (in the example above, it opens Notepad with the filename as a parameter).
Both assoc and ftype are able to change the settings (for example to open .txt files with another editor). But if you try that, do yourself a favor and note the original settings, so you are able to revert your changes when needed.
The changes can also be done directly in the registry (not recommended, when you are not experienced in handling the registry)
For Node.js, you can use child_process to shell out to the start command which does similar things as the File Explorer.
E.g. start some/path/to/file.docx will open that file in the default program associated with the format.

have to set port every time in command line when trying to trigger any Perforce command

I'm new to Perforce, need to work in command line, i'm so confused why all the commands on the tutorial websites all write like $p4 command, but I have to add the port every time when try to trigger that command, for an example, for $p4 sync, i have to type $p4 -p myhost:myport sync every time even after I logged in, if i missed the host and port, like if i just typing $p4 sync, the program will just hang in there... anyone can provide some suggestions?
There are a couple ways to make myhost:1666 the default. These are, in the order of decreasing precedence:
command-line options (like -p myhost:1666)
the P4CONFIG file
environment variables (%P4PORT%)
on Windows, the registry (use p4 set P4PORT=myhost:1666 to set it)
See the docs here.
In your case, I guess the registry (if on Windows) or the env. var. (if on Linux) is the best option.
Type:
p4 set P4PORT=myhost:myport
From that point on, "myhost:myport" will be used as the P4PORT when you run commands.
If you use multiple workspaces/servers, P4CONFIG files make it easy to have different sets of settings (based on your working directory), but for a single value, "p4 set" is a nice persistent one-shot method.

Vim remote editing: why no --remote-send-silent?

I would like to send commands to a named vim server. If the named server
doesn't exist, it should be created automatically, and the commands run in the
new instance of vim.
My problem is that there isn't a "silent" version of --remote-send. I think an
option such as --remote-send-silent would do exactly what I want, but it
doesn't exist.
Is there a way to achieve this? Alternatively, is there a way to
query (programmatically) whether a named vim server exists, so I can switch
the behaviour accordingly?

GVim taking forever to load when connected to office network

When I load GVim from the Cygwin command line or when I'm not connected to the office network (mapped to U:/) it loads instantaneously. It takes a good minute or so to open when I'm on the network. What is going on here?
You probably need to set your $HOME directory to something other than U:/. Create a $HOME environment variable for Windows that points to My Documents or whatever and it won't try and use U:/. You may need to log-off/log-in to pick up the changes.
You should check what your $HOME directory is mapped to in each case. I bet that it is different depending on if you are connected to the network or not.
Do you have any custom .vimrc or other config files read at startup? If nothing else, vim will query your $HOME directory to look for such files. If your network is slow, it could cause your problem.
See ":help startup" inside vim for more details on the startup process.
It might also be a good idea to set the directory and backupdir options so they prefer a local directory. Something along the lines of
set backupdir^=C:/Temp
set directory^=C:/Temp//
The ^= syntax puts the directory at the start of the list of directories for each option. The trailing // for directory tells Vim to encode the full path to the file being edited in the swapfile's name. This allows for swapfiles to be created in one directory when editing multiple files with the same name, but different paths.

Resources