I want to create different vim files for different task in vim. I know you you can create different vim files, which can be loaded on the fly based on the extension of the file. My problem is I am using vundle to maintain plugins and I really don't know how to separate these plugins in different files.
I searched about separating vim and I found you can use ftplugin, something like ftplugin/python.vim or ftplugin/matlab.vim. But I don't know should I write vundle part in each .vim file or everything should be in one vim file.
Please let me know if you need more information. Below is my current .vimrc file.
" Configuration file for vim
set modelines=0 " CVE-2007-2438
" Normally we use vim-extensions. If you want true vi-compatibility
" remove change the following statements
set nocompatible " Use Vim defaults instead of 100% vi compatibility
filetype off " required
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
"===================================================================
"Plugins
" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'
" For autocomplete
Bundle 'Valloric/YouCompleteMe'
" For folding
Plugin 'tmhedberg/SimpylFold'
" For indent python
Plugin 'vim-scripts/indentpython.vim'
" For syntax
Plugin 'w0rp/ale'
" Check Python files with flake8 and pylint.
let b:ale_linters = ['flake8', 'pylint']
" Fix Python files with autopep8 and yapf.
let b:ale_fixers = ['autopep8', 'yapf']
" Disable warnings about trailing whitespace for Python files.
let b:ale_warn_about_trailing_whitespace = 0
syntax on
" For color Schemes
"Plugin 'jnurmine/Zenburn'
Plugin 'flazz/vim-colorschemes'
Plugin 'morhetz/gruvbox'
" For PowerLine
"Plugin 'powerline/powerline', {'rtp': 'powerline/bindings/vim/'}
Plugin 'vim-airline/vim-airline'
Plugin 'vim-airline/vim-airline-themes'
"For the nerd tree
Plugin 'scrooloose/nerdtree'
" add all your plugins here (note older versions of Vundle
" used Bundle instead of Plugin)
" ...
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
"===================================================================
" For UTF-8
set encoding=utf-8
"System Clipboard
if has('mac')
set clipboard=unnamed
elseif has('unix')
set clipboard=unnamedplus
endif
"set Line Numbering
set nu
"to handle the backspace problem
set bs=2
"Set up mouse
set mouse=a
"For Highlighting searched text
set hlsearch
"For confirming before exit (save)
set confirm
"Maping Ctrl+A for select all
map <C-a> <esc>ggVG<CR>
"===================================================================
" Mapping NERDtree toggling
nmap <F6> :NERDTreeToggle<CR>
"===================================================================
"Few settings for plugins
" colorscheme
colorscheme py-darcula
" to see the docstrings for folded code
let g:SimpylFold_docstring_preview=1
let mapleader=" "
"The first line ensures that the auto-complete window goes away when you’re
"done with it, and the second defines a shortcut for goto definition (second
"one I need to learn)
let g:ycm_autoclose_preview_window_after_completion=1
let g:ycm_min_num_of_chars_for_completion = 1
"map <leader>g :YcmCompleter GoToDefinition<CR>
"To handle vitural env for YCM
let g:ycm_python_binary_path = 'python3'
Using separate configuration files is possible (you can override the default .vimrc via the -u {vimrc} command-line argument; a shell alias can make this very easy). However, this complexity should not be necessary for most users.
In particular, Vim has built-in scoping of settings for different types of files in the form of buffer-local options and filetype plugins. So, if you want different indentation for Python vs. text files, that should work out of the box. Even though you're globally installing a plugin like vim-scripts/indentpython.vim (via Vundle in your case), it will only activate on files where :setlocal filetype? returns python. (By the way, that plugin was last updated 9 years ago, and Vim now ships with a $VIMRUNTIME/indent/python.vim that's actively maintained.)
For global plugins, it usually doesn't harm to have them installed all the time, even though you might only use them with certain projects. Vim's autoload mechanism dynamically includes the main plugin functionality on demand to keep Vim startup time short. Activating different plugin sets only makes sense for very few advanced users (and these would already have very deep knowledge of Vim's plugin mechanisms and not need to ask such questions).
You'll find more information about this at :help filetypes and :help local-options.
As I understand, the existed plugins work fine but you want to know the proper way to write your own ones. Am I right?
If so, then you don’t have to write your plugins (or other vim files) in any relation to Vundle or any other plugin manager. All you need is:
Read :help rtp.
Create a folder for your files wherever your want.
Set up the runtimepath option to the new folder. Typically, it’s just adding the new path with += operator.
Knowing about the list of directories which are searched for runtime files, create the functionality you want to get.
Yet another time: leave Vundle if you’re writing your own vim file. Vundle,
like any other plugin manager, is just a convenient tool to retrieve the code from a github repository and to set up the rtp option according to the new data.
Related
I have installed with Vundle this github colours theme. I installed is with :VundleInstall and it seems to work just fine. The directory ~/.vim/bundle/vim-colors-github is there. Indeed, I can switch the color scheme with colorscheme github.
Next, I have added the following lines to ~/.vimrc to make this change permanent:
" github colors
let g:github_colors_soft = 1
Plugin 'cormacrelf/vim-colors-github'
colorscheme github
But this raises the error "E185: colorscheme «github» not found".
It just doesn't work during the loading of vim!? What's going on here? I guess there is something that hasn't been set yet at the time of calling the change in the colorscheme. How could I debug this?
You seem to be missing the call to vundle#end() at the end of your plug-in configuration. See the quick start guide which shows an example of defining plug-ins in your vimrc:
call vundle#begin()
Plugin ...
call vundle#end() " required
filetype plugin indent on " required
In your case, adding those lines around your Plugin definition will most likely fix the issue:
" load plugins
call vundle#begin()
Plugin 'cormacrelf/vim-colors-github'
call vundle#end() " required
filetype plugin indent on " required
" github colors
let g:github_colors_soft = 1
colorscheme github
Also note that Vundle hasn't really been very thoroughly maintained. While there's nothing wrong with it, vim-plug is a compatible alternative (works the same way, uses similar configuration and similar commands) which is well maintained and offers improvements in terms of performance and features. I'd definitely recommend switching to vim-plug, particularly if you're getting started with a Vim plug-in manager of this style.
Color schemes are searched along 'runtimepath' and 'packpath'. Therefore they will only be found on startup if you install plugins with respect to :h packages (i.e. under 'packpath'), not under arbitrary ~/.vim/bundle.
As for Vundle and such you are expected to manually set up 'runtimepath', so that it includes all plugins before executing :colorscheme. For Vundle it is done by calling vundle#end().
I enabled Linux coding style in $HOME/.vimrc as:
let g:linuxsty_patterns = [ '/home/mark/sample1', '/home/mark/sample2', '/home/mark/sample3' ]
But is it possible to enable it per file? As I know, it is possible to pass vim settings in comments in C files. Also, I tried to manually set linuxsty_patterns while editing opened file in vim, but it didn't take any effect.
What am I doing wrong?
You should have stated that your question relates to a specific plugin.
Those questions are better addressed directly to the plugin maintainer.
Now, reading its source code, it seems you just need to specific a list of regexes that match the source files to which you which to apply the plugin setting. It seems this is the only control you could expect with this plugin.
I don't see file types in your example, but I use autogroup like this.
augroup go
autocmd!
" Write file before :make, :GoBuild, :GoTest|Func, :GoRun
autocmd FileType go set autowrite
" go fmt uses tabs for indentation, ts and sw only affect viewer
autocmd FileType go setlocal noexpandtab tabstop=4 shiftwidth=4
" Enable Vim syntax highlighting for Go template files
......
augroup END
I'm getting pretty annoyed of vim automatically generating swap files when I press control-z. Is there any way to disable this feature (and not just delete them)?
Put this in your .vimrc:
set noswapfile
Edit: You could also consider moving backup files to a location where they won't get in your way. I have this in my .vimrc:
set noswapfile
" Alternatively, store your swap files in your local .vim folder
" call system('mkdir ~/.vim/swap')
" set dir=~/.vim/swap/
if has('persistent_undo')
set undolevels=5000
call system('mkdir ~/.vim/undo')
set undodir=~/.vim/undo
set undofile
endif
call system('mkdir ~/.vim/backups')
set backupdir=~/.vim/backups/
" The 'n' here is a prefix specifying which viminfo property is being set -
" in this case, the Name of the viminfo file.
" :h 'viminfo'
set viminfo+=n~/.vim/viminfo
I really like the persistent undo, meaning even after quitting vim, restarting the computer etc., you can just undo/redo changes from previous sessions.
Note that if you are using both console vim under Cygwin and windows gvim, you'll need to wrap all of this in an if v:progname != "gvim.exe" block, since windows won't understand paths like ~/.vim. I have this section duplicated in my _gvim file using windows paths, for the odd occasion where I use gvim.
Gvim is behaving weird and I can't find the reason. I use Vundle, and all the plugins declared in my .vimrc are working fine. I declared some additional settings and plugins in .vim/after/ftplugin/java.vim.
The mappings work fine, but the plugins do not work. If I choose a different file in my current gvim session, I get those error messages:
Error detected while processing function vundle#config#bundle[2]..<SNR>14_check_bundle_name:
line 2:
Vundle error: Name collision for Plugin Raimondi/delimitMate. Plugin Raimondi/delimitMate previously used the name "delimitMate". Skipping Plugin Raimondi/delimitMate.
Vundle error: Name collision for Plugin artur-shaik/vim-javacomplete2...
[comment: same error message for all plugins declared in the ftplugin]
I noticed, that if I run :VundleInstall the plugins are suddenly working (the error messages stay when I change the file, no plugins are installed when I use the command).
Here is the beginning of my .vimrc:
syntax on
set guifont=Inconsolata\ Medium\ 12
set nocompatible
set t_Co=256
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
"[comment: all plugins I use for every filetype]
call vundle#end() " required
filetype plugin indent on
and this is my java.vim file:
filetype off
"to automatically close brackets
Plugin 'Raimondi/delimitMate'
"omni-complete for Java
Plugin 'artur-shaik/vim-javacomplete2'
"use tab to navigate through insert completion
Plugin 'ervandew/supertab'
filetype plugin indent on
"needed to make javacomplete2 working properly
autocmd FileType java setlocal omnifunc=javacomplete#Complete
My OS is Ubuntu 16.04.
You're mistaken regarding what ftplugins are doing and what they should contain.
Ftplugins are loaded once per buffer, every time a new buffer is created/opened.
They are meant to contain buffer local definitions:
:map <buffer> keybinding action
:iab <buffer> keybinding expanded sequence
:setlocal option[=value]
:command -b CommandName :Action
:let b:option = value
set the localleader (but be certain it's done before any other ftplugin for the same filetype) (EDIT: localleader is actually a global setting, my mistake)
They could then load other things that work the same way with :runtime or :so. They could contain functions, but it's best to define them into autoload plugins since Vim7. They may contain buffer local menu definitions, but this requires a plugin as this is not standard.
They are definitively not meant to contain global definition like the ones you have defined. It's not really the place to load global plugins that'll stay activated afterwards.
I know that some plugins manager load plugins on the fly depending on the type of the file we work on. I've never shared this need when we are using properly defined ftplugins, and lightweight plugins that only define a few mappings and keep their functions into autoload plugins.
Last thing, ftplugins are supposed to contain anti reinclusion guards. On a typical scenario this is not that useful. Many use b:did_ftplugin for that purpose, but I avoid this variable as I prefer to have as many ftplugins (for a same filetype) as themes (one that specializes the brackets pairs, one that defines the mapping to automatically expand a switch statement from the type of a variable, one that defines abbreviations for control statements, and so on). As a consequence I cannot use the same guard for all files.
All your :Plugin commands are supposed to be between these two lines:
call vundle#begin()
" :Plugin commands go here
call vundle#end()
Try another plugin manager if you absolutely need lazy loading.
is there a way to hide columns of a buffer (text file, you know what I mean) while editing it in Vim? e.g. text visible in the buffer before hiding column 2&3:
abbcccccc
accdddddd
And after hiding them:
acccccc
adddddd
(Not to mention I'm working with really huge files (sometimes over 200 gb).)
And yeah, I had found foldcol.vim, but it requires a patch, and I don't have gcc to compile it as a user on a server.
Thanks in advance.
Cannot be done in stock vim; there is a conceal patch that has not been accepted. The most recent version is only for vim7, and not 7.2 (much less 7.2+patches), so it's probably best considered dead.
Is foldcol.vim maybe what you need? No clue if it works on your huge files though. 200 gb! Impressive in a geeky kind of way. =)
The best version I have seen so far is following:
https://github.com/paulhybryant/foldcol
this github project is based on
http://vim.sourceforge.net/scripts/script.php?script_id=1161
however it has some improvements - it actually shows hidden column as '*'
it needs vim-maktaba plugin, so in order to install this in your vim, then do following:
add to your ~/.vimrc file :
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
" Install vim-maktaba plugin for plugin developers - used in foldcol
Plugin 'google/vim-maktaba'
" Install foldcol - folding columns using <ctrl-v> visual mark, then :VFoldCol
Plugin 'paulhybryant/foldcol'
" All of your Plugins must be added before the following line
call vundle#end() " required
Notice the two plugins added in the vundle.begin -> vundle.end section ; the vim-maktaba and the foldcol
After adding this to your ~/.vimrc file then start vim as administrator or if you are running on ubuntu then write sudo vim
then write :PluginInstall and if needed then write your user and password for your GitHub account - this will give you access to downloading and installing vim plugins from github
example usage in terminal vim started; use <ctrl-v> and mark column :
it may seem cumbersome, however it is actually just adding two lines to your ~/.vimrc file and running :PluginInstall
enjoy