Saving preferences VIM - vim

Hi I'm a new user to vim text editor (love it) and would like to save my preferences in VIM ie font and size and background colour, ive searched and the only things i can find say modify the rc file however they do not specify how except to advise on customisations such as line spacing. Please could someone advise?

On a Linux machine, you can start making a .vimrc file in your home folder by running the following in the terminal:
vim ~/.vimrc
This is the "rc" file that they are talking about.
Regarding the formatting of this file, you can put every setting on a separate line:
" This line is a comment, the following 2 lines are settings:
colorscheme desert
set history=500
While still in vim, save with :wq.
The next time you start vim, it will use the settings that you just specified in your ~/.vimrc.

Here is the $ vimtutor section dedicated to that very subject:
Lesson 7.2: CREATE A STARTUP SCRIPT
** Enable Vim features **
Vim has many more features than Vi, but most of them are disabled by
default. To start using more features you have to create a "vimrc" file.
1. Start editing the "vimrc" file. This depends on your system:
:e ~/.vimrc for Unix
:e ~/_vimrc for Windows
2. Now read the example "vimrc" file contents:
:r $VIMRUNTIME/vimrc_example.vim
3. Write the file with:
:w
The next time you start Vim it will use syntax highlighting.
You can add all your preferred settings to this "vimrc" file.
For more information type :help vimrc-intro

Related

How to jump back to netrw when splitbelow is on

