vim: ft=c: in initial comment does not trigger C-Mode - c

Using the sequence "vim: command ...:" inside the first line of a file usually triggers vim to execute the given command. However, my files contain
/* vim: set ft=c: */
and VIM is not setup in C-mode. How could I fix this?

Related

Can I skip one line and stop?

In gdb I have this define in order to skip one line
define skip
tbreak +1
jump +1
end
Can one do the same with lldb?
lldb doesn't have a define. One option is creating an lldb script with the commands you want. From there, you can define an alias named skip that runs the commands.
For example, here's the contents of a file named ~/scripts/lldb/skip:
tbreak +1
jump +1
To run this script, do:
command source ~/scripts/lldb/skip
To make this more convenient, you can create an alias in your ~/.lldbinit:
command alias skip command source ~/scripts/lldb/skip

My batch script is reporting an error stating "was unexpected at this time"

The Windows batch file I am trying to run contains the following assignment:
set ANT_HOME="C:/Program Files/apache-ant-1.8.4"
The offending line is:
call %ANT_HOME%/bin/ant -f ../config/common.xml start_db
And when I run the script with echo on I get:
call "C:/Program_Files/apache-ant-1.8.4"/bin/ant -f ../config/common.xml start_db
Files/apache-ant-1.8.4""=="" was unexpected at this time.
I've moved the second quote to to the end of the path, after the ant, but I receive the same error message.
If ant were an .exe I would say your code should work. But I suspect that ant is a batch file, and the error is occurring within the ant script.
I base my conclusion on your error message - specifically the following portion of it: ""=="". The error message is a batch parsing error, and I don't see how your code could generate those characters. So I figure ant must be a batch script that is causing the problem.
I suspect ant.bat has #echo off at the top, so you are not seeing the actual line that is failing.
Not having access to the ant.bat script, I couldn't possibly diagnose exactly what is failing, nor can I guess on how to fix it.
Update - exact problem found
I found a copy of ant.bat online.
It has the following line of code within:
if "%ANT_HOME%"=="" set ANT_HOME=%DEFAULT_ANT_HOME%
Your definition of ANT_HOME includes enclosing quotes, so the code is trying to execute
if ""C:/Program Files/apache-ant-1.8.4""=="" set ANT_HOME=%DEFAULT_ANT_HOME%
The space is not quoted, and you have your error.
All you need to do to fix everything is to remove the quotes from the definition of ANT_HOME, and then add quotes to your CALL statement:
set "ANT_HOME=C:/Program Files/apache-ant-1.8.4"
call "%ANT_HOME%/bin/ant" -f ../config/common.xml start_db
Forward-slashes are not always reliable as folder delimiters within Windows. See Why does the cmd.exe shell on Windows fail with paths using a forward-slash ('/'') path separator?.
Better to use back-slashes.
set "ANT_HOME=C:\Program Files\apache-ant-1.8.4"
call "%ANT_HOME%\bin\ant" -f ..\config\common.xml start_db
The quotes have to completely surround a file name. You can't use them for partial names. Try this instead:
set ANT_HOME=C:\Program Files\apache-ant-1.8.4
call "%ANT_HOME%\bin\ant" -f ../config/common.xml start_db
Oh, and I changed some of your slashes to backslashes (DOS doesn't like forward slashes). I assume you are allowed to use / in that parameter you are passing though.

.bat to .sh converting for SQL*Loader Start on UNIX PC

I have a simple .bat file
#echo; set nls_lang=russian_cis.ru8pc866
#echo off
SET NLS_NUMERIC_CHARACTERS=. '
sqlldr.exe userid=PRB/0611#TSESTDB control=control_file.ctl LOG=fdb_log.log errors=100
cmd
and i need to convert to .sh file for running on the UNIX based pc.
I began to read "BASH Programming - Introduction HOW-TO" (is it suitable for beginners?), but it is a episodical task and dead line comes.
Could anybody help me to convert file? Thanks a lot!!!
rewriting your script.
#!/bin/bash
# #echo;
# set nls_lang=russian_cis.ru8pc866
export NLS_LANG=russian_cis.ru8pc866
# not needed #echo off
# SET NLS_NUMERIC_CHARACTERS=. '
export NLS_NUMERIC_CHARACTERS='.'
PATH="/path/to/sqlDir/install:${PATH}"
# sqlldr.exe userid=PRB/0611#TSESTDB control=control_file.ctl LOG=fdb_log.log errors=100
sqlldr userid=PRB/0611#TSESTDB control=control_file.ctl LOG=fdb_log.log errors=100
# ? cmd
I've left your code in, but commented out (using the shell comment char '#'). The uncommented lines are the 'translation' of .bat syntax into Linux/Unix bash/shell syntax.
There some things above that you may need to fix:
You'll have to include the correct value in the resetting of PATH,
note that the value there is strictly to illustrate the issue.
export is used so that variables set in the current shell (the
shell script) are visible to child processes that run from the shell
script, in this case the important one being sqlldr
I'm not sure what values you really need assigned to
NLS_NUMERIC_CHARACTERS. Note that by quoting with the single-quote
char ' available to the shell, you should get exactly the value
used that you intended. If '*' or other reg-exp chars are used, this
may cause problems.
You may find that sqlldr.exe has a different name altogether. The
linux/unix convention for executable commands does not require the
.exe extension, so I have used sqlldr. Just use the full name of
the program you find in the installed directory.
The line with #!/bin/bash needs to be the first line in the file, with no leading spaces.
You'll also need to inform your OS that the script is intended to be executable. From a bash cmd line, IN the directory that contains this script, do
chmod 755 mySQLLDR_runningScript
Finally, not sure why you have cmd at the end of your .bat file, to open a new window? You'll need to experiment on your system to find the correct cmd to do that. Maybe xterm.
I hope this helps.

How to list the file paths of all buffers open in Vim?

Is there a way to list all open buffers in Vim? I’d like to view the full file path to every open buffer and save the list to an external file, or yank it for pasting into another text document.
Solution
This was a very hard contest! All three of the suggestions below worked well. I went with Luc Hermitte’s and added this to my .vimrc file:
noremap <silent> <leader>so :call writefile( map(filter(range(0,bufnr('$')), 'buflisted(v:val)'), 'fnamemodify(bufname(v:val), ":p")'), 'open_buffers.txt' )<CR>
So now typing ,so will save all the full path of all open buffers to the current directory in the open_buffers.txt file.
I'd have use the "simple":
echo map(filter(range(0,bufnr('$')), 'buflisted(v:val)'), 'fnamemodify(bufname(v:val), ":p")')
With:
range(0,bufnr('$')) to have a |List| of all possible buffer numbers
filter(possible_buffers, 'buflisted(v:val)') to restrict the list to the buffers that are actually listed -- you may prefer bufexist() that'll also show the help buffers, etc.
map(listed_buffer, 'nr_to_fullpath(v:val)') to transform all the buffer numbers into full pathnames
bufname() to transform a single buffer number into a (simplified) pathname
fnamemodify(pathname, ':p') to have a full absolute pathname from a relative pathname.
Change :echo to call writefile(pathname_list, 'filename'), and that's all, or to :put=, etc.
To list the absolute path for a buffer you can use:
:!echo %:p
If you wrap that into a recording you will get what you need, e.g.:
qq
:!echo %:p >> my_buffers
:bnext
q
Now execute the macro number of times as you have buffers, e.g.:
10#q
and you will have the result in the file my_buffers
Probably a better way though :-)
This should work:
:redi #"|ls|redi END
:new +pu
:%s/[^"]*"\([^"]*\)".*/\=fnamemodify(submatch(1), ":p")/e
:g/^$/d
Explanation:
:redi will redirect the messages
:redi #" will redirect the message to #" aka the unnamed register
:redi END stops redirection
:ls will print out all non-hidden buffers
:new create a buffer in a split
:new +{cmd} the +cmd will execute a command for the new buffer.
:new +pu execute the :pu or put command on the new buffer
regex basically matches the entire line and captures the content between the quotes
\= in the replacement part of :s/ will execute an expression
fnamemodify(submatch(1), ":p") will expand the captured data aka submatch(1)
:g/^$/d delete all blank lines
More information:
:h /\=
:h :g
:h :new
:h :pu
:h :redi
:h :ls
:h fnamemodify()
:h :d
The bufexplorer script shows the path of all open buffers, however it also shows other information so it is not ideal for yanking and pasting into another document. Here's a screenshot

Stupid Batch File Behavior. Tries to execute comments

I have tried prefixing lines with semicolons, 'REM', etc.. but no matter what when I run my batch file I keep getting "unknown command REM whatever"
"REM test" It is not recognized, and it is windows vista. I simply get "rem" output back to my console.
That's entirely normal behavior. Batch files are simply sequences of commands that are run one after another. So every line will get output to the console as if it were typed there.
H:\>echo rem test > test.cmd
H:\>test
yields the output
H:\>rem test
as if I typed rem test directly to the console.
You can suppress this by either prefixing the line with #:
#rem test
or by including echo off in the batch file:
#echo off
rem test
If I put ":: test" and execute it I get back "Test".
Can't reproduce here.
If I put "; test" it recursively executes itself
A semicolon at the start of the line seemingly gets ignored.
If you're talking about cmd.exe batch files under Windows, you can use:
rem this method or
:: this method.
For bash and a lot of other UNIX-type shells, you use:
# this method.
I'm pretty certain you're not using cmd.exe since that would give you an error like:
'rem' is not recognized as an internal or external command,
operable program or batch file.
rather then:
Unknown command ...
If you are using a UNIX-type shell, the # character is almost certainly what you're after. If you let us know exactly the shell you're using, we can probably help out further.
you probably created an UNICODE file. These files contain 2 bytes header named BOM
which is not shown by any editor but cmd attempts to execute them and fails.
To make sure this is indeed an issue: type any other command at the very beginning
of your file and see it throws the same error - for example #echo test
To fix it, just create a new plain text file and copy content of the original file there.
then remove the original file and replace it by the newly created one.
In my case the problems are line endings. Somehow Maven or the Jenkins pipeline running on a Linux machine changed the line endings from Windows style (CR LF) to Unix style (LF). Changing them back solves the issue for me.

Resources