How do I configure my vimrc to use different theme? - vim

My vimrc is located at /usr/share/vim/vimrc and I have got .vim file for theme I want to use. In which directory I put my .vim theme file and what I change in my vimrc file?
Here is my vimrc file:
" All system-wide defaults are set in $VIMRUNTIME/debian.vim (usually just
" /usr/share/vim/vimcurrent/debian.vim) and sourced by the call to :runtime
" you can find below. If you wish to change any of those settings, you should
" do it in this file (/etc/vim/vimrc), since debian.vim will be overwritten
" everytime an upgrade of the vim packages is performed. It is recommended to
" make changes after sourcing debian.vim since it alters the value of the
" 'compatible' option.
" 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
" Uncomment the next line to make Vim more Vi-compatible
" NOTE: debian.vim sets 'nocompatible'. Setting 'compatible' changes numerous
" options, so any other options should be set AFTER setting 'compatible'.
"set compatible
" Vim5 and later versions support syntax highlighting. Uncommenting the next
" line enables syntax highlighting by default.
if has("syntax")
syntax on
endif
" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
"set background=dark
" Uncomment the following to have Vim jump to the last position when
" reopening a file
"if has("autocmd")
" au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
"endif
" Uncomment the following to have Vim load indentation rules and plugins
" according to the detected filetype.
"if has("autocmd")
" filetype plugin indent on
"endif
" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.
"set showcmd " Show (partial) command in status line.
"set showmatch " Show matching brackets.
"set ignorecase " Do case insensitive matching
"set smartcase " Do smart case matching
"set incsearch " Incremental search
"set autowrite " Automatically save before commands like :next and :make
"set hidden " Hide buffers when they are abandoned
"set mouse=a " Enable mouse usage (all modes)
set autoindent
" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
source /etc/vim/vimrc.local
endif

That file is not your vimrc: it is a default vimrc that is made available system-wide to make Vim behave in a slightly predictable way. Don't touch it.
The correct location for your vimrc is:
$HOME/.vimrc
and the correct location of your config (including colorschemes) is:
$HOME/.vim/
NEVER do anything in /usr/share/vim/: your changes won't work reliably or even predictably and they can be overwritten during an update.

See :help :colorscheme.
You can type :colo and then ctrl-d to list all available colorschemes.
Put your colorscheme in either $HOME/.vim/colors (Unix) or %USERPROFILE%\vimfiles\colors (Windows).
Example:
Put your colorscheme foo.vim into $HOME/.vim/colors and then colorscheme foo into your vimrc.

In Vim
:version
You will get:
System vimrc file: $VIM/vimrc
User vimrc file: $HOME/.vimrc
and run:
:scriptnames
you will get a list of path of your vimrc file:
1: /usr/share/vim/vimrc
2: /usr/share/vim/vim74/debian.vim
3: /usr/share/vim/vim74/syntax/syntax.vim
4: /usr/share/vim/vim74/syntax/synload.vim
5: /usr/share/vim/vim74/syntax/syncolor.vim
6: /usr/share/vim/vim74/filetype.vim
7: ~/.vimrc
8: /usr/share/vim/vim74/vimrc_example.vim
9: /usr/share/vim/vim74/syntax/nosyntax.vim
10: /usr/share/vim/vim74/ftplugin.vim
11: /usr/share/vim/vim74/indent.vim
12: /usr/share/vim/vim74/mswin.vi
...
So you may find that your vimrc file should be under ~/.vimrc. And like #romainl said never put your own file under /usr/share/vim, all changes may be overwritten during the update.

Related

vim help produces "unable to open swap file" error

