Neovim how to call commands from Powershell? - processing

I am planning on using neovim as my primary text editor for my Processing sketches, so I need a way to conveniently run my Processing sketches from vim itself.
When I type in processing-java --sketch="path" --run in my powershell window, everything works as I expected. However, when I included the code below in my init.vim file, everytime I use the command, I receive Error: Could not find or load main class processing.mode.java.Commander
nnoremap <leader>r :call RunProcessingSketch()<CR>
function! RunProcessingSketch()
execute "!processing-java.exe --sketch=" . getCwd(). " --run"
endfunction

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.

VIM "!" and the Windows start command

I have configured <F5> to use the Windows start command, but trying to use the command line option "/wait" confuses VIM so that the command is not found anymore.
Here my old mapping:
noremap <F5> :w<CR>:!start "%:p"<CR>
I changed the mapping to:
nnoremap <F5> :w<CR>:!start /wait "%:p"<CR>
Using the later cause the following error:
E371: command not found
But why "command not found", the command is still "start", isn't it?
Thanks in advance!
Vim implement :!start command it-self since Vim must handle background command correctly. And it doesn't have /wait option. See :help :!start.
Using "start" stops Vim switching to another screen, opening a new console,
or waiting for the program to complete; it indicates that you are running a
program that does not affect the files you are editing. Programs begun
with :!start do not get passed Vim's open file handles, which means they do
not have to be closed before Vim.
To avoid this special treatment, use ":! start".
:nnoremap <F5> :w<CR>:! start /wait %:p<CR>
FYI: original start command doesn't require double-quote for argument.

How do I open a shell but still have access to vim

I am running gvim on Windows 7.
I use this mapping to execute the current file with powershell:
nnoremap <C-q> :! & '%:p'<cr>
It works great except I can't access vim until I close the powershell window. Sometimes I want the shell to remain open so I can run additional commands or I want to access vim with the shell still open so I can check the lines where errors were generated.
Ideally (don't know if this is possible) I want to have an already open shell execute the command. So I always have vim and a shell open (on separate monitors) and I can execute the script in that same shell.
How can I achieve this?
GVIM on Windows has a special :!start command to execute the external command asynchronously; i.e. Vim doesn't wait for its return. Just replace the :! with it. See :help :!start for more information.
On Unix, such special isn't necessary; you can just append & (a shell feature) to execute the command asynchronously.

vim shell key mapping to execute shell commands

i am using vimshell to execute commands inside vim
nnoremap <leader>vs :VimShellPop<CR>
with this key mapping i can open vim shell and execute commands like 'bundle install' and then
type exit to exit VimShellPop window but i want set a key mapping
nnoremap <leader>bi :
to open up vimshellpop execute the bundle install command and exit once i get completed..is it possible in vimshell?
The vimshell plugin provides an interactive shell inside a Vim buffer. Apparently, you don't need the interactivity (because you intend to immediately exit after issuing the shell command). For that, you don't need the plugin itself; the built-in :! command already allows you to launch external commands:
:nnoremap <leader>bi :!bundle install<CR>
If you want to keep the output visible, you can read it into a scratch buffer:
:nnoremap <leader>bi :new<Bar>0r!bundle install<CR>
Having an interactive shell in Vim is one of Vim's stated non-goals (cp. :help design-not), so the plugin has to jump through several hoops to make this possible. Those hacks are causing these problems (of defining a proper mapping, as evidenced by the attempts in the question's comments); lack of automation (like through mappings) is a limitation of this approach.
You may contact vimshell's author (via email or GitHub issue); he's usually very open and responsive! He's in the best position to make such mapping work.

How can I invoke VIM with C-X e for long, complex, tricky commands?

I found an awesome tip here. You can "[r]apidly invoke an editor to write a long, complex, or tricky command". However, when I press the key combination above, I get Emacs open. I would like to switch it to Vim. How can I invoke Vim with C-X e?
[1. Problem SOLVED by Brian Cambell]
export EDITOR=vim
Add to your .bashrc or appropriate shell rc file
[2. Problem SOLVED thanks to Pax]
I was unable to get the tricky command back to Bash. The errors were:
> Error detected while processing BufRead Auto commands for "*":
> E117: Unknown function: JumpToLastPosition
Quotes in .vimrc solved the second problem. I am still unsure about the part in my .vimrc:
" augroup misc
" autocmd!
" autocmd BufReadPost * call JumpToLastPosition()
" autocmd FileChangedShell * call WarningMsg("File changed outside of vim")
" augroup end
[3. Problem]
What do the above part in .vimrc do?
On most Linux installs (all the ones I tested), bash recognizes both the Emacs and Vi command history keys (or you can use "set -o vi" to force it).
So, you can just use the vi-mode "<ESC>v" to to enter visual mode, this will start editing in a Vim session.
To run the command, you just save and exit from Vim ("ZZ" or ":wq"). To cancel the command, you need to delete the contents, save and exit ("1GdGZZ").
In addition to running it by exiting, you can also save it while in the editor to another location (":w /tmp/myscript").
Keep in mind that visual mode will work with the currently selected line so you don't have to start with a blank command ("<ESC>v"). You can use the normal vi-mode tools to select a line from the history first and then enter visual mode ("<ESC>kv" for last command, "<ESC>/grep<ENTER>nnv" for third-last grep command and so on).
Using this method has the advantage of not changing the "EDITOR" variable which may be used for other things (unless you want Vim for everything, which is a very sensible position to take IMNSHO).
Update:
Regarding your error, posted after the question:
JumpToLastPosition() is the function called by Vim for all files to put the cursor where it was when you last edited the file. I'm going to assume you're actually getting this error when the editing starts, not when you exit, since this is the auto function following a buffer read.
Can you start a "normal" vim session ("vim xx.txt" and then "vim xx") without this error occurring? You may find you get the same problem (and possibly only on the last one).
If you do have the same problem, you need to look at your startup files. It's possible the autocmd for BufRead is broken somehow. Have a look inside your vimrc and you filetype.vim files to see where that function is called and/or defined (I suspect it's called but not defined and that may be a mismatch between the two files or one of them has been damaged).
export EDITOR=vim
Add to your .bashrc or appropriate shell rc file
The link that you provided contains the answer:
Next time you are using your shell, try typing ctrl-x e (that is holding control key press x and then e). The shell will take what you've written on the command line thus far and paste it into the editor specified by $EDITOR.
You need to set the EDITOR environment variable (like #Brian Campbell)

Resources