I have pathogen set up in my vim installation and various plugins installed.
"Call pathogen to set up various plugins
"filetype off
call pathogen#infect()
call pathogen#incubate()
call pathogen#helptags()
When I write my .vimrc in vim, the following command is supposed to reload the file (and it does seem to work).
" Source the vimrc file after saving it
if has("autocmd")
autocmd bufwritepost .vimrc source $MYVIMRC
endif
After writing .vimrc, however, pathogen does not reload.
Here is the output of :set rtp? after starting vim:
runtimepath=~/.vim,~/.vim/bundle/Jellybeans,~/.vim/bundle/TwitVim,~/.vim/bundl
e/badwolf,~/.vim/bundle/calendar,~/.vim/bundle/tagbar,~/.vim/bundle/vim-airline,
~/.vim/bundle/vim-colors-solarized,~/.vim/bundle/vim-colorschemes,~/.vim/bundle/
vizardry,/var/lib/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/vim74,/usr/s
hare/vim/vimfiles/after,/var/lib/vim/addons/after,~/.vim/after
and after :w in .vimrc it returns to the default.
runtimepath=~/.vim,/var/lib/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/
vim74,/usr/share/vim/vimfiles/after,/var/lib/vim/addons/after,~/.vim/after
I tried adding the following modification to no avail...
if has("autocmd")
autocmd bufwritepost .vimrc source $MYVIMRC
autocmd bufwritepost .vimrc call pathogen#incubate()
endif
I've been looking around and can't seem to find a solution other than just restarting vim every time I modify my .vimrc, which is fairly disruptive. Any help would be appreciated.
edit: output of tree -d -L 2...
.
├── autoload
└── bundle
├── badwolf
├── calendar
├── color~
├── Jellybeans
├── tagbar
├── TwitVim
├── vim-airline
├── vim-colorschemes
├── vim-colors-solarized
└── vizardry
The problem may be the following lines on your .vimrc:
" This line should not be removed as it ensures that various options are
" properly set to work with the Vim-related packages available in Debian.
runtime! debian.vim
On $VIMRUNTIME/debian.vim there is a line that reset the runtime path:
" Debian system-wide default configuration Vim
set runtimepath=~/.vim,/var/lib/vim/addons,/usr/share/vim/vimfiles,/usr/share/vim/vim74,/usr/share/vim/vimfiles/after,/var/lib/vim/addons/after,~/.vim/after
The problem doesn't happens when the .vimrc is loaded on startup because these lines are executed before call pathogen#infect(). When you reload your .vimrc you are overwriting your &rtp, but pathogen doesn't set it again (possible because s:done_bundles is already set).
Related
I want to turn off htmlbeautify for md files.
I am using the plug in vim-jsbeautify and use a plug in on save the following way: in my vimfiles/ftplugin folder
├── ftplugin
│ ├── html
│ │ └── main.vim
I have added a html folder and added a main.vim file with the content
autocmd BufWritePre <buffer> call HtmlBeautify()
noremap <buffer> <c-f> :call HtmlBeautify()<cr>
so that html files are formatted on save. The command verbose set filetype returns
filetype=markdown
Last set from /usr/share/vim/vim80/filetype.vim
for md files
Some how the md files are also considered of html files. how can I turn this of?
Inside $VIMRUNTIME/ftplugin/markdown.vim you will find the following line:
runtime! ftplugin/html.vim ftplugin/html_*.vim ftplugin/html/*.vim
This will source html ftplugins for markdown files as Markdown uses html in its syntax.
One way to prevent this is do add an :if to avoid these inclusion for markdown.
if &filetype == 'html'
autocmd BufWritePre <buffer> call HtmlBeautify()
noremap <buffer> <c-f> :call HtmlBeautify()<cr>
endif
I can't seem to make any xml.vim plugin work for my vim setup. I have tried two (https://www.vim.org/scripts/script.php?script_id=1397 and its predecessor https://www.vim.org/scripts/script.php?script_id=301). They seem totally nonfunctional. I have tried to view their documentation from within vim (:help xml C-d), and nothing appears except the default xml syntax help.
I have been installing them using pathogen, the standard way (e.g. git clone https://github.com/sukima/xmledit.git ~/.vim/bundle/xmledit). After installation, I have tried opening a test.xml file to load helptext, with no results.
I saw the other question posted here with no resolution, and it didn't help: turn on xml.vim ftplugin in vim
So, does anyone know why this is going wrong? This is running on Ubuntu through Windows Subsystem for Linux, but I have other working plugins (tslime and vim-slime).
Edit: After looking at this some more, I tried :scriptnames and the plugin (currently xmledit) doesn't appear to be in it, although the bundle/xmledit directory is in the runtimepath. Here are the contents of bundle/xmledit:
xmledit/
├── build.vim
├── doc
│ └── xml-plugin.txt
├── ftplugin
│ ├── html.vim
│ ├── php.vim
│ ├── xhtml.vim
│ └── xml.vim
├── Makefile
├── README.mkd
└── tests
├── Gemfile
├── Gemfile.lock
├── Rakefile
├── README.md
└── spec
├── spec_helper.rb
└── xmledit_spec.rb
vim version: 7.4. included patches: 1-1689, extra patches: 8.0.0056
.vimrc:
" mapleader definition has to be on top:
let mapleader="," " leader is comma
" necessary for pathogen:
execute pathogen#infect()
" the good settings:
set background=dark " obvious
set tabstop=4 " number of visual spaces per tab
set shiftwidth=4 " similar
set softtabstop=4 " number of spaces added/removed while editing
set expandtab " tabs become spaces
set smartindent " do smart indenting when starting a new line
set autoindent " copies previous indent when starting a newline
filetype indent on " makes filetype-based indenting work
set number " show line numbers
set wildmenu " cyclical menu for autocompletion
set showmatch " highlight matching bracket
set incsearch " search as you type
set hlsearch " highlight search results
" turn off search highlight
noremap <leader><space> :nohlsearch<CR>
" move vertically by visual line (don't skip over wrapped lines)
nnoremap j gj
nnoremap k gk
" highlight last inserted text - doesn't work??
" nnoremap gV `[v`]
" edit vimrc with ev
nnoremap <leader>ev :vsp ~/.vimrc<CR>
" load vimrc with sv
nnoremap <leader>sv :source ~/.vimrc<CR>
" save session (reopen with vim -S)
nnoremap <leader>s :mksession<CR>
" set html indentation lower:
autocmd FileType html setlocal softtabstop=2 shiftwidth=2 tabstop=2
" for scheme/lisp:
let g:tslime_ensure_trailing_newlines = 1
" don't use, but useful to have documented:
" set cursorline " highlight current line
" idk:
"highlight Normal ctermbg=LightGray
"syntax enable " enables syntax highlighting; not sure why this is disabled but it works anyway?
" FROM good vimrc
" CtrlP settings
"let g:ctrlp_match_window = 'bottom,order:ttb'
"let g:ctrlp_switch_buffer = 0
"let g:ctrlp_working_path_mode = 0
"let g:ctrlp_user_command = 'ag %s -l --nocolor --hidden -g ""'
" --- NOTES ---
" C-[ is escape.... ugh...
" also, somehow M-; is still getting through???
" mapleader is ,
" useful page: https://dougblack.io/words/a-good-vimrc.html
" most keybindings are from here
" RETURN TO:
" silver searcher? see good vimrc ^ for it
" also ctrl-p. I should get both of these
Ok it finally started working. I solved it by trying a few things that I thought were not necessary for Vim 7.4:
I added a filetype plugin on line after execute pathogen#infect().
I added a filetype off line to .vimrc before execute pathogen#infect().
I also used the :helptags command (which I thought Pathogen did on its own).
I don't have the patience to spend more hours identifying exactly which configuration is necessary to fix the issue, but hopefully this is sufficient for similar problems. My guess is that turning filetype plugins on is the primary culprit.
I want to synchronize the vim settings across my Mac and remote linux Ubuntu server. I am using NeoBundle for package management. I did the following:
On the Mac I installed NeoBundle and created a vimrc file in ~/.vim/. See below for the .vimrc file.
On the Mac I symlinked to this vimrc file using ln -s ~/.vim/vimrc ~/.vimrc
I entered .vim directory and made it into a git repository adding everything to the repository except .netrwhist and *.swp
Then I pushed this repository to bitbucket.
I logged into the server. Deleted .vim and .vimrc. Created a symlink ln -s ~/.vim/vimrc ~/.vimrc.
Then I created .vim on the server and ran git clone of the pushed repository. I see all the files on the server that I see on my mac.
The bundles are all in .vim/bundles. So they are available.
The Vim versions are different. Is that the problem?
On Mac it says:
VIM - Vi IMproved 7.3 (2010 Aug 15, compiled Dec 19 2013 15:19:49)
whereas on the server it says:
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Jan 2 2014 19:39:32)
Problem: Vim works great on the Mac. But on the server when I run vim I get the following error:
Error detected while processing /home/admin/.vimrc:
line 16:
E117: Unknown function: neobundle#begin
line 20:
E492: Not an editor command: NeoBundleFetch 'Shougo/neobundle.vim'
line 26:
E117: Unknown function: neobundle#end
line 33:
E492: Not an editor command: NeoBundleCheck
line 38:
E492: Not an editor command: NeoBundle 'scrooloose/nerdtree'
line 39:
E492: Not an editor command: NeoBundle 'terryma/vim-multiple-cursors'
line 40:
E492: Not an editor command: NeoBundle 'tomasr/molokai'
line 41:
E492: Not an editor command: NeoBundle '29decibel/codeschool-vim-theme'
line 42:
E492: Not an editor command: NeoBundle 'Lokaltog/vim-easymotion'
line 43:
E492: Not an editor command: NeoBundle 'jnurmine/Zenburn'
line 64:
E185: Cannot find color scheme 'zenburn'
The .vimrc contains:
"================================================================================
" NeoBundle settings (copied from NeoBundle github page)
"================================================================================
" Note: Skip initialization for vim-tiny or vim-small.
if !1 | finish | endif
if has('vim_starting')
set nocompatible " Be iMproved
" Required:
set runtimepath+=~/.vim/bundle/neobundle.vim/
endif
" Required:
call neobundle#begin(expand('~/.vim/bundle/'))
" Let NeoBundle manage NeoBundle
" Required:
NeoBundleFetch 'Shougo/neobundle.vim'
" My Bundles here:
" Refer to |:NeoBundle-examples|.
" Note: You don't set neobundle setting in .gvimrc!
call neobundle#end()
" Required:
filetype plugin indent on
" If there are uninstalled bundles found on startup,
" this will conveniently prompt you to install them.
NeoBundleCheck
"================================================================================
" Install these packages
NeoBundle 'scrooloose/nerdtree'
NeoBundle 'terryma/vim-multiple-cursors'
NeoBundle 'tomasr/molokai'
NeoBundle '29decibel/codeschool-vim-theme'
NeoBundle 'Lokaltog/vim-easymotion'
NeoBundle 'jnurmine/Zenburn'
"================================================================================
" Editor view settings
"================================================================================
syntax on
set number
" size of a hard tabstop
set tabstop=4
" size of an indent
set shiftwidth=4
" always use spaces instead of tab characters
set expandtab
set guifont=Monaco:h16
if has("gui_running")
colorscheme codeschool
else
colorscheme zenburn
endif
"=================================================================================
" Other settings
"=================================================================================
" Use Ctrl-s to save a file in insert mode.
inoremap <C-s> <C-c>:w<ENTER>
" make working directory same as the file being edited
" may interfere with some plugins (see here: http://vim.wikia.com/wiki/Set_working_directory_to_the_current_file)
set autochdir
Even though this post is aging, as there is still no answers, I figured I might give my take on this issue. As I'm synchronizing my configuration directories across computers mixing OSX and Linux, I thought I'd share the way I've done it, for future reference, if you did solve your question.
First of all, I split my vim configuration in two directories:
~/.vim/ that contains the vimrc configuration file and neobundle, meant to be shared across all computers
~/.local/vim that contains the bundles, swap files and undo files.
Here's a tree of the first ~/.vim/:
$HOME/.vim
├── README.md
├── neobundle.vim
│ ├── LICENSE-MIT.txt
│ ├── Makefile
│ └── […] (all neobundle contents)
└── vimrc
First let's set up undofiles in the ~/.vim/vimrc file:
" undo file
set undofile
set undodir=~/.local/vim/undofiles
set undolevels=2000
set history=200
and swapfiles:
" swap files
set directory=~/.local/vim/swapfiles
so that they're not synchronized between computers and mess up with each others. No, you don't want the undo of computer A on computer B, and even worst, you don't want all your standard unix /home/foo/* mixed with the non-standard /Users/foo/*…
Then, in my ~/.vim/vimrc, I setup neobundle the following way:
" NeoBundle setup {{{
filetype off
set runtimepath+=~/.vim/neobundle.vim/
call neobundle#begin(expand('~/.local/vim/bundle'))
NeoBundleFetch 'Shougo/neobundle.vim'
" }}}
that's where the trick is: you set up the runtimepath to add the neobundle.vim addon bundle "manually" to the runtimepath of vim within ~/.vim, then you start neobundle by telling him where to find/install bundles. Following that in the vimrc file, you setup all your favorite bundles, and finally you end it with:
" NeoBundle Prologue {{{
call neobundle#end()
filetype plugin indent on " required!
NeoBundleCheck
" }}}
So, now, when I'm deploying vim on a new computer, all I have to do, is:
git clone https://github.com/guyzmo/vimrc ~/.vimrc
mkdir -p ~/.local/vim/bundle
mkdir ~/.local/vim/undofiles
mkdir ~/.local/vim/swapfiles
vim +NeoBundleInstall +qall
Finally, if that solution answers your question is that you keep in sync only the necessary static stuff (what plugins and what configuration), and generate all the dynamic stuff locally to each computer. So, you leave Neobundle do its job, cloning git repositories, compiling and installing files. For example, look at youcompleteme setup, where it is defined how to install it depending on the host you're running your vim on. And also, you'll never have any more git issues.
HTH
Let's say I want one group of settings for HTML, CSS and JavaScript files but another set for Ruby files (completely different). What's the simplest way to do this?
You can put ftplugin directory with filetype-specific settings inside
.vim directory
.vim
└── ftplugin
└── ruby.vim
└── markdown.vim
And keep your settings there. The are applied when file with
corresponding filetype is opened.
Also, you might need to have filetype detection(if not detected
properly). You can put this to your .vimrc
autocmd BufNewFile,BufRead *.markdown,*.md,*.mdown,*.mkd,*.mkdn set ft=markdown
Or, put it into ftdetect directory
.vim
└── ftdetect
└── markdown.vim
You can give global settings like this.
For other files:
set shiftwidth=4
for Ruby files:
autocmd BufRead,BufNewFile *.rb set shiftwidth=2
You can get what you want via autocmd, it's format as follows:
au[tocmd] [group] {event} {pattern} [nested] {cmd}
[group] and [nested] are optional.As I give the example above, BufRead,BufNewFile is the event, *.rb is the pattern, and set shiftwidth=2 is the cmd.
more information about autocmd, please refer: :help automcd
I want to bind something like this:
For CSS, HTML files: <c-space> <c-x><c-n>
For Ruby files: <c-space> <c-x><c-u>
How to do this?
The documentation is more complete, precise and correct, but briefly:
Make a file in your ftplugin folder (create this folder if necessary) starting with the filetype you'd like to use.
├── vim
│ ├── after
│ ├── autoload
│ ├── bundle
│ ├── ftplugin
│ │ ├── python.vim
│ │ ├── rnoweb.vim
│ │ └── tex.vim
│ └── syntax
and in one of of these files, the python.vim one for example, a line like
noremap! <buffer> <F5> <Esc>:w<CR>:!python % <CR>
will be a bind only defined for this filetype, just in this buffer. Make sure filetype plugin on or similar appears in your vimrc.
Edit: excellent suggestions by Peter Rincker incorporated: noremap version of map command and <buffer> flag. He also reminds us to use setlocal instead of set in our filetype plugin files.
Use autocmd:
autocmd filetype css inoremap <buffer> <c-space> <c-x><c-n>
autocmd filetype html inoremap <buffer> <c-space> <c-x><c-n>
autocmd filetype ruby inoremap <buffer> <c-space> <c-x><c-u>
Put the following in your .vimrc. Substitute the do stuff lines with your bindings.
:if match(#%, ".css") >=0
: do css stuff
:endif
:if match(#%, ".rb") >=0
: do ruby stuff
:endif