(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.
Related
One thing I like about Sublime Text is that you can drag any folder in the left panel and this folder can be expanded independently from the others. How can I achieve the same functionality in Vim?
I'm currently using NERDTree which currently supports a single root. When you open another folder it replaces the current hierarchy. So I wouldn't mind dropping this plugin in favor of another solution.
The netrw plugin that ships with Vim allows to open multiple, different splits to different locations, e.g. vertically with :Vexplore.
To make it show a recursive tree, use:
:let g:netrw_liststyle=3
I don't know any plugin that does this, but from my brief forays into NERDTree's source code, I know that modifying the plugin to do what you want is not out of the question. It would involve delving into the logic and modifying / commenting out the parts that search and re-use the current NERDTree buffer. If you're familiar with Vimscript, not a huge challenge. (Maybe you could even introduce a configuration setting for it and send it to the author for inclusion.)
It took me a while, but I managed to work something out.
I made it into a separate plugin: Vimpanel
I put a lot of other usefull things in there, apart from the "killer feature" of being able to have multiple roots.
This is my issue with Vim: you have it open for a couple of days. You're ready to close vim. You don't necessarily want to save all files... you want to skip any files which don't have modified changes, and you want to be left (or be asked) what you want to do with the remaining buffers with unmodified changes…
For anyone that has used Photoshop, this is very familiar… you use it for a week, and when you close Photoshop, it is really trying to close the application, and skips all files which haven't been touched, let's you chose what you want to do with the remaining files, and then closes itself.
It seems like every time I close Vim, I have to go through this circus of doing :qa, then running into a file, doing :bd!, then doing :qa again, run into a file I want, :w, and it's just a huge pain. There has to be a better way of doing this.
If it isn't already obvious… I have :set hidden in my .vimrc.
How about
:confirm qa
It asks you for each modified file whether to save or abandon it (or all remaining). This is the same behavior that GVIM exhibits when you close it via the X in the window title.
does :xa! solve your problem ?
:xa[ll]! Write all changed buffers, even the ones that are readonly,
and exit Vim. If there are buffers without a file name or
which cannot be written for another reason, Vim will not quit.
I was able to find the plugin BufOnly, and then with the help of someone else on StackOverflow, I got an answer that satisfies me:
https://stackoverflow.com/a/14690570/240287
A typical workflow for me is opening Vim (MacVim to be precise), doing:
:NERDTree <bookmark>
then manually opening various subdirectories I want to use. Often it's the same set of directories I had open when I was last working on the project. I'm aware of the O recursive-open command but if it's a large tree I then have to go and close a load of them to clear the screen up.
Is there any way of saving the ones that are open / the general 'state'?
Unfortunately, there is no way to do this in NERDTree - yet. If you feel like the feature deserves attention, however, you can add it yourself or submit a request for it on GitHub, and it will be available to you soon.
Edit: I took the liberty of submitting the feature request myself; you can track its status here.
Sure just save the session with ":mksession ~/mysession.vim". ":mks" works too. Then just source the file and there you go.
I am thinking of installing a buffer explorer for vim. Both minibufexpl and bufexplorer have very good rating. Can anyone explain the differences or the pros and cons between them. Or is only a matter of taste?
Thanks!
I've used both of those plugins. I used minibuf explorer for a long while (couple of years) and it was pretty good except in situations where you have large numbers of buffers open. Then it just becomes confusing and starts to take up alot of screen space.
buffer explorer doesn't give you a constant view of what buffers you have open but it's actually a much more solid (less flaky) plugin and when you switch into buffer explore mode it lets you quickly delete buffers you're not using etc. I like it much more now.
Basically, I'd say minibuf if you don't regularly edit more than 8 files. Buf explorer if you edit tonnes of files at once.
i've used both but moved to fuzzyfinder. minibuf gives you a little window to easily switch between buffers and bufexplorer gives you a window you can invoke to call an open buffer.
Now let me sell you on fuzzyfinder, you invoke the window and start typing to match the name of the file that's open. Could be the buffer id or any part to the full path of the file including the file name. Fuzzyfinder also works with your tags file so you can easily jump to any tag within your project. Also works with directories, markers, and most recently used files. It can also open in a split window, tab, or the current window.
I think that using MiniBufExplorer with a lot of files (more than 8-10) is probably not very efficient since it takes a lot of screen space unless you have a big monitor.
I ran into some issues using MiniBufExplorer with multiple buffer splits open at the same time, and I modified the plugin to get around these limitations.
The part that made the plugin unusable was the fact that there was no indication of what buffer the cursor was currently active in, and it was very easy to get lost while switching buffers. I use H and L to move to the previous/next buffer.
I also updated the plugin so that it always reflects the current buffer's state, wether it's unmodified or modified, without having to switch buffers for the plugin to update.
I think these changes really make MBE much more usable, both in terms of the sheer number of open buffers as well as moving between them, which is important.
You can find the updated changes here: https://github.com/fholgado/minibufexpl.vim
I have tried them both and I prefer minibuf. The fact that you have all your buffers and their numbers at a glance allows you to switch to the buffer you want with:
N CTRL-^
where N is the number of the buffer you want to open.
I haven't found any other buffer explorer as fast. However, as Benj said, if you often work with many files you'd better choose something like bufexplorer or selectbuf (a kind of bufexplorer more customizable).
You also can try 0scan plugin. Just press 0b and select buffer or enter tags like dir name or extension of part of the file name to reduce selection list size.
If you selected buffer but it wasn't the only one from the list you can select next or previous after with keys 0j and 0k. Good if you need to switch between buffers from certain dir or with certain extension.
I first tried minibufexpl but noticed some strange characters would show up while in insert mode, like repeating characters when typing a space character or using navigation arrows or hjkl. Then uninstalled and tried BufExplorer, which I like better and the issue of strange charaters was resolved for me. I use vim on both my mac and ubuntu; and had the strange charater issue on both until I removed minibufexpl. My vim setup is here: https://github.com/pixelhandler/vim-config
So I was hoping that some old school Vim'ers could help me out. These are all separate questions and normally I would put them up each on their own but I'm not sure if that qualifies as question whoring here.
Plus I think if you know enough to be asking any of these questions they will all be coming up in the near future:
I have a library I'm writing and a series of applications that use that library. There doesn't seem to be an easy way(from what I can tell) to build a ctags file for the library and build one for each of my applications and make sure one references the other when I'm in vim.
Using gf to open files from command mode is awesome, but a lot of my include files
don't contain the full path. They refer to an include directory I set in the IDE. How can I set this directory as another point for Vim to start looking for files?
Is there a way to compile a file inside Vim and send the output to a buffer? I'm currently using MSVS 2k3 but I'll be porting over to Linux in a few weeks so if this is possible on either system I'd appreciate it.
Re 3)
If you put a makefile in your root dir, you can simply write
:make
This will run make and (iirc) put any errors into a seperate buffer, and make vim goto the first compile error. From there you can navigate all erroring lines using :next-error
Also, see this page
http://wiki.beyondunreal.com/Legacy:Vim
and
http://linux.byexamples.com/archives/287/perform-grep-and-make-in-vim/
for details on how to show the result in a seperate console.
1- tags files are independent, and can be used together. See :h 'tags'
I can't tell what is the easy way to build tags files. I have one that consists in using two plugins of mine:
one (draft) plugin that knows how to update C++ tags files (it should be easy to adapt it to other filetypes),
and another (local_vimrc) that helps me define directories-local .vimrc. Thus for any files within a given directory hierarchy, I can adapt the &tags options to use the relevant tag files, and the current tag file that will be rebuilt automatically (or when a keybinding is triggered). (Plugins like project should do the trick as well)
2- :h 'path'
3- :h :make
HTH.
2)
:cd {path}
For help:
:he cd
A few others like :lcd might be better suited. Just scroll down that help page.
This is rather off topic, but might still be useful: if you're using Visual Studio a lot and like Vim, you might want to look at ViEmu. It's the best Vim-emulation for any IDE I've yet seen, and the cost is really low. :) And no, I'm not getting a commission. :P
It's not obvious, but if you open a directory instead of a file, it's nicely browseable.
e.g.
:e . (colon-e-dot)
:e .. (colon-e-dot-dot)
will let you browse from your current directory or its parent.
(understanding that you were probably hoping for a capability to have vim accept e.g.
:e abc.txt
and have it look in several directories, which I don't know how to do.)