In vim, frequently when I perform a ':help ' command, I get an error. Here's an error I see when I perform ':help tags' for example:
"tagsrch.txt.gz" [readonly][noeol] 42L, 11288C
Error detected while processing function gzip#read:
line 51:
E303: Unable to open swap file for "/usr/share/vim/vim74/doc/tagsrch.txt.gz", recovery impossible
41 fewer lines
Press ENTER or type command to continue
When I press enter, the help comes up as desired, but this is still a nuisance. What have I done wrong? My google-foo is apparently too weak for this because I don't see other people complaining about this.
Is this because I have this set for my swap directory?
set directory=~/.vim/swap,.
Let me know if it would be helpful to paste my entire vimrc. I'm on rhel7 with vim 7.4, in case it's helpful.
Here's my ~/.vimrc:
" vim:softtabstop=4:shiftwidth=4:et
" Tab preferences
set shiftwidth=4
set softtabstop=4
set autoindent
set expandtab
execute pathogen#infect()
" Where to store swap files. By default, they will go into ~/.vim/swap, but
" if that doesn't work, they will go in cwd.
set directory=~/.vim/swap,.
filetype plugin indent on " enables filetype indent specific plugins
" Instructions on how to tab complete filenames.
" set wildmode=longest,list,full
set wildmode=longest,list
set wildmenu
" In case there are vim modelines at the top of the file, as there
" is with this one.
set modeline
" Always show the status line.
set laststatus=2
" Look for a tags file.
set tags=./tags,tags;
" Also search for .git/tags files.
set tags^=./.git/tags,*/.git/tags;~
" Make Ctrl-] show the list of options by default.
nnoremap <C-]> g<C-]>
nnoremap <C-w><C-]> <C-w>g<C-]>
" Colors
" Have syntax highlighting in terminals which can display colours:
if has('syntax') && (&t_Co > 2)
syntax on
else
syntax off
endif
set background=dark
set hlsearch
set incsearch
" I so often type teh instead of the.
abbreviate teh the
" To help vim deal with pasting text
:map <F9> :set invpaste <CR>
set pt=<F9>
" Toggle vim's spell checker with <F5>
:map <F5> :setlocal spell! spelllang=en_us<cr>
" Shortcuts for c code.
map! ,bc /* */^[hhi
map! ,bz #if 0^M#endif /* 0 */^[O
" Ignore whitespace when diffing files.
map ,iw :set diffopt+=iwhite<CR>
set path^=/home/bneradt/work/trafficserver/**
In my situation / partition is full. Cleaned it and it works now.

How to let vim show BOM as <feff>

When I look at a file on one of our servers I see something like this:
<feff>sku;qty
productsku;1
When I download the file and open it with vi I don't see the <feff>
When I do :e ++bin I can see the <feff> but I also see ^M now
<feff>sku;qty^M
productsku;1^M
But I don't want to set the ^M. I just want to see the <feff>.
Another example is <80> which I had in another file.
How can I set up vim to show me those special chars?
~ EDIT ~
The command vi --version tells me the following:
VIM - Vi IMproved 7.0 (2006 May 7, compiled Aug 4 2010 07:21:08)
It also says that the system-vimrc-file is /etc/vimrc which has the following content:
if v:lang =~ "utf8$" || v:lang =~ "UTF-8$"
set fileencodings=utf-8,latin1
endif
set term=builtin_ansi
set nocompatible " Use Vim defaults (much better!)
set bs=indent,eol,start " allow backspacing over everything in insert mode
"set ai " always set autoindenting on
"set backup " keep a backup file
set viminfo='20,\"50 " read/write a .viminfo file, don't store more
" than 50 lines of registers
set history=50 " keep 50 lines of command line history
set ruler " show the cursor position all the time
" Only do this part when compiled with support for autocommands
if has("autocmd")
augroup redhat
" In text files, always limit the width of text to 78 characters
autocmd BufRead *.txt set tw=78
" When editing a file, always jump to the last cursor position
autocmd BufReadPost *
\ if line("'\"") > 0 && line ("'\"") <= line("$") |
\ exe "normal! g'\"" |
\ endif
augroup END
endif
if has("cscope") && filereadable("/usr/bin/cscope")
set csprg=/usr/bin/cscope
set csto=0
set cst
set nocsverb
" add any database in current directory
if filereadable("cscope.out")
cs add cscope.out
" else add database pointed to by environment
elseif $CSCOPE_DB != ""
cs add $CSCOPE_DB
endif
set csverb
endif
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
if &term=="xterm"
set t_Co=8
set t_Sb=^[[4%dm
set t_Sf=^[[3%dm
endif
I copied this and added it to my ~/.vimrc but none of these changes does what I want. A few things are in if cases so I might have to play around with these too.
Does anyone know if there are other files than the one stated in vi --version that will be read when editing a file?
:help 'bomb' explains Vim's behavior:
When Vim reads a file and 'fileencodings' starts with "ucs-bom", a
check for the presence of the BOM is done and 'bomb' set accordingly.
Unless 'binary' is set, it is removed from the first line, so that you
don't see it when editing.
So,
:set fencs-=ucs-bom
would turn this off, but then the encoding detection is broken, too! According to my experiments, explicit encoding setting (via :edit ++enc=ucs2-le) also sets 'bomb' and removes the <feff> mark. So, this avenue leads nowhere.
Alternatives
Editing in binary mode, as you've found out. I wouldn't recommend it, since it has drawbacks.
Including the indication in the statusline. You have to look somewhere else, but it's always visible, not just at the beginning of the document. Highly recommended as the right way™ in Vim. And easy to achieve, too:
set statusline+=\ %{&bomb?'BOM':''}

Vim Starts on Insert Mode and Inserts Special Characters

So vim just suddenly started flaking out on me today and I can't pinpont the problem. Haven't touch the configuration file and the last thing I worked on before I noticed the problem was updating my sshd_config and sshd_config.pacnew files.
What I noticed is that upon opening the sshd_config file is vim starting out in insert mode and automatically inserted a series special characters wherever the curser was at the moment. So it overwrites information in configuration files. I guess that can become somewhat problematic =)
So if I start a new file touch test_vim && vim test_vim this is what I see:
:bfff/00fe/00fe/13fe[>85;95;0c
I have a feeling this is going to be one of those things that's really stupid and I completely overlooked. Does anyone have any idea what's going on?
" An example for a vimrc file.
"
" Maintainer: Bram Moolenaar <Bram#vim.org>
" Last change: 2014 Feb 05
"
" To use it, copy it to
" for Unix and OS/2: ~/.vimrc
" for Amiga: s:.vimrc
" for MS-DOS and Win32: $VIM\_vimrc
" for OpenVMS: sys$login:.vimrc
" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
finish
endif
" Use Vim settings, rather than Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
if has("vms")
set nobackup " do not keep a backup file, use versions instead
else
set backup " keep a backup file (restore to previous version)
set undofile " keep an undo file (undo changes after closing)
endif
set history=50 " keep 50 lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")
" Don't use Ex mode, use Q for formatting
map Q gq
" CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>
" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
set mouse=a
endif
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
au!
" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
" Also don't do it when the mark is in the first line, that is the default
" position when opening a file.
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
augroup END
else
set autoindent " always set autoindenting on
endif " has("autocmd")
" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
\ | wincmd p | diffthis
endif
This is a recent Vim bug. You should probably roll back to an earlier release while a proper fix is worked on.
You can have a look about changing the vim configuration files on this post
this is the official vim wiki page
Vim wiki
So the bug seems to affect urxvt terminals running with transparency. Using a different terminal, or in my case disabling transparency via /.Xresources will temporarily solve the issue until they release a patch.

Vim shows multiple errors before starting

SOLVED: bad colorscheme .vim file.
Whenever I start up vim, I always get a flood of errors and then a "Press ENTER or type command to continue" message. Then vim works fine.
I just have no idea what the cause of it is.I am on a Linux machine.
line 5045:
E488: Trailing characters: </div>
line 5048:
E488: Trailing characters: <script crossorigin=
line 5049:
E488: Trailing characters: <script async=
line 5052:
E488: Trailing characters: <script async src=
line 5053:
E488: Trailing characters: </body>
line 5054:
E488: Trailing characters: </html>
Press ENTER or type command to continue
Here is my .vimrc file. It is just the example one with some editing. I am still a beginner.
" An example for a vimrc file.
"
" Maintainer: Bram Moolenaar <Bram#vim.org>
" Last change: 2011 Apr 15
"
" To use it, copy it to
" for Unix and OS/2: ~/.vimrc
" for Amiga: s:.vimrc
" for MS-DOS and Win32: $VIM\_vimrc
" for OpenVMS: sys$login:.vimrc
" When started as "evim", evim.vim will already have done these settings.
if v:progname =~? "evim"
finish
endif
syntax enable
colorscheme solarized
" Use Vim settings, rather than Vi settings (much better!).
" This must be first, because it changes other options as a side effect.
set nocompatible
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
if has("vms")
set nobackup " do not keep a backup file, use versions instead
else
set backup " keep a backup file
endif
set history=50 " keep 50 lines of command line history
set ruler " show the cursor position all the time
set showcmd " display incomplete commands
set incsearch " do incremental searching
" For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries
" let &guioptions = substitute(&guioptions, "t", "", "g")
" Don't use Ex mode, use Q for formatting
map Q gq
" CTRL-U in insert mode deletes a lot. Use CTRL-G u to first break undo,
" so that you can undo CTRL-U after inserting a line break.
inoremap <C-U> <C-G>u<C-U>
" In many terminal emulators the mouse works just fine, thus enable it.
if has('mouse')
set mouse=a
endif
" Switch syntax highlighting on, when the terminal has colors
" Also switch on highlighting the last used search pattern.
if &t_Co > 2 || has("gui_running")
syntax on
set hlsearch
endif
execute pathogen#infect()
set nopaste
" Only do this part when compiled with support for autocommands.
if has("autocmd")
" Enable file type detection.
" Use the default filetype settings, so that mail gets 'tw' set to 72,
" 'cindent' is on in C files, etc.
" Also load indent files, to automatically do language-dependent indenting.
filetype plugin indent on
" Put these in an autocmd group, so that we can delete them easily.
augroup vimrcEx
au!
" For all text files set 'textwidth' to 78 characters.
autocmd FileType text setlocal textwidth=78
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
" Also don't do it when the mark is in the first line, that is the default
" position when opening a file.
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
augroup END
else
set autoindent " always set autoindenting on
endif " has("autocmd")
" Convenient command to see the difference between the current buffer and the
" file it was loaded from, thus the changes you made.
" Only define it when not defined already.
if !exists(":DiffOrig")
command DiffOrig vert new | set bt=nofile | r ++edit # | 0d_ | diffthis
\ | wincmd p | diffthis
endif
set number
Vim complains about HTML tags, so it looks like you've installed a bad Vimscript, grabbing a (formatted) web page instead of the raw contents.
Either go back to the page and copy/paste from the browser, or (e.g. in GitHub) get the raw file contents and save that.

How do I enable Ruby syntax highlighting in Neovim?

I'm a new user of Neovim and trying to figure out how to enable syntax highlighting for Ruby.
What config should i edit?
edit:
This is my current config:
➜ ~ cat ~/.nvimrc
filetype plugin indent on
syntax on
set tabstop=2
set number
set noswapfile
" Automatically indent on new lines
set autoindent
" Copy the indentation of the previous line if auto indent doesn't know what to do
set copyindent
" Indenting a line with >> or << will indent or un-indent by 2
set shiftwidth=2
" Pressing tab in insert mode will use 4 spaces
set softtabstop=2
" Use spaces instead of tabs
set expandtab
" [SEARCH]
:set incsearch
:set hlsearch
" <Ctrl-l> redraws the screen and removes any search highlighting.
nnoremap <silent> <C-l> :nohl<CR><C-l>
And this is the error i get when loading Neovim:
➜ ~ nvim test.rb
Error detected while processing /Users/user/.nvimrc:
line 2:
E484: Can't open file /usr/local/Cellar/neovim/HEAD/share/vim/syntax/syntax.vim
Press ENTER or type command to continue
Neovim uses the xdg specification for their config files. If you are already using vim. (If you are transferring from an old version of neovim ~/.nvimrc is now $XDG_CONFIG_HOME/nvim/init.vim and ~/.nvim is now $XDG_CONFIG_HOME/nvim)
mkdir -p ${XDG_CONFIG_HOME:=$HOME/.config}
ln -s ~/.vim $XDG_CONFIG_HOME/nvim
ln -s ~/.vimrc $XDG_CONFIG_HOME/nvim/init.vim
should get you close to running with neovim (This might not work for all plugins but its a start).
All you should need in $XDG_CONFIG_HOME/nvim/init.vim is the following
filetype plugin indent on
syntax on
to get syntax highlighting for ruby.

Resources