I was editing my .vimrc, and I set encoding and fileencoding to utf-16 out of curiosity. I saved and quit the file, and now my .vimrc looks like this.
How can I restore my .vimrc to default encoding and get back my VIM settings? I'm on macOS 12.4.
^#"^# ^#V^#I^#M^#-^#P^#L^#U^#G^#
^#c^#a^#l^#l^# ^#p^#l^#u^#g^##^#b^#e^#g^#i^#n^#(^#'^#~^#/^#.^#v^#i^#m^#/^#p^#l^#u^#g^#g^#e^#d^#'^#)^#
^# ^# ^# ^# ^#P^#l^#u^#g^# ^#'^#j^#u^#n^#e^#g^#u^#n^#n^#/^#f^#z^#f^#'^#,^# ^#{^# ^#'^#d^#o^#'^#:^# ^#{^# ^#-^#>^# ^#f^#z^#f^##^#i^#n^#s^#t^#a^#l^#l^#(^#)^# ^#}^# ^#}^#
^# ^# ^# ^# ^#P^#l^#u^#g^# ^#'^#j^#u^#n^#e^#g^#u^#n^#n^#/^#f^#z^#f^#.^#v^#i^#m^#'^#
^# ^# ^# ^# ^#P^#l^#u^#g^# ^#'^#v^#i^#m^#-^#a^#i^#r^#l^#i^#n^#e^#/^#v^#i^#m^#-^#a^#i^#r^#l^#i^#n^#e^#'^#
^# ^# ^# ^# ^#P^#l^#u^#g^# ^#'^#v^#i^#m^#-^#a^#i^#r^#l^#i^#n^#e^#/^#v^#i^#m^#-^#a^#i^#r^#l^#i^#n^#e^#-^#t^#h^#e^#m^#e^#s^#'^#
^#c^#a^#l^#l^# ^#p^#l^#u^#g^##^#e^#n^#d^#(^#)^#
^#
^#s^#y^#n^#t^#a^#x^# ^#o^#n^#
^#s^#e^#t^# ^#t^#e^#r^#m^#g^#u^#i^#c^#o^#l^#o^#r^#s^#
^#s^#e^#t^# ^#b^#a^#c^#k^#g^#r^#o^#u^#n^#d^#=^#d^#a^#r^#k^#
^#c^#o^#l^#o^#r^#s^#c^#h^#e^#m^#e^# ^#b^#r^#o^#g^#r^#a^#m^#m^#e^#r^#
^#l^#e^#t^# ^#g^#:^#a^#i^#r^#l^#i^#n^#e^#_^#t^#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=utf-16
:set fileencoding=ascii " or utf-8
:x " save and exit
Verify:
vim ~/.vimrc # or any other fie
(open any file using fixed ~/.vimrc as the config file).
Related
I have a vimscript function shown below that performs a search and replace on the currently yanked/copied text buffer and pastes them into a file.
function Repaste(s, ...)
for i in a:000
let sub = substitute(getreg('"'), a:s, i, 'ge')
let sane = substitute(sub, '[^[:print:]]', '\n', 'ge')
call append(line('.'), sane)
endfor
endfunction
command -nargs=* RP call Repaste(<f-args>)
When I call this function I get ^# characters in place of new lines.
Here is an example of the yanked/copied text
set cindent
Here is an example of the command executed
:RP c d e f
Here is the output
set findent ^#
set eindent ^#
set dindent ^#
How do i remove these characters and why do they appear? Thanks.
The append() function is a low-level one. :help append() shows that the {expr} as a String type is inserted as one text line, regardless of newlines in its content. The ^# is the representation of \n inside a line; cp :help <Nul>.
If you really want to keep using append(), you have to provide a List type; to obtain this, you can split() your String:
call append(line('.'), split(sane, '\n'))
However, I think you're better off by using a higher-level function to insert the created lines, using :put with the expression register to insert the contents of your variable:
put =sane
This will:
automatically handle embedded newlines
set the change marks '[ and '] to the inserted text
print a message 4 more lines (if the inserted number exceeds the 'report' threshold).
Replacing the call to append with put=sub produces the required result.
I have a file
aaaaa0
bbbbb1
ccccc2
ddddd3
eeeee4
fffff5
ggggg6
How do I delete the last char in the first three line?
And the file will be
aaaaa
bbbbb
ccccc
ddddd3
eeeee4
fffff5
ggggg6
With a substitution:
:1,3s/.$
With a macro:
:1,3norm $x
See :help range, :help :s, :help :norm, :help $, :help x.
I need to convert utf-8 between cp936 in vim, I would like to map F3 to do this job, What should I write in ./_vimrc
like this:
map <F3>
If fenc == uft-8
set fenc = cp936
else fenc == cp936
set fenc = utf-8
I really need your help!
Add the line to ~/.vimrc :
map <F3> :if &fileencoding =~# 'utf-8'<CR>set fenc=cp936<CR>else<CR>set fenc=utf-8<CR>endif<CR><CR>
In other words, just as you can use :s/x/y/g and :s|x|y|g and :s#x#y#g so too, can you use :v\0x\0y\0norm 0?
No you can't, because the ASCII NUL works as delimiter in the C code base of Vim and so it will truncate the entered string.
The text under :help E146 describes the possible delimiters:
Instead of the '/' which surrounds the pattern and replacement string, you
can use any other single-byte character, but not an alphanumeric character,
'\', '"' or '|'.
Note that <Nul> (shown as ^# = CTRL-#) is internally represented as a linefeed (ASCII 10) (see :help <nul>), but you can enter it in the command line via Ctrl + V, 0 0 0 or Ctrl + V, Ctrl + #.
Therefore, though you can type a substitution with <nul> separator chars, Vim will internally represent this with linefeed ^J = <NL> characters.
% sub ^#will^#MY_new_TexT^#gc works
I have this function in my vimrc to jump to the first nonblank character on the line:
function! SmartHome()
let s:col = col(".")
normal! ^
if s:col == col(".")
normal! 0
endif
endfunction
This works well outside of a tmux session.
But inside of a tmux session it will just jump to the first character on the line - which is wrong!
I have mapped this function this way:
" smart home function
nnoremap <silent> <Home> :call SmartHome()<CR>
inoremap <silent> <Home> <C-O>:call SmartHome()<CR>
How can I solve this?
I could solve this problem by removing the following line from my .bashrc file
export TERM=xterm-256color
This works since xterm and the screen "like" protocol from tmux does not send/expect the same values for the HOME key:
$ tput -T screen khome | xxd
0000000: 1b5b 317e .[1~
$ tput -T xterm khome | xxd
0000000: 1b4f 48 .OH