Show Vim command options - vim

This was a feature I used to have when I was first learning vim, and sometime between me customizing my .vimrc file, I must have disabled it some how.
Lets say I have this command I can enter
:TmuxNavigate
Now this command could take Left, Right, Up, or Down as options. Early on in my learning of Vim, I had a small line above the command line that would show any available commands that start with :TmuxNavigate
I've tried enabling set showcmdor laststatus=2 but wasn't able to enable this feature.
Is this a feature I can enable or have I just completely lost my mind and imagined this? Any help is appreciated.

Just add this line to your ~/.vimrc:
set wildmenu
Every command set up to complete arguments will do what you expect.
See :help 'wildmenu' and :help 'wildmode'.

[space] [Ctrl+d] after command like:
:colorscheme [space] [Ctrl+d]

Related

How to source vimrc in All buffers

To source vimrc in all buffers in the current window I do :bufdo so~/.vimrc ,to source vimrc in the ACTIVE buffers in all windows I do :windo so~/.vimrc. How to source vimrc in all buffers in all windows?
for some reason if I do:bufdo so~/.vimrc | :windo so~/.vimrc the active buffer in the non-active window changes.
example: if I set set number in my .vimrc, I want all buffers in all windows affect the change.
the solution might be something like this:
for window in windowlist
execute 'bufdo so~/.vimrc'
I use vim 8.2 .
PLEASE NOTE: I did try all of the commands you guys suggested but it seems that things aren't clear enough. all of the commands that includes :tabdo :windo :bufdo or combination of them doesn't work properly for what I want. please note that this is the same as changing vimrc and sourcing it with chain of these commands like :tabdo bufdo so~/.vimrc. for example :windo bufdo set number does set number to all buffers(active or hidden) in the active window but on non-active windows only does set number for the active buffer(buffer that is shown in the window) or :tabdo windo set number only does set number in active buffers in every window meaning that hidden buffers won't get line numbers.
I even made a reddit post about this problem on r/vim and made a video about it but I don't know why nobody gets what I say. honestly don't think this problem will be solved by someone else but me even though its a simple one.
The :bufdo command will consume | as part of the command to execute, so in effect you're running the :windo command for each buffer that you have active!
See :help :bar, which documents this behavior.
That help section also mentions a way to work around this behavior, by using the :execute command to run the first command from a string, which allows you to delimit the first command. Like so:
:execute 'bufdo so ~/.vimrc' | windo so ~/.vimrc
Please note that sourcing your vimrc file "in all buffers" or "in all windows" doesn't make much sense... The vimrc file typically has global commands that usually need to be sourced only once, and usually if you modify your vimrc, sourcing it again only once should be enough...
This might make sense with a separate *.vim script that affects local settings and is meant to act on a single buffer. The ftplugin, indent and syntax scripts come to mind. But also with those, they're normally run per buffer, not per window... It's not completely inconceivable that you'd have scripts that you want to run on every buffer and window, but it surely seems odd...
.vimrc shall only contain global definitions. That the way it's supposed to be used. Sourcing it in several buffers makes no sense.
I wonder if you're fighting with local settings for which the best tool to use is either ftplugin (when the setting are filetype driven), or a local_vimrc plugin for project driven settings.
To apply in all buffers and all windows:
:windo bufdo set number
If you have tabs, from :tabe, :tabf, :tab and friends. Just add tabdo like this:
:tabdo windo bufdo set number
I would advise not to source your vimrc like this. If you want a quick setting, just use the set command and friends.
:help tabdo
:help windo
:help bufdo
:help source
While I agree with most answers on sourcing your vimrc. I do believe there are uses of the source command. Particularly batch fixing. I've never tried using
:windo with this, I mostly use :argdo and :cdo. As I have more fine-grained control on what files I need to apply.
Batch fixing is particularly useful on a large codebase. You do your fixes with :g, :v, :s for example, and save them in a file called fix.vim. This is so useful, you could even pair macros with those commands (:g and :v) via :norm command.
:help norm
Then update your argslist via :args *.js or similar commands (like backtick expression) and finally do the :argdo source fix.vim

Where to get the default shortcuts for all the commands in vimrc file? (like ts for tabstop)

I want to make my vimrc file crisp. So I want to know where I can get all the abbreviatoins for all the commands like ts for tabstop, sw for shiftwidth, etc?
It can be found by searching the command name here,
http://vimdoc.sourceforge.net/htmldoc/quickref.html
Or, you can search it in vim itself with help command.
:help quickref

vim: Use insert-mode-like completion for command completion

Is it possible to use a vertical command line completion just the way it appears when using CTRL-N in insert mode?
I personally like
set wildmode=longest,list
It behaves sort of like bash completion. (It also shows the same information as <c-d> when you hit <tab>).
You can have such a menu when doing completion in the command-line window (q:) but you can't have it in the command-line itself.
But set wildmenu (see also :help wildmode) is good enough in my opinion.