If I open a file in a current directory using netrw and then reopen the netrw using :Sexplore the netrw window opens below (I have splitbelow set), but the cursor remains in the file being edited and I cannot move to the netrw window using CTRL-W combinations.
Am I doing something wrong or is this a bug?
Steps to reproduce
run vim .
netrw opens, highlight a file in the current directory (let's say test.txt) and press Return, file test.txt opens
run :Sexplore cmd
netrw opens below but the cursor remains in the file opened previously.
My .vimrc
set nocompatible
set splitbelow
VIM version
VIM - Vi IMproved 7.4 (2013 Aug 10, compiled Dec 8 2015 23:11:08)
MacOS X (unix) version
Included patches: 1-944
This is how it looks like:
I cannot reproduce with version 154a (use :echo g:loaded_netrwPlugin to check your netrw version).
Try with the latest version.
Edit:
It is possible that the problem is cause by some other plugin interference or settings. You could try following the approach described at Vim FAQ 2.5:
2.5. I have a "xyz" (some) problem with Vim. How do I determine it is a
problem with my setup or with Vim? / Have I found a bug in Vim?
First, you need to find out, whether the error is in the actual
runtime files or any plugin that is distributed with Vim or whether it
is a simple side effect of any configuration option from your .vimrc
or .gvimrc. So first, start vim like this:
vim -u NONE -U NONE -N -i NONE
This starts Vim in nocompatible mode (-N), without reading your
viminfo file (-i NONE), without reading any configuration file (-u
NONE for not reading .vimrc file and -U NONE for not reading a .gvimrc
file) or even plugin.
(...)
If the error does not occur when starting Vim this way, then the
problem is either related to some plugin of yours or some setting in
one of your local setup files. You need to find out, what triggers the
error, you try starting Vim this way:
vim -u NONE -U NONE -N
If the error occurs, the problem is your .viminfo file. Simply delete
the viminfo file then. If the error does not occur, try:
vim -u ~/.vimrc --noplugin -N -i NONE
This will simply use your .vimrc as configuration file, but not load
any plugins. If the error occurs this time, the error is possibly
caused by some configuration option inside your .vimrc file. Depending
on the length of your vimrc file, it can be quite hard to trace the
origin within that file.
The best way is to add :finish command in the middle of your .vimrc.
Then restart again using the same command line. If the error still
occurs, the bug must be caused because of a setting in the first half
of your .vimrc. If it doesn't happen, the problematic setting must be
in the second half of your .vimrc. So move the :finish command to the
middle of that half, of which you know that triggers the error and
move your way along, until you find the problematic option. If your
.vimrc is 350 lines long, you need at a maximum 9 tries to find the
offending line (in practise, this can often be further reduced, since
often lines depend on each other).
Obviously you will have to load netrw manually (which can be done by sourcing plugin/netrwPlugin.vim -- if you are using some plugin manager you will have to move the plugin to ~/.vim/ or change your runtime path due to the autoload functions) and set nocompatible and splitbelow.
Actually there is an adapted version of this procedure in :help netrw-debug:
Step 2: assuming that you've installed the latest version of netrw,
check that your problem is really due to netrw. Create a file called
netrw.vimrc with the following contents:
set nocp
so $HOME/.vim/plugin/netrwPlugin.vim
Then run netrw as follows:
vim -u netrw.vimrc --noplugins [some path here]
Perform whatever
netrw commands you need to, and check that the problem is still
present. This procedure sidesteps any issues due to personal .vimrc
settings and other plugins. If the problem does not appear, then you
need to determine what setting in your .vimrc is causing the conflict
with netrw or which plugin.
Step 3: If the problem still is present, then get a debugging trace
from netrw:
(...)

How to turn on syntax highlighting in VIM 7.3 OSX

System = OSX 10.9.4
I am trying to turn on syntax highlighting in vim while using the terminal. However, I am unable to get it to work properly.
Things I've tried:
located the vimrc file and added the following code:
set ai " auto indenting
set history=100 " keep 100 lines of history
set ruler " show the cursor position
syntax on " syntax highlighting
set hlsearch " highlight the last searched term
filetype plugin on " use the file type plugins
Located vimrc under directory:
cd /usr/share/vim/
The interesting thing is that once I add the code to the vimrc using vim, followed by exiting (x), and re-opening the file again, syntax is correctly highlighted in the vimrc.
However, when I try to make a new vim file called "test", copy the same code, save and exit. Re-open it, the syntax is not highlighted at all.
It appears that syntax highlighting only works when I open the actually vimrc file---and not when I try to create a new one or open another file that should have syntax highlighting.
I've also tried to create a .vimrc (exact copy) under the ~/ (directory). No success.
Made a new file called "test" and tried turning it on while active as well:
vim test
"then within vim"
:syntax on
I am really confused as to why this partially works.
Any help is much appreciated.
Cheers!
p.s. I have followed these instructions as well from: http://geekology.co.za/article/2009/03/how-to-enable-syntax-highlighting-and-other-options-in-vim
*I am aware of macvim, but would like a solution for the native vim in terminal. Thanks.
NEVER do anything in $VIM as it will work only by luck, cause unexpected behaviors and likely be overwritten next time Vim is updated.
What you have put in /usr/share/vim/vimrc should be in ~/.vimrc.
filetype on and syntax on are the bare minimum you need in your ~/.vimrc for syntax highlighting to work.
$ vim ~/.vimrc gives you syntax highlighting because the file is recognized by Vim as a vim file. Filetype detection is mostly dependent on file extensions so you can't expect any syntax highlighting in a file called test.
$ vim test.py, on the other hand, should give you syntax highlighting.
If the filetype is not detected, you can force it with :set filetype=python.
You most probably want to enable indentation along with syntax highlighting, so add these to lines to ~/.vimrc
filetype plugin indent on
syntax on
Steps with screenshots can be found here
http://osxandiosdaily.com/how-to-enable-vim-syntax-highlighting-on-mac-osx/
Inside of your file, enter command mode and enter the command
:syntax on

ctags not working as expected with Vim plus general setup problems (C programming)

I have installed cvim and NodeTree plugins and generated an exuberant ctags file for my build tree.
This is what my ~/.vim/.vimrc file looks like:
:noremap :TlistToggle
:let Tlist_Show_One_File = 1
:let Tlist_Exit_OnlyWindow = 1
:let Tlist_Use_Right_Window = 1
set tags=./tags;/
set number
set tabstop=4
set incsearch
When I start editing a file, I notice that Ctrl ] does not work and I have to resort to typing ta: funcname - which gets tiring after a while. Interestingly enough, Ctrl T pops me off the tag stack as expected - I don't understand whats going on - how do I fix this?
Incidentally, vim (appears to) completely ignores the contents of my .vimrc file and I always have to type the same commands in the editor, so as to get the settings I want - very annoying.
Last but not the least, I used to be able to type :make in the editor window, drop to the console and then have the build results displayed in a little window which I can then go to and select a line (with an error or warning say), and then have the editor automagically take me to the offending line - unfortunately, I don't remember the plugin (or commands) I used to allow me to build from within vim.
So, how do I:
Fix my vim setup so that I can move to definitions/declarations using Ctrl-]
Fix my .vimrc file so that contents are actually applied to my vim session.
Find the appropriate plugin to install to allow builds (using make) from within vim
You're asking about a weird mix of problems.
Fix my vim setup so that I can move to definitions/declarations using Ctrl-]
The tags functionality is working; I suspect that you have a mapping blocking Ctrl-]. Try
:verbose nmap <C-]>
and
:nunmap <C-]>
Fix my .vimrc file so that contents are actually applied to my vim session.
:echo $MYVIMRC
will tell you the location of the .vimrc that Vim uses. Also, check the output of :scriptnames which scripts get loaded, and read :help vimrc to understand the logic Vim applies.
Find the appropriate plugin to install to allow builds (using make) from within vim
That's built into Vim. With the appropriate 'makeprg' set (it defaults to make), you can run :make. Vim parses the output (through the 'errorformat' option), and you can open the quickfix list via :copen.
Your vimrc is:
~/.vim/.vimrc
If you run Vim 7.4, it should be:
~/.vim/vimrc
or
~/.vimrc
If you run Vim 7.3 or older, it should be:
~/.vimrc
And... what Ingo said.

