Starting st from a vim keybind failes - bash

I am using vim as an editor for LaTeX and I use bib-files for my citations.
I want to write a function with which vim opens the currently used bib-file in a terminal which itself runs vim on the .bib-file and lets me edit it.
In the bash script I am using the line
st -t bibfile_edit_terminal_floating -e nvim $BIBFILE_PATH &
where $BIBFILE_PATH is the path of the file (which is correct and works).
When I run the line from a terminal, it opens a st as a separate process and in st opens the file in vim as I want it.
If I call the same line from vim / nvim as a command in a script, the command opens a terminal for a split second and then closes again.
I don't know what is going on.
If I use the line
st -t bibfile_edit_terminal_floating -e nvim $BIBFILE_PATH (without the ampersand at the ending), the file opens in a terminal like I want it but I cannot edit my original document as it waits for the process to finish, which is not what I want.
Please help!

Related

How to start emacs from the terminal with an emacs command that runs soon after emacs is opened

Is there a way to launch Emacs from terminal and execute some Emacs command automatically soon after Emacs is launched (the command to be executed inside of emacs is provided along with the Emacs-launching command executed from the shell.)
What I want to do exactly is to have a command to launch Emacs and then open a new empty buffer and activate org mode inside of this buffer.
I want something that might look like this
emacs -fs --command="evil-buffer-new && org-mode"
I want the -fs flag because I want Emacs to open in full-screen in this case.
Update
--eval flag didn't work. Forget about evil-buffer-new, I have tried something as simple as:
emacs --eval="(org-mode)" txt.txt
txt.txt is an empty text file created before executing the above command (and please don't ask me why I didn't use .org file extension).
after Emacs opened, org-mode wasn't active. I had to run pp-eval-expression then (org-mode) to activate it, and then it worked.
Am I missing something here? How about rephrasing the question like this:
How to open an empty text file (having .txt file extension) with Emacs from the terminal and have org-mode activated in that buffer automatically?
See C-hig (emacs)Action Arguments or even just run emacs --help -- there are several options for loading and evaluating arbitrary code.
--command="evil-buffer-new && org-mode"
More like:
--eval="(progn (evil-buffer-new) (org-mode))"
But you'll have to figure it out for yourself, because I don't know what evil-buffer-new is specifically.
You told an empty file is created before emacs is started. But instead of an empty file could you create a file with file-local mode variable specifying the org mode ? For example with bash:
#!/bin/bash
cat <<EOF >> "$1"
; -*- mode: Org;-*-
EOF
emacs "$1" &
Now the mode is always resolved correctly with normal major mode selection procedure.

Spawn another vim terminal split by shell command while in terminal mode?

I like the new command :terminal, now I try to use it for my usual terminal tasks.
When I run $xterm & in that Vim terminal mode 'split' it opens a new terminal window with WM. Can I have some shell command to run another terminal inside parent Vim?
It seems that you want a shell command that opens vim in terminal mode?
You can simply use -c while invoking vim to supply a command. For instance you could put
[[ $VIMTERM ]] || VIMTERM=true vim +terminal +start
in your .bashrc to open vim in terminal mode when opening a new shell.
If you want to create a new terminal window within vim you could first exit TERMINAL mode with CTRL-\ CTRL-n and then use :split +term or :vs +term
Edit after comments below
If you want to send keys to vim from the command line you need to use its --servername functionality. For instance, start your first instance with
vim --servername vimserv
Then once inside vim's terminal you can use
vim --servername vimserv --remote-send "<C-w>:term<CR>"

Execute a bash command in the text of a vim buffer

I know that I can get into bash while in vim via:
Ctrlz
or
:sh
or
:shell
etc.
Then use bash commands as normal, and get back out using fg.
What I am wondering is, can I execute a line of code from a script in vim straight to Bash, without having to exit vim, or having to copy it (via highlighting in visual mode for example) from vim, then going to a terminal and pasting it and hitting enter etc.?
Easiest way is to put the cursor on the line and type:
!!shreturn
This will replace the line with the output of the script. If you don't want that, simply follow up with u.
Arguably easiest way:
Yank the text you want to execute.
Open the cmdline (by pressing :)
type ! and then press ctrl-r and ", which will paste the content of the unnamed register to the cmdline (which will contain the text you wanted to execute)
press Enter

Geany "LIBDBUSMENU-GTK-CRITICAL **: watch_submenu: assertion `GTK_IS_MENU_SHELL(menu)' failed"

I'm doing this Ruby on Rails tutorial, and everytime I input
:~/rails_projects/first_app$ geany .gitignore
I get this
(geany:12043): LIBDBUSMENU-GTK-CRITICAL **: watch_submenu: assertioN
`GTK_IS_MENU_SHELL(menu)' failed
#ubuntu:~/rails_projects/first_app$ geany .gitignore
(geany:12369): LIBDBUSMENU-GTK-CRITICAL **: watch_submenu: assertion
`GTK_IS_MENU_SHELL(menu)' failed
The text editor still opens, but the terminal doesn't let me input anything unless I close the text editor, unlike the tutorial where he has it open, and the terminal still works.How can I get the functioning terminal with the text editor?
I have the same question.
Any ideas on how to correct it??
The way I found to continue to use the command line and still have the geany opened is:
$ geany file &
$ <ctrl+c>
It's useful, but not perfect.
A solution would be good
Cut and paste the following bash function definition into your bash profile ~/.bash_profile to use this from a login bash terminal (or into ~/.bashrc to use this from a non-login terminal). This function will be available only in terminals started after this change is made.
geany() {
$(which geany) --no-msgwin --no-session "$#" &>/dev/null & disown
}
Now typing geany followed by zero or more filenames will have the desired effect.
Explanation:
$(which geany) finds the path to geany by searching your PATH, and substitutes that path in place of the text $(which geany).
The options --no-msgwin and --no-session are optional, but respectively start geany without its message window at the bottom and without remembering to open files that were open the last time geany was closed.
"$#" is the bash way to substitute into this command the rest of your command line (i.e. all the filenames you type after you type geany to use this function).
&>/dev/null redirects geany's standard output and standard error output to /dev/null which stops any messages from geany being displayed in the console.
& disown runs geany as a separate process that is not a child process of the terminal that starts geany. So it is immediately not a job associated with the terminal, and no termination message will appear in the terminal when you quit geany.

open a file in an emacs buffer while in emacs terminal

Suppose I am in terminal in Emacs (M-x term), and I list the following files in current directory:
text_code.R
Now I am in bash-3.2$ (terminal) and hope to open this .R file in another Emacs buffer and then edit. Is there a way to do it? This might be a trivial question, for I am a newbie to Linux and Emacs. Thanks in advance!
Remember that in Term Mode you can type C-c C-f to open a file (just like C-x C-f outside Term Mode). The prompt will already be on your current directory, so you just have to start typing the name of the file and autocomplete it with TAB.
I don't know the official procedure for what you want to do, but here is a procedure that works:
Either tell emacs to run as a daemon (Ref: EmacsAsDaemon) or in emacs start daemon via M-x server-start.
In the term, a command like emacsclient -n filename will start editing the specified file in the current window. Note, emacsclient also has a -c, --create-frame option to edit in a new frame. You probably will want to use a -n option as above, so you can continue using your term, after selecting it from the buffers list in another pane or frame.
If you start the daemon via M-x server-start in emacs, the daemon will terminate when you exit from emacs. If you set it up via reference mentioned above, use kill-emacs or save-buffers-kill-emacs commands or shell command emacsclient -e '(kill-emacs)' to stop it, as mentioned in part 6 of reference.

Resources