Quickest Way to Revert Spaces to TABs in VIM

I have always been one to replace TABs in VIM with x amount of spaces (usually 4).
Four lines I almost always use in my .vimrc config file are:
set tabstop=4
set shiftwidth=4
set expandtab
syntax on
Basically, there are moments when I NEED to use a single TAB (such as Makefiles), and I don't know how else to work around that other than leaving the file, editing my .vimrc, and then reloading the file of interest.
That said, what is the quickest way (from within VIM) to revert it back to using TABS, and then reverting back to my original settings? I'm looking for the least-hassle, least-keystrokes solution.
VIM will automatically enable the TAB for a makefile, assuming you name it "makefile," as opposed to "Makefile." Not sure why VIM still doesn't detect the type with a lower-uppercase difference, but such is life. (#Sedrik)
That aside, other alternative solutions are:
Filetype Binding (#ThorstenS #tungd):
autocmd FileType make setlocal noexpandtab
RealTime Switch (#ThorstenS):
Assuming the .vimrc configuration mentioned in the question, do:
:set noet (to switch from spaces to TAB)
and :set et (to switch back)
Just use the magical escape key available in insert mode.
On the *NIX's it is ^V by default when you are in insert mode. On Windows, you need to find out what the magical escape character is - ^V is taken for something else; I think it may be ^Q or ^S?
So! In your makefile:
this: this.c
<C-V><Tab>cc this.c
where the usual meanings apply:
means hit ctrl-V (you should see a ^ hiding away under the cursor)
- hit the tab key. Bingo.
Works for me.
Note: if you use vim settings or startup code which smashes tabs as you read a file, this obviously is a short-term fix. I prefer to learn how to use the retab command to ensure a file is tab-clean, because I don't like a file to be touched unless I consciously choose to do so.
Just type set noexpandtab . Perhaps you bind this to a function key.
Only this configuration helped me solve this problem.
filetype plugin indent on
filetype detect
autocmd FileType make set noexpandtab
Vim defaults to tabstop=8 and noexpandtab, so the defaults are well suited to working with Makefiles. If your .vimrc uses custom options for tabstop, expandtab, etc., one simple solution is to bypass your .vimrc while working with Makefiles.
From the manpage (emphasis mine):
-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.
Since I can never remember the necessary flag/value/formatting, I've created a Bash alias which remembers for me: alias vimnone='vim -u NONE'
You can create a custom configuration per file type.
mkdir -p ~/.vim/after/indent
echo 'set noexpandtab' >> ~/.vim/after/indent/make.vim
Basically, here we created a new indent configuration for makefiles that will be loaded after other scripts.
source

Emacs like strict auto-indent in vim

Emacs, while editing a C file, forces me to follow a particular indentation. When I press tab on an incorrectly indented line, it corrects the indentation. I want this behaviour from my vim editor. Till now I have done the following :
set cindent
set smartindent
set autoindent
set expandtab
set tabstop=2
set shiftwidth=2
set cinkeys=0{,0},:,0#,!,!^F
in my .vimrc file. However, I am not achieving the same emacs-like forced effect as I want.
Is it possible at all in vim ?
'smartindent' is obsolete. There's really no reason you need to have that in your vimrc.
'cindent' overrules 'smartindent', so setting both in your vimrc is pointless. Setting 'cindent' in your vimrc isn't very useful either, since it only really works well on C-like languages.
filetype indent on will enable the filetype-specific indentation plugins (c.f., the indent directory under $VIMRUNTIME). That paired with 'autoindent' at least gives you basic automatic indentation support regardless of what filetype you're editing.
If you want to add indent settings for a specific filetype, you can create your own indent script in ~/.vim/indent/<filetype>.vim, or ~/.vim/after/indent/<filetype>.vim if you're augmenting an existing system-wide indent script.
As the settings you posted show, pressing Ctrlf in insert mode will do what Emacs does when you press Tab. This is described at :help indentkeys-format. 'cinkeys' is used when 'cindent' is enabled and 'indentexpr' is empty. 'indentkeys' is for the reverse. It's just a slight change to modify the setting so Tab can be used in place of/in addition to Ctrlf.
On a final note, I'd recommend learning your way around Vim's help. It's very thorough and easy to use once you figure things out. :help usr_toc is a good place to start for user-level documentation. :help describes some of the basic about navigating the help, how to search for topics, etc.
The == command is what you want, if I understand you correctly. It reindents the current line according to syntax rules.
As for binding it to tab, that's certainly possible, but I have not done that and am not completely sure as to how you can catch the right moment when it should actually insert the tab and when it should reindent.
Personally, I find it less confusing to just press ==. = accepts a range even, so you can go into visual mode, make a selection and tap = and the region will be reindented.

Resources