So I'm using the gVim editor to code in c++, and I would like that everytime I re-open gVim the previous tabs+files get restored. I tried adding that to my _vimrc:
autocmd VimLeave * nested let buffernr = bufnr("$") |
\ let buflist = [] |
\ while buffernr > 0 |
\ if buflisted(buffernr) |
\ let buflist += [ bufname(buffernr) ] |
\ endif |
\ let buffernr -= 1 |
\ endwhile |
\ if (!isdirectory($HOME . "/.vim")) |
\ call mkdir($HOME . "/.vim") |
\ endif |
\ call writefile(reverse(buflist), $HOME . "/.vim/buflist.txt")
autocmd VimEnter * nested if argc() == 0 && filereadable($HOME . "/.vim/buflist.txt") |
\ for line in readfile($HOME . "/.vim/buflist.txt") |
\ if filereadable(line) |
\ execute "tabedit " . line |
\ set bufhidden=delete |
\ endif |
\ endfor |
\ tabclose 1 |
\ endif
However this does not work, I took it from here
Any ideas?
Thanks in advance.
Related
What setting should I add to my .vimrc file so that no information about previous open buffers is saved to .viminfo? I do want to save command history though.
By not preserving buffer history I mean when I open a fresh vim instance and I do Ctrl+o or Ctrl+i to not show buffers that were open in a previous session, but only buffers that were opened during the current session.
Thanks
Add this into your .vimrc:
autocmd VimEnter *
\ execute "
\ let i = 0 |
\ while i < 100 |
\ mark ' |
\ let i = i + 1 |
\ endwhile |
\ unlet i |
\ delm A-Z0-9"
This will wipe out the jump list for every session and delete marks.
I tried to implement a version of Ingo's answer from here
In my _vimrcfile I have the following:
:autocmd BufEnter,FileType * if &ft ==# 'sql' colorscheme SummerFruit256 | elseif &ft ==? 'python' | colorscheme IntelliJ | else | colorscheme pyte | endif
I've taken the \ characters out of Ingo's answer and tried to do it on one line but I still get an E15.
How are spaces treated in these vim scripts? and why doesn't this script work?
Ingo's Answer is copied below.
:autocmd BufEnter,FileType *
\ if &ft ==# 'c' || &ft ==# 'cpp' | colorscheme darkblue |
\ elseif &ft ==? 'r' | colorscheme desert |
\ else | colorscheme default |
\ endif
The \ characters tell vim that the command should be on the same line as the previous one (if its at the beginning of the line.) This allows long commands to be more readable.
Spaces are treated as separators between inputs to the commands so it doesn't matter how many there are.
In your command I believe you are missing a pipe | after the first if.
... if &ft ==# 'sql' colorscheme SummerFruit256 | ...
Should be
... if &ft ==# 'sql' | colorscheme SummerFruit256 | ...
So the whole command would be
:autocmd BufEnter,FileType * if &ft ==# 'sql' | colorscheme SummerFruit256 | elseif &ft ==? 'python' | colorscheme IntelliJ | else | colorscheme pyte | endif
Note: Since these commands are in your vimrc file, You don't need to the leading :
I am trying to set the cursor in insert mode to be a thin vertical line and I am unable to. I have tried this in my .vimrc file:
set guicursor+=i:ver100-iCursor
It does not set the cursor to a vertical bar on insert mode.
What am I missing and how do I do this?
This code in my /home/el/.vimrc worked for my console:
if $TERM_PROGRAM =~ "iTerm"
let &t_SI = "\<Esc>]50;CursorShape=1\x7" " Vertical bar in insert mode
let &t_EI = "\<Esc>]50;CursorShape=0\x7" " Block in normal mode
endif
Which does this for me:
Source:
https://hamberg.no/erlend/posts/2014-03-09-change-vim-cursor-in-iterm.html
For gnome terminal version>3.15
Add this to your ~/.vimrc.
if has("autocmd")
au VimEnter,InsertLeave * silent execute '!echo -ne "\e[2 q"' | redraw!
au InsertEnter,InsertChange *
\ if v:insertmode == 'i' |
\ silent execute '!echo -ne "\e[6 q"' | redraw! |
\ elseif v:insertmode == 'r' |
\ silent execute '!echo -ne "\e[4 q"' | redraw! |
\ endif
au VimLeave * silent execute '!echo -ne "\e[ q"' | redraw!
endif
You will get a block cursor in normal mode and a thin one in insert mode.
This did the trick:
set guicursor=i:ver25-iCursor
I had to reduce the 100 to 25
I use iTerm2 on mac and none of the above worked. Silly (vim and interface ain't right) but works. To switch between vertical bar or box. Profiles -> Open Profiles... -> Edit Profiles... -> Text
I have this in my .vimrc:
augroup filetype_colorscheme
au BufEnter *
\ if !exists('b:colors_name')
\ | if &ft == "vim"
\ | let b:colors_name = 'color_dark'
\ | else
\ | let b:colors_name = 'color_light'
\ | endif
\ | endif
\ | exe 'colorscheme' b:colors_name
augroup END
What it does:
When I open a .vim page it opens my dark colorscheme "color_dark.vim"
when I open whatever other page it opens my light colorscheme "color_light.vim"
This is very nice but it is not so nice in split windows.
Every time when I click in a split window with p.e. a text file, all split windows become light colored with the light colorscheme (even the .vim files).
When I switch to a vim file in a split window all other files in the other split windows become dark as well.
Is it possible to retain every filetype his own colorscheme in a split window?
What do I have to change in above code?
EDIT
If this is not possible would it be possible to disable above code when I enter in a split window? (in order to let me choose the colorscheme myself, the same for all split windows)
Colorschemes will always affect the entire vim instance. It is not possible to have a different color scheme per split window.
Edit 1: To answer your second question in the edit, you can probably add && winnr('$') == 1 to that first if to stop this from happening when you have multiple split windows open.
Edit 2: Whoops, the edit above would not work, however I think wrapping everything in another if should.
Edit 3: Missed a couple of pipes.
augroup filetype_colorscheme
au BufEnter *
\ | if winnr('$') == 1
\ if !exists('b:colors_name')
\ | if &ft == "vim"
\ | let b:colors_name = 'color_dark'
\ | else
\ | let b:colors_name = 'color_light'
\ | endif
\ | endif
\ | exe 'colorscheme' b:colors_name
\ | endif
augroup END
How do i make Vim always start at the line I was at when i exited that given file last time?
Put this in your .vimrc:
" When editing a file, always jump to the last cursor position
au BufReadPost *
\ if ! exists("g:leave_my_cursor_position_alone") |
\ if line("'\"") > 0 && line ("'\"") <= line("$") |
\ exe "normal g'\"" |
\ endif |
\ endif
then you can use :let g:leave_my_cursor_position_alone=1 at runtime to deactivate the feature.
put this into your .vimrc
set viewoptions=cursor,folds
au BufWinLeave * mkview
au BufWinEnter * silent loadview