How to cleanup tabs with vim, adjust sts and sw? - vim

I created c++ files in vim with these tab settings
set sts=4
set sw=4
meanwhile i use
set sts=3
set sw=3
and want to change all the files.
Is this possible?
EDIT
I go with indent, a few other options come handy.

I don't know of an automated way to do this with vim, but there's no reason you can't open up each of those files individually and use :retab! to have them use your new settings.
If you want to re-indent a whole bunch of files at once, you may look into something like GNU Indent.

Not VIM-specific, but if you want to batch process all the source files in one shot, the indent command line tool is incredibly useful.

Related

How to set ctag in vim editor one time

I have created ctags for my project. Now every time, I open file in vim editor I set ctag location. Is it possible to set the ctag location for one time in some where that I don't know, So that when I open a file from my project in vim, it will start working, I do not need to fire this command set tags=~/tags.
Please help.
Use the :echo $MYVIMRC within Vim to print the location of your .vimrc file. If the variable is not set, you'll want to create the file yourself. Typically its location is ~/.vimrc, but as the comments mention there are other supported locations. Once you've created the file, you can just add the command as you normally would: set tags=~/tags. As other comments mentioned, it's probably for the best to put your tags file in some constant, relative-to-the-project-root-folder place. I personally follow Tim Pope's ctags guide for all my Git projects.
I mean, which would you rather have,
set tags=./tags
or
set tags=/some/project/tags,/some/other/project/tags,/yet/another/project/tags,...

How to automaticaly set VIM file type?

I like to create my own documentation using the VIM help page syntax. When I open a file with VIM, I must use the command set filetype=help to switch from plain text to a help page colored syntax (see picture below). How can I tell VIM to set the filetype automatically for my help file ? Is it possible to use a special file extension or to add something in the beginning of the file ?
Try this in your .vimrc.
au BufRead,BufNewFile *.txt set filetype=help
This will do all txt files though, but you can change it above if you want to target more specific filenames.
You can use a modeline:
" vim: set ft=help:
...or, of course, configure some extensions like #alex pointed out.
But in this case I would rather prefer this approach in order to make the files more portable.

How do you set up formatting in vim?

Earlier, when I used open .py files in vim on ubuntu, they would be well formatted, with separate colours for separate segments of the program. Now, when I am using VIM on ubuntu, all the text in the .py file appears black. How can I correct this?
Formating in Vim means text formatting; e.g. indenting lists and breaking long lines. You're concerned about syntax highlighting, which is purely about the visual appearance of code.
First, it needs to be turned on.
:syntax on
does that.
Second, you probably want Vim to automatically detect the used language (e.g. Python) and choose the correct syntax plugin for you.
:filetype on
does that, though you usually enable more via :filetype plugin indent on.
To make these settings persistent, put them into your ~/.vimrc configuration.
Check man vim. In a nutshell, find a copy of a vimrc file, one might be under /usr/share/vim/ subtree. It may be named vimrc_example.vim. Copy to your home directory and rename it as .vimrc.

Any default settings possible for VIM editor?

I use ":set ai sw=4" and ":set number" (and some other cmd) commands each time when I open any file in VIM.
For every new instance of VIM I have to enter set of commands. Is there any way where I can put these commands and VIM will execute it every time while opening any file like default settings.
Just paste those lines on the file ~/.vimrc and they'll be executed everytime VIM is openned. If it does not exist, create one.
Two recommendations:
Use a plugin that will auto-load .vimrc when you save it. Being confortable with editting .vimrc is very important. Building it up with your preferences and key-mappings as you learn VIM is one of the reasons it is so powerful.
Google now for some ready .vimrc setups as they override some not-so-optimal VIM configurations. For example, you probably won't want that annoying bell beep, among many other things.
You need to create a .vimrc file.
You should create it in your home directory.

Can you remove default color schemes from vim in a vimrc?

I've reduced the number of custom color schemes in vim to the bare minimum of great ones, but I still have all of the crazy defaults, like elflord, which I'd rather not have to tab through. Can I remove these without hacking my MacVim install and having to do it in the next update?
Obviously this is splitting hairs, but configuring my .vimrc in the first place is splitting hairs.
tmcw,
My installation of vim73 has the colors stored in \path\to\vim\vim73\colors.
In there I see elflord.vim and a host of other files.
Presumably removing them from this directory should remove them altogether.
Then, you can just tab through whatever you want.
Edit: If you want to have something that goes in and removes the files from the colors directory after an update, perhaps you may have to write a script to manage that--I'm not really sure.
HTH
I presume you are tabbing through your colorschemes for editing different filetypes? why not just set up your colorscheme preference in corresponding filetype-specific entries using autocmd FileType or via individual vim files in the ftplugin directory. Make sure you have filetype plugin on
How many colorschemes do you actually use? If it's just a few (and you really need to change them frequently, like whether it's dark or bright daylight), I'd define shortcut commands, like:
command -bar Col1 colorscheme default
command -bar Col2 colorscheme darkblue
You could remove the colorschemes from $VIMRUNTIME/colors/, but you're right about having to do this after every Vim upgrade.
A (complex) alternative would be writing a custom :Colorscheme command, with a custom completion that uses something like a blacklist to suppress certain schemes. As a bonus, with the cmdalias plugin, you could even overwrite the original :colorscheme command, to make this fully transparent.

Resources