Vim: My plugins and color schemes won't work?

I was trying to play around with my vimrc file and discovered plugins (specifically one that should allow me to scroll through color schemes) however it seems that the plugins are not working. What I mean by this is that the 'ScrollColors.vim' file should create a :SCROLL command to scroll through the colorschemes, but when I try that in vim it says "E492: Not an editor command: SCROLL". Also, I tried adding a line ":Colorscheme Mustang" to my vimrc file (mustang is a colorscheme file in the colors directory) but when I start vim it says "E185: Cannot find color scheme Mustang"
Any help would be appreciated!
Also, if this helps, this is my vim directory:
SDs-macbook:MacVim-ppc-i386-10_5-7_3-53 Simona$ ls
MacVim.app README.txt colors mvim plugin
And my plugin directory:
SDs-macbook:plugin Simona$ ls
ScrollColors.vim color_sample_pack.vim mimicpak.vim
Commands in Vim are case-sensitive; built-in commands like :colorscheme are lowercase, custom commands defined by plugins must start with an uppercase letter, but rarely are all-caps, because that is hard to type. The command may be :Scroll instead.
You can use Tab to complete commands (e.g. :S<Tab>), and use :command to list all defined commands. (But reading the plugin's help is usually easier.)

vim line numbers - how to have them on by default?

I can :set number from within a file I'm editing but how can I have them always be on by default?
Add set number to your .vimrc file in your home directory.
If the .vimrc file is not in your home directory create one with
vim .vimrc and add the commands you want at open.
Here's a site that explains the vimrc and how to use it.
To change the default setting to display line numbers in vi/vim:
vi ~/.vimrc
then add the following line to the file:
set number
Either we can source ~/.vimrc or save and quit by :wq, now future vi/vim sessions will have numbering :)
set nu
set ai
set tabstop=4
set ls=2
set autoindent
Add the above code in your .vimrc file. if .vimrc file is not present please create in your home directory (/home/name of user)
set nu -> This makes Vim display line numbers
set ai -> This makes Vim enable auto-indentation
set ls=2 -> This makes Vim show a status line
set tabstop=4 -> This makes Vim set tab of length 4 spaces (it is 8 by default)
The filename will also be displayed.
Terminal > su > password > vim /etc/vimrc
Click here and edit as in line number (13):
set nu
If you don't want to add/edit .vimrc, you can start with
vi "+set number" /path/to/file
I did not have a .vimrc file in my home directory. I created one, added this line:
set number
and that solved the problem.
in home directory you will find a file called ".vimrc" in that file add this code "set nu" and save and exit and open new vi file and you will find line numbers on that.
I'm using Debian 7 64-bit.
I didn't have a .vimrc file in my home folder. I created one and was able to set user defaults for vim.
However, for Debian 7, another way is to edit /etc/vim/vimrc
Here is a comment block in that 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.
Add any command you want to have by default to your ~/.vimrc file (named _vimrc on Windows systems)

Resources