What is the "--servername" in "vim --servername VIM test.R"? - linux

I just installed the vim-r-plugin on a Linux server and I found this issue (see below figure) prompted from the R console window (vimcom: Did you pass the --servername argument to Vim? ...) when I typed "\rf":
To solve the issue I followed the instructions here and was trying to find the "servername" and tested some commands such like:
But I have no idea what's the "--servername" I should use here. Any suggestions or answers? Thanks!

--servername is usually followed by some arbitrarily chosen name. This allows external processes like those used by your R plugin to interact with a running instance of Vim.
When the feature is available, GVim always starts as if you added --servername GVIMn where n is a number incremented for each new GUI window. You can see it on the right of the window title.
But you are using Vim so you'll need to do that explicitely:
$ vim --servername FOO

Related

Can I write a script to tell me which files are currently being edited in vim?

I'm using tmux with many windows, and I frequently lose track of which files I'm editing in vim. I'd like to have another shell open that runs a script that tells me the paths of files that vim is currently editing.
I'm running Mac OS.
The way I would tackle the problem is to query all remote Vim processes for their opened buffers. You can use Vim's clientserver functionality for that. The GVIM server names are usually sequentially named: GVIM, GVIM1, ...; for terminal Vim, you'd have to name them with the --servername argument (e.g. via a shell alias).
You can then query the list of open files via the --remote-expr argument. A simple expression to loop over all listed buffers (like what the :ls command shows) is:
map(filter(range(1, bufnr('$')), 'buflisted(v:val) && ! empty(bufname(v:val))'), 'bufname(v:val)')
As you can see, it's a bit involved and might affect your workflow of launching Vim. Think hard whether you really need this!
That I know of there is no way to get every open vim buffer from an external process. Instead of using separate tmux layouts and a separate instance of vim to edit multiple files, you could have one instance of vim and edit multiple separate files using :split and :tabnew. Then in that vim instance you can use :ls to see the paths of all open files relative to the current working directory. :pwd also works.
If this isn't your style and you'd still like to use vim in separate layouts, you can use ps to see the arguments to each vim process and check the cwd of these processes. Something like:
paste <(pgrep vim | xargs pwdx) <(pgrep vim | xargs ps -o %a | sed 1d)
Note that if you use multiple buffers in vim the above won't quite work because it will only list the arguments given to each vim command and not list the actual buffers.
You could tweak around with the piped commands ps -eF | grep vim for your script.
At the end of each line, of the result, you'll see you the different processes dealing with anything related to 'vim'. Therefore you'll find which files are currently being edited by vim('vim foo.txt' for instance), as well as 'grep vim' that was being active to get this result. To have a pretty output, you'd have to filter all of these with a script.
I hope this will help you.

How to activate an existing GVim window

What I'm searching for is a command similar to:
gvim --remote-silent FILE
But without the FILE part. So basically: launch a new GVim instance if none exists, and otherwise activate/focus the existing window. I prefer not to use a dummy file (eg. gvim --remote-silent ~/.vimrc) as that would mess up my bufferlist/MRU.
The reason I'm looking for something like this, is that I'd like to configure a shortcut for GVim (Mod+8) to use in the Linux XFCE window manager.
You can re-activate an existing GVIM instance with
$ gvim --remote-send ":call foreground()<CR>"
That fails when there's no existing server. In that case, just spawn a fresh instance, or check beforehand with gvim --serverlist.
In Ubuntu gvim --remote-silent works but doesn't activate editor window and just waves its icon in sidebar. To change this behavior look here.
This behaviour can be changed from the command line, open a terminal
and type:
dconf write
/org/compiz/profiles/unity/plugins/core/focus-prevention-level 0
To restore the default value:
dconf write
/org/compiz/profiles/unity/plugins/core/focus-prevention-level 1

How do I use Vim with Rebar

Trying to get up and running Vim + Rebar.
Separately they work but not together. What I want to achieve is to run eunit without leaving the Vim.
I guess this is doable with following plugin https://github.com/mbbx6spp/vim-rebar . Unfortunately is very poorly documented.
How do I run my tests quickly, see the output, code and once again.
All your feedback will be appreciated.
I don't know how to integrate rebar into vim, but perhaps you could try tmux? This works for me. In one window I keep opened vim, another window i use as compilation/attach session to erlang node.
One quick way to get out of Vim is to suspend it with Ctrl+z, run your commands, and then foreground it again with fg afterwards. Works at least on bash in Os X and Ubuntu Linux.
You can also run command line commands with :! <command name> directly from Vim, e.g. :! ls.
Yet another way is to use screen, with one window running vim and another still on the command line.
The best solution I've found is to use a Makefile in my project. Since vim is capable of running shell commands, you can call make & have it use your makefile. Then map these shell commands to shortcuts of your choosing.
For example, my Makefile has the following:
test:
$(REBAR) skip_deps=true eunit
In my .vimrc:
command MakeErlangTest !make test
nmap <leader>r :MakeErlangTest<CR>

