set vim background transparent - matrix

I am using the Matrix colorscheme along with CSApprox for my terminal vim.
I can not seem to be able to set the background as transparent. I have tried editing the matrix.vim file but it doesn't make it any better.
here is the matrix.vim
" vim:set ts=8 sts=2 sw=2 tw=0:
"
" matrix.vim - MATRIX like colorscheme.
"
" Maintainer: MURAOKA Taro <koron#tka.att.ne.jp>
" Last Change: 10-Jun-2003.
set background=dark
hi clear
if exists("syntax_on")
syntax reset
endif
let g:colors_name = 'matrix'
hi Comment guifg=#226622
hi Constant guifg=#55ff55
hi Special guifg=#44cc44
hi Identifier guifg=#55ff55
hi Statement guifg=#55ff55 gui=bold
hi PreProc guifg=#339933
hi Type guifg=#55ff55 gui=bold
hi Underlined guifg=#55ff55 gui=underline
hi Error guifg=#55ff55
hi Todo guifg=#113311 gui=none
hi Cursor guifg=#226622
hi lCursor guifg=#226622
hi CursorIM guifg=#226622
hi Directory guifg=#55ff55
hi DiffAdd guifg=#55ff55 gui=none
hi DiffChange guifg=#55ff55 gui=none
hi DiffDelete guifg=#113311 gui=none
hi DiffText guifg=#55ff55 gui=bold
hi ErrorMsg guifg=#55ff55
hi VertSplit guifg=#339933
hi Folded guifg=#44cc44
hi FoldColumn guifg=#44cc44
hi IncSearch guifg=#226622 gui=none
hi LineNr guifg=#44cc44 gui=none
hi ModeMsg guifg=#44cc44
hi MoreMsg guifg=#44cc44
hi NonText guifg=#44cc44 guibg=NONE ctermbg=none
hi Normal guifg=#44cc44 guibg=NONE ctermbg=none
hi Question guifg=#44cc44
hi Search guifg=#113311 gui=none
hi SpecialKey guifg=#44cc44
hi StatusLine guifg=#55ff55 gui=none
hi StatusLineNC guifg=#113311 gui=none
hi Title guifg=#55ff55 gui=bold
hi Visual guifg=#55ff55 gui=none
hi VisualNOS guifg=#44cc44
hi WarningMsg guifg=#55ff55
hi WildMenu guifg=#226622
and my .vimrc file
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim/
call vundle#begin()
Plugin 'gmarik/Vundle.vim'
Plugin 'fatih/vim-go'
Plugin 'vim-airline/vim-airline'
" Plugin 'vim-airline/vim-airline-themes'
Plugin 'airblade/vim-gitgutter'
" Plugin 'altercation/vim-colors-solarized'
Bundle 'morhetz/gruvbox'
Plugin 'tpope/vim-git'
Plugin 'Valloric/YouCompleteMe'
Plugin 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
" Plugin 'flazz/vim-colorschemes'
Plugin 'godlygeek/csapprox'
call vundle#end()
filetype plugin indent on
syntax on
syntax enable
#...
#...
#...
#...
#...
set t_Co=256
colorscheme matrix
if i enter hi Normal guifg=#44cc44 guibg=NONE ctermbg=none in the command prompt, it looks as expected. but not when it's only declared in matrix.vim. i also tried adding it after colorscheme matrix in .vimrc, but it does not help.
How it looks like when first loaded.
How it looks like after i enter command

You don't have to change anything in your colorscheme just add the following to your .vimrc:
hi Normal guibg=NONE ctermbg=NONE
Update:
As Liam mentioned in the comments:
This line needs to go below the colorscheme in .vimrc

If you load a plugin at line 5 of your .vimrc for example, then if you change line 6, it doesn't mean that Vim load the plugin completely and then run your line 6!!
That's why, you should use autocmd command, because in this case, it ensures that all of your plugins are loaded completely and then your command will run after that!
In this case:
" transparent bg
autocmd vimenter * hi Normal guibg=NONE ctermbg=NONE
" For Vim<8, replace EndOfBuffer by NonText
autocmd vimenter * hi EndOfBuffer guibg=NONE ctermbg=NONE
Now you sure that after all the things are loaded, you are running your commands.

Use this gist.
I compile some settings to make vim transparent.

