iTerm don't save 'set' parameters to use vim - vim

I'm using iTerm2 with vim to work with python files. When I create or start editing a file using 'vi', I always have to introduce all the configuration values like ':set number', ':syntax on', etc. I have edited '.vimrc' from MacVim to save this parameters, but when I restart iTerm I have to put the values again, the configuration didn't save this 'set' values.
This is an example how i start the program: 'vi file.py'. It opens vim but without the 'set' values I have previously introduced.
It would be nice if someone could help me. Thank you.

First rule: NEVER DO ANYTHING IN VIM'S RUNTIME FILES.
In Vim, do :echo $VIM. That directory, /Applications/MacVim.app/Contents/Resources/vim, in your case, is off limits. You are not supposed to change/add/remove anything, there. There's no good reason to even look at it!
Second rule: ALWAYS DO CUSTOMIZATION IN YOUR HOME DIRECTORY.
Your customization belongs to your home directory.
Your vimrc is here:
~/.vimrc ~/ being a shortcut for /Users/username/
Your vim/ is here:
~/.vim/ ~/ being a shortcut for /Users/username/
You must create those files and directories if they don't already exist.
Note: MacVim is a GUI app that won't work in your terminal unless you did some (simple) specific things. Did you do anything toward that goal? It looks like you are just using the default Vim that will obviously not source MacVim's runtime files.

Related

Opening a file via Vim on GIT

I'm following a tutorial on Uniswap forking (just to learn how this works) and I'm stuck a particular step.
How does one go from:
vim migrations/2_deploy_contracts.js
to
I'm only able to see:
How do I see the folders and directories ?
The user in that particular video is using the NERDTree plugin for Vim. Vim is very powerful and extensible, and it's possible to load a variety of extensions written in Vimscript to customize the interface, add editor features (such as LSP support), or various other functionality.
They're also using a custom colorscheme which is probably based on the Solarized palette. You can also load a custom colorscheme with the :colorscheme ex command.
There is another thing to notice, besides mentioned NerdTree plugin.
I think you are running your command from the wrong place.
vim migrations/2_deploy_contracts.js
This command tries to open the file set by relative path, or creates a new file, if that does not exist. As we see from your screenshots - the file exists in the tutorial, but it does not exist on your machine (the [+] mark after the filename on the second screenshot shows that).
My guess you need to cd to the right directory first (tutorial project root) and then only run your vim command to open the file.
As for your question about seeing the files and directories, you can do it without NerdTree plugin, using built-in netrw. Just type :Ex in vim normal mode.

How to execute a file everytime before opening Vim

I have recently started using vim and I really like it. I have added a few easy mappings in my vimrc file.
But the problem is I get to use a lot of remote machines a lot of time and I can't copy my vimrc on to them but most of the times I won't have enough permissions to do that.
So, I was wondering if there is any way I can put all my vim mappings in a file and tell vim to run it every time it loads, just like a vimrc?
The action that is "parsing" the .vimrc is called source.
In runtime, you can reapply/reparse your .vimrc by using
:source ~/.vimrc
So if you can somehow copy your .vimrc, even if not in your home, but a folder like /tmp you should be able to source it from there, with
:source /tmp/.vimrc
This question has more details and solutions.
One option would be to specify an alternative .vimrc file while launching the program.
The vim man pages has this to say about specifying a vimrc file:
-u {vimrc}
Use the commands in the file {vimrc} for initializations. All the other initializations are skipped. Use this
to edit a special kind of files. It can also be used to skip all
initializations by giving the name "NONE".
See ":help initialization" within vim for more details.
Note that this option overrides the default vimrc file, so you'll have to specify all of your settings/options in this file.
As was mentioned in another answer, you can place your custom vimrc file anywhere you want (or have access to) and then specify the the -u option with the path to your vimrc file.
You could even combine this method with managing your custom vimrc file in an online version control system (like github) - this way you will be able to wget your file from the web instead of having to manually copy it from machine to machine.

How to create my custom vim snippets?

