Open variable in readonly split window in vim? - json

Here is the current code that i am using in vim
function! NpmDocs()
let package_name = input('Package name: ')
if package_name != ''
let url = 'https://registry.npmjs.org/' . package_name
let res = webapi#http#get(url)
let obj =webapi#json#decode(res.content)
echo obj.readme
endif
endfunction
The problem is the echo part. Basically i want to open the output in a new split window like the one we get in help page. Can someone please help me out with how to go with it?

Related

Change the connectionString Arg by values data entry by the user in an input with Razor Web Page

First, I quite apologize to you for my poor English (cause I'm french).
My problem is that, I need to recover some data like server IP, user name and password witch was get back by the user in some input on submit and use these data for change the connectionString witch is in web.config. But I don't know how to do.
I hope to have been clear and thank you in advance for your help.
Well, after a lot of search and work, I have chose to change my connectionString like it:
#{
Layout = "~/_Layout.cshtml";
Page.Title = "Dossier Racine";
var srv = Request.QueryString["server"];
var usr = Request.QueryString["username"];
var pwd = Request.QueryString["password"];
var db = Database.OpenConnectionString("server="+srv+";database=ReportServer;uid="+usr+";pwd="+pwd+"","System.Data.SqlClient");
var sqlFile = " SELECT *"
+ " FROM Catalog";
var selectedData = db.Query(sqlFile);
}

How to begin debugging POST and GET requests in Django and Python Shell

I have written the following code.
The issue that I am having is that the database is not being updated and a new record is not being made. I am assuming that the way I am retrieving my POST are incorrect but that's why I am asking where do I begin to debug? I have created template variables for quantity,action,building, and test. When I try to call them in the html {{ test }} for example nothing ever shows up even the one that is hardcoded. I used firebug and the form is indeed posting the values that should be posted.
the form consists of two drop down menus one for action and one for building. A numerical input quantity, a text box and a submit button. If anyone can offer me some advice it would be appreciated. I really don't understand why the hardcoded one doesn't show up
If you need any more information please let me know.
def update(request,Type_slug, slug, id):
error = False
Slug = slug
ID = id
Type = Type_slug
test = 'test'
quantity = request.POST['Qty']
action = request.POST['Action']
building = request.POST['Building']
comments = request.POST['Comments']
if Type == 'Chemicals':
item = Chemicals.objects.filter(S_field=Slug, id= ID)
New_Record = ChemicalRecord(Name=item.Name,Barcode=item.Barcode,Cost=item.Cost,Action=action,Building=building)
if building == 'Marcus':
building_two = 'Pettit'
elif building =='Pettit':
building_two ='Marcus'
Record_one = ChemicalRecord.objects.filter(Barcode=New_Record.Barcode).filter(Building=New_Record.Building)
if Record_one:
Record_one = ChemicalRecord.objects.filter(Barcode=New_Record.Barcode).filter(Building=New_Record.Building).latest('id')
New_Record.On_hand = Record_one.On_hand
else:
New_Record.On_hand = 0
if action == 'Receiving':
New_Record.On_hand = New_Record.On_hand+quantity
elif action == 'Removing':
New_Record.On_hand = New_Record.On_hand-quantity
Record_two = ChemicalRecord.objects.filter(Barcode=New_Record.Barcode).filter(Building=building_two)
if Record_two:
Record_two = ChemicalRecord.objects.filter(Barcode=New_Record.Barcode).filter(Building=building_two).latest('id')
Record_two_qty = Record_two.On_hand
else:
Record_two_qty = 0
New_qty = New_Record.On_hand+Record_two_qty
Chemicals.objects.filter(Barcode=obj.Barcode).update(On_hand=New_qty)
New_Record.save()
You can use import pdb;pdb.set_trace() for debugging.

Change vim's linestatus colors

