In Vim, show path of file from where the code autocompletion is coming from - vim

In Vim, when doing auto completion with ^n, I see autocompletion suggestions from the current file as well as different files all mixed together.
I would like to get a behavior similar to what is shown on the below picture, i.e. display the path of the file containing the suggestion if the suggestion is coming from file other than the current one.

Related

vim and skim file update

I have a MacBook and I am writing a latex file in vim and I render to created pdf in Skim. I have setup Skim to check for file changes. Every time I save my latex file, I get an error from Skim that says: "Unable to load file". The file is still loaded correctly, so I am not sure why I am getting this error. Is there something that I need to do in order not to get this error?
This may be related to the way that Vim is writing the buffer. With the default value of 'backupcopy', Vim renames the original file, and then writes a new one with the updated contents. Other applications that observe the original file for changes might get confused about that, resulting in that error you see.
Try :setlocal backupcopy=yes. If that gets rid of the error, you can define this globally (with :set) in your ~/.vimrc, or just for Latex files via the corresponding :help ftplugin-overrule.

UltiSnips doesn't automatically reload changes to snippets file

(Documenting this here because I couldn't find a good answer online.)
When using UltiSnips, the documentation says (2:12 in this screencast) that writing the .snippets file is enough to cause an automatic reload of the snippet. However, this doesn't work for me. What's happening?
I had this question myself, as frequently updating my own .snippets files and not having them immediately available is unpleasant. After some experiments I discovered the answer:
:call UltiSnips#RefreshSnippets()
In case you are curious, I found it by typing :call <C-d> (a very long list, by the way).
However, this command does not update the autocompletion list of YouCompleteMe (which is mostly irrelevant, but sometimes you might want to browse through your options with description next to it).
Looks like the UltiSnips reload applies within a vim instance. So make sure to open & save the snippets file within the vim instance that you want the changes to take effect in.
To help with this, the command :UltiSnipsEdit will open the .snippets file corresponding to your correct file. You can configure how the snippets file opens using this command:
g:UltiSnipsEditSplit Defines how the edit window is opened. Possible
values:
|normal| Default. Opens in the current window.
|tabdo| Opens the window in a new tab.
|horizontal| Splits the window horizontally.
|vertical| Splits the window vertically.
|context| Splits the window vertically or
horizontally depending on context.
Sample usage in .vimrc: let g:UltiSnipsEditSplit="context"
Note that this doesn't work as well if you'd like to make the changes in a different snippets file (e.g. you're working on a cpp file and you want to add a snippet for all c files (and your cpp.snippets file does extends c). If you're in this situation and you're editing your snippets frequently, consider keeping that snippets file open in a tab/pane.
Other suggestions / input welcome!
(from Documentation)
I haven't been able to find a satisfactory answer to this either. Until somebody can post something better, I recommend just using
:e!
This reloads the current window to the most recently-saved file. I know it's not much, but it's what I'm using until I find a better way to do it.

How to change VIM PHP auto formatting options

I have tried googling this extensively, but all I can find are plugins which format code in the author's preferred way. What I would like to do is change the auto format options so that I can setup VIM to use the same formatting as the other editors my team uses.
For example, I would like:
public function test($param)
{
// code here
}
rather than:
public function test($param){
// code here
}
or
public function test($param)
{
// code here
}
Is this possible without a plugin? Are there formatting templates somewhere that I can edit? Thanks :)
Is this possible without a plugin?
Yes.
Are there formatting templates somewhere that I can edit?
Sure. Vim is the most customizable text editor in universe. :)
So, let's start understanding snippets.
Snippets are blocks of text that can be inserted in your text using some pre-defined keys. The idea of snippets is to easily put in your file some chunk of text you use often. Snippets are these "templates" you mentioned.
To use snippets with Vim, you need to install the garbas/vim-snipmate plugin. You probably had it installed, since it seems that you can use them. This plugin search in you .vim folder for .snippets files and open them every time you open a file with predetermined extension. For example, when you create the foo.html file, vim-snipmate plugin searches for the html.snippets file and load it. After that, everytime you type, for example, html and press tab, Vim will write the <html> tag, because in your html.snippets file there's a snippet telling Vim to do so. Every programming language needs its own .snippets file, and loads it at the start. It's common to have a _.snippets file too, that loads with all file extension. It's a global snippet file.
To edit your snippets, you have to find where are your .snippets files. In Linux, open your terminal and type:
cd ~/.vim
find -name *.snippets
And then you'll see where are your snippet files. Assuming they are ~/.vim/snippets, for example, you open your java snippets with a:
vim ~/.vim/snippets/java.snippets
A .snippets file commonly looks like this: java.snippets file
These +-- lines are compressed lines you can expand and contract typing za in normal mode. In the blue line you always see snippet something written. The something is the shortcut you need to type and press tab when you're editing a file to use the snippet. For example in this java.snippets file there is a snippet called snippet po. So, when you're editing a java file, type po and press tab, Vim will inserted protected {}.
Snippets have a simple language, you can understand a lot just by seeing them in the .snippets file and typing them in another one. If you want to understand more about creating snippets, Google about vim snippets, and you'll find lots of stuff about it.
If you find that you don't have snippets in your .vim folder, or have insufficient ones, you can install a lot of excelent scripts with the honza/vim-snippets extension on Github.

_vimrc getting renamed to _vimrc.2014

I noticed that for whatever reason, my _vimrc wasn't being loaded this morning. I keep my entire vim directory saved to my Google Drive to the location I specify in my _vimrc. I didn't worry about it since I'd recently backed it up, but now when I dump it into my vim folder, whenever I start up gVim, it looks like it renames it to _vimrc.2014.
I can't find anything about this behavior, is it normal? It doesn't really affect me too much since it still gets source, but I just want to know why it's doing that.
Vim certainly is not doing this. I'm not certain it's causing YOUR problem, but Google Drive has problems replacing files with a new file of the same name. Under the hood, that is exactly what Vim is doing when it writes a file with default settings. See https://groups.google.com/d/topic/vim_use/jkw_nnHz9cE/discussion : you can use either the 'backupskip' or 'writebackup' options to force Vim to write the file directly instead of replacing it with a new file when editing inside your Google Drive folder. I'm using this line in my .vimrc to accomplish the task:
let &backupskip.=','.expand('$HOME/Google\ Drive/').'*'

gvim to show file path in all the tabs (even current one)

By default shows gvim in my tabs: the names of files. They're however shown in a way like this:
if is in the same as the currently opened tab/buffer => no path shown (only file name)
otherwise abbreviated path and file name are shown
however when I change the tab this causes tab names to change and brings me quite some confusion.
Any chance to have it constantly going for: abbreviated path and file name are shown?
I've seen following:
:set guitablabel=%!expand(\"\%:t\")
however it goes the other way, so shows only file names on all the tabs (no path at all).
in http://objectmix.com/editors/148913-display-gvim-tabs.html
How about this:
:set guitablabel=%!pathshorten(expand(\"\%:p\"))
This uses the :p filename-modifier to get the full absolute path, and then shortens the path via pathshorten() in the way it is usually done in the tab labels.

Resources