how do I start nvim in search mode? (I do not want to execute a search, merely for nvim to be ready to accept a search string) - neovim

I would like to open a file and have nvim automatically be in search mode once the file is opened.
I need to find the correct command to use, probably in the form of nvim -c Command file.txt
To clarify, I want to start nvim and be able to start searching by typing in my search string without first pressing '/' to enter search mode.
running nvim -c '/searchString' executes the search immediately and is not what I want
My use case is that I use nvim as a scrollback pager for kitty.
# kitty passes text to nvim via stdinput which i write to a tmp file in /tmp/kitty_scrollback_buffer
# I then open this file with the nvim terminal by catting the file
# is there anyway to then automatically enter command search mode so that nvim is ready to search when i enter a search string (I do not want to type /, i want to be able to search immediately)
exec nvim \
-u NONE \
-c "silent! write! /tmp/kitty_scrollback_buffer | terminal cat /tmp/kitty_scrollback_buffer - " \

Yeah, you are right there. If you want to search foo in file.txt, run this:
nvim -c "/foo" file.txt

Related

How do I create my own custom command line script in zsh?

I want to be able to run simple one line commands on my terminal, but instead of them being complicated I want them to be very simple, writing my own commands for these complex command lines that I have to write out so frequently. I am using the zsh command line and for example I would want to do this.
% npx tailwindcss -i ./static/styles.css -o ./static/output.css --watch
into something much easier to read such as
% build tailwindcss
Another problem/example is where if I would like to use http-server, but I want to turn off the caching, I don't think you can change the default settings for http-server module to turn off the caching, I have to do this:
% http-server -c-1
I know it is not too much of a big deal but I would like to at least pretend that the zero caching is the default. So I could do something like this with the command line:
% run server
And that would just run the server.
Also as a side note if this is not the best command line tool to do stuff like this in like maybe bash would be better I would be open to using a different command line tool as well.
Using aliases
If you run the exact same command every time you could alias it like this:
alias http-server="http-server -c-1"
alias <alias-name>="npx tailwindcss -i ./static/styles.css -o ./static/output.css --watch"
Now http-server expands to http-server -c-1 and <alias-name> expands to npx tailwindcss -i ./static/styles.css -o ./static/output.css --watch
Using functions
If you want to choose the input file each time you could write a function instead:
build(){
npx tailwindcss -i $1 -o ./static/output.css --watch
}
Then you can build with build file.css
Add the alias or function to ~/.zshrc if you want it available every time you start zsh
Using bck-i-search
Use Ctrl+r to search history. Pressing Ctrl+r and writing "tailwind" will likely show you the full command. You can even comment the function with some arbitrary words to make them easier to find in history (e.g. "aaa")
npx tailwindcss -i ./static/styles.css -o ./static/output.css --watch #aaa

Open files from remote ssh host in VSCode

I'm using using VSCode Remote SSH from my laptop (Linux) to work on projects that resides on a Linux host.
If I open an internal terminal in VSCode I can open files from the host by doing code some_file.txt. I frequently want to be able to do the same from terminals that are not originating from VSCode.
Is there anyway to open files in the VSCode-server while connected to a standard (Non VSCode internal) terminal?
From another StackOverflow answer, I learned that if you open an integrated terminal and find the VSCODE_IPC_HOOK_CLI environment variable, and set it to the same value in the non-integrated terminal, then run code from the code server install directory ~/.vscode-server, it will work. That article didn't mention that you can have more than one install in the ~/.vscode-server directory. The current install can be extracted from the VSCODE_GIT_ASKPASS_MODE variable, it looks like this:
$ echo $VSCODE_GIT_ASKPASS_NODE
/home/<user>/.vscode-server/bin/054a9295330880ed74ceaedda236253b4f39a335/node
Just chop off the node and add bin, and so run something like
$ /home/<user>/.vscode-server/bin/054a9295330880ed74ceaedda236253b4f39a335/bin/code myfile.txt
Edit:
Here is a small script that will connect the terminal to the latest created vscode window.
❯ cat ~/.local/bin/connect_vscode.sh
export PATH="${HOME}/.vscode-server/bin/$(ls -t1 ${HOME}/.vscode-server/bin | head -n 1)/bin:${PATH}"
export VSCODE_IPC_HOOK_CLI="$(ls -t1 /run/user/$(id -u)/vscode-ipc-* | head -n 1)"
# Tell tmux to set these variables for new windows/panes.
# Remove if you don't use tmux
tmux setenv PATH "$PATH"
tmux setenv VSCODE_IPC_HOOK_CLI "$VSCODE_IPC_HOOK_CLI"
None of the answers on this thread worked for me (due to more recent versions of VS-Code changing it's internal paths and I'm running a preview version).
I'm linking this similar/identical question+my solution:
VSCode Remote SSH doesn't open file from terminal
Hope it helps. 😉
C. R. Oldham's answer covers the technical detail of why/how.
If you want a 1-liner that works as an alias in your ~/.bash_profile:
# Open file in most recently-connected remote VSCode session.
alias code=$'VSCODE_IPC_HOOK_CLI=/run/user/`id -u`/$(ls -lt /run/user/`id -u`/ | egrep \.sock$ | head -1 | awk \'END {print $NF}\') `ls -lt ~/.vscode-server/bin/** | fgrep bin/remote-cli/code | head -1 | awk \'END {print $NF}\'`'

