vim omni-complete may delete my previous selected word? - html

I'm writing HTML with gvim, but what annoys me is that the omni-complete always delete my previous word, even my previous selected ones.
For example, assume I'm writing the following code**('_' means the cursor, hereafter)**:
<a style="_" ></a>
After I Press ^X-^O, it pops out the hint list, and I select "color:"
<a style="color:_" >
And I Press ^X-^O again, it does pops out the proper hints("rgb(", "#"), but it deletes the previous word in the meanwhile, like this:
<a style="rgb(_" >
Can anyone give me some help? Thanks a lot. And this is my gvimrc:
set guifont=文泉驿等宽微米黑\ 14
colorscheme neverness_modified
set number
set guioptions-=T
winpos 0 0
set columns=1000
set lines=1000
set fileencodings=utf-8,gb18030
set smartindent
set tabstop=4
set shiftwidth=4
set expandtab
filetype on
filetype indent on
syntax on
set cindent
set completeopt+=longest
function Maximize_Window()
silent !wmctrl -r :ACTIVE: -b add,maximized_vert,maximized_horz
endfunction
" ========================
" TagList
" ========================
set tags+=/home/fish47/.vim/tags/STL.tags
" ========================
" TagList
" ========================
let Tlist_Show_One_File=1
let Tlist_Exit_OnlyWindow=1
" ========================
" WinManager
" ========================
let g:winManagerWindowLayout='FileExplorer|TagList'
WMToggle
" ========================
" OmniCppComplete
" ========================
set nocp
filetype plugin on
let OmniCpp_SelectFirstItem=2
let OmniCpp_MayCompleteDot=1
let OmniCpp_MayCompleteArrow=1
let OmniCpp_MayCompleteScope=1
set showcmd
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags

This is a bug in the htmlcomplete.vim script. You can work around this by inserting a <Space> between property and value, as romainl has pointed out.
Please submit a bug report (basically a link to this page) to the script's author, Mikolaj Machowski; his email address is in the script's header; the script is located at autoload/htmlcomplete.vim in the Vim install directory.
As the last change was from Apr-2011, there's a good chance the author is still maintaining it. Should you not get a response, please inform the vim_dev mailing list (cp. http://www.vim.org/community.php; you need to register first) about this; hopefully, someone else will pick it up.

Let csscomplete.vim to handle the html completion may be a solution to my problem. You can do that by adding "autocmd FileType html set omnifunc=csscomplete#CompleteCSS" in gvimrc.

It's a bug and a regression for a newer version of vim. This csscomplete.vim plugin was written for an earlier version and you using a newer version, there's an unexpected regression.
If you hack the plugin, you'll see the delete happens because it moves the cursor in reverse looking for the most obvious context, and that reverse cursor movement gets interpreted as an erase by your vim.
For me the bug was in these lines:
...
let compl_begin = col('.') - 2
while start >= 0 && line[start - 1] =~ '\%(\k\|-\)'
let start -= 1
endwhile
So yeh there's yer problem: the variable named start is passed back to vim through omnifunc and vim used to leave the existing text as-is, but newer versions interpret that motion as an erase.
So change the second while clause condition asserting the hyphen, and now you're off to the races. But that exposes a new problem, typing a letter and initiating omnifunc slows down as csscomplete.vim bogs down. But hey, one problem at a time huh.
It's like buying a car with the steering wheel mounted on the roof. It's like yeh that's not going to work bub. But this is Vim, if you're not in this for the low level hacking, then you're in the wrong machine shop.

Related

Extraction - only numbers from address