The answers above don't solve all the problems, they change the bg to transparent when we enter vim (hence the "VimEnte" event) but when you source your init.vim file again, the background reverts back (this is because when the file is sourced the VimEnter auto command is not executed).
Instead of directly posting the correct answer, I'll explain how to reach it:
So, First, we need to understand what happens when vim is open:
vi -V10debug.log +q
This will create a debug.log where you can see what auto commands are executed and their order.
autocmd vimenter * hi Normal guibg=NONE ctermbg=NONE
" For Vim<8, replace EndOfBuffer by NonText
autocmd vimenter * hi EndOfBuffer guibg=NONE ctermbg=NONE```
If we are using this, we see in the log that VimEnter change the bg to NONE (so far its good).
But, and the following command opens vim, then source the vimrc and then exit (for faster finding I have putted some print statements)
vi -V10debug_so.log +'!echo sourcing' +'source ~/.config/nvim/init.vim' +'!echo sourced' +q
In the new log, we see, after so VimEnter is not called again and the bg is reverted back to theme default.
But, We also can notice when a file is sourced there are some events that occur, we will focus on the following
SourcePre - before sourcing
SourcePost - after sourcing
There the above incomplete solutions can be fixed using the SourcePost event. so the new and correct autocommand is (Final Answer)
" Workaround for creating transparent bg
autocmd SourcePost * highlight Normal ctermbg=NONE guibg=NONE
\ | highlight LineNr ctermbg=NONE guibg=NONE
\ | highlight SignColumn ctermbg=NONE guibg=NONE
Always use this in a group, see this for as reference - https://github.com/kalkayan/dotfiles/blob/main/.config/nvim/init.vim

In my case, I've just added this 2 line just after the colorscheme declaration :
hi NonText ctermbg=none
hi Normal guibg=NONE ctermbg=NONE

I use macvim, and the hi Normal guibg=NONE ctermbg=NONE don't work for me even I put it after the colorscheme in .vimrc
But I found :set transparency=20 | :set blurradius=90 work quite good for me. From the help of macvim, they do state that this two commands are {not in Vi} and {only in MacVim GUI}.

Pure LUA version for NeoVim to set fully-transparent background:
vim.api.nvim_set_hl(0, "Normal", {guibg=NONE, ctermbg=NONE})

Related

NeoVim: Broken Syntax Highlighting after heredoc "lua << EOF" in VimScript

I'm facing the problem that my init.vim becomes not highlighted properly after the line with lua << EOF in NeoVim. The weird behaviour is 1) paired brackets are colored differently; 2) After lua << EOF a Lua context does begin, yet it doesn't seem to be ended after the next EOF, instead it continues being highlighted in a Lua syntax (all lines later on are affected). From the screenshot below you can see that the brackets in line 59 are displayed as white and red separately, and the Lua syntax stays after line 60.
The code itself is assumed as okay, since it can be sourced without any error or warning, and the editing functions normally. It should namly only be a problem with the highlighting.
Sadly I can't tell the context of this problem. I first noticed it today without doing anything special (e.g. installing a new plugin) and I'm not sure when it occured. I have no clue what is causing this, even after doing research on Google for more than one hour - I haven't seen any post describing a similar situation.
The problem remains with the default color scheme.
I was guessing the CoC extension coc-vimlsp could be relevant, but the problem remains after I disabled it. Otherwise I can't remember any NeoVim plugin that could have something to do with the highlighting.
EDIT: I noticed that the broken highlighting after EOF is relevant to the broken brackets. If I write no brackets in the heredoc block, the highlighting will work correctly. Looks like the Lua highlighting remains after the heredoc block because it thinks the brackets aren't closed properly. And this is only about round brackets (), other brackets like [] {} "" would cause no problem.
My init.vim:
" Indentation
set shiftwidth=4
set ai
set si
" Show line numbers
set nu
" Show command at the bottom right of the screen
set sc
" Limit the number of items shown in popup
set ph=20
" Set the minimal number of lines below the cursor
set so=15
" Disable auto comment insertion
au Filetype * setlocal fo-=c fo-=o fo-=r
" vim-plug config
call plug#begin()
" Themes
Plug 'catppuccin/nvim', {'as': 'catppuccin'}
Plug 'tiagovla/tokyodark.nvim'
" Icon support
Plug 'ryanoasis/vim-devicons'
" Statusbar
Plug 'nvim-lualine/lualine.nvim'
" Fish support
Plug 'dag/vim-fish'
" Makrdown support
Plug 'preservim/vim-markdown'
" Markdown preview
Plug 'iamcco/markdown-preview.nvim', { 'for': ['markdown', 'vim-plug'] }
" TeX support
Plug 'lervag/vimtex'
" Auto close XML-like tags
Plug 'alvan/vim-closetag'
" Auto close brackets
Plug 'jiangmiao/auto-pairs'
" CoC completion engine
Plug 'neoclide/coc.nvim', { 'branch': 'release' }
call plug#end()
" catppuccin config
let g:catppuccin_flavour = "mocha" " latte, frappe, macchiato, mocha
lua << EOF
require("catppuccin").setup()
EOF
" Set colorscheme
colorscheme catppuccin
" lualine config
lua << EOF
require('lualine').setup({
options = {
theme = "horizon"
}
})
EOF
" vim-markdown config
let g:tex_conceal = ""
let g:vim_markdown_math = 1
let g:vim_markdown_folding_disabled = 1
let g:vim_markdown_frontmatter = 1
let g:vim_markdown_new_list_item_indent = 0
" Enable vimtex for Markdown files
" Not ideal, since this enables ALL features of vimtex
au Filetype md,markdown call vimtex#init()
" VimTeX config
let g:vimtex_compiler_latexmk = {'continuous': 0}
" CoC config
exe 'so ~/.config/nvim/coc_config.vim'
Operating system: MacOS Monterey 12.4
Output of nvim -v:
NVIM v0.8.0
Build type: Release
LuaJIT 2.1.0-beta3
Compiled by brew#Monterey
Features: +acl +iconv +tui
See ...
The issue raised in both of Neovim and Vim repository.
Neovim side: https://github.com/neovim/neovim/issues/20456
Vim side: https://github.com/vim/vim/issues/11277
Workaround from the comment: reverting to v0.7.2 lua syntax:
curl -sS https://raw.githubusercontent.com/neovim/neovim/v0.7.2/runtime/syntax/lua.vim > $VIMRUNTIME/syntax/lua.vim

terminal text not displayed in tcltk window real time

I am comfortable with tcl but newbie with tk.
I want to display some texts on a window and after several search I found here an example that seem good for me.
My issue is that the display is not put in real time but only when the program end.
Here is the main lines of my program.
Main_program.tcl
#!/bin/sh
# -*- tcl -*-
# The next line is executed by /bin/sh, but not tcl \
exec /usr/local/Cellar/tcl-tk/bin/tclsh "$0" "$#"
set DEBUG 1
source ./GUI_mgt.tcl
source ./utils.tcl
for {set i 0} {$i<500} {incr i} {
after 10
debug_puts $i
}
utils.tcl
proc debug_puts {message} {
if {$::DEBUG} { writeToLog $message }
}
GUI_mgt.tcl
package require Tk
grid [text .log -state disabled -width 80 -height 24 -wrap none]
proc writeToLog {msg} {
set numlines [lindex [split [.log index "end - 1 line"] "."] 0]
.log configure -state normal
if {$numlines==24} {.log delete 1.0 2.0}
if {[.log index "end-1c"]!="1.0"} {.log insert end "\n"}
.log insert end "$msg"
.log configure -state disabled
}
Question: what is wrong or missed in this code ?
Do you know some package or example I can use to display sentences on a separate window ?
Note: I use tcl tk 8.6.6 on macOS Sierra 10.12.5
Your test program is not written in an event driven fashion, so the problems with updating the screen are exacerbated.
The after 10 statement will hang the program and not allow the event loop to be reentered. For purposes of testing only, try:
set ::w10 0
after 10 [list set ::w10 1]
vwait ::w10
instead of the after 10 command. Use of the vwait command is not normally recommended, as nested vwait's will not work as expected.
When you have a very busy loop, the Tk program may never have a chance to re-enter its event loop, and the display is never updated.
The simplest solution is to put an
update
statement at the end of the writeToLog procedure. This is not always the best way to handle this type of issue, but it works.
It will also slow down your loop, as the window must be redrawn each time a log message is written.
Another method would be to put the calculation process into a separate thread or process and send the status updates to the main GUI process.
Ok, so for those of you who use the "update" command or "update idletasks" command, you may have noticed that your GUI or Text Widget will freeze, if you try and move the GUI around on the screen with your mouse, or even try to maximize or resize it. This is a side effect of using this command. It causes an "external event". Which causes the GUI to freeze, or to display "Not responding".
Enter the following two lines of code in place of "update idletasks" and you will not have this freezing issue:
after 500 {set go_on yes}
vwait go_on
I had the same issue with a few different TCL scripts. All we were looking for was a bare bone basic Text window, to display all of our "puts" messages in real-time in the log window, or in a TK text widget.
As Brad mentioned, I found the simplest solution was to use the "update" command. I used the command "update idletasks" and it works perfectly for both "puts" or "insert" commands for your text widget.
Here is my example using a basic TK text widget.
I used two separate procs. One to create the Text logging window, and the second for printing a desired message throughout the script.
The result is real-time logging, WHILE your TCL script is running...and not all displayed at once when your script completes. THANK GOD!!! It was so frustrating trying to track down how to do this. Finally I learned about the "update" command. :P
proc REALTIME_TEXT_LOGGING {} {
# Creates a text widget
text .t -yscrollcommand ".scroll set" -setgrid true -width 40 -height 10 -wrap word
scrollbar .scroll -command ".t yview"
pack .scroll -side right -fill y
pack .t -expand yes -fill both
# Set up the tags
.t tag configure big -font {-family helvetica -size 24 -weight bold}
.t tag configure color1 -foreground red
.t tag configure sunken -relief sunken -borderwidth 1
#Button to activate the display of messages
button .b -text "PRINT MESSAGES TO THE LOG" \
-command {
Insert_Text "HELLO EVERYONE!! This is MSG #1"
after 5000
Insert_Text "HELLO EVERYONE!! This is MSG #2"
after 5000
Insert_Text "HELLO EVERYONE!! This is MSG #3"
after 5000
Insert_Text "HELLO EVERYONE!! This is MSG #4"
after 5000
Insert_Text "HELLO EVERYONE!! This is MSG #5"
}
.t window create end -window .b
}
proc Insert_Text {message} {
# Insert text that has the property of the tags from your TK text widget.
# I also used the "puts" command here, to show printing to the default TCL logging window.
.t insert end "$message\n"
puts "$message\n"
update idletasks
}

Is there a Vim plugin for Ruby which provides a "switch to/from test" command outside of Rails?

Tim Pope's rails.vim provides a command :A (and a set of related commands) which opens the "alternate" file. For most classes, that's the test, and for the test, the class.
It would sure be nice to have that functionality in non-Rails Ruby projects. Is there a plugin which provides that? Bonus points if it helps me create the test file when I create the implementation file. :)
Our hero tpope wrote rake.vim too. It does the very same things rails.vim does but in Ruby projects.
I created the following command that makes it possible to do
:E /pattern/replace
to jump to the file that is the current filename and substituting pattern by replace
For example, if your tests files are in /test/code.js and your src files in /src/code.js you could write the following command:
command! -nargs=* Es :call EditSubstitute("/test/src")
command! -nargs=* Et :call EditSubstitute("/src/test")
to have the command :Es to jump from testfile to source file and the command :Et to jump from source file to testfile.
Here's the function that does that :
function! EditSubstitute(args)
if (len(a:args))<2
return
endif
let s:delimiter = (a:args[0])
let s:split = split(a:args,s:delimiter,1)[1:]
let s:fullpath = expand('%:p')
let s:bar = substitute(s:fullpath, s:split[0], s:split[1], "")
echo (s:bar)
silent execute('edit '.s:bar)
endfunction
command! -nargs=* E :call EditSubstitute(<q-args>)
I know this doesn't really answer your question at all... but I use VIM buffers to provide easy accessibility to a file and its tests.
I keep my test on top, and the file on the bottom. Then I can view both at the same time.
I use NERDTree to make browsing easier too, but that is not a per-requisite.
You can get a full reference of what I use here:
https://github.com/coderjoe/dotfiles
If you like it I'd recommend NOT using my dotfiles from the above repo, but start with something like RyanB's dotfiles and build your own sets based on your own preferences. :)
Have a look at the vimrc of the guy from 'Destroy all software' https://github.com/garybernhardt/dotfiles/blob/master/.vimrc#L280
pressing <leader>. will switch you between your code and the spec code.
-frbl

How do I get the output of an Xcode user script to auto indent?

The Problem
I want to press a key when I have a line highlighted and convert from a single line:
JGLogEntry *logEntry = [JGLogEntry applicationNoWindowsFrom:date1 to:date2 intoMOC:mockRawMOC];
to a multiline statement:
JGLogEntry *logEntry = [JGLogEntry applicationNoWindowsFrom:date1
to:date2
intoMOC:mockRawMOC];
What I've Tried
I've got a simple ruby script that almost gets me there.
#!/usr/bin/env ruby
s = STDIN.read
s.gsub!(/(:.+?\w) (\w.+?)/,'\1' + "\n\t" +'\2')
print s
When I set the output to "Replace Selection", I get this:
JGLogEntry *logEntry = [JGLogEntry applicationNoWindowsFrom:date1
to:date2
intoMOC:mockRawMOC];
When I set the output to "Place on Clipboard", then paste it in, I get the desired result:
JGLogEntry *logEntry = [JGLogEntry applicationNoWindowsFrom:date1
to:date2
intoMOC:mockRawMOC];
However, this is two keypresses which is clumsy.
Any ideas how I can get the replaced text to obey Xcode's auto indent rules?
Check the pre-installed script for "Convert tabs to spaces", and how it executes an in-line applescript. Use that to tell XCode to perform the menu item
Edit > Format > Re-Indent
I'm not sure how you do that with ruby, nor the details about the applescript content, but I would wager it's fairly straight-forward..

Highlight under-cursor code block?

I'm looking for a way to highlight the code block currently under the cursor while in normal mode.
This would work kinda like the set showmatch config options does, but the detection and highlighting would stretch over the entire block.
Any way to achieve this functionality either with config options or a (preferably existing) script ?
Short answer: no.
Long answer: there are ways to achieve this, but you'll have to sacrifice a lot of other fairly essential highlighting features.
There is certainly no way to do it with a simple option. The problem that you may come across is that Vim doesn't allow overlapping regions, so if you have rainbow.vim installed or anything else that makes a region in the area of your block, it's lost. It's also difficult (although I'd welcome any corrections) to have multiple highlighted groups, so one that sets the background colour and another that sets the foreground. This is very limiting as you'll see.
However, if fancy playing around, read on.
I'm making the assumption here that you're using C code in the same coding style as me, but this could easily be changed...
Here's a simple function that should help show you what's involved:
function! HighlightBlock()
" Search backwards and forwards for an opening and closing brace
" at the start of the line (change this according to your coding
" style or how you define a block).
let startmatch = search('^{', 'bcnW')
let endmatch = search('^}', 'cnW')
" Search in the other direction for each to catch the situation
" where we're in between blocks.
let checkstart = search('^{', 'cnW')
let checkend = search('^}', 'bcnW')
" Clear BlockRegion if it exists already (requires Vim 7 probably)
try
syn clear BlockRegion
catch
endtry
" If we're not in a block, give up
if ((startmatch < checkstart) && (endmatch > checkstart))
\ || ((startmatch < checkend) && (endmatch > checkend))
\ || (startmatch == 0)
\ || (endmatch == 0)
return
endif
" Create a new syntax region called "BlockRegion" that starts
" on the specific lines found above (see :help \%l for more
" information).
exec 'syn region BlockRegion'
\ 'start=' . '"\%' . startmatch . 'l"'
\ 'end=' . '"\%' . (endmatch+1) . 'l"'
" Add "contains=ALL" onto the end for a different way of
" highlighting, but it's not much better...
" Define the colours - not an ideal place to do this,
" but good for an example
if &background == 'light'
hi default BlockRegion guibg='#AAAAAA'
else
hi default BlockRegion guibg='#333333'
endif
endfunction
To use the function, source it from somewhere and then create an autocmd to call it whenever something changes, e.g.
au CursorMoved *.c call HighlightBlock()
See the following for some autocommands you may want to consider:
:help CursorHold
:help CursorHoldI
:help CursorMoved
:help CursorMovedI

Resources