I am trying to disable spellcheck in vim.
I have tried adding set nospell to my .vimrc but that has no effect. If I type :set nospell while editing a file it works - but I want to disable it globally. Any suggestions?
If you follow :help 'spell', you'll see that this option is local to window. If you use :set during Vim startup (e.g. in your ~/.vimrc), you'll set the global default and the first window's option, but this doesn't mean that filetype plugins or other :autocmd cannot change the option again later.
Vim can usually tell you who set an option last, via
:verbose set spell?
This often gives you a hint how to undo or prevent an undesired configuration change. Plugins usually have configuration, and filetype plugins can be overridden via the after-directory.
Related
In my _vimrc file I have:
set colorcolumn=80
I'd like to disable/modify this but I can't. When I use 120 instead of 80 nothing changes, and when I delete this line the column still keeps highlighted. However, :set colorcoumn=120 does work when I enter it manually in a Vim session. Where is the problem?
By giving :verbose set colorcolumn, you have received
Last set from ~\vimfiles\bundle\python-mode\ftplugin\python\pymode.vim
The plugin file called pymode.vim has changed the value of colorcolumn to colorcolumn+1, whenever you opened file through vim.
To overrride this behaviour,
You can give
:au BufEnter *.* :set colorcolumn=120
in ~/.vimrc.
This will override your plugin's behavior.
(Other alternate solutions: you can remove the plugin if you don't want. Or, remove that line in the plugin if it doesn't affect anything in the functions.)
I am using vim inside tmux. For some reason, my vim settings are getting constantly reset. --EDIT-- more detail: specifically, tabstop and autoindent are being set to default values, namely tabstop=8 and noautoindent. I don't think its something in my settings that is setting them to that, because when I type :so $MYVIMRC it resets to the proper values from my vimrc. I think vim is somehow "forgetting" my settings?
I haven't been able to figure out exactly what is causing it, but it happens pretty frequently, almost every couple of minutes. It seems to happen most often when I focus on another window, or switch panes in tmux. But it doesn't happen every time, and sometimes it just happens while typing. I have no idea what the problem is but its very frustrating. Also, it seems to happen most with python, slightly less with javascript, and even less frequently with PHP or other languages. Though this could be that I spend most of my time working in python and javascript...
I was having a problem earlier where I was getting gibberish entered into my status bar: Vim inside Tmux: <C-w>l (swapping between vim splits) enters ^]lfilename^] into vim. That fixed that issue, but seems to have caused this new one.
Here are what I think are the relevant parts of my .vimrc, .tmux.con and .bashrc. These are all of my settings, I didn't include keybindings.
.vimrc
set nocompatible
set showmatch
execute pathogen#infect()
syntax enable
filetype plugin indent on
colorscheme desert
set t_Co=256
set shiftwidth=4
set softtabstop=4
set backspace=indent,eol,start " consume expanded tabs if possible
set expandtab
set shiftround
set autoindent
set relativenumber
set showmode
set showcmd
set hidden
set autoread
set ignorecase
set smartcase
set incsearch
set autochdir
set laststatus=2
set statusline=%<%F\ %h%m%r%=%-14.(%l,%c%V%)\ %13.L\ %P
set titlestring=%F
set splitbelow
.bashrc:
export TERM=screen-256color
.tmux.conf
export TERM=screen-256color
Some settings are local to a buffer or window. Indent settings, e.g. 'shiftwidth', 'softtabstop', and 'expandtab', are local to a buffer and not global. This makes sense because different filetypes have different needs. A good example of types that need completely different indent settings would be python and makefile.
Setting up indent setting per filetype are usually done one of the following ways:
Use modelines for each file. Gross! (:h modeline)
Use autocmd's in your ~/.vimrc. e.g. autocmd FileType c,cpp,cs,java setlocal shiftwidt=4 softtabstop=4 expandtab
Put these setting in ~/.vim/after/ftplugin/python.vim. Replace python with any filetype you want to have specific settings for.
Note: You can find a buffer's file type via :set ft?
Personally I like the after directory structure as it is nice and neat and keeps the clutter out of my ~/.vimrc file.
For more help see:
:h local-options
:h 'sw
:h 'rtp
:h after-directory
:h ftplugin-overrule
You said you work in javascript and python and that you notice the difference when changing between them. Are you sure this is changing and not that you get different behavior for javascript and python?
Note the pathogen#infect(). You probably have something like syntastic installed which in turn will have lint tools for javascript and python. Those tools may have file type specific indentation settings. If you have something following PEP8 for python it's probably defaulting to spacing instead of tabs for indentation.
Check .vim/ftplugin and .vim/ftdetect, filetype specific settings can be put there which will override the default behavior specified in your .vimrc.
After I installed Vundle, my vim no longer obeys the expandtab settings I had. My tabs were set to 2 spaces, but now in python files it no longer does that. The problem is being called by this line:
filetype plugin on
What does this line do (It is required by vundle)? Also, what can I do to make sure my settings are obeyed?
Thanks!
VIMRC: pastebin.com/tGmfCi78
The problem is that your settings are being overridden by a filetype plugin that's part of Vim. The issue is in ftplugin/python.vim:
" As suggested by PEP8.
setlocal expandtab shiftwidth=4 softtabstop=4 tabstop=8
The python plugin attempts to setup your source code to be PEP8 compliant by default, so it's adjusting the tabstop. You'll want some of what these plugins have to offer, but you may need to setup your own autocommands to fixup anything you don't like.
There are two ways to go about doing this. If you have a ~/.vim folder, the easiest way is to add the file ~/.vim/after/ftplugin/python.vim:
" Here, you can set the setting directly, or call a command or function
" to help you. We'll call a command, and then implement that command in
" your top-level vimrc to help keep things in one place.
SetupPython
In your .vimrc, add:
function! SetupPython()
" Here, you can have the final say on what is set. So
" fixup any settings you don't like.
setlocal softtabstop=2
setlocal tabstop=2
setlocal shiftwidth=2
endfunction
command! -bar SetupPython call SetupPython()
The latter bit just allows you to call the function as SetupPython rather than call SetupPython() in the after file.
The other way, is to keep everything in your .vimrc, but you use the VimEnter autocommand to setup a FileType autocommand for python to set your preferences. By waiting until VimEnter is triggered, all the other plugins will have had time to setup their autocommands, so your's will be added to the end of the list. This allows you to run after the python plugin's FileType autocommand and set your own settings. This is a bit of a mess though, and the after/ mechanism above is the preferred way of doing this.
FWIW, many common settings I keep in a SetupSource() function to be called from a number of different FileTypes. Then I'd have SetupPython() call SetupSource(). This helps to keep the specific functions a little cleaner and reduce some duplication. If it helps, take a look at the functions in my vimfiles here: https://github.com/jszakmeister/vimfiles/blob/master/vimrc#L5328
Overridden settings
It could be that the settings are being overridden by language-specific settings. See http://vim.wikia.com/wiki/Keep_your_vimrc_file_clean for more information:
The quick way to get started is to move all the language-specific stuff from your .vimrc file into a file named .vim/ftplugin/language.vim (or $HOME/vimfiles/ftplugin/language.vim on Windows).
Check in those locations for a python specific .vim file.
Filetype on
Vundle appears to require filetype off, and I'm not sure if you should turn it back on. There's a thread on the github issues page for Vundle explaining why filetype on is required. Perhaps this will provide some insight.
I also think having filetype plugin indent on followed by filetype on is redundent. According to the vim help docs, the former turns detection, plugin and indent on, and the latter turn detection on and leaves the plugin and indent unchanged:
Overview: *:filetype-overview*
command detection plugin indent
:filetype on on unchanged unchanged
:filetype off off unchanged unchanged
:filetype plugin on on on unchanged
:filetype plugin off unchanged off unchanged
:filetype indent on on unchanged on
:filetype indent off unchanged unchanged off
:filetype plugin indent on on on on
:filetype plugin indent off unchanged off off
I am new to vim and I want to use it for scripting Python3. anyone knows how to customize vim for editing Python 3 scripts? (mainly for indentations, coloring and tab suggestions... )
Thanks
Python wiki suggests putting the following in your ~/.vimrc:
syntax on
filetype indent plugin on
set tabstop=8
set expandtab
set shiftwidth=4
set softtabstop=4
Edit: the above does have the side-effect of using the tab settings in all files edited with vim. Other approaches are discussed in the wiki as well.
There's also the python.vim script for syntax highlighting and such.
You should put customized settings in to ~/.vim/ftplugin/python.vim This will be sourced when vim sees a file with a filetype python.
To make sure the settings only affect the current buffer use setlocal.
To make sure that mappings only affect the current buffer use noremap <buffer>
Just make sure to have filetype plugin indent on in ~/.vimrc
In a vim plugin, how can I tell if a user has already set a variable in their .vimrc file?
For instance, I have in .vimrc:
set shiftwidth=2
Then I load a plugin that has
set shiftwidth=3
So I think to modify the plugin like so:
if !exists("shiftwidth")
set shiftwidth=3
endif
But when I load up a new vim window with the revised plugin loaded, my tabs are still set to 3 and not 2.
How can I make it so that it only sets shiftwidth=3 unless otherwise specified in .vimrc?
These commands should show where shiftwidth was set:
:set verbose=15
:set shiftwidth
:set verbose=0
If you want to programmatically do something with that info you'd need to redirect the verbose output and parse it for what you want:
:redir => myvariable
:set verbose=15
:set shiftwidth
:set verbose=0
:redir END
myvariable will now have text that would otherwise have been printed to screen.
REVISED ANSWER
Here is a way I think you could do what you clarify in your comments.
Add a last line to user's vimrc to save the current value of shiftwidth to a global variable. The value will be saved before any plugins are loaded, unless plugins are explicitly sourced in the vimrc before the last line. You can then reset shiftwidth to this value in your own plugin.
[everything in vimrc comes before this line]
:let g:vimrc_shiftwidth = &shiftwidth
You can programmatically add this line with something like the write >> [file] command. Presumably you would include a comment indicating what plugin had added this command to the vimrc. Also, I don't think this would capture the correct value, e.g., in case where user uses exrc option and sets shiftwidth in a different vimrc. All in all, still not recommended.