I :set number in ~/.vimrc to show line numbers. When I type :help to view documentation, the line numbers don't show in the new window.
If I type :setl number?, it prints nonumber. If type :setg number?, it prints number.
I want to know why ~/.vimrc doesn't work. Which script resets the local number option?
I've checked the $VIMRUNTIME/ftplugin/help.vim, but it doesn't reset the number.
Currently, I'm using:
if has('autocmd')
auto FileType help set number
endif
Thanks.
I'm not sure what is the problem you're having. Numbers don't show up in help - yes, if I recall correctly that is a design decision and a feature - a good one, in my opinion, since why would one want line numbers in help files? (Okey, you could say "to quote a particular line from help file" but tags seems sufficient for that).
As far as the other thing go, when I set
setl nonumber
setg number
and open a new buffer in a split, numbers show.
If I start a new vim session, setlocal and setglobal number being nonumber and set number they're both changed.
Is this the behaviour you're having too?
After opening vim, simply type:
:auto FileType
Do you see set number listed under help? If not, your .vimrc is not being read.
Related
Non-Slimv Behavior
At first, let me show the normal Vim behavior when Slimv is not enabled.
Create a new file: vim foo.c.
Enter insert mode: i
Enter this code: void f()
Press enter
The cursor is now at position 2,1 (2nd row, 1st column).
Slimv Behavior
After installing Slimv, if I perform the steps above, at the end, I find the cursor at position 2,5 (2nd row, 5th column) with four spaces inserted as indentation before the 5th column automatically.
How can I disable this Slimv behavior for non-Lisp files (such as .c files)?
The issue is caused by this line in paredit.vim:
filetype indent on
I added the option g:paredit_disable_ftindent to paredit.vim to disable the loading of indent files, please add this line to your .vimrc when using paredit.vim (or slimv that also contains paredit.vim):
let g:paredit_disable_ftindent=1
First, add to your vimrc file the following two lines:
filetype indent off
filetype plugin indent off
Then you have to hope that it’ll work! But there is a large probability that it won’t…
If the solution doesn’t work, you may have to make quite complicated actions to solve the trouble.
The problem is that many of your vim options are constantly changed by a lot of triggers and auto commands. The only way I found is to mark the important options (the options I don’t want to be changed) with a special symbol, and then to restore them forcibly after any possible impact. So, I did the following in my vimrc:
augroup MyVimrc
autocmd!
augroup END
"The options I want to keep unchanged, I mark with the “❗” symbol.
"The usual exclamation sign “!” will work as well.
"Of course, you’re free using any other symbol you like,
"but don’t forget the lambda-function in the hack below.
"These are the options that may influence on the indent.
set formatoptions=j "❗
set autoindent "❗
set nosmartindent "❗
set indentexpr= "❗
set copyindent "❗
set preserveindent "❗
"And I marked with the same way a number of other
"important (for me) options… (not shown here)
"At the bottom of the vimrc file, I wrote this dirty hack.
function! s:keep_options()
for line in filter(readfile($MYVIMRC), 'v:val =~ ''\v\".*(!|❗)\s*$''')
exe line
endfor
endfunction
command! KeepOptions call <SID>keep_options()
"Note, the “OptionSet” trigger doesn’t work always, so that I preferred “BufEnter”.
autocmd MyVimrc BufEnter * KeepOptions
And all the troubles with unpredictable changes in my settings, at last, have gone.
I am using Vim 7.3.154 cli on Linux Mint 12 "Lisa"(x64).
I prefer using a tabstop and shiftwidth of 2 columns.
My .vimrc has
:set ts=2
:set sw=2
to accomplish the same.
Whenever I open a new instance of Vim, tabstop value is retained, so existing tabs are rendered according to .vimrc. But somehow the shiftwidth value gets changed to 3. This results in 3 column indention while auto-indenting.
Running :set sw=2 on the new instance of Vim fixes this issue.
Can anyone tell me why Vim is ignoring/changing shiftwidth value from .vimrc?
I tried disabling all plugins to no avail.
Vim compiled options | .vimrc
This answer just summarizes what we discussed in the comments. :)
This is most likely caused by the fact that you have file specific settings enabled. Check :h modeline for more info on that. Make sure that those files you have the problems with don't have this line in them.
Instead of only setting tabstop and shiftwidth you should also setup a couple more settings regarding whitespace and tabs.
set noexpandtab " Make sure that every file uses real tabs, not spaces
set shiftround " Round indent to multiple of 'shiftwidth'
set smartindent " Do smart indenting when starting a new line
set autoindent " Copy indent from current line, over to the new line
" Set the tab width
let s:tabwidth=4
exec 'set tabstop=' .s:tabwidth
exec 'set shiftwidth=' .s:tabwidth
exec 'set softtabstop='.s:tabwidth
Check this video for some extra info: http://vimcasts.org/episodes/tabs-and-spaces/
So this is the answer to the actual problem that you were able to solve. That php.php file was in the /plugin directory. That directory gets loaded once, each and every time Vim starts up. Check this: http://learnvimscriptthehardway.stevelosh.com/chapters/42.html#vimplugin
If what you want is that file to load only on PHP files then you should put it in the /ftplugin folder: http://learnvimscriptthehardway.stevelosh.com/chapters/42.html#vimftplugin
Read the documentation there, it should be a .vim file, in other words in this case it would be called php.vim.
What Pathogen or Vundle do is modify the runtimepath (:h runtimepath), nothing more, nothing less.
So you can now accept this answer, by clicking the little green arrow to the left of this answer. :)
You can run:
verbose set shiftwidth ?
to check what is setting the value of shiftwidth. It might coming from a plugin. You can also choose to modify the value there.
Well, I'm a newb at Vim, so I'm guessing there's a 99% chance it's a user error!
Vim was soft wrapping long lines very nicely thank you, then a couple of days ago it started to insert hard wraps but only when I had saved the file.
I have been through wrap, nolinebreak, textwidth, nolist, and all combinations thereof to try to get softwrap back but to no avail. Heck, I even read the help pages. All of 'em.
Here's the relevant bits from my .vimrc (as you can tell, I'm getting desperate):
" Editing
set aw ai
set et ts=8 sts=2 sw=2 nu
set fo+=tcrqw fo-=o
set showmatch matchtime=5
set whichwrap=<,>,h,l,[,]
set cursorline
set nofoldenable
set wrap
set linebreak
let mapleader = ","
I picked up this .vimrc from using Vundle.
I found the culprit, Tim Pope's Vim Markdown plugin. Lovely plugin but personally prefer soft wraps, will have to find how to change it!
but only when I had saved the file.
This should hint to you that some plugin is touching the buffer Pre-Write.
Find out which it is by doing
:au BufWrite,BufWritePre,BufWriteCmd
:au FileWriteCmd,FileWritePre
To see where the trigger was installed from:
:verbose au BufWrite,BufWritePre,BufWriteCmd
:verbose au FileWriteCmd,FileWritePre
I have a suspicion this is probably caused by your fo line. Having "t" in the formatoptions option means that if a textwidth is set for the current buffer then vim will break lines at this width. You may notice that this only happens for certain filetypes because different ftplugins may be setting textwidth without you knowing.
The next time you see this happening, I'd suggest running :verbose set textwidth? (with the question mark) and seeing if the value is set. This command will also point you to where it was last set.
Another test would be to just remove "t" from your fo line and see if the problem goes away.
Janus is another Vim plugin that fiddles with linewrap/linebreak and textwidth.
:verbose set tw?
told me:
textwidth=72
Last set from ~/.vim/janus/vim/core/before/plugin/filetypes.vim
Now I just need to figure out the right incantation to disable that... for now, I just added set textwidth=99 to my ~/.vimrc.after file, but there may be a better way...
I'm using a Python file with the following modeline at the end:
# vim: sts=4:ts=4:sw=4
If I start Vim with this file the modeline is ignored. How can I fix this? And BTW, I have nocompatible set in my .vimrc.
Here is what you check...
Step 1
Make sure your settings are right. Do...
:verbose set modeline? modelines?
If you see either of these values returned, it's not going to work.
nomodeline
modelines=0
(By adding verbose before the set command, you will be told what file produced that setting. Thank you, drew010)
What you need to see is this (where that 4 is anything greater than 0)
modeline
Last set from /usr/share/vim/vimrc
modelines=4
Last set from ~/.vim/vimrc
Note from the comments: If you have either nomodeline or modelines=0, you are going to need to add set and the corresponding setting from the previous code block. (Thank you #pilat)
Step 2
Do you have a line with a vim: that is not touching any else within the last <modelines> lines of your document?
Seriously, that's all it takes.
These modelines all work...
# vim: cursorline
// vim: cursorline
; vim: cursorline
vim: cursorline
# anything here vim: cursorline
even without a valid comment vim: cursorline
literally anything as long a space separates> vim: cursorline
# vim: set cursorline: <-that colon is required if you use the word "set" and this comment after the colon does not affect it.
Notice that the only way to have a comment after the modeline is to use the word set. But if you use set, you must put a colon at the end of your settings even if you have no comment. Thank you, Amadan
Step 3
And this is an important one! Are you using the word set? (as described as the "second form" in the options doc) Take out the set or add a colon to the end.
None of these work...
# vim: set cursorline
^^^ issue: use of the word set without a trailing colon (:)
# vim:cursorline
^ issue: no space after the colon
#vim: cursorline
^ issue: no space before the word vim
Step 4
Have you been awake for more than 18 hours? Before you lose your mind, get some sleep. It'll still be broken tomorrow. You'll be more likely to notice the issue when you go through this list again then.
Update notes
This answer used to include this claim:
Are you using the word set? (as described as the "second form" in the options doc) Well, that doesn't work in version 8, and I don't know when it stopped working. Use the "first form".
I was wrong. It was pointed out by #Amadan and I have corrected Step 3.
I had a similar issue with my modeline not working. The answers in this thread helped me find my answer (which was adding set modeline to my ~/.vimrc)
https://superuser.com/questions/323712/modeline-not-work-in-vim
Also one thing that helped me debug this was to type :set in vim. This will tell you the different values that are currently set.
If you are saving and loading views, for example with something like the following, your modeline will not be reevaluated when you reopen a file.
autocmd BufWinLeave *.* mkview
autocmd BufWinEnter *.* silent loadview
I tracked the problem to a local plugin, called local_vimrc.vim. The fact that modeline does not work is a side-effect of the plugin.
The first step is always look in
/usr/share/vim/vim74/debian.vim
and comment out the nomodeline line.
Kubuntu distributions consider it a security
threat.
(EG: libcal allows you to run an arbitrary program)
This is only an issue if someone off system can run vim via a webpage. (don't trust user input.)
It is also possible to do a ddos attack using spell checker. (don't trust user input.)
I have had such problem with my modeline and "noexpandtab":
# vim: noexpandtab ft=python
but if I write:
# vim: ft=python noexpandtab
it works again. (Thank you guys for knowledge about :verbose set ... !)
This has bugged me for a long time, and try as I might I can't find a way round it.
When I'm editing text (specifically latex, but that doesn't matter) files, I want it to auto-wrap at 80 columns. It does this, except if I happen to be in the middle of a parenthetical clause, it indents the text which is very annoying. For example, this works fine
Here is some text... over
two lines.
but this doesn't
Here is some text... (over
two
lines
If anyone can tell me how to turn this off (just for text/latex files) I'd be really grateful. Presumably it has something to do with the fact that this is desired behaviour in C, but I still can't figure out what's wrong.
:set nocindent
The other options do nothing, and the filetype detection doesn't change it.
There are three options you may need to turn off: set noai, set nosi, and setnocin (autoindent, smartindent, and cindent).
This may be related, when pasting from gui into terminal window, vim cannot distinguish paste modes, so to stop any odd things from occuring:
set paste
then paste text
set nopaste
I had similar issues trying to paste xml text, it would just keep indenting. :)
gvim, the gui version of vim, can detect paste modes.
You can have a look at the autoindent option :
autoindent - ai
Copy indent from current line when starting a new line (typing
in Insert mode or when using the "o" or "O" command). If you do not
type anything on the new line except and then type or
, the indent is deleted again. When autoindent is on,
formatting (with the "gq" command or when you reach 'textwidth' in
Insert mode) uses the indentation of the first line. When
'smartindent' or 'cindent' is on the indent is changed in specific
cases. The 'autoindent' option is reset when the 'paste' option is
set. {small difference from Vi: After the indent is deleted when
typing or , the cursor position when moving up or down is
after the deleted indent; Vi puts the cursor somewhere in the deleted
indent}.
From the official Vim documentation
filetype plugin indent on
This switches on three very clever
mechanisms:
Filetype detection. Whenever you start editing a file, Vim will try to
figure out what kind of file this
is. When you edit "main.c", Vim will
see the ".c" extension and
recognize this as a "c" filetype.
When you edit a file that starts with
"#!/bin/sh", Vim will recognize it as
a "sh" filetype. The filetype
detection is used for syntax
highlighting and the other two
items below. See |filetypes|.
Using filetype plugin files Many different filetypes are edited with
different options. For example,
when you edit a "c" file, it's very
useful to set the 'cindent' option to
automatically indent the lines. These
commonly useful option settings are
included with Vim in filetype plugins.
You can also add your own, see
|write-filetype-plugin|.
Using indent files When editing programs, the indent of a line can
often be computed automatically.
Vim comes with these indent rules for
a number of filetypes. See
|:filetype-indent-on| and
'indentexpr'.
:set noai
sets no auto indent tt may be smartindent though. Check out the doc and see if you can find something more
http://www.vim.org/htmldoc/indent.html