vim in screen: vim does not highlight syntax when I'm in a screen session

I cannot see any syntax highlighting in any language (e.g. python, c++ and sh) when I use vim within a screen session. The line numbers are in color though.
I precise that my terminal (in screen too) is able to show 256 colors schemes (I tested with the 256colors perl script found here: http://frexx.de/xterm-256-notes/ ).
How can I fix that?
OK, here is the issue/solution:
I used to call vim by using $vi, indeed:
$ which vi
alias vi='vim'
/usr/bin/vim
But:
$ screen
$ which vi
/bin/vi
I just learnt that screen doesn't load this system level alias which is tricky.
I had this problem. In my case, I was running a version of screen from brew. brew doesn't use ~/.screenrc as its startup file. So there's two solutions to this.
1) Set your term in the screenrc that brew_screen is expecting. This might be /opt/etc/screenrc. I didn't try this method, so I'm not sure.
2) Make an alias for screen that sets the term to what you want it to be. In this case, screen-256color is sufficient. I added the following line to my bash_profile, which is symlinked to my bashrc (mac problems):
alias screen='screen -T screen-256color'

Is it possible to "extend" IntelliJ such that I can open the current file in VIM

I use IntelliJ for most of my Java programming, but every once in a while I need to make certain changes which are much easier done in VIM.
Thus, the question:
While I'm editing a file in IntelliJ, it is somehow possible to tell IntelliJ to start VIM with the same file that is currently under cursor.
Thanks !!
Absolutely!
Go to File -> Settings -> External Tools and add a new one.
Program and Working Directory fields should be self-explanatory. The parameter field should be $FilePath$. Click the Insert macro button to see more token values that you could use.
You can also bind keyboard shortcuts to the external tools you define.
See the help page on configuring third party tools for more info.
Also, see the answers below with helpful screenshots for Windows or Mac.
Even though the original question is about VIM, I'd like to share my settings for GVIM. Especially useful is the parameter used to take it to the current line.
I find it useful to have Gvim open up the file AND take me to the current line. This is done using the following parameters: +$LineNumber$ $FilePath$.
When executed, Gvim should open up and take you to the line you were at in Intellij.
Here's how to set this up with the Homebrew version of MacVim (i.e. the mvim command) on Intellij IDEA 14.
Go to Preferences->Tools->External Tools and click the plus symbol.
Set up the new tool with these parameters
Program:
/usr/local/bin/mvim
Parameters:
+"silent! "$LineNumber$"|norm! zz" $FilePath$
Working Directory:
$SourcepathEntry$
For macOS 10.12+ users, If you want to open it in iTerm2, here is a latest solution:
#!/bin/sh
vim="vim $1"
osascript -e "
tell application \"iTerm\"
set myterm to (create window with default profile)
tell myterm
activate current session
launch session \"Default Session\"
tell the current session
write text \"$vim\"
end tell
end tell
end tell
"
Date: Apr 5, 2018
iTerm2: 3.1.5
IntelliJ IDEA: 2018.1
https://gist.github.com/backslash112/open_vim_in_iterm.sh
This was somewhat more involved on the Mac OS X (Lion), especially if you'd like to use Terminal.app
The only difference on Linux is the shell script would be much simpler... (really it'd be simple to not even use a shell script for this on Linux, with a terminal that accepts the -e argument!)
Here's my working solution:
#! /bin/sh
vim="vim $1"
osascript -e "tell app \"Terminal\"
activate
do script \"$vim\"
end tell"
I am using these parametrs for launching vim: +$LineNumber$ --remote-tab-silent "$FilePath$". It allows you to open each new file in vim's tabs. Works fine)
Go to Settings -> Tools -> External Tools
Click the + to add a tool.
Here are the settings I use:
Name: Vim
Program: /usr/bin/gvim
Arguments: --servername $ProjectFileDir$ --remote "+call cursor($LineNumber$,$ColumnNumber$)" $FileDir$/$FileName$
Working directory: $ProjectFileDir$
I turn off "Open console for tool output".
The arguments will use Vim in client-server mode, so if you jump to Vim from IntelliJ in the same project dir multiple times, the existing Vim instance will be reused, and they will also place the cursor in Vim exactly where it is in IntelliJ.
Try out the VIM Plugin, http://plugins.intellij.net/plugin/?id=164
I have experienced some bugs but for the most part it works.

Resources