The address of Japan is written in many sites as 〒000 - 0000.
From this, I would like to extract only numbers using imacros.
In other words, I want to remove 〒 and -.
I want to copy the extracted data, save it on the clipboard and paste it in another place.
Thank you.
(chrome 70.0.3538.102, Win10_x64)
Posting as a separate Solution, as the Input from the Extract is now "a bit" different and changes the Syntax in 'EVAL()' quite a bit, even if I tried to reuse a bit the same Syntax with the same Commands like in Answer_#1. (And that gives a 2nd Code Example...)
SET !EXTRACT "〒 000-0000"
SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.substr(2); y=x.split('-'); z=y[0]+y[1]; z;")
SET !CLIPBOARD {{!VAR1}}
PROMPT EXTRACT:<SP>_{{!EXTRACT}}_<BR>Numbers:<SP>_{{!VAR1}}_
(Tested on iMacros for FF v8.8.2, Pale Moon v26.3.3 (=FF47), Win10_x64.)
And again, there would be more than 10 different ways to implement the same Functionality to get the same Result...
"Nice" to select the 'Chrome' + 'Firefox' Forum Tags but more useful would be if you had mentioned your FCI for both Browsers..., but the following Implementation for example should work in both Browsers for all iMacros Versions:
SET !EXTRACT "〒000 - 0000"
SET !VAR1 EVAL("var s='{{!EXTRACT}}'; var x,y,z; x=s.substr(1); y=x.split(' '); z=y[0]+y[2]; z;")
SET !CLIPBOARD {{!VAR1}}
PROMPT EXTRACT:<SP>_{{!EXTRACT}}_<BR>Numbers:<SP>_{{!VAR1}}_
(Tested on iMacros for FF v8.8.2, Pale Moon v26.3.3 (=FF47), Win10_x64.)
"for example" => as you could implement the Functionality that you want in more than 10 ways using all kinds of different Combinations with other JS String Methods...
(I didn't include the Content of '{{!CLIPBOARD}}' in the 'PROMPT' as this is not supported on CR, but a 'Paste' from your OS Clipboard in 'Notepad' for example should still work...)

Sublime text 2 how to delete comments only

In my sass code, I have inline comments and I wish to remove these in sublime text. Is it possible to permanently delete all comment content alone?
#function emCalc($values) {
$emValues: '';
$max: length($values); //Get the total number of parameters passed
#for $i from 1 through $max {
$value: (nth($values, $i)); //Take the individual parameter
$value: $value / ($value * 0 + 1); //Doing this gets you one unit (1px)
$value: $value / $em-base * 1em; //Divide the px value by emBase and return the value as em
$emValues: #{$emValues + $value}; //Append to array
#if $i < $max {
$emValues: #{$emValues + " "}; //Adding space between parameters (except last), if there are multiple parameters
}
}
#return $emValues; //Call emCalc like so emCalc(10, 20, 30, 40) it should return margin: 0.625em 1.25em 1.875em 2.5em
}
You'll need to double check this (have a backup handy!), but the following regular expression should work in the "replace" window, with regular expressions enabled (the * icon):
Open the "replace" window (ctrl + h / cmd + option + f)
Enable regular expression matching by making sure the * icon is selected
Enter the following in the "Find What?" box
\/\/.*
Leave the "replace with" box empty to delete found text.
Click "Replace All"
Edit
as #ollie noted, this also will delete any urls prefixed with //. The following (lightly tested) regex should serve to better target comments: (^\/\/.*)|(\s+\/\/.*)
Edit v2
A solution for single and multi-line comments (^\/\/.*)|(\s+\/\/.*)|((\/\*)(.|\n)+?(\*\/))
If you have no other possibility, you could select every // (Select first // then CtrlD while there's comments left if my memory is correct).
Then press ShiftEnd to select every end of line with a // and Del ! :)
(There's probably a plugin for that, but this is the simplest method I think. This suggest that all your // refers to the beginning of a comment, of course)
None of the answers here seem to take advantage of the fact that the syntax highlighting has already determined where all the comments are - just execute this in the Python console (View menu -> Show Console) to select all comments:
view.sel().clear(); view.sel().add_all(view.find_by_selector('comment'))
(press Enter after typing/pasting it to execute it)
then press Delete to delete all the selections and Esc to go back to single selection mode
None of the other answers cover all cases (multi-line comments, single line comments, double-slash comments and slash-star/star-slash comments).
In order to match all possible cases (without matching URLs), use the following:
(^[\s]*?\/\/.*)|(/\*[\s\S]+?\*/)
Here is what I do in ST3 in HTML to strip all comments, especially nasty comments embedded within <p> body text, for example ...
package control install SelectUntil
quit and restart sublime
ctrl+f <!--
alt+enter to select all instances of <!--
ctrl+shift+s will pull up an input field, where
you can type: -->
hit delete!
Well well, there is an easy way to do it in mac Sublime Text if you are sure there are no // in print statements.
search for // and hit that cmd+ctrl+G and then to select the whole line which has hit cmd+shift+Arrow and delete it. Assuming you have used only single line comments

Shortcut to paste multiple lines - Sublime Text 2

I am using Windows 8 OS
I have some projects where I repeatedly add the same tags to different types of elements, but the format of how the elements are presented through code always stays the same. I'm looking for shortcuts that will help me do these tasks quickly. Is there a shortcut that lets you add the same tag for multiple lines that you specify? I know you can do (CTR + F3) To select clone tags and change all of them, but I want to add tags to elements that previously had no tag. Is there a way you can make your own shortcuts for your tags, like if I type in "li" It will automatically put in "" and all I have to do is hit enter?
Here is an example of the elements and tags I added:
<ul>
<li type="square">Extra Grip
<li type="square">Made of Titanium
<li type="square">Built in Selsoft Processor
<li type="square">Portable</ul>
<b>MBS:</b> 44 kN (10000 lbf)<br>
<b>Weight:</b> 1 lbs 13.2 oz (828 g)<br>
<b>Length:</b> 14.40" (36.6 cm)<br>
<b>Width:</b> 3.75" (9.5 cm)<br>
<b>Height:</b> 1.00" (2.5 cm)<br>
<b>Material:</b> Titanium
Ctrl+C, Ctrl+X and Ctrl+V let you copy/cut/paste lines if you don't select anything. So, Ctrl+X doesn't "delete" a line, it cuts it. To delete a line, the default shortcut is Ctrl+Shift+K :)
Highlighting a bunch of lines then hitting Cmd (Ctrl?) +Shift+L gives you multi-cursors on each line. I do that, followed by Cmd + Right arrow (End?) to get easily get a cursor at the end of a series of lines to simultaneously type something after each.
Ctrl+Shift+J expands the selection to the indentation level of the current line. So if you want to select a block of code with the same indentation it's really useful.
Alt + F3 select all occurrences of current word for multiple editing. Very useful.
A few written about in more detail: http://whiletruecode.com/post/7-handy-text-manipulation-tricks-sublime-text-2
Have you tried to make your own snippets? It may not be exactly what you are asking for, but could be another way to do it.
Try the New Snippet command in the Tools-menu and add the following and save it:
<snippet>
<content><![CDATA[
<li type="square">${1:Item} ${2:}
]]></content>
<tabTrigger>li</tabTrigger>
</snippet>
This will enter an <li>-tag in the current file if you type li and then press Tab.
You can also add a <scope> tag to limit it to HTML-files.

