set tab-stop = 2 in vim permanently for a file - vim

How to set the tab size as 2 for a file permanently in vim as whenever I open a file in other editors like nano or upload the file in github then my indentations are all incorrent whenever I try to resize the tab to 2 for an existing file which has all incorrect indentations. The tab-stop=2 does not permanently resizes the tab and I see all incorrect indentation when I open the same file in nano or view it in github.

Tabs don't have an inherent size so it is up to each program to decide how to display them and there is simply no way to guarantee that a tab will always look the same everywhere.
This is precisely the main issue people have with tabs: you can tell $SOME_TOOL and $SOME_OTHER_TOOL that a tab takes two spaces but that setting can't possibly be carried over to every tool.
Modelines are editor-specific (and they are too intrusive anyway) and Editorconfig is not universally supported so there is really no universal solution beyond using spaces for indentation.

Related

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 do I configure Kate to automatically detect spaces/tabs indentation?

I mess with software written by completely unrelated groups of people, and it all uses completely different indentation standards. I'm okay with having to set the indentation width, but there's nothing more annoying than opening up a file with tabs, making some changes, and finding that my changes used spaces for indentation instead.
All the software I write uses four-space indentation. Then I go to make a Quake 3 mod and the entire codebase uses tabs. When I make changes I have to be incredibly careful to set my indentation settings first or I'm going to have to manually rewrite the indentation before committing, every single time.
I went through the settings and couldn't find anything. The tabs-and-spaces mode literally doesn't do anything special and just sets it to tabs mode instead (after a reset). I went through google and all I found was this extremely unhelpful mailing list message. Detecting consistent indentation isn't that difficult, other text editors manage it fine, it doesn't have to be perfect, it just has to work most of the time.
If Kate has a setting for this, where is it, and if it doesn't, when is it going to get such a setting? If I can't make Kate do this I'm going to have to switch off of it. I already went through Notepad++ and Geany, but they both have serious problems with doing regexes on extremely large files (say, tens of megabytes of text) or with rendering monospace non-european text.
Unfortunately, kate does not support this right now. There is a bug report for this from 2005, but noone implemented that yet (yes, 13 years ago).
What Kate does support though are Kate modeline (also called document variables). For instance, you can write in your text document e.g.:
// kate: replace-tabs on; indent-width 4;
And then the document containing this comment will automatically use 4 spaces and use spaces to indent.
Instead of writing these kind of comments into files, you can also write this into files called .kateconfig. You can find more information about .kateconfig files and modelines in this article.

Opening files in tabs in Macvim

I am trying to learn MacVim with the Janus build. I've done the Vim tutorial and now I want to dive in and create some simple websites. My first project is a site that will convert roman numerals to arabic. But I can't seem to do the simplest thing - create new files in seperate tabs in one window for html, css, and js - using MacVim. I can create blank files from the terminal and then open the finder and drag these files to an open MacVim window and achieve my goal but it seems like a very convoluted approach. What I want to do is launch MacVim and create my blank html file in the open window and then create a blank css file in an adjacent tab and then create a blank js file in a third adjacent tab and then get to work on them. But when I use the command line in MacVim to create a new file (:!mvim roman.html), I get a new window. So I end up with a series of windows instead of a series of tabs. I googled around and it seems like others have had this problem. Their solution is to modify .bashrc or .bash_profie with an alias (MacVim Open File In Existing Window), but when I tried this and attempted to open a file in MacVim, I got a file filled with garbage, not an empty file. I'm also trying to make sense of NERDTRee. Maybe there is a simple solution there but I am just starting to explore it. Any guidance would be appreciated. Thanks.
You didn't ask for that much but here we go…
Drop Janus as soon as you can. This piece of shit gives you a false sense of comfort while actively preventing you from learning how to use Vim and making it a lot harder than necessary to customize it to your liking.
Vim's tabs are not like tabs in other editors: they are not and can't be 1-to-1 proxies for files. In Vim, a file is loaded in a "buffer" and that buffer may or may not be displayed in zero or more "windows", in zero or more "tabs". This particularity will probably bite you one of these days so you'd better get used to deal with buffers.
In Vim, creating a new file works the same as in any editor: you edit a new empty file and, when you are done, you write it to disk.
:e[dit] file.html
(editing)
:w[rite]
Use :sp[lit] file.js to edit file.js in a new horizontally window.
Use :vs[plit] file.html to edit file.html in a new vertical window.
Use :tabe[dit] file.css to edit file.css in a new tab.
If you want to postpone the decision of the filename, :enew, :new, :vnew and :tabnew create empty buffers in place, in an horizontal window, in a vertical one and a tab.
You don't really need to create those files from outside of Vim.
From the Finder, the simplest way to edit a file in MacVim is to right-click on it and choose "Edit in MacVim". Same for three files.
There is a drop menu, somewhere in MacVim's Preferences window, that lets you define the default behavior when MacVim is launched by other programs. Try it.
Since you seem to have installed the mvim script, editing a file in the MacVim GUI is done with $ mvim filename and editing the same file directly in your shell is done with $ mvim -v filename.
You can also open multiples files (even if they don't exist) in their own tabs from your shell:
$ mvim -p file1 file2 file3
Your command, :!mvim filename, does exactly what it's supposed to do: it launches a new MacVim instance.
Vim already comes with a file explorer that does a lot more than NERDTree called Netrw. See :help netrw.
Did I tell you that you shouldn't use tabs if you don't have a solid understanding of what they are and what they do?
I think the command you want is :tabe something.html. That creates a new tab in the current window with the file something.html in it, and will create a new file if that doesn't exist. (Technically it won't create the new file until you save it).
If you like using tabs, it's probably worth your time to read :help tab-page-commands.
Command + T
Creates a new tab in MacVim.

Disable split window automatically showing input files (Vim)

In Vim, if you input Latex files vie the \input command, Vim opens up a split window displaying the included files.
This is a pretty cool feature, but after a while it gets really irritating b/c if one opens up a horizontal split that means that there are now 3 (or possibly 4) split windows: 2 that you desire and 2 more telling you what files are included for those 2 files.
you can close the window manually, but then upon saving the file it reappears again. How can I disable this for include statements only?
EDIT: I do not want to remove the split entirely. It does sometimes provide useful information. For example, if I type "see figure \ref{foo_bar}" it will warn me that I should instead use "see figure~\ref{foo_bar}". But that will go away after I fix the problem and save it. With \input statements, however, the split window never does.

ViM: minibufexpl versus bufexplorer plugins

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

Resources