I want to create some snippets when writting c++.
for example:
create a file, cpp.snippets.
priority -1
snippet exam
This is an example!
endsnippet
and put it in ~/.vim/my-snippets/snippets/.
then, add following statement in ~/.vimrc:
set runtimepath+=~/.vim/my-snippets/
let g:UltiSnipsSnippetsDir='~/.vim/my-snippets/'
let g:UltiSnipsSnippetDirectories=["snippets"]
But it not work, how can i fix it ?
UltiSnips plugin includes detailed documentation. Have you read the following help page?
:help UltiSnips-snippet-search-path
Update:
One of the things that was obvious when I read that help section was that in UltiSnips the name "snippets" can't be used in g:UltiSnipsSnippetDirectories because it is reserved for snipMate compatible snippets. This does not happen in the link shared in the comment below, where the name "my-snippets" is used instead.
I do not use UltiSnips, but from the documentation I would suggest the following approach:
Do not set g:UltiSnipsSnippetsDir nor g:UltiSnipsSnippetDirectories.
Keep the runtimepath+= configuration.
Create the following directory: ~/.vim/my-snippets/UltiSnips.
Place the personal snippets under this new directory.
Reasoning:
By default UltiSnips searches for all UltiSnips directories under your runtime paths, so no configuration is required if this name is used.
Although the runtime setting is required for personal snippets, this configuration is automatically maintained if a plugin manager is used.
The last point allows the installation of vim plugins that contain snippets. For example, this plugin contains various snippets for both snipMate and UltiSnips, including C++.
If you are using the sirver/ultisnips plugin (UltiSnips) the correct way to do this is simply run the :UltiSnipsEdit command which opens up a custom snippets file for the current language / filetype.
I had so much grief with this. Here is an answer for future reference for those of you who do not want to suffer headaches.
I have a shared .vimrc served on a samba share. Both Windows gViM and ViM use this file.
Relevant Part of .vimrc for Windows
I have a samba share mounted under L:. Note that I actually had to use POSIX for the path, not Windows backslashes \ despite being a path for Windows.
if has('win32') || has('win64') "If gVim under Windows"
let g:UltiSnipsSnippetDirectories=["L:/.vim/custom_snippets"]
endif
Relevant Part of .vimrc for Unix
My terminal opens xterm-256color for more colors, but you could exchange that with xterm. Here the path can expand ~ correctly, since this is the real home directory where my ``.vim` lives.
if $TERM == "xterm-256color"
let g:UltiSnipsSnippetDirectories=["~/.vim/custom_snippets"]
endif
Finishing Touches to Load custom_snippets
You don't need any! The following changes are NOT necessary:
"let g:UltiSnipsSnippetDirectories=["custom_snippets"]
"let g:UltiSnipsSnippetsDir="~/.vim/snippets_custom/"
However, Putty does not pass the tab key or control key properly it seems, despite all paths working fine. I tested the paths with :UltiSnipsEdit while in a file type environment set ft=tex and it took me to ~/.vim/snippets_custom/tex.snippets as it should (both in gvim on Windows and from my unix console).
Perhaps Useful for enabling in Putty
Patch: Creating a ctrl+tab keybinding in PuTTY
How to solve the collision of TAB key mapping of `UltiSnips` plugin in the Vim
https://unix.stackexchange.com/questions/53581/sending-function-keys-f1-f12-over-ssh

Editing _vimrc in Windows

I am having some trouble with VIM on windows, and I was wondering if anyone could be of assistance. As of right now, I am trying to make it so that when VIM starts, it changes it's working directory to one besides the default (C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Vim 7.3). The way I am going about this is adding in cd $HOME\Desktop\VimFiles, where $HOME is C:\Users\Alphabet (Alphabet is the name of my account).
The issue I am running into right now is that after opening up _vimrc and adding in the line stated above, I cannot save the file, even when forcing it (with w!). I was wondering why this is and how I can go about fixing this. As an added note, I am running this in GVIM.
Note: I have attempted to do the same thing in VIM, and am able to edit the _vimrc file fine, but when I go to it's location and open it with GVIM or Notepad++, the "cd" line doesn't show up. Is there a reason for this?
Any help is appreciated. Thank you!
It looks like you are trying to write a file in a protected directory without the proper privileges.
In Vim, :echo $HOME tells you where you are supposed to put your _vimrc. In your case, your _vimrc should be C:\Users\Alphabet\_vimrc and you should put your plugins and whatnot in C:\Users\Alphabet\vimfile\.
Never touch system files!

VIM: Overwriting system vimrc

I work on multiple MAC OS X systems, which do not save changes after log out. As you know VIM is on every new mac, just type in vim in the terminal. I always bring my vimrc file with me, and the problem is that every single time I start vim i have to load it with :so command.
I want to use the fact that vim is available on every unix, but I also want to take advantage of the nifty integration with the terminal for doing quick tests, I just switch back to the terminal, but for that I need to close vim. When I reopen it, I again have to load the vimrc. And I am a newb, I don't even have plugins yet...
I want to keep the integration with the terminal and only develop a super quick way of introducing my changes to vim. Think of the conditions as if though you are sitting on newly installed operating system.
Thanks !
Not directly to your question, but you can always invoke vim with -u, which will let you specify your vimrc file instead of launching vim and then running :so.
The default location for your .vimrc file is ~/.vimrc (on the mac, ~ is /Users/_you_, eg /Users/matt). If you can write your file there, it will be loaded when vim starts up every time.
The system vimrc file on the mac is at /usr/share/vim/vimrc, but it sounds like these systems are not under your control, so you won't be able to write that file. Have a look at: How can I override ~/.vim and ~/.vimrc paths (but no others) in vim?, which uses the -u option to change the path vim looks for plugins under. But, in all cases, you must either be able to write your .vimrc into your home directory (which it sounds like your system does not permit) or specify the path to it at runtime (as with the command-line option I mention above, or with the normal command :so which you're currently using).
Depending on the kind of testing you need to do, you can always run shell commands within vim, by using the ! in normal mode. For instance, I frequently make changes to a python file in a buffer, and then (in normal mode) run !nosetests within vim—that writes terminal output into a temporary buffer at the bottom, and doesn't require me to leave or suspend vim. I can review the output, and any key-press takes me back to my buffer.
I don't have any experience with Mac-Os terminal. However I think if you could cp your .vimrc file to your home directory. everytime you start vim, vim will load the .vimrc file from your home directory.
If you want to swtich back to terminal from vim to do some testing/execute some commands and back to vim. you could consider to:
open multiple terminal windows
try something like screen or tmux. personaly I am using tmux, and it's very nice.
try Conque Shell plugin: http://www.vim.org/scripts/script.php?script_id=2771 I have this plugin installed too.
type Ctrl-z in vim to back to terminal
If you want to sync your .vimrc on different machines, you could put your .vimrc file in
a scm repository like gitHub, bitbucket... (I perfer this option, since you could have different branches for different settings)
dropbox
I hope this helps.
How is it possible that your changes are not saved after you log out? What would be the point of such a machine? An internet kiosk in an airport? Do you log as a user without a "home" directory?
If you have a "home" directory, just create a blank ~/.vimrc and put your settings there.
If you don't have a "home" directory but you are able to write somewhere else, create a blank vimrc file where you can, write your settings there and learn this command by heart:
$ vim -u /path/to/your/vimrc
If you don't have a "home" directory and you are really sure that you can't save anything on these machines, put your settings in a file somewhere online, preferably a place under your control, and learn this command by heart:
$ vim -u http://domain.name/yourvimrc
If you are lucky, the command you use will be remembered by your shell for you and it will be easy to issue it again without much typing.
For running your tests, you can either:
Hit <C-z> to suspend Vim. You are back at the prompt from where you started Vim and you can do your thing. Type $ fg to go back to Vim.
Type :sh to launch a new shell from the current directory. To go back to Vim, type $ exit.

Resources