Custom autocompletion for zsh - vim

ZSH has builtin autocompletion for scp, so a command like
scp user#host/path/
would show directory listings on the remote server.
However, this does not work when opening a remote file in vim
vim scp://user#host/path/
I have googled around for documentation on the zsh autocomplete functions but it seems very complicated. How can I enable autocomplete for vim scp?

Complete autocompletion documentation is located in man zshall (if you don't want to view all sections in one man, see index in man zsh). Completion for vim is located in /usr/share/zsh/$ZSH_VERSION/functions/Completion/Unix/_vim, I guess you need to modify _vim_files function located at the top of the file and somehow export function _remote_files located in the /usr/share/zsh/$ZSH_VERSION/functions/Completion/Unix/_ssh.

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.

vim unmap everything (completely stripped down vim)

Love vim. Tried Janus. Like the idea, but it's too slow, 100 plugins competing for keybindings. I want to actually understand what every vim configuration I make does.
Is there a way to "unmap" all vim keys or as much as possible. Remove most commands, etc. The point of this is an exercise for myself. I want a super small subset of maps, settings, bindings, so I can add things one by one as I need them.
Have you seen efforts like this?
Try to run vim with the following command :
"vim -u NONE"
from man vim
-u {vimrc} Use the commands in the file {vimrc} for initializations.
All the other initializations are skipped. Use this to
edit a special kind of files. It can also be used to skip
all initializations by giving the name "NONE". See ":help
initialization" within vim for more details.
It should start vim without any plugin or customisation.
Aside from
:mapclear
:nmapclear
:vmapclear
:xmapclear
:smapclear
:omapclear
:mapclear
:imapclear
:lmapclear
:cmapclear
starting it like
vim -U NONE -C -Z
will start
-U without startupfile
-C in compatible mode
-Z in restricted mode
I tried to do something similar and posted that on reddit post.
I try to restrict the mappings I define in my vimrc and load only some
plugins that I find essential.

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.

How to get Command history by cursor key in Linux tclsh

Can get the command history by using cursor key (like up arrow key) in TCL shell (tclsh).
I am running tclsh on fedora with linux version 2.6.21.
You want access to the readline library, you can do that with rlwrap:
$ rlwrap tclsh
Useful options are -c for file name completion, and -f to add words from a file to the completion list:
$ rlwrap -cf my_complete_file tclsh
Since you almost always want to use rlwrap, adding a shell alias is useful:
alias tclsh='rlwrap tclsh'
I usually use tkcon which comes with ActiveTcl, or as a separate installation. tkcon has many features, but the one I use the most is the command-line editing aspect.
Another good pure-terminal option is tclsh-wrapper
Link to tclsh-wrapper on github
It provides rich command line editing, history, aliasing, and keyword completion but does not require X11. Documentation for the key mapping is also available.

How do I set the UI language in vim?

I saw this on reddit, and it reminded me of one of my vim gripes: It shows the UI in German. I want English. But since my OS is set up in German (the standard at our office), I guess vim is actually trying to be helpful.
What magic incantations must I perform to get vim to switch the UI language? I have tried googling on various occasions, but can't seem to find an answer.
For reference, in Windows (7) I just deleted the directory C:\Program Files (x86)\Vim\vim72\lang. That made it fallback to en_US.
Try this in _vimrc. It works with my win7.
set langmenu=en_US
let $LANG = 'en_US'
source $VIMRUNTIME/delmenu.vim
source $VIMRUNTIME/menu.vim
As Ken noted, you want the :language command.
Note that putting this in your .vimrc or .gvimrc won’t help you with the menus in gvim, since their definition is loaded once at startup, very early on, and not re-read again later. So you really do need to set LC_ALL (or more specifically LC_MESSAGES) in your environment – or on non-Unixoid systems (eg. Windows), you can pass the --cmd switch (which executes the given command first thing, as opposed to the -c option):
gvim --cmd "lang en_US"
As I mentioned, you don’t need to use LC_ALL, which will forcibly switch all aspects of your computing environment. You can do more nuanced stuff. F.ex., my own locale settings look like this:
LANG=en_US.utf8
LC_CTYPE=de_DE.utf8
LC_COLLATE=C
This means I get a largely English system, but with German semantics for letters, except that the default sort order is ASCIIbetical (ie. sort by codepoint, not according to language conventions). You could use a different variation; see man 7 locale for more.
Putting this line of code at the top of my _vimrc file saved my day:
set langmenu=en_US.UTF-8
This worked for changing vim's menu language
set langmenu=en_US.UTF-8 [or just set langmenu=en for short]
But
language en
gave me an error sayng it couldn't set en as a language but this line did the job
:let $LANG = 'en'
The latter come from the Vim's docs. I added both lines at the beginning of the _vimrc file. I use a Windows 7 64 computer.
PS: this line changes both language and menus language
language messages en
In the .vimrc file (or _vimrc file if you are in windows)
Ubuntu 10.10 + VIM 7.2 IMproved. Code below changes language for console vim.
Add it at top of your vim.rc
if has('unix')
language messages C
else
language messages en
endif
Adding this to _vimrc works for me in windows 8:
set langmenu=en_US
let $LANG = 'en_US'
(note that _vimrc is in the same directory that contains my vim74 dir, thats the _vimrc file that vim reads at startup)
:help language
:language fr_FR.ISO_8859-1
These two lines at the begining of your .vimrc file will do the job:
let $LANG = 'en'
set langmenu=none
Start vim with a changed locale:
LC_ALL=en_GB.utf-8 vim
Or export that variable per default in your bashrc/profile.
Two Vim installations on Windows
Nothing from here around have helped me until I have realized that I have 2 Vim installed.
Git Bash via MinGW (Cygwin, mintty)
A separate installation in the Program Files on Windows
Next command will filter you all watched vimrc-files and their locations.
vim --version | grep vimrc
_vimrc (Windows & CMD)
.vimrc (Bash for Git)
vimrc (has different locations for both)
1: Vim on Windows & CMD
Only renaming (deletion) of the lang folder helped me.
You can find it here C:\Program Files (x86)\Vim\vim80\lang
I tried all config settings listed here around and it was useless.
2.1: Git Bash through MinGW, Cygwin, mintty
For Git Bash I added language messages en_US at the top of C:\Program Files\Git\etc\vimrc
Of course, if you prefer to delete the lang folder you can find it here
C:\Program Files\Git\usr\share\vim\vim80\lang
C:\Users\User_name_xxx\AppData\Local\Programs\Git\usr\share\vim\vim80\lang for a local user installation.
2.2: Tuning only Git's Bash (MinGW64, Cygwin, mintty)
At the end, for Bash on Windows I have chosen to skip manipulations with vimrc
I opened C:\Program Files\Git\etc\bash.bashrc
and added the following line
LANG='en_US'
or
LANG=C
Try to do not use en_US.UTF-8 because it forces some bash commands to produce weird chars. For example in find 'xxx_yyy_zzz_aaa.bbbddd' for a non-existing file.
I don't know why all of the above answers did not work for me. I kept getting errors about the locales not existing. Maybe it's a Windows thing. At any rate, my solution was to add this to my vimrc:
let $LANG = 'en'
Ah, I spoke too soon. The menus of gVim are still in Japanese, but the intro screen is in English.
Try adding this to your _vimrc:
let $LANG='en_US'
I simply disabled the Native Language Support when installing gvim
(thus making it a custom installation).
Tested successfully with gvim82.exe under Windows 7.
Had similar issue, but neither one of above solution worked:
https://superuser.com/questions/552504/vim-ui-language-issue/552523
I've resolved it by removing all vim packets and build vim from sources.
Hope it'll help someone.
If you're on Windows and don't want to be bothered issuing commands
To prevent the GUI from loading localization files
Just go to Program Files\Vim\vim80\lang and put an underscore as a prefix in front of all the files that look like they have something to do with your locale.
To prevent VIM itself from loading localization files
In the same folder as above, prefix with an underscore the folder named with your country code.
Note: Windows 10 will probably ask for Administrator privileges by raising a UAC warning.
By the way
This same technique can be applied to a lot of Unix/Linux tools ported on Windows, and generally all software packages where the localization files can readily be accessed. If you rename those to prevent the application from finding them, the fallback language will most probably be English.

Resources