Why doesn't the cursor stay at the same place?

I have a very strange problem which I can't resolve after trying the whole morning.
This is my function and mapping:
nnoremap ,zz :call SwapAW("2-2","5")<CR>
nnoremap ,zc :call SwapAW("2-2","5")<CR>
function! SwapAW(keyw,number)
let li = line('.')
let co = col('.')
exe "call cursor(li,co)"
let linew= line('.')
let conew= col('.')
echo linew conew
endfunction
,zc --> moves the cursor to the right
,zz --> the cursor stays where it is
I changed everything but can't find out why the cursor doesn't stay where it is in both cases.
I changed p.e. the mapping, from ,zc to ,zd and ,zz to ,zw (tried others as well) and changed the leaderkey from , to \, and tried to swap both mapping lines.
Nothing changes.
What's happening?
What did I wrong?
Thanks in advance.
You have a trailing <Space> character in your ,zc mapping (after the <CR>). That moves the cursor after the function invocation.
With mappings, one must be careful with hidden characters. Therefore, it's advisable (and sometimes, e.g. at the beginning of a mapping, necessary) to literally write the special form <Space> when you actually need to include one.
My ShowTrailingWhitespace plugin will highlight those trailing spaces and tabs, as many code guidelines frown on them. The plugin page also contains links to alternatives.

Deleting entire function definition in Vim

