0

I coding a simple code in vim

#include<stdio.h>

int main(){
    int n;
    scanf("%d", &n);
    printf("%d\n", n);
    return 0;
}

and copy the same phase to the web.

and I copy again the same phase to dev c++ editor from the web.

enter image description here

Look! error stray '\240'!!

please look below I copy the same phase to here(stackoverflow.com)

#include<stdio.h>

int main() {
????int n;
????scanf("%d", &n);
????printf("%d\n", n);
????return 0;
}

I figure out character '?' is add up. I can not see character '?' in dev c++ editor. However, It is very difficultly to delete because I cannot see '?' in dev c++ edtor.

I have to copy phase some code to web. and somebody have to copy phase the same code to dev c++. I guess the someone will compile and will error stray '\240'.

I like to use vim. can some know how not to add '?'('?' is '\240') up using vim?

alexparkjw
  • 113
  • 1
  • 6
  • How are you copying it out of vim? Using your os copy copy or are you placing it on the system pasteboard from inside vim – Doon Oct 01 '16 at 11:20
  • @Doon, it's kind of homework. my code in mac -> copy phase -> "web page". and someone copy the phase on "web page" to someone's windows computer(dev c++). – alexparkjw Oct 01 '16 at 11:27
  • updated my answer to remove the windowisms and replace them with MacOS keys ... – Doon Oct 01 '16 at 11:34

1 Answers1

1

If you would like to copy to the primary system clipboard you can yank into *. Then you should be able to paste it using the normal cmd-v into websites, or other text fields. If you are just selecting all the txt and hitting cmd-c to copy it, it appears that you are getting the control chars as well the text. I have the following in my vimrc to make cutting and pasting between vim and the system clipboard way easier.

" Yank text to the OS X clipboard
noremap <leader>y "*y
noremap <leader>d "*d
noremap <leader>p :set paste<CR>:put  *<CR>:set nopaste<CR>

so this way I can select what I want, and hit leader y and then paste it wherever it needs to go, and not have to worry about touching the rodent (mouse). The Leader p is handy so that vim doesn't reformat your text on paste (Which happens a lot with code and cmd-v).

Doon
  • 19,719
  • 3
  • 40
  • 44
  • "*y will yank to * which is the system clipboard on OS X. So you can then use cmd-v to paste into something that isn't vim. And it won't grab any control chars. Especially if you are running vim in a terminal. – Doon Oct 01 '16 at 12:17
  • What part isn't working.? The yanking to the system clipboard or are you still getting control chars? – Doon Oct 01 '16 at 13:53
  • the yanking to the system clipboard. – alexparkjw Oct 01 '16 at 19:16
  • And you are selecting your text, then hitting "*y to put it on the system clipboard. Odd. What version of vim are you using ? It is possible that it has been compiled without access to the system clipboard. – Doon Oct 01 '16 at 20:28
  • version 7.4, not working yy, y1y, y2y, ...what does it mean "*y – alexparkjw Oct 02 '16 at 02:46
  • Select what you want to copy, then hit the keys " then * then y in that order. Hence the reason I map them to leader y (my leader is space) so I can select and hit space y and it copies. – Doon Oct 02 '16 at 12:27
  • how well do you know vi? . a quite simple hack would be to just cat the file, and then cut and paste the part that you want, using normal os keys. – Doon Oct 02 '16 at 16:02
  • see http://stackoverflow.com/questions/1497958/how-do-i-use-vim-registers for more info on registers, on osx `*` and `+` are the same. – Doon Oct 02 '16 at 16:10
  • `yy`, yanks to the unnamed register. `"*yy` will yank the * register which is the system clipboard. Read the link about registers I think i will help? – Doon Oct 02 '16 at 21:55
  • it's not about what yank or not yank, it's about copy-phase(cmd+v). what I yank is not what i copy-phase. – alexparkjw Oct 03 '16 at 15:49
  • Because you need to yank it to a specific register. If you yank to the * or + register that puts it on the system clipboard and makes it available to be pasted. – Doon Oct 04 '16 at 00:19