Slimv - Change REPL Vertical Split - vim

I am using Slimv (version 0.9.13) with Vim (version 7.4). When I compile or run code or do anything that opens the REPL, it always opens in a window above my code, with the height split 50/50. Is it possible to make it open in a smaller window and below my source code by default?

According to the documentation (https://github.com/vim-scripts/slimv.vim/blob/master/doc/slimv.txt#L461) doing the below should make the REPL open in a split below the current window.
let g:slimv_repl_split=2
As for the size of the window, I don't think slimv provides an option for that.
However, I think an autocommand could do the trick.
autocmd BufEnter REPL :20wincmd _
'20' Can be replaced by whatever height you want the window to be, and 'REPL' should be replaced by the name of the REPL buffer. The default value g:slimv_repl_name is 'REPL' so it should work. If you need any more information on the commands used in this solution, you can read these in vim:
:help :autocmd
:help autocmd-events
:help :wincmd

Related

How to source vimrc in All buffers

To source vimrc in all buffers in the current window I do :bufdo so~/.vimrc ,to source vimrc in the ACTIVE buffers in all windows I do :windo so~/.vimrc. How to source vimrc in all buffers in all windows?
for some reason if I do:bufdo so~/.vimrc | :windo so~/.vimrc the active buffer in the non-active window changes.
example: if I set set number in my .vimrc, I want all buffers in all windows affect the change.
the solution might be something like this:
for window in windowlist
execute 'bufdo so~/.vimrc'
I use vim 8.2 .
PLEASE NOTE: I did try all of the commands you guys suggested but it seems that things aren't clear enough. all of the commands that includes :tabdo :windo :bufdo or combination of them doesn't work properly for what I want. please note that this is the same as changing vimrc and sourcing it with chain of these commands like :tabdo bufdo so~/.vimrc. for example :windo bufdo set number does set number to all buffers(active or hidden) in the active window but on non-active windows only does set number for the active buffer(buffer that is shown in the window) or :tabdo windo set number only does set number in active buffers in every window meaning that hidden buffers won't get line numbers.
I even made a reddit post about this problem on r/vim and made a video about it but I don't know why nobody gets what I say. honestly don't think this problem will be solved by someone else but me even though its a simple one.
The :bufdo command will consume | as part of the command to execute, so in effect you're running the :windo command for each buffer that you have active!
See :help :bar, which documents this behavior.
That help section also mentions a way to work around this behavior, by using the :execute command to run the first command from a string, which allows you to delimit the first command. Like so:
:execute 'bufdo so ~/.vimrc' | windo so ~/.vimrc
Please note that sourcing your vimrc file "in all buffers" or "in all windows" doesn't make much sense... The vimrc file typically has global commands that usually need to be sourced only once, and usually if you modify your vimrc, sourcing it again only once should be enough...
This might make sense with a separate *.vim script that affects local settings and is meant to act on a single buffer. The ftplugin, indent and syntax scripts come to mind. But also with those, they're normally run per buffer, not per window... It's not completely inconceivable that you'd have scripts that you want to run on every buffer and window, but it surely seems odd...
.vimrc shall only contain global definitions. That the way it's supposed to be used. Sourcing it in several buffers makes no sense.
I wonder if you're fighting with local settings for which the best tool to use is either ftplugin (when the setting are filetype driven), or a local_vimrc plugin for project driven settings.
To apply in all buffers and all windows:
:windo bufdo set number
If you have tabs, from :tabe, :tabf, :tab and friends. Just add tabdo like this:
:tabdo windo bufdo set number
I would advise not to source your vimrc like this. If you want a quick setting, just use the set command and friends.
:help tabdo
:help windo
:help bufdo
:help source
While I agree with most answers on sourcing your vimrc. I do believe there are uses of the source command. Particularly batch fixing. I've never tried using
:windo with this, I mostly use :argdo and :cdo. As I have more fine-grained control on what files I need to apply.
Batch fixing is particularly useful on a large codebase. You do your fixes with :g, :v, :s for example, and save them in a file called fix.vim. This is so useful, you could even pair macros with those commands (:g and :v) via :norm command.
:help norm
Then update your argslist via :args *.js or similar commands (like backtick expression) and finally do the :argdo source fix.vim

LaTeX code was abbreviatedly displaied by Vimwiki in Vim

My GVim distribution on a Windows 8.1 machine has both vimwiki and Vim-Latex-Suite installed through Vundle.
It bothers me that the following display (on the left) will occur when I do the following:
Open a *.wiki file (thereby enter the filetype vimwiki once);
In the same GVim session, open another *.tex file.
Notice that almost all those math symbols are no longer readable on the left. The quoted code-segment was displayed correctly (on the right) when opened by itself, through a new Gvim.exe session.
For this specific case, my guess is that, Vim is incapable of:
Correctly identify and display all math symbols (e.g. subscripts are displayed as a square);
Correctly displaying math symbols in full-width. (By default, half-width is default and this is why those \phi or \int are hiding all its right part.)
The goal for this post is not to "display math symbols in Vim" correctly. It is too wild and LyX can handle it pretty well. Instead, I would like to know:
How can I stop Vimwiki from interfering the display of *.tex
documents?
Any suggestion? Thank you in advance :)
Original answer from #Sato Katsura
This is the conceal feature. It works better in gVim, provided that you use a font that has all the relevant symbols. You can disable it with:
set conceallevel=0
Further details for Vimwiki
Vimwiki has specified g:vimwiki_conceallevel=2 by default according to line 2100 of the help file. Unfortunately, this "default value" was set globally for all buffers.
Specific solution:
For ~\vimfiles\ftplugin\tex.vim, add the following to the end:
setlocal conceallevel=0
For ~\vimfiles\ftplugin\vimwiki.vim, add the following to the end:
setlocal conceallevel=2
I've had the same problem what made me research until reach this mapping:
nnoremap <Leader>c :let &cole=(&cole == 2) ? 0 : 2 <bar> echo 'conceallevel ' . &cole <CR>
It toggles between conceallevel=0 to conceallevel=2

