I know how to set the initial window size in gVim, but how do I get it to automatically restore the window dimensions from last session? Is this even possible?
Edit: Corrected my answer. The mentioned winsize sessionoption only refers to the vim internal window layout, not the external dimensions.
If you use
:mksession
and load the session on vim startup with
gvim -S Session.vim
you can include the window position and size into the session by including winpos and resize in the sessionoptions, see
:help 'sessionoptions
With autocommands you could even automate the saving and restoring of the session on Vim entry and exit.
These lines save and restore just the position and size:
set sessionoptions+=resize,winpos
autocmd VIMEnter * :source C:/session.vim
autocmd VIMLeave * :mksession! C:/session.vim
Additionally:
In your .vimrc:
set ssop+=resize,winpos,winsize,blank,buffers,curdir,folds,help,options,tabpages
Then, use the script from this article. It works beautifully!
I had the same question, and to expand on the above answer, you can simply add the following to your .vimrc to get the behaviour you want:
set sessionoptions+=resize,winpos
see :h ssop
gvim -geom 85x55
as in, putting this in your .bashrc:
alias G='gvim -geom 85x55'
If you just want vim to open to the same size every time, you can edit your user's vimrc in C:/Users/<yourUserName>/_vimrc (this is preferred to editing the system _vimrc in your vim installation folder)
to include the line set lines=<yourHeight> columns=<yourWidth>
Related
I am using a oh-my-zsh shell in an Apple terminal (2.11) in full screen, and by default the name of the tabs is the name of the program being run (eg. vim).
Is there an easy way to set the title of the individual terminal tabs to the filename currently opened with vim?
The terminal window title is already set, but not visible in full screen mode. What I'm looking for is to get at a glance the title of all terminal tabs where vim is opened.
Screenshot below:
The solution seems to use vim script shared in https://stackoverflow.com/a/48975505/4756084. It sets the title dynamically based on what file is currently being viewed — which you cannot obtain by going into Terminal Preferences > Tab, and checking "Active process name" and "Arguments" (that would only display the name of the file opened when typing vim file.ext, ignoring any file opened with :e file2.txt, switches between vim panes, etc.)
(With oh-my-zsh, uncommenting DISABLE_AUTO_TITLE="true" in ~/.zshrc might help, as suggested in https://superuser.com/questions/292652/change-iterm2-window-and-tab-titles-in-zsh, although it seems optional after the step above.)
I am on windows 10. I set up my files like this.
~/.vimrc
set nocp
source ~/vimfiles/autoload/pathogen.vim "location of my pathogen.vim
call pathogen#infect()
call pathogen#helptags()
autocmd vimenter * NERDTree
syntax on
filetype plugin indent on
~/vimfiles/autoload/pathogen.vim
~/vimfiles/bundle/nerdtree
When I open via the desktop application Vim I can use the :NerdTree command okay, I can also use other pluings, but when I open the vim editor from git bash or cmd.
One thing to note is that I do not need the autocmd vimenter command to run :NERDTree in Vim application, but it errors when I try to open :NerdTree from the vim editor.
Any ideas for what I can check?
On Windows, Vim expects your vimrc to be in either of these two locations:
%UserProfile%\_vimrc (note that it's a _, not a .),
%UserProfile%\vimfiles\vimrc (note that there's no _ or . anymore).
The latter is generally recommended because it allows you to keep all your Vim stuff under a single, easy to move around, directory.
Once you have moved your vimrc to a correct location you can remove the first line which is completely useless as Vim sets the nocompatible option itself when it finds a vimrc at an expected location.
See :help vimrc and :help 'nocompatible'.
The second line is also useless because lines 3 and 4 use a feature called "autoloading" through which Vim already knows where to find those functions.
See :help autoload.
I use iterm in Mac as my command line terminal. In iterm I use tmux as the terminal manager. When I open my code files in Vim copying has become painful in this. To copy text in vim I need to hold "option" key and then select the text. When holding option there are multiple issues:
1) I am unable to scroll while in select mode
2) When I split my terminal into 2 panes, select using option copies across panes making it tough.
I am not sure about the reason for this issue and where to find a workaround. Could anyone help me with it?
You cannot depend on iTerm's clipboard support because it will not know anything about Vim's or tmux's splits. Use native Vim copy instead.
:help v
:help V
:help y
:help d
:help "*
:help clipboard
So e.g. in order to copy two lines, you can do "*2yy (to clipboard register, two line yank); or you can mark something using visual mode, then just "*y (to clipboard register, yank). If you want the clipboard register to be always automatically used unless another register is specified, you can add the following to your .vimrc:
set clipboard+=unnamed
Then a simple 2yy will copy two lines, and you can just paste it in iTerm or any other application.
I encounted a problem after I change the syntax of mac's terminal vim. Right now, when I open vim, it just shows up under many line's of my shell command (screenshot below) instead of like before open a clean window and cannot see my shell command. So how can I reset it back that open my vim that in a clean terminal window?
Finally find out that because of the TERM is not set to xterm, so I fixed this issue by adding export TERM=xterm-color in my .bash_profile file. If you have the same issue, hope this would help.
When I start GVim and start writing my little program I'd like to save the file to the Desktop but it seems that Vim is starting the command line in:
C:\Windows\System32
How would I go about changing that to:
C:\Users\Casey
so then I could just:
:w Desktop\my_program.py
Assuming you're starting gvim from an icon/shortcut in Windows (from the kind of paths you supply), you can change the starting directory (completely independent from the fact that it IS gvim: it would be the same from any other app!) by editing the "starting directory" property of that Windows icon/shortcut.
Within vim, you can change the current directory with the :cd command:
:cd c:\users\casey
I found this way to be better:
Open gVim
:cd $vim
:e _gvimrc
Add the following line:
:cd c:\users\user\desktop\
I found that :Ex is slow on large directories like c:\windows\system32\ (where gVim usually starts).
Also, here is my full _gvimrc in case anyone is interested. I prefer Consolas for coding. The tabstop setting helps when coding especially in Python, and Ctrl+Tab/Ctrl+Shift+Tab is great for switching between buffers:
set guifont=Consolas:h12:cANSI
set tabstop=4 softtabstop=4 shiftwidth=4 expandtab
map <C-Tab> :bnext<cr>
map <C-S-Tab> :bprevious<cr>
:cd c:\users\user\desktop\
How about changing your starting position?
vim icon -> right click -> property -> shortcut -> Start in -> your path you want to change.
but it works perfectly.
I think :cd yourpath also works. but it will change when you don't want to change.
Use :cd c:\users\casey,
after that save into session (in gVim there is button up and down in red, click on it and save as mySessionProject.vim). Next time you need to go to that directory, open that session (you can also use :source mySessionProject.vim)
for command line:
:mksession! yourdir/yourVimConfName.vim
to load
:source yourDir/yourVimConfName.vim
I found the following to be very useful. I am on Windows 7 and vim 7.3.46, and am using gVim.
I edited startup settings, which wound up altering the _vimrc in c:\Users\me\.
I also tried using :version and editing the _vimrc files I found at $VIM, as well as the _vimrc I found at c:\windows\system32.
Editing those files to include :cd c:\Users\me did not result in my default startup directory changing after starting vim. I wanted my default directory to be c:\Users\me\, and editing c:\Users\me\_vimrc achieved that. That is I entered
:e $MYVIMRC
and added
cd c:\Users\cnorton.Arlington1\
to that file.
Just to to put this up incase anyone needs it:
vimrc accepts enironmental parameters. you can put cd $USERPROFILE in your vimrc
Use this mapping in your .vimrc file
:cd $USERPROFILE\Desktop<cr>
or the same shorter
cd ~\Desktop<cr>
A mapping that also displays afterwards the path instead of the command
nmap <leader>d :cd ~\Desktop<cr>:pwd<cr>
Inside init.vim, I use:
lcd $HOME/Projects