Always show full prompt regardless of window width?

I have tried a few of the prompts that are available through the fish config tool. All of them have had prompts that become progressively shorter with a smaller window width. I personally don't like this as I always want to see the folder and git branch that I am in.
Is there a simple setting (or a popular off the shelf prompt) that makes the prompt be full width regardless of window width.
You can run the command fish_config, it will open a new tab in your browser, then select the Prompt tab and you will see some pre-setup prompts. If any of those suits you then you need to configure a prompt by yourself. On terminal you can do:
Go to .config/fish (generally it is located in your home folder. Linux or macOS you can do: cd ~/.config/fish
Create a folder named functions (mkdir functions ; cd functions)
Create a file named fish_prompt.fish with the content bellow:
function fish_prompt --description 'Informative prompt'
#Save the return status of the previous command
set -l last_pipestatus $pipestatus
switch "$USER"
case root toor
printf '%s#%s %s%s%s# ' $USER (prompt_hostname) (set -q fish_color_cwd_root
and set_color $fish_color_cwd_root
or set_color $fish_color_cwd) \
(prompt_pwd) (set_color normal)
case '*'
set -l pipestatus_string (__fish_print_pipestatus "[" "] " "|" (set_color $fish_color_status) \
(set_color --bold $fish_color_status) $last_pipestatus)
printf '\f\r> %s%s#%s %s%s %s%s%s' (set_color brblue) \
$USER (prompt_hostname) (set_color $fish_color_cwd) $PWD \
(set_color normal)
end
end
Please, note that the code bellow is adapted from the Informative prompt
The Awesome Fish repository has some interesting prompts that you can install if you like.

Eclipse Oxygen: Reading input from a file with <, Run configuration

So in the terminal, I can run my program with
./letter --stack -b ship -e shot -c --output W < input.txt > output.txt
How do I achieve the same functionality in Eclipse? I've figured out how to do --stack -b ship -e shot -c --output W by going to the arguments tab under Run configuration.
I've looked online and seen a lot of posts about using the Common tab to input and output redirection but I can't get it working. When I check only the input file, it doesn't work and the Debug perspective shows it's stuck somewhere trying to read from a stream. When I check allocate console and input file, then it gets stuck on user input (aka I can manually type stuff) in the console.
So how do I get < input.txt and by extension > output.txt working?

Is it possible to launch vim from a capistrano task?

I want to use capistrano for a custom sets of tasks on a remote server not directly related to deployment, it would be useful for me if I can start vim using capistrano, I've tried with this:
set :pty, true
execute "vim #{shared_path}/my_file.txt"
But I receive this (for obvious reasons)
01 stdin: is not a tty
01 Vim: Warning: Output is not to a terminal
01 Vim: Warning: Input is not from a terminal
It's there anyway to make it work?
As far as I know you can't start vim without a terminal. You could start a terminal with vim in it, here are a few ways to do this:
Start a terminal like st, xterm or similar. Examples:
x-terminal-emulator -e vim
st -e vim
xterm -e vim
This solution is not the best, as terminal-emulators can have different switches for executing commands on call. -e is working for st and xterm.
A better solution is to start a shell like zsh, bash or similar, because almost every shell works with the same switch, which is -c to start a program directly in it. Example:
zsh -c vim
bash -c vim