How to open a terminal in new tab from VIM?

When I'm working with lets say 4 files, all are open in tabs(VIM). I want to save the changes and compile it without having to close the tabs, i.e I want to open a terminal in new tab along with the existing 4?
How should I do this in VIM?
:tab ter
opens a terminal in a new tab instead of opening it in a new window as :ter does. You can also use the equivalent, longer :tab terminal form.
Credits to user wolloda in this Reddit post.
Extra information
Terminating the shell with Ctrl-d or exit closes the terminal buffer.
Ctrl-w N or Ctrl-\ Ctrl-n put the buffer in the terminal-normal mode:
Keystrokes are not forwarded to the shell, but are used by Vim as in a normal buffer
(although the shell job is still running). Then you can use gt to change tabs,
type Ex commands such as :ls, etc. To bring the terminal buffer back to life,
i, a, ...
If you are going to map this, I recommend using :tab ter++kill=hup, so that when you :qa the terminal job does not prevent Vim from quitting.
And this is the signal normal terminal emulators send to its jobs when closed anyway.
For terminal mode mappings, use tnoremap, for example
tnoremap <S-Tab> <C-W>:tabprevious<CR>
tnoremap <C-N> <C-W>N
More information on :help :terminal and :help :tab.
In 2019, vim now has a Terminal mode.
:help terminal
For example, you can use it like this.
# go to terminal-job mode
:terminal
# go to terminal-normal mode
ctrl-w N
# go back to terminal-job mode
i
A more vim like way of doing this would be to use :make
:make
:make will execute the 'makeprg'. It defaults to make which is great of C projects
After running :make the quickfix list will be contain any errors.
Set your compiler via the :compiler command.
Extra parameter can be passed like so :make foo-command
Current filename can be represented by %. e.g. :make %
quickfix list
Use :cnext and :cprev to move between your errors.
:copen to open up the quickfix list in a window (:cclose to close)
:cwindow to open quickfix list window only if there are errors
May want to use better mappings for :cnext and friends. I suggest Tim Pope's unimpaired plugin
Alternatives and Plugins
Just use <c-z> to suspend vim and run your build system. (Cons: loose out on the quickfix list)
Use :! to compile. (Same cons as suspending) e.g. :!make
Syntastic is a syntax checking system that checks files on save
Dispatch can be used to run things in the background. Great for test suites
As #brettanomyces mentioned you may want to consider terminal multiplexers like tmux or screen.
SingleComplile tries and takes some of the work out of using :make
Conclusion
If you are just starting out I would suggest you learn how to use :make and the quickfix list. There is a nice Vimcast episode that intros the quickfix list: Search multiple files with :vimgrep. Additionally Syntastic is a great way to get up and running with linters quickly.
Aside about tabs
Vim's tabs are not like most text editors tab. They are more like viewports into a group of windows/splits. Additionally, Vim is buffer centric, not tab centric like most editors. Therefore using features like the quickfix list is often easier without tabs (See :h 'switchbuf if you must use tabs). Vim's tabs often get in the way of using a splits as there are better window and buffer navigation commands available. I personally have many files open (sometimes 100+) use no tabs and use on average 1-2 splits without any issue. Bottom line: Learn to use buffers effectively.
For more help see the following:
:h :make
:h 'makeprg
:h quickfix
:h :cnext
:h :cope
Vim 8.1 now has a built in terminal that can be opened with the :term command. This provides much more complete integration with the rest of the Vim features.
Original Answer:
I would suggest looking at tmux or screen. I use tmux myself and along with vim-tmux-navigator moving between the terminal and vim is very easy.
For anyone using NeoVim:
The highest voted answer uses :tab ter. This doesn't work on NeoVim (at least for me). However, it's still fairly simple:
:tabe term://bash
tabe is open a new tab and edit file.
term:// is a NeoVim way of opening a terminal
bash is the kind of shell you want to use (e.g. I use zsh, so my command is actually :tabe term://zsh)
Some helpful commands that I created:
" open terminal
if has('nvim')
command Terminal vsplit term://zsh
command TerminalTab tabe term://zsh
else
command Terminal vert term
command TerminalTab tab ter
endif
Another way
Ctrl-w :
That gets me to the command line, then one can enter tablast tabnext or tabprevious
or the short versions tabl, tabn, tabp
Or this way:
Ctrl-w gt and Ctrl-w gT
(Next tab and Previous Tab)
Or Ctrl-w Number gt (for a specific tab)
That works too.

vim, switching between files rapidly using vanilla Vim (no plugins)

I understand that limiting myself to vanilla Vim (not using plugins) limits the power of the editor, but as I switch between different machines frequently, it is often too much trouble to move my environment around everywhere. I want to just stay in vanilla Vim.
Something that holds me back is the ability to quickly switch between files.
I (believe at least) have a good understanding of buffers, windows, tabs, as well as netrw (Vex, Ex, etc).
But in an editor such as Sublime Text, I can just type ctrl-p and instantly I am at the file.
I know that I can drop down to the shell, but I wonder if there are any other "hidden" secrets to rapidly switching between files in Vim based off more than just the filename.
The closest equivalent ("closest", not "exact") to ST2's Ctrl+P is a plugin called, get ready… CtrlP. There are other similar plugins like Command-T or FuzzyFinder.
I use CtrlP and I love it but I wholeheartedly support your decision to go "plugin-free". It's not the easiest way to go but it will pay off in the long run.
Opening files
The most basic way to open a file is :e /path/to/filename. Thankfully, you get tab-completion and wildcards: the classic * and a special one, **, which stands for "any subdirectory".
Combining all of that, you can do:
:e **/*foo<Tab>
to choose from all the files containing foo in their name under the working directory or:
:e **/*foo/*bar<Tab>
to choose from all the files containing bar in their name under any subdirectory containing foo in its name, anywhere under the working directory.
Of course, that works for :tabe[dit], :sp[lit] and :vs[plit], too.
Those commands are limited to one file, though. Use :next to open multiple files:
:next **/*.js
and take a look at :help arglist.
Jumping between buffers
:b[uffer] is the basic buffer-switching command:
:b4 " switch to buffer number 4
:bn " switch to next buffer in the buffer list
:bp " switch to previous buffer in the buffer list
:bf " switch to first buffer in the buffer list
:bl " switch to last buffer in the buffer list
:b foo<Tab> " switch by buffer name with tab-completion
:b# " switch to the alternate file
Note that many of these commands and their relatives accept a count.
The :ls command shows you a list of loaded buffers. It is a bit "special", though: buffers are assigned a number when they are created so you can have a list that looks like 1 2 5 if you delete buffers. This is a bit awkward, yes, and that makes switching to a buffer by its number a bit too troublesome. Prefer switching by partial name, :b foo<Tab> or cycling, :bn :bp.
Anyway, here is a cool mapping that lists all loaded buffers and populates the prompt for you, waiting for you to type the number of a buffer and press <enter>:
nnoremap gb :ls<CR>:b<Space>
With this mapping, switching to another buffer is as simple as:
gb
(quickly scanning the list)
3<CR>
or:
gb
(quickly scanning the list)
foo<tab><CR>
The idea comes from this image taken from Bairui's collection of Vim infographics:
Vim also has <C-^> (or <C-6> on some keyboards)—the normal mode equivalent of :b#—to jump between the current buffer and the previous one. Use it if you often alternate between two buffers.
Read all about buffers in :help buffers.
Go to declaration
Within a file, you can use gd or gD.
Within a project, Vim's "tags" feature is your friend but you'll need an external code indexer like ctags or cscope. The most basic commands are :tag foo and <C-]> with the cursor on a method name. Both tools are well integrated into Vim: see :help tags, :help ctags and :help cscope.
For what it's worth, I use tag navigation extensively to move within a project (using CtrlP's :CtrlPTag and :CtrlPBufTag commands, mostly, but the buit-in ones too) and my favorite "generic" buffer switching method is by name.
Deploying your config
A lot of Vim users put their config under version control which makes it very quick and easy to install your own config on a new machine. Think about it.
EDIT
A few months ago, I had to work on a remote machine with an outdated Vim. I could have installed a proper Vim and cloned my own beloved config but I decided to travel light, this time, in order to "sharpen the saw". I quickly built a minimalist .vimrc and revisited a couple of half forgotten native features. After that gig, I decided CtrlP wasn't that necessary and got rid of it: native features and custom mappings are not as sexy but they get the job done without much dependencies.
Juggling with files
set path=.,**
nnoremap <leader>f :find *
nnoremap <leader>s :sfind *
nnoremap <leader>v :vert sfind *
nnoremap <leader>t :tabfind *
:find is a truly great command as soon as you set path correctly. With my settings, ,ffoo<Tab> will find all the files containing foo under the current directory, recursively. It's quick, intuitive and lightweight. Of course, I benefit from the same completion and wildcards as with :edit and friends.
To make the process even quicker, the following mappings allow me to skip entire parts of the project and find files recursively under the directory of the current file:
nnoremap <leader>F :find <C-R>=expand('%:h').'/*'<CR>
nnoremap <leader>S :sfind <C-R>=expand('%:h').'/*'<CR>
nnoremap <leader>V :vert sfind <C-R>=expand('%:h').'/*'<CR>
nnoremap <leader>T :tabfind <C-R>=expand('%:h').'/*'<CR>
WARNING! The path option is extremely powerful. The value above—.,**—works for me, as a default fallback value. In the real world, the exact value of the option will differ from project/language/framework/workflow to project/language/framework/workflow, so the proper value depends entirely on your needs. Don't blindly copy that line and expect it to solve all your problems.
Juggling with buffers
set wildcharm=<C-z>
nnoremap <leader>b :buffer <C-z><S-Tab>
nnoremap <leader>B :sbuffer <C-z><S-Tab>
The mappings above list the available buffers in the "wildmenu" with an empty prompt, allowing me to either navigate the menu with <Tab> or type a few letters and <Tab> again to narrow down the list. Like with the file mappings above, the process is quick and almost friction-less.
nnoremap <PageUp> :bprevious<CR>
nnoremap <PageDown> :bnext<CR>
Those mappings speak for themselves.
Juggling with tags
nnoremap <leader>j :tjump /
This mapping uses regex search instead of whole word search so I can do ,jba<Tab> to find tag foobarbaz().
Yes, fuzzy matching is addictive but you can be just as productive without it. And for a fraction of the cost.
MORE EDIT
A couple of additional tips/tricks…
Wildmenu options
The "wildmenu", enabled with set wildmenu, makes file/buffer navigation easier. Its behavior is governed by a bunch of options that are worth investigating:
wildmode tells Vim how you want the "wildmenu" to behave:
set wildmode=list:full
wildignore filters out all the cruft:
set wildignore=*.swp,*.bak
set wildignore+=*.pyc,*.class,*.sln,*.Master,*.csproj,*.csproj.user,*.cache,*.dll,*.pdb,*.min.*
set wildignore+=*/.git/**/*,*/.hg/**/*,*/.svn/**/*
set wildignore+=tags
set wildignore+=*.tar.*
wildignorecase allows you to search for foo and find Foo:
set wildignorecase
File marks
augroup VIMRC
autocmd!
autocmd BufLeave *.css normal! mC
autocmd BufLeave *.html normal! mH
autocmd BufLeave *.js normal! mJ
autocmd BufLeave *.php normal! mP
augroup END
I recently found this gem in someone else's ~/.vimrc. It creates a file mark at the exact position of the cursor whenever you leave a buffer so that, wherever you are, 'J jumps to the latest JavaScript buffer you edited. Awesome.
The answer depends a lot on your preferences and circumstances. Some examples:
If it's mostly two files (e.g. a C header and implementation file), <C-^> is very handy. In general, the alternate file is an important concept.
If you use a large editor window, window :splits turn the problem of locating a buffer from locating the window (once you've got all buffers opened). You can use [N]<C-w><C-w> to quickly switch to it.
If you can memorize (a few) buffer numbers, the :[N]b[uffer] and :[N]sb[uffer] commands are quite handy; :ls tells you the numbers.
Plugins (or at least custom mappings) can improve things a lot, and there's a whole variety on this topic on vim.org. There are various mechanisms to distribute your config (Pathogen + GitHub, Dropbox, ...), or you could remotely edit server files through the netrw plugin that ships with Vim.
Sometimes it is also handy to go sequentially through a list of files (e.g., if you did something like vim *.php to open several files at once). Then you can use :n[ext] (as well as :prev[ious], :fir[st], and :la[st]) for navigation (in addition to what was suggested in the other answers).
You can do wildcard tab completion on the command line without any plugins. e.g.
:e src/**/foo*<tab>
will let you cycle through all the files starting with 'foo' in the directory tree under ./src and select the one you want to edit.
If you have already edited the file and it is still in a buffer then you can switch to it with:
:b foo<tab>
which will cycle through all the buffers with 'foo' in the path.
You may need to set the wildmode and wildmenu options to get the behaviour you want. I have
wildmode=longest:full
wildmenu
in my .vimrc.
If you are on a filename and want to jump to that file, gf will do it for you. I also like using ctags, which isn't a plugin; you just build the tags and can easily jump around your codebase.
If you want switch between files in vim editor, please see below answer
First press Esc key to exit from edit mode.
Then type :e to check current file path.
if you want to go another file then type :e /path-of-file.txt/ using this you are able to switch.
If you want to go previous file simply type :e# which switch to previous file path.
I had the same issue with Vim.
The last thing I want is to depend on plugins for a task as mundane as file switching.
I added the following lines to .vimrc
set path+=**
set wildmenu
And BAM! I can now :find any/filename/in/any/folder/ as long as vim is in the root directory of the project. Tab completion works. Wildcards work!
Once files are opened already, and there are a ton of buffers in the background (you could use :ls to see all buffers), running :b any/file <TAB> will fuzzy search for all buffers and jumps to the required file. In case it is not unique there will be a wildmenu of tabs (hence the 2nd line in .vimrc) which can be selected using tab.
My answer is coming from this awesome video
https://www.youtube.com/watch?v=XA2WjJbmmoM&feature=youtu.be&t=489
There are more tricks in and I recommend watching it.

How to fix buffer in a window in vim?

Can I fix a buffer so that the only way to remove it from vim window is closing it?
For instance, I'm using the NERDtree plugin, which displays the filesystem in a vim window. Sometimes I forget to change focus to other window before using the quickfix commands and the erroneus file ends up replacing the file tree. (Not to mention that NERDtree's window default width is only 31)
Edit:
What I'm trying to achieve with this question is to simulate Eclipse's notion of views and editors inside vim. In this terms, NERDTree (and other plugins destined to exclusively display information) would be a view while the other windows would be editors.
This isn't exactly an answer, but if you screw up, Ctrl-^ undoes a change in a buffer's content.
I've written an autocommand that does this. Adding the following to vimrc will prevent NERDtree buffers from being overwritten:
autocmd BufEnter * if bufname("#") =~ "NERD_tree" && bufname("%") !~ "NERD_tree" | b# | endif
The autocommand runs every time a new buffer is opened -- if it detects that the previous buffer was NERDtree and the current buffer is not NERDtree, then it will go back to the NERDtree buffer, essentially 'locking' NERDtree in place.

Resources