I used to use Nerdtree but I am switching to Netrw. In my .vimrc I have:
let g:netrw_browse_split = 4
let g:netrw_altv = 1
autocmd VimEnter * Vex
autocmd VimEnter * set winfixwidth
The Behavior currently is that when I press enter the file will open on the right split which is what I want. This works correctly as long as the buffer remains unmodified. If the buffer is modified, pressing enter in the netrw split brings up a prompt asking me if I want to save.
The behavior I want is that if I have a modified buffer open in the right vsplit, and I press enter on a different file in the netrw split, to open a split in the right vsplit like this:
----------------
|Netrw|Modified|
| | |
| |--------|
| |New |
----------------
Is this possible with Netrw?
Related
my problem is quite simple, but I can't figure how to solve it. So I wanted to have a tree file explorer, thus I searched and found netrw. Online, I managed to find a good configuration that I modified a little and put in my .vimrc :
let g:netrw_banner = 0
let g:netrw_liststyle = 3
let g:netrw_browse_split = 3
let g:netrw_altv = 1
let g:netrw_winsize = 25
augroup ProjectDrawer
autocmd!
autocmd TabNew * :Vexplore
autocmd VimEnter * :Vexplore
augroup END
So thanks to that, the tree appears when I enter vim, and if I click on a file it opens in a new tab. But in this tab, the content of the splitted screens are inverted : I get the content of the file in the little left screen, and the tree in the large right screen. I tried to modify the .vimrc config, changing Vexplore to Lexplore, but I get the same result... what must I do to get what I want ?
autocmd TabNew * :Vexplore!
Should do the trick.
Supertab works correctly in most cases.
I am writing a simple line of java Integer.toHexString. This has appeared in other parts of the file.
If I press tab after In, it gives me Integer correctly. If I press tab after to (another line), it gives me toHexString correctly, too. But, if I press tab after typing Integer. or Integer.to, tab automatically moves to the next line without any completion. (still in insert mode)
Here is my .vimrc the part related to supertab.
let g:SuperTabLongestHighlight = 1
let g:SuperTabDefaultCompletionType = "context"
autocmd FileType *
\ if &omnifunc != '' |
\ call SuperTabChain(&omnifunc, "<c-p>") |
\ endif
set omnifunc=syntaxcomplete#Complete
Here is the result from running :verbose imap <Tab>
i <Tab> <Plug>SuperTabForward
Last set from ~/.vim/bundle/supertab/plugin/supertab.vim
When I switch buffer and then go back to it (when I get back to any buffer that was previously opened), cursor is placed in the middle of the screen, loosing previous screen position (e.g. cursor at top of the screen). Maybe this is the normal behaviour of vim, but is there any way to fix this?
This problem happens when I use :bn and bp: to switch buffers. However this behaviour does not happen when switching between tabs which is really strange.
See http://vim.wikia.com/wiki/Avoid_scrolling_when_switch_buffers
" When switching buffers, preserve window view.
if v:version >= 700
au BufLeave * if !&diff | let b:winview = winsaveview() | endif
au BufEnter * if exists('b:winview') && !&diff | call winrestview(b:winview) | endif
endif
how do I make vim horizontally center the text of the open file?
I don't want to modify the file, just to change the way vim displays it.
To be more clear, when I open a file I currently have this situation:
|<------ textwidth=80 ------->|<-------------- padding -------------->|
|lorem ipsum dolor sit amet..
|dsdsda da dsa dsa
What I'd like to have is the following:
|<--- padding/2 --->|<------ textwidth=80 ------->|<--- padding/2 --->|
| lorem ipsum dolor sit amet..
| dsdsda da dsa dsa
Of course, for every value of textwidth and padding.
Vim isn't meant to be a single, centered document editor (when programming, you want to fill every single pixel with relevant information), so there are only workarounds:
a) You can achieve a larger left margin by expanding the fold column. Unfortunately, this is limited to 12 character cells:
:let &foldcolumn = (&columns - &textwidth) / 2
b) You can create an empty padding window to the left (and potentially also to the right, for symmetry).
:execute 'topleft' ((&columns - &textwidth) / 2 - 1) . 'vsplit _paddding_' | wincmd p
The annoying window split can be cleared with:
:hi VertSplit guifg=bg guibg=NONE gui=NONE
I think you could reach the point using screen.
you can open three different windows tiled vertically with
CTRL+a , SHIFT+|
then move to the second one.
Exist several plugins that allow you to get that look, most of them seem to be inspired by Writeroom editor for MacOS.
See for example this screenshot of the the VimRoom plugin, or just search the web for "vim writeroom plugin".
I use NERDTree for that reason. NERDTree is a file explorer for vim. You can load NERDTree at startup with any width you like:
This is how I run NERDTree at startup to get what you see in the image. I use vim-plug (a package manager for vim) to load NERDTree.
# Load NERDTree Plugin via vim-plug
call plug#begin()
Plug 'scrooloose/nerdtree', { 'on': 'NERDTreeToggle' }
call plug#end()
let g:NERDTreeWinSize=60 # Set NERDTree width.
NERDTreeToggle # Open NERDTree at startup.
au VimEnter * wincmd l # Remove focus from NERDTree window at startup.
I was looking for something similar and thanks to #ingo-karkat answer I managed to create a function to toggle the center content on/off.
function! WriteRoomToggle()
let l:name = '_writeroom_'
if bufwinnr(l:name) > 0
wincmd o
else
let l:width = (&columns - &textwidth) / 5
execute 'topleft' l:width . 'vsplit +setlocal\ nobuflisted' l:name | wincmd p
execute 'botright' l:width . 'vsplit +setlocal\ nobuflisted' l:name | wincmd p
endif
endfunction
Suggested options and mappings:
" hide vertical split separator
hi VertSplit guifg=bg guibg=NONE gui=NONE
" Do not resize windows on close (good if you also use NERDTree)
set noequalalways
" toggle writeroom on/off
map <silent><Leader>v :call WriteRoomToggle()<CR>
" delete buffer without closing the window
command! Bdelete if len(getbufinfo({'buflisted':1})) > 1 | bprev | bdelete# | else | bdelete | endif
noremap <Leader>x :Bdelete<CR>
I have the following autocmd in my .vimrc:
autocmd FocusLost,BufLeave,BufWritePre *.py :exe "normal! ma" | :%s/\s\+$//e | :exe "normal `a"
This command has the purposes to remove all trailing whitespace from my buffer while keeping the cursor at the current position.
The problem is that when the command is invoked and some text is selected, the text is replaced by ma. How can I modify my autocmd declaration in order to:
Still work when some text is selected
Keep the text intact
Keep the selection if some text was selected
Keep the cursor position if no text was selected
Note: I'm using MacVim.
You can save the cursor position (and overall window “view”) with winsaveview(). The saved position (and view) can be restored with winrestview().
The following code uses the buffer-local variable b:spacestrip_view to store the view (instead of overwriting the mark a):
autocmd FocusLost,BufLeave,BufWrite *.py let b:spacestrip_view=winsaveview()|%s/\s\+$//e|call winrestview(b:spacestrip_view)