I've been trying Vim for any text editing work for almost a week now. I want to know the fastest way to select a C function definition.
For example, if I have a function like this:
void helloworlds( int num )
{
int n;
for ( n = 0; n < num; ++n ) {
printf( "Hello World!\n" );
}
}
How would I be able to delete the whole definition including the function name?
As is common in Vim, there are a bunch of ways!
Note that the first two solutions depend on an absence of blank lines.
If your cursor is on the line with the function name, try d}. It will delete everything to the next block (i.e. your function body).
Within the function body itself, dap will delete the 'paragraph'.
You can delete a curly brace block with da}. (If you like this syntax, I recommend Tim Pope's fantastic surround.vim, which adds more features with a similar feel).
You could also try using regular expressions to delete until the next far left-indented closing curly brace: d/^}Enter
]] and [[ move to the next/previous first-column curly brace (equivalent to using / and ? with that regex I mentioned above. Combine with the d motion, and you acheive the same effect. In addons like Python-mode, these operators are redefined to mean exactly what you're looking for: move from function to function.
How to delete the whole block, header included
If you're on the header/name, or the line before the block, da} should do the trick.
If you're below a block, you can also make use of the handy 'offset' feature of a Vim search. d?^{?-1 will delete backwards to one line before the first occurrence of a first-column opening curly brace. This command's a bit tricky to type. Maybe you could make a <leader> shortcut out of it.
Plugins
I don't do much C programming in Vim, but there are surely plugins to help with such a thing. Try Vim Scripts or their mirror at GitHub.
To delete an entire function, including its definition, such as:
function tick() {
// ...
}
Move to the line with the function name.
Move the cursor to the opening brace, f{ should do it, or simply $.
Press V%d (Visual line, move to matching pair, delete)
If your functions look like this:
function tick()
{
// ...
}
Move to the line with the function name.
Press J (join the current line with line bellow. This also puts your cursor at the last character on the resulting line, {, just the one we need for the next command.)
Press V%d (Visual line, move to matching pair, delete.)
or
Move to the line with the function name.
Press V[Down]%d (Visual line, move one line down, move to matching pair, delete.)
If you are willing to install plugins vim-textobj-function will give you vif for Visual select Inside Function and vaf for Visual select A Function.
daf will delete the function, both the line with the signature and the function body ({})
The text object defined by this plugin are more specific and they don't rely on the function body being a contiguous block of text or { being placed at the first character on the line.
The drawback is that you depend on an external plugin.
You can use this shortcut to delete not only the function, also the lines between curly braces, i.e the code between if-else statements,while,for loops ,etc.
Press Shitf + v [Will get you in visual Mode] at the curly brace start/end.
Then Press ] + } i.e ] + Shitf ] - If you are in start brace.
Then Press [ + { i.e [ + Shitf [ - If you are in end brace.
Then DEL to delete the lines selected.
The simplest and most direct way way is as follows (works anywhere inside function):
v enter visual mode
{ move to first brace in function (may have to press more than once)
o exchange cursor from top to bottom of selection
} extend selection to bottom of function
d delete selected text
The complete command sequence would be v{o}d. Note that you can do other operations besides delete the same way. For example, to copy the function, use y (yank) instead of d.
Use this simple way
1.Go to the function definition
2.dd - delete function definition
3.d -start delete operation
4.shift+5(%) - delete the lines between { to }
If your function were separated by the blank lines, just type:
dip
which means "delete inner paragraph".
Another way is to go to the line of the start of your function and hit: Vj% (or V%% if your style puts the opening brace on the same line). This puts you into Visual-Line mode and the percent takes you to the matching closing brace. In the second style, the first % takes you to the opening brace on the line that you selected and the second to its matching closing brace.
Also works for parentheses, brackets, C-style multi-line comments and preprocessor directives.
See the manual for more info.
Pre-condition: be somewhere inside the function.
Go to the previous closing curly bracket on the first line using
[]
Then delete down to the next closing curly bracket on the first line using
d][
Most posted methods have a downside or two. Usually, when working withing a class definition of some object oriented language, you might not have an empty line after the function body, because many code formatters put the closing braces of last method and class on consecutive lines. Also, you might have annotations on top of the function. To make matters worse, there might be empty lines within your function body. Additionally you'd prefer a method that works with the cursor anywhere within the function, because having to move it to a specific line or worse, character, takes valuable time. Imagine something like
public class Test {
/* ... */
#Test
public void testStuff() {
// given
doSetup();
// when
doSomething();
// then
assertSomething();
}
}
In this scenario, vap won't do you any good, since it stops at the first empty line within your function. v{o} is out for the same reason. va{V is better but doesn't catch the annotation on top of the method. So what I would do in the most general case is va{o{. va{ selects the whole function body (caveat: if your cursor is within a nested block, for instance an inner if statement, then you'll only get that block), o puts the cursor to the beginning of the selection and { selects the whole paragraph prepending your selection. This means you'll get the function definition, all annotations and doc comments.
the most easy way I found is:
Get to the line where the function starts and do this: ^^vf{% to mark the entire function and then whatever you like.
^^ - start of the line
v - start visual mode
f - jump to the next search character
{ - this is the search character
% - jump to the closing brackets
This is also very logical after you have used it a few times.
non-visual way:
d/^}/e
... delete by searching for } at line beining, including it for deletion.
without /e (not mentioned in above answers), solution is incomplete.
with /e - searching goes to end of match, so closing bracket is included, and command is well for yanking too:
y/^}/e
if you use neovim version :>0.5
the modern way is to use treesitter and build your model, then you can be selected or yanked or deleted...
Tree-sitter is a parser generator tool and an incremental parsing library. It can build a concrete syntax tree for a source file and efficiently update the syntax tree as the source file is edited
I suggested this video on youtube to learn how to use treesitter to build your model : Let's create a Neovim plugin using Treesitter and Lua
I tried all the top answers here, but none of them works except the one by Nick which suggests to press f{ to get to the opening curly brace. Then V%d to delete the whole function.
Note that, the whole function gets yanked, so you can paste it elsewhere. I come across this use-case frequently, especially when moving if blocks inside another.
I use this map. It work for me
"delete function definition
"only support function body surround by {}
nnoremap <LEADER>df {v/{<cr>%d