I have successfully set my linestatus configuration. However, the only thing missing is some background color, either for the whole line as well as in particular elements. How can I set them?
You need to define the colours as new highlighting groups User1, User2, etc:
hi User1 ctermbg=blue ctermfg=white guibg=blue guifg=white
hi User2 ctermbg=black ctermfg=red guibg=black guifg=red
Then you can specify them in the statusline string like so:
set statusline=
set statusline+=%1* " Switch to colour User1
set statusline+=%F
set statusline+=%* " Switch to default colour
set statusline+=%P
set statusline+=%2* " Switch to colour User2
set statusline+=%c
EDIT
This probably belongs in a new question, but here is the method I use to find the existing colouring for a highlight group. In this example I set the Folded syntax to be the same as the current Normal syntax. I do this by directing the output of hi Normal to a variable, and then extracting the various information from it.
redir => hinorm
sil exe 'hi Normal'
redir END
if hinorm =~ 'cleared'
sil exe 'hi clear Folded'
else
let guibg = matchstr(strtrans(hinorm),'guibg=[#a-zA-Z0-9]*')
let guifg = matchstr(strtrans(hinorm),'guifg=[#a-zA-Z0-9]*')
sil exe 'hi Folded ' . guibg
sil exe 'hi Folded ' . guifg
endif
If there is a cleaner method, let me know!

Skipping a window in VIM with Ctrl-W_W

When I have several windows open in VIM, I'd like to always skip one of them (the one containing my project using Aric Blumer's Project plugin), whenever I press Ctrl-W_W.
In other words I'd like to cycle through my document windows as if the Project window wasn't one of them. When I actually do want to go into the project window, I'll use the mapping I created especially for this purpose.
Is there a way to mark a window so that it's skipped by Ctrl-W_W or would I need a script? I'm loving Vim but am still in the steep part of the learning curve.
You would have to write a function (it's easier to maintain) that cycles to the next window, and skip it if it matches the name of the windows you don't want to go into.
Something like:
function! s:NextWindowBut(skip,dir)
let w0 = winnr()
let nok = 1
while nok
" exe "normal! \<c-W>w"
" or better
exe 'wincmd '.a:dir
let w = winnr()
let n = bufname('%')
let nok = (n=~a:skip) && (w != w0)
" echo "skip(".n."):".(n=~a:skip)." w!=w0:".(w != w0)." --> ".nok
endwhile
if w == w0
echomsg "No other acceptable window"
endif
endfunction
nnoremap <silent> <C-W>w :call <sid>NextWindowBut('thepattern','w')<cr>
nnoremap <silent> <C-W>W :call <sid>NextWindowBut('thepattern','W')<cr>

html indenting in vim

I don't know if this is possible, but does anyone know of an indent script that will support this scenario?
(| is cursor)
given
<div>|<div>
if I press enter, I want to see
<div>
|
</div>
instead of
<div>
|<div>
delimitMate will take care of this for you.
You will however, need two additional settings...
add the >:< pair to the list of html files:
au FileType html let delimitMate_matchpairs = "(:),[:],{:},>:<"
and tell it what pattern you'd like to add after inserting a
au FileType html let b:delimitMate_expand_cr = "\<CR>\<CR>\<Up>\<Tab>"
(this will, instead of inserting two a , insert two s, press up, then insert a tab)
Ended up going with brian Carpers answer, only modified very slightly
"fancy html indenting
function! NewlineInTag()
let lnum = getline('.')
let cnum = col('.')
let chars = strpart(lnum, cnum - 2, 3)
if chars =~ '></'
return "\<CR>\<ESC>\<UP>$o"
else
return "\<CR>"
endif
endfunction
autocmd FileType eruby,html imap <CR> <C-R>=NewlineInTag()<CR>
You could do something like this:
function! NewlineInTag()
let lnum = getline('.')
let cnum = col('.')
let chars = strpart(lnum, cnum - 2, 2)
if chars =~ '><'
return "\<CR>\<ESC>\<UP>$o"
else
return "\<CR>"
endif
endfunction
imap <CR> <C-R>=NewlineInTag()<CR>