Editting Vim Configurations - linux

I have a very simple and easy question, but I do not know how to do it. I am on a ubuntu machine, logged in via ssh. I want to edit my vim so that I dont have to keep typing :set number or :colorscheme elflord. I would like it to remember that information. When browsing around I found out that I need to change a .vimrc file, and that is supposedly located in my home directory, however it is not, and furthermore #locate .vimrc does not locate anything. Can any help me with finding where this file is and editing the above commands?

Create ~/.vimrc with the lines you want in it:
set number
colorscheme elflord
See :help vimrc and :help vimrc-intro for more information.

Your global vimrc is located in /etc/vim you can just create a .vimrc in your home directory. This question however should be asked on http://unix.stackexchange.com or http://askubuntu.com.

You may edit it from anywhere with this command:
:e $MYVIMRC
If the file doesn't exist, just create it in ~/.vimrc

Related

Activation of `.vimrc` file

I have got a .vimrc file from one of my friends, however, vim ignores it. How can I make vim use .vimrc? Thank you for the answer.
Open vim and type ":version" and hit Enter. You will get paths to your vimrc files. Make sure that your vimrc file is not overwritten by another one (with a higher priority). Please refer to Open vimrc file.
EDIT: To see a home directory, type in vim :echo $HOME

MacVim: Pydiction unable to use

I'm trying to add Pydiction into MacVim, I followed the readme file.
Put python_pydiction.vim in ~/.vim/after/ftplugin/ and write:
let g:pydiction_location = '~/pydiction/complete-dict'
into my .vimrc file. But when I press tab in MacVim, an error will rise:
undefined variable g:pydiction_location
Can anyone tell me where am I wrong ?
As discussed in the comments, you were editing a file that wasn't actually your .vimrc file. You may have typed:
:e vimrc
:e ~/vimrc
:e .vimrc
none of which will probably edit your actual .vimrc file. It must have a dot in front of it AND be located in your home directory. You can also type :pwd in vim to see the current working directory. If you do :e .vimrc it will create a new file in whatever directory you are in if it doesn't exist.
Do you use NERDTree? If so it seems that Pydiction and NERDTree conflict with each other in some way.

What is the issue with vim -u /path_to/vimrc?

I share an user with other people.
Everyone has created a directory into home directory and everyone is working in his "own" directory.
I want to use my own setting when I use vim and I don't want to bother others with my preferences.
I created my .vimrc file into $HOME/my_directory
I've defined an alias my_vim="vim -u /full_path_to_home/my_directory/.vimrc"
When I edit a file with my_vim, I don't have the right colors.
I have the same problem when I use the command
:source /full_path_to_home/my_directory/.vimrc
If I copy my .vimrc file into $HOME directory, everything is fine.
Where is the problem ?
From :help vimrc
If Vim was started with "-u filename",
the file "filename" is used.
All following initializations until 4.
are skipped.
So by specifying a vimrc file, its ignoring the system-wide vimrc (/erc/vimrc/) where syntax highlighting and other things are configured. You can work around this problem by adding the following code to the top of your vimrc:
if filereadable("/etc/vimrc")
source /etc/vimrc
endif
If this sort of thing comes up a lot, I would recommend changing your $HOME to point to the current $HOME/my_directory whenever you log in.

Vim commands :Explore :Sexplore :Hexplore doesn't work in cygwin

3.3 in cywing 2.721, the installation was made using cywing, every thing works but when I try to use the following command.
:Explore
vim said E492: Not an editor command
also neither :Sexplore or :Hexplore works.
is there any way to activate this functionality?
This is in machine with windows xp.
Well I solved reading the
:help usr_01.txt
It said that is necessary to run this command !cp -i $VIMRUNTIME/vimrc_example.vim ~/.vimrc inside vim, it just copy a .vimrc to home user.
I close and opened vim and :Explore, Hexplore, Vexplore worked.
I had the same problem as well. Since it's a fresh install of Vim you don't have a .vimrc (or _vimrc on Windows). A vimrc is Vim's configuration file, and once you have one Vim will no longer try to be compatible with Vi (usually what you want).
So all you have to do is create a vimrc file and you should be ready to :Explore all you want. Below are locations you can put your vimrc file, and the filename to use for it. (depending on your system)
Unix/Linux/OSX: $HOME/.vimrc or $HOME/.vim/vimrc
MS-Windows: $HOME/_vimrc, $HOME/vimfiles/vimrc
or $VIM/_vimrc
sources:
* :help 'compatible'
* :help 'vimrc'
I also recommend following atomsfat's answer as well to give you a simple vimrc to start out with.
Those commands are provided by the netrw plugin. Check :scriptnames to see if that plugin is loaded.

Vim :e starting directory?

I code in Vim, not an IDE.
My source code is often nested 2-3 directories deep.
~/foo$ find
xyz
bar/abc
bar/def
~/foo$ vim
// inside of vim
:e bar/abc
... some work ...
:e <-- is there a way I can have this :e start in ~/foo/bar instead of ~/foo ?
Basically, I want :e to start the directory in "pathname of last edited file"
Thanks!
There's a lot of reasons not to like autochdir as it messes up some plugins and if you end up doing :e ../../../foo.txt you are not gaining anything. Just as an idea try this cmap I knocked up
:cnoremap red edit <c-r>=expand("%:h")<cr>/
then you can type :red and get
:e /the/path/to/your/current/files/dir/
(edit: perhaps use z instead of red as there are commands that start with red)
To expand the topic, also check out the FuzzyFinder plugin and some custom mappings to rapidly jump to common files you are always editing. Eg
10 or so of your regular files should be no more than 2 keystrokes away. It helps if they are systematically named
Here's an idea I use for django.
http://code.djangoproject.com/wiki/UsingVimWithDjango#Mappings
Try the autochdir option. It will automatically change the current working directory to whatever file was most recently opened or selected. In .vimrc:
set autochdir
For more info, :help autochdir
To always change the working directory to the current file's directory I have this in my .vimrc:
if has("autocmd")
autocmd BufEnter * :lcd %:p:h
endif " has("autocmd")
Sorry, but vim's :edit command takes a path which is interpreted relative to the present working directory of the vim instance.
You do have a :cd command which you could use to :cd bar then work for a while, then :cd ...
Hope that help some.
Some time ago I asked questions related to this on the vim mailing list: http://www.mail-archive.com/vim_use#googlegroups.com/msg03266.html Maybe you will find useful tips in that thread.
I tested a lot of plugins, but since CLI based GUIs are not my taste, I simply ended up using standard vim with a few configuration settings.
As honk pointed out, this line sets the working directory to the same as the file your working on:
autocmd BufEnter * lcd %:p:h
My other tip is to use the wildmenu. It makes it easier to get an overview of the files in your current directory when you go :e and then TAB. I'm a python programmer so the last line shows how to hide auto generated files that the python interpreter spits out, but you could use it to hide java .class files or c .obj files or whatever.
set wildmode=list:longest
set wildignore=*.pyc,*pyo
:cd changes directory
:pwd prints the current one.
why not just :E? Explore directory of current file.
:help :E
This isn't exactly what you wanted, but check out NERDTree.
On vim/gVim I just have cd C:/blah/blah at the top of my vimrc. I imagine it works on all platforms.
I personally use vagrant for each project so one CD is enough, but I think you can get vim to use different config files too, -u flag I think.
Or map a key to each project you have so pressing Ctrl+F1 does cd path/to/project/1 and Ctrl+F2 does cd path/to/project/2 perhaps?
Note: I